zoukankan      html  css  js  c++  java
  • 【练习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 }

    结果图片:

    要言妙道:

      

    借鉴参考:

  • 相关阅读:
    P1197 [JSOI2008]星球大战[并查集+图论]
    P1955 [NOI2015]程序自动分析[离散化+并查集]
    取模运算律[简单数学]
    P1462 通往奥格瑞玛的道路[最短路+二分+堆优化]
    P1330 封锁阳光大学[搜索+染色]
    P1168 中位数[堆 优先队列]
    P2661 信息传递[最小环+边带权并查集]
    P1080 【NOIP 2012】 国王游戏[贪心+高精度]
    P2085 最小函数值[优先队列]
    【转】priority_queue的用法
  • 原文地址:https://www.cnblogs.com/tingshuixuan2012/p/4510762.html
Copyright © 2011-2022 走看看