【练习8.2】使用指定标志创建序列cvCreateSeq、在序列中插入元素

 

页内索引
题目要求程序代码结果图片要言妙道借鉴参考

 

 

  

题目要求:

 用CvSeq的函数创建一个圆,这个圆用点序列来表示

 

程序代码:

 

 1 // OpenCVExerciseTesting.cpp : 定义控制台应用程序的入口点。
 2 //
 3 //D:\\Work\\Work_Programming\\Source\\Image\\lena.jpg
 4 
 5 
 6 #include "stdafx.h"
 7 #include<string>
 8 #include <cv.h>
 9 #include <highgui.h>
10 #include <iostream>
11 #include<math.h>
12 
13 #include <opencv2/legacy/legacy.hpp>
14 //#pragma comment(lib, "opencv_legacy2411.lib")
15 
16 using namespace cv;
17 using namespace std;
18 
19 //函数声明-->--->-->--->-->--->-->--->//
20 
21 
22 //<--<--<--<--<--<--<--<--<--函数声明//
23 
24 int _tmain(int argc, _TCHAR* argv[])
25 {
26 
27     CvMemStorage *sotrage = cvCreateMemStorage();
28     int flags = CV_SEQ_ELTYPE_POINT | CV_SEQ_FLAG_CLOSED;
29     CvSeq * seq_circle = cvCreateSeq(flags, sizeof(CvSeq), sizeof(CvPoint), sotrage);
30 
31     IplImage * image_circle = cvCreateImage(cvSize(201, 201), IPL_DEPTH_8U, 1);
32     cvZero(image_circle);
33 
34     int center_x = 100;
35     int center_y = 100;
36     int r = 100;
37 
38     int x_temp, y_temp;
39     for (int x = 0; x <= 200; ++x)
40     {
41         for (int y = 0; y <= 200; ++y)
42         {
43             if (x < center_x)
44             {
45                 x_temp = center_x - x;
46             }
47             else
48             {
49                 x_temp = x - center_x;
50             }
51 
52             if (y < center_y)
53             {
54                 y_temp = center_y - y;
55             }
56             else
57             {
58                 y_temp = y - center_y;
59             }
60 
61             if ((pow(x_temp, 2) + pow(y_temp, 2)) == pow(r, 2))
62             {
63                 CvPoint pt;
64                 pt.x = x;
65                 pt.y = y;
66                 cvSeqPush(seq_circle, &pt);
67                 //cvSetReal2D(image_circle, pt.x, pt.y, 255);
68             }
69         }
70     }
71 
72     for (int i = 0; i < seq_circle->total; ++i)
73     {
74         CvPoint * pt = (CvPoint*)cvGetSeqElem(seq_circle, i);
75         cvSetReal2D(image_circle, pt->x, pt->y, 255);
76     }
77 
78     cvNamedWindow("图像", CV_WINDOW_AUTOSIZE);
79     cvShowImage("图像",image_circle);
80 
81     cvWaitKey(0);
82 
83     cvReleaseImage(&image_circle);
84     cvDestroyAllWindows();
85 
86     return 0;
87 }

 

 

结果图片:

 

要言妙道:

  

 

借鉴参考:

 

转载于:https://www.cnblogs.com/tingshuixuan2012/p/4510762.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值