-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathex15.cpp
More file actions
47 lines (42 loc) · 930 Bytes
/
Copy pathex15.cpp
File metadata and controls
47 lines (42 loc) · 930 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#include <opencv2/opencv.hpp>
int main()
{
IplImage* src = cvLoadImage("C:\\temp\\Lena.png");
CvSize size = cvGetSize(src);
IplImage* dst = cvCreateImage(size, 8, 3);
int w = size.width;
int h = size.height;
int blocksize = 30;
for (int y = 0; y < h-blocksize; y+=blocksize)
{
printf("%d\n", y);
for (int x = 0; x < w-blocksize; x+=blocksize)
{
float sum[3] = { 0 };
for (int i = 0; i < blocksize; i++)
{
for (int j = 0; j < blocksize; j++)
{
CvScalar f = cvGet2D(src, y+i,x+ j);
for (int k = 0; k < 3; k++)
{
sum[k] += f.val[k];
}
}
}
for (int k = 0; k < 3; k++)
sum[k] /= blocksize * blocksize;
for (int i = 0; i < blocksize; i++)
{
for (int j = 0; j < blocksize; j++)
{
cvSet2D(dst, y + i, x + j, cvScalar(sum[0], sum[1], sum[2]));
}
}
}
}
cvShowImage("src", src);
cvShowImage("dst", dst);
cvWaitKey();
return 0;
}