小男孩‘自慰网亚洲一区二区,亚洲一级在线播放毛片,亚洲中文字幕av每天更新,黄aⅴ永久免费无码,91成人午夜在线精品,色网站免费在线观看,亚洲欧洲wwwww在线观看

分享

角點(diǎn)檢測(cè)(Corner Detection) cvFindCornerSubPix 使用范例【轉(zhuǎn)】

 iuv 2012-02-21
角點(diǎn)檢測(cè)(Corner Detection) cvFindCornerSubPix 使用范例【轉(zhuǎn)】
2011-10-16 22:17

這段范例包含如何使用函數(shù)cvGoodFeaturesToTrack 和cvFindCornerSubPix 來進(jìn)行角點(diǎn)檢測(cè)的(Corner Detection)。 我發(fā)現(xiàn)cvFindCornerSubPix的范例在網(wǎng)絡(luò)上比較少, 所以把我的這段程序整理了出來,并給出這個(gè)函數(shù)最后2個(gè)參數(shù)的解釋,希望對(duì)大家有幫助。

注意,cvFindCornerSubPix函數(shù)的使用必須是在cvGoodFeaturesToTrack實(shí)現(xiàn)基礎(chǔ)上的,因?yàn)槭莝ubpix函數(shù)是對(duì)于goodfeature函數(shù)結(jié)果的進(jìn)一步精確估計(jì)。估計(jì)的方法參見OReilly.Learning.OpenCV. pp. 319-321。

另外,cvFindCornerSubPix的使用難點(diǎn)是最后的兩個(gè)參數(shù),第一個(gè),cvSize(-1,-1)表示不忽略corner臨近的像素進(jìn)行精確估計(jì),如果設(shè)置成cvSize(1,1)就表示成忽略掉相鄰1個(gè)像素,再進(jìn)行精確估計(jì)。 原因是出于計(jì)算的角度,如果過于考慮相鄰的像素,可能不會(huì)得出可逆的矩陣。(詳見P321)

最后一個(gè)參數(shù),對(duì)于精確估計(jì),有2個(gè)參數(shù)可以限制精度:迭代次數(shù)(iteration)或者最小精度(epsilon),可以單一使用,也可以同時(shí)使用。在這個(gè)例子中,我同時(shí)使用了2個(gè)。(可以簡(jiǎn)單理解為,如果達(dá)不到epsilon =0.01的時(shí)候,就迭代iteration =20次吧,如果10次就達(dá)到了0.01,也就不用迭代20次了。)結(jié)果和源碼如下:



Corner detection by Good features

Corner detection by Sub Pixels

源代碼如下:

#include "stdafx.h"
#include <iostream>
#include <stdlib.h>

#include <cv.h>
#include <cxcore.h>
#include <highgui.h>
#include <math.h>

using namespace std;

//by Huang, Haiqiao 5 Dec. 2009
int main(int argc, char** argv)
{
   cout << "Corner Detection OpenCV!"<<endl; 
   char* filename="D:\\OpenCV_stuff\\SampleImages\\pattern.bmp";
   IplImage* imgRGB = cvLoadImage(filename); 
   IplImage* imgRGB2 = cvLoadImage(filename); 
   IplImage* imgGrey = cvLoadImage(filename,CV_LOAD_IMAGE_GRAYSCALE); 
    
   if (imgGrey==NULL){//image validation
      cout << "No valid image input."<<endl; 
      char c=getchar();
      return 1;
   } 
   int w=imgGrey->width;
   int h=imgGrey->height;

   IplImage* eig_image = cvCreateImage(cvSize(w, h),IPL_DEPTH_32F, 1);
   IplImage* temp_image = cvCreateImage(cvSize(w, h),IPL_DEPTH_32F, 1); 

   const int MAX_CORNERS = 140;//estimate a corner number
   CvPoint2D32f corners[MAX_CORNERS] = {0};// coordinates of corners
   //CvPoint2D32f* corners = new CvPoint2D32f[ MAX_CORNERS ]; //another method of declaring an array
   int corner_count = MAX_CORNERS; 
   double quality_level = 0.1;//threshold for the eigenvalues
   double min_distance = 5;//minimum distance between two corners
   int eig_block_size = 3;//window size
   int use_harris = false;//use 'harris method' or not

   //----------initial guess by cvGoodFeaturesToTrack---------------
   cvGoodFeaturesToTrack(imgGrey,
            eig_image,   // output                 
            temp_image,
            corners,
            &corner_count,
            quality_level,
            min_distance,
            NULL,
            eig_block_size,
            use_harris);


   int r=2; //rectangle size
   int lineWidth=1; // rectangle line width
   //-----draw good feature corners on the original RGB image---------
   for (int i=0;i<corner_count;i++){
      cvRectangle(imgRGB2, cvPoint(corners[i].x-r,corners[i].y-r), 
            cvPoint(corners[i].x+r,corners[i].y+r), cvScalar(255,0,0),lineWidth);
   }
   
   int half_win_size=3;//the window size will be 3+1+3=7
   int iteration=20;
   double epislon=0.1; 
   cvFindCornerSubPix(
         imgGrey,
         corners,
         corner_count,
         cvSize(half_win_size,half_win_size),
         cvSize(-1,-1),//no ignoring the neighbours of the center corner
         cvTermCriteria(CV_TERMCRIT_ITER|CV_TERMCRIT_EPS,iteration,epislon)
   );

   //------draw subpix corners on another original RGB image------------
   for (int i=0;i<corner_count;i++){
      cvRectangle(imgRGB, cvPoint(corners[i].x-r,corners[i].y-r), 
            cvPoint(corners[i].x+r,corners[i].y+r), cvScalar(0,0,255),lineWidth);
   }
   
   //to display a coordinate of the third corner
   cout<<"x="<<corners[2].x;
   cout<<",y="<<corners[2].y<<endl;

   cvNamedWindow("cvFindCornerSubPix", CV_WINDOW_AUTOSIZE );
   cvShowImage( "cvFindCornerSubPix", imgRGB );
   cvNamedWindow("cvGoodFeaturesToTrack", CV_WINDOW_AUTOSIZE );
   cvShowImage( "cvGoodFeaturesToTrack", imgRGB2 );
   

   cvWaitKey(0); 
   cvReleaseImage(&imgGrey);
   cvReleaseImage(&imgRGB);
   cvReleaseImage(&imgRGB2);
   cvDestroyWindow("cvGoodFeaturesToTrack");
   cvDestroyWindow("cvFindCornerSubPix");

   //char c=getchar();
   return 0;
}

FROM:http://www./forum/viewtopic.php?t=8777

    本站是提供個(gè)人知識(shí)管理的網(wǎng)絡(luò)存儲(chǔ)空間,所有內(nèi)容均由用戶發(fā)布,不代表本站觀點(diǎn)。請(qǐng)注意甄別內(nèi)容中的聯(lián)系方式、誘導(dǎo)購買等信息,謹(jǐn)防詐騙。如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請(qǐng)點(diǎn)擊一鍵舉報(bào)。
    轉(zhuǎn)藏 分享 獻(xiàn)花(0

    0條評(píng)論

    發(fā)表

    請(qǐng)遵守用戶 評(píng)論公約

    類似文章 更多