-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathex19.cpp
More file actions
44 lines (38 loc) · 814 Bytes
/
Copy pathex19.cpp
File metadata and controls
44 lines (38 loc) · 814 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
#include <opencv2/opencv.hpp>
CvScalar conDown(CvScalar f)
{
f.val[0] *= 0.5;
f.val[1] *= 0.5;
f.val[2] *= 0.5;
return f;
}
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;
for (int y = 0; y < h; y++)
{
for (int x = 0; x < w; x++)
{
CvScalar f = cvGet2D(src, y, x);
CvScalar g;
int cx = (float)x / w * 4;
int cy = (float)y / h * 4;
float nx = 2 * ((float)x - cx * w / 4)/w*4.0 - 1;
float ny = 2 * ((float)y - cy * h / 4)/h*4.0 - 1;
float alpha = sqrt((nx * nx) + (ny * ny));
if (alpha > 1)
g = conDown(f);
else
g = f;
cvSet2D(dst, y, x, g);
}
}
cvShowImage("src", src);
cvShowImage("dst", dst);
cvWaitKey();
return 0;
}