第一個CV程序,對圖片做徑向梯度變換。 紀念下~
1
// HelloOpencv.cpp : 定義控制臺應用程序的入口點。
2
3
#include "stdafx.h"
4
#include"cxcore.h"
5
#include "highgui.h"
6
#include<math.h>
7
using namespace cv;
8
using namespace std;
9
10
int _tmain(int argc, _TCHAR* argv[])
11

{
12
CvPoint center;
13
double scale = -3;
14
IplImage* image = (argc == 2 )? cvLoadImage(argv[1]) : 0;
15
if( ! image ) return -1;
16
center = cvPoint( image->width/2 , image->height/2 );
17
for( int i = 0; i<image->height; i++ )
18
for( int j = 0; j<image->width; j++ )
{
19
double dx = ( double )( j-center.x )/center.x;
20
double dy = ( double )( i-center.y )/center.y;
21
double wight = exp( (dx*dx+dy*dy)*scale );
22
uchar* ptr = &CV_IMAGE_ELEM( image, uchar, i, j*3 );
23
ptr[0] = cvRound(ptr[0]*wight);
24
ptr[1] = cvRound(ptr[1]*wight);
25
ptr[2] = cvRound(ptr[2]*wight);
26
}
27
cvSaveImage("new.png",image);
28
cvNamedWindow("_飛寒の TEST",1);
29
cvShowImage("_飛寒の TEST",image);
30
cvWaitKey();
31
return 0;
32
}
33
34

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

效果如下:
