《学习OpenCV》练习题第三章第五题

 1 #include <highgui.h>

 2 #include <cv.h>

 3 #include <stdio.h>

 4 

 5 #pragma comment (lib,"opencv_calib3d231d.lib")

 6 #pragma comment (lib,"opencv_contrib231d.lib")

 7 #pragma comment (lib,"opencv_core231d.lib")

 8 #pragma comment (lib,"opencv_features2d231d.lib")

 9 #pragma comment (lib,"opencv_flann231d.lib")

10 #pragma comment (lib,"opencv_gpu231d.lib")

11 #pragma comment (lib,"opencv_haartraining_engined.lib")

12 #pragma comment (lib,"opencv_highgui231d.lib")

13 #pragma comment (lib,"opencv_imgproc231d.lib")

14 #pragma comment (lib,"opencv_legacy231d.lib")

15 #pragma comment (lib,"opencv_ml231d.lib")

16 #pragma comment (lib,"opencv_objdetect231d.lib")

17 #pragma comment (lib,"opencv_ts231d.lib")

18 #pragma comment (lib,"opencv_video231d.lib")

19 

20 /*

21  *《学习OpenCV》第三章第五题

22  * 完成时间:2:49 3/2 星期六 2013

23  */

24 

25 // 图像高宽

26 #define IMG_SIZE   420

27 

28 // 边界宽度

29 #define BORDER_WIDTH 10

30 

31 int main()

32 {

33     // 创建8位单通道图像

34     IplImage * image = cvCreateImage(cvSize(IMG_SIZE, IMG_SIZE), 8, 1);

35 

36     // 初始化置零

37     cvZero(image);

38     

39     // 灰度值

40     int value = 0;

41     // ROI区域大小

42     int rect_size = IMG_SIZE;

43     for(int length = IMG_SIZE; length >= 0 && value <= 200; length -= BORDER_WIDTH, value += 10)

44     {

45         cvSetImageROI(image, cvRect(IMG_SIZE - length, IMG_SIZE- length, rect_size, rect_size));

46 

47         rect_size -= 2 *BORDER_WIDTH;

48         cvSet(image, cvScalarAll(value));

49         cvResetImageROI(image);

50     }

51 

52     cvNamedWindow("img", 1);

53     cvShowImage("img", image);

54 

55     cvWaitKey(0);

56     cvReleaseImage(&image);

57     cvDestroyAllWindows();

58 

59     return 0;

60 }

运行结果:

《学习OpenCV》练习题第三章第五题

你可能感兴趣的:(opencv)