• <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>

            熱轉(zhuǎn)印www.yxheatpress.com

            公司網(wǎng)站模板http://qiyemoban.software8.co/

            常用鏈接

            統(tǒng)計

            友情鏈接

            最新評論

            由點集序列或數(shù)組創(chuàng)建凸邊形

            下面是一個有點集序列或數(shù)組創(chuàng)建凸邊形的簡單示例

            1. #include<cv.h>  
            2. #include<highgui.h>  
            3. #include<stdlib.h>  
            4.   
            5. #define ARRAY 0  
            6.   
            7. int main()  
            8. {  
            9.     IplImage* img = cvCreateImage (cvSize(500, 500), 8, 3);  
            10.     cvNamedWindow ("hull", 1);  
            11.   
            12. #if ! ARRAY  
            13.     CvMemStorage* storage = cvCreateMemStorage (0);  
            14. #endif  
            15.     int i;  
            16.     int contour = rand() % 100 + 1;  
            17.     int hullcontour;  
            18.     CvPoint pt0;  
            19. #if ! ARRAY  
            20.     CvSeq* ptseq = cvCreateSeq (CV_SEQ_KIND_GENERIC | CV_32SC2, sizeof(CvContour), sizeof(CvPoint), storage);  
            21.     CvSeq* hull;  
            22.     for (i = 0; i < contour; i++)  
            23.     {  
            24.         pt0.x = rand() % (img->width / 2) + img->width / 4;  
            25.         pt0.y = rand() % (img->height / 2) + img->height / 4;  
            26.         cvSeqPush (ptseq, &pt0);  
            27.     }  
            28.     hull = cvConvexHull2 (ptseq, 0, CV_CLOCKWISE, 0);  
            29.     /*hull = cvConvexHull2 (ptseq, 0, CV_CLOCKWISE, 1);*/  
            30.     hullcontour = hull->total;  
            31. #else  
            32.     CvPoint* points = (CvPoint*)malloc(contour * sizeof(points[0]));  
            33.     int* hull = (int*)malloc(contour * sizeof(hull[0]));  
            34.     CvMat point_mat = cvMat (1, contour, CV_32SC2, points);  
            35.     CvMat hull_mat = cvMat (1, contour, CV_32SC1, hull);  
            36.     for (i = 0; i < contour; i++)  
            37.     {  
            38.         pt0.x = rand() % (img->width / 2) + img->width / 4;  
            39.         pt0.y = rand() % (img->height / 2) + img->height / 4;  
            40.         points[i] = pt0;  
            41.     }  
            42.     cvConvexHull2 (&point_mat, &hull_mat, CV_CLOCKWISE, 0);  
            43.     hullcontour = hull_mat.cols;  
            44. #endif  
            45.     cvZero (img);  
            46.     for (i = 0; i < contour; i++)  
            47.     {  
            48. #if ! ARRAY  
            49.         pt0 = * CV_GET_SEQ_ELEM(CvPoint, ptseq, i);  
            50.         /*pt0 = ** CV_GET_SEQ_ELEM(CvPoint*, ptseq, i);*/  
            51. #else  
            52.         pt0 = points[i];  
            53. #endif  
            54.         cvCircle (img, pt0, 2, CV_RGB(255, 0, 0), CV_FILLED);  
            55.     }  
            56. #if ! ARRAY  
            57.     pt0 = ** CV_GET_SEQ_ELEM(CvPoint*, hull, hullcontour - 1);  
            58.     /*pt0 = * CV_GET_SEQ_ELEM(CvPoint, hull, hullcontour - 1);*/  
            59. #else  
            60.     pt0 = points[hull[hullcontour - 1]];  
            61. #endif  
            62.   
            63.     for (i = 0; i < hullcontour; i++)  
            64.     {  
            65. #if ! ARRAY  
            66.         CvPoint pt = **CV_GET_SEQ_ELEM(CvPoint*, hull, i);  
            67.         /*CvPoint pt = *CV_GET_SEQ_ELEM(CvPoint, hull, i);*/  
            68. #else  
            69.         CvPoint pt = points[hull[i]];  
            70. #endif  
            71.         cvLine (img, pt0, pt, CV_RGB(255, 0, 0));  
            72.         pt0 = pt;  
            73.     }  
            74.   
            75.     cvShowImage ("hull", img);  
            76.   
            77.     cvWaitKey (0);  
            78.   
            79. #if ! ARRAY   
            80.     cvClearMemStorage (storage);  
            81. #else  
            82.     free (points);  
            83.     free (hull);  
            84. #endif  
            85.     return 0;  
            86.   
            87. }  


            代碼中有3條注釋語句,這是我在學(xué)習(xí)這個程序時遇到的問題,自己寫的測試代碼。這個代碼相對來說還是比較

            好理解的,主要就是開始對程序中CV_GET_SEQ_ELEM宏的使用有些不太理解。這個宏是用來在序列中提取元

            素的,本程序中共有3處用到了。

            第一處:

            1. pt0 = * CV_GET_SEQ_ELEM(CvPoint, ptseq, i);  

            第二處:

            1. pt0 = ** CV_GET_SEQ_ELEM(CvPoint*, hull, hullcontour - 1);  

            第三處:

            1. CvPoint pt = **CV_GET_SEQ_ELEM(CvPoint*, hull, i);  

            顯然,第一處的調(diào)用方式和后面兩處是不同的。但這里pt0pt的類型都是CvPoint,ptseqhull都是CvSeq*

            型的,唯一不同的是宏里的第一個參數(shù),這個參數(shù)表上宏返回的類型+*,比如:第一處這個參數(shù)是CvPoint,則

            返回CvPoint*,以此類推。這樣的話這兩個宏最后結(jié)果都是返回一個CvPoint類型值。這里對宏的使用是不是有

            點類型于函數(shù)重載呢!既然如此,我想干脆都用相同的方式調(diào)用這個宏,于是我把第一處的代碼改為

            1. pt0 = ** CV_GET_SEQ_ELEM(CvPoint*, ptseq, i);  

            運行后程序中止了,于是我把這里又改回來,然后改動后兩處,改為

            1. pt0 = * CV_GET_SEQ_ELEM(CvPoint, hull, hullcontour - 1);  
            2.   
            3. CvPoint pt = *CV_GET_SEQ_ELEM(CvPoint, hull, i);  

            運行后程序依然中止啦。這樣起碼說明了在這里關(guān)于這個宏的調(diào)用方式是不可以互換的。但具體為什么,確實

            糾結(jié)了很久,當就要絕望時,在Opencv中文論壇上看到了關(guān)于使用cvConvexHull2函數(shù)得到的凸包的問題,里

            面有句話對我很有幫助:當return_points=0時,用cvConvexHull2函數(shù)得到的是凸外形,包含的是輪廓的定點

            的指針或下標,而當return_points非0時,得到的是外形點本身。cvConvexHull2函數(shù)調(diào)用代碼如下

            1. hull = cvConvexHull2 (ptseq, 0, CV_CLOCKWISE, 0);  

            這里的return_points被設(shè)置為0了,說明hull并不是直接指向輪廓點的序列,而是指向指向輪廓點序列的指針,

            這就有點像hull是個二級指針啦!所以在后兩處對宏的調(diào)用第一個參數(shù)設(shè)置為CvPoint*,這樣的話就返回

            CvPoint**類型。到目前為止,這還只是我個人推測,還需要進一步的驗證。于是我把上面代碼中最后一個參數(shù)

            return_points改為1,運行。一切正常啦!注:這里后面兩處對宏的調(diào)用已經(jīng)在前面改了,所以就不必在修改

            了。以上所有的分析和理解都只是我個人的看法,不一定就是對的。希望大家能夠一起交流下這個問題,也希

            望各位大神能夠不吝賜教!?。?/strong>

            posted on 2012-10-17 12:01 不聽話的 閱讀(1056) 評論(0)  編輯 收藏 引用

            久久青青草原精品国产软件| 狠狠88综合久久久久综合网| 国内精品久久久久久久久电影网| 久久91精品综合国产首页| 久久久久久国产精品美女| 精品久久久久久久国产潘金莲| 99久久国产亚洲综合精品| 狠狠色丁香久久婷婷综合五月| 91精品久久久久久无码| 久久综合久久美利坚合众国| 久久婷婷综合中文字幕| 久久无码专区国产精品发布| 久久国产精品-久久精品| 久久综合九色综合网站| 精品国产91久久久久久久a| 中文字幕日本人妻久久久免费| 亚洲精品国产成人99久久| 久久综合久久自在自线精品自| 久久久久久一区国产精品| 久久久中文字幕| 精品久久久久香蕉网| 久久精品国产亚洲αv忘忧草| 99久久国产综合精品网成人影院| 亚洲精品乱码久久久久久| 亚洲人成无码www久久久| 久久成人国产精品一区二区| 久久亚洲精品中文字幕三区| 久久久久久毛片免费播放| 无码AV波多野结衣久久| 久久综合久久美利坚合众国| 三级韩国一区久久二区综合| 久久高潮一级毛片免费| 国内精品久久久久久麻豆| 91精品免费久久久久久久久| 91精品国产综合久久四虎久久无码一级| 亚洲AV无码久久| 久久精品亚洲一区二区三区浴池| 午夜人妻久久久久久久久| 亚洲精品乱码久久久久久自慰| 亚洲午夜久久久久久久久电影网| 久久亚洲精品国产亚洲老地址 |