2014年6月5日 星期四

使用OpenCV的cvPreCornerDetect做角點偵測 ( Corner Detection using cvPreCornerDetect in OpenCV )

介紹:
  • 如何使用cvPreCornerDetect做角點偵測
Introduction:
  • How to do corner detection using cvPreCornerDetect Function in OpenCV library. 

開發環境:
  • Visual Studio 2010
  • Windows 7
  • OpenCV 2.4.5

#include "stdafx.h"
#include "cvaux.h"
#include "highgui.h"

int main()
{
 IplImage *pImg;
 IplImage *pGrayImg;
 IplImage *pCornerImg_32F;
 IplImage *pCornerImg_8U;
 CvCapture *capture = cvCaptureFromCAM(0);
 bool createMemory = false;

 while(true)
 {
  pImg = cvQueryFrame(capture);
  if(!createMemory)
  {
   pGrayImg = cvCreateImage( cvGetSize(pImg),
    pImg->depth, 1);
   pCornerImg_32F = cvCreateImage( cvGetSize(pImg),
    IPL_DEPTH_32F, 1);
   pCornerImg_8U = cvCreateImage( cvGetSize(pImg),
    IPL_DEPTH_8U, 1);
   createMemory = !createMemory;
  }

  cvCvtColor( pImg, pGrayImg, CV_BGR2GRAY);
  cvPreCornerDetect(pGrayImg, pCornerImg_32F, 7);       
        
  cvDilate( pCornerImg_32F, pCornerImg_32F, 0, 1 );
  cvConvertScale( pCornerImg_32F, pCornerImg_8U, 255 );
        
  cvShowImage("Gray", pGrayImg);
  cvShowImage("CornerDetect", pCornerImg_8U);
  cvWaitKey(30);
 }

 cvReleaseImage( &pImg );
 cvReleaseImage( &pGrayImg );
 cvReleaseImage( &pCornerImg_32F );
 cvReleaseImage( &pCornerImg_8U );
 cvReleaseCapture( &capture );
}

編譯成功後,會顯示角點偵測後的結果。


void cvPreCornerDetect( const CvArr* image, CvArr* corners, int aperture_size=3 )

  • image:輸入影像
  • corners:儲存角點的陣列
  • aperture_size:Sobel運算子

相關文章:OpenCV學習日記

0 意見:

張貼留言