码迷,mamicode.com
首页 > 其他好文 > 详细

学习opencv——习题8-6改变cvFindDominantPoints函数最后四个参数的大小对检测结果的影响

时间:2019-08-16 11:48:26      阅读:111      评论:0      收藏:0      [点我收藏+]

标签:函数   find   release   vco   include   cal   eof   lib   gray   

//改变参数没有多大差别,参数2不宜设置的过大,否则检测不到关键点
//参数1必须小于参数2,参数3必须小于参数2,否则程序出错

#include <cv.h>
#include <opencv2/legacy/legacy.hpp>
#include <stdio.h>
#include <stdlib.h>
#include "highgui.h"
using namespace std;
using namespace cv;

int main( int argc, char** argv )
{
int i, idx;
CvPoint p;
CvMemStorage* storage_ct = cvCreateMemStorage(0);
CvMemStorage* storage_dp = cvCreateMemStorage(0);
IplImage* img = cvLoadImage("tu8-5.jpg", CV_LOAD_IMAGE_GRAYSCALE);
cvNamedWindow("image");
cvShowImage("image",img);

IplImage* img_threshold=cvCreateImage(cvGetSize(img),img->depth,1);
cvThreshold(img,img_threshold,100,255,CV_THRESH_BINARY);

cvZero(img);
CvSeq* contours = 0;
cvFindContours( img_threshold, storage_ct, &contours, sizeof(CvContour),
CV_RETR_TREE, CV_CHAIN_APPROX_SIMPLE );
//多边形逼近
contours = cvApproxPoly( contours, sizeof(CvContour), storage_ct, CV_POLY_APPROX_DP, 3, 1 );
cvDrawContours(img, contours, cvScalarAll(100), cvScalarAll(200), 100 );
cvNamedWindow( "contour" );
cvShowImage( "contour", img );

CvSeq* dps = 0;
dps = cvFindDominantPoints( contours, storage_dp, CV_DOMINANT_IPAN, 19, 20, 25, 100 );
printf("found %d DPs and %d Contours \n", dps->total, contours->total );
cvZero(img);
for ( i = 0; i < dps->total; i++)
{
idx = *(int *) cvGetSeqElem(dps, i);
p = *(CvPoint *) cvGetSeqElem(contours, idx);
cvDrawCircle( img, p , 1, cvScalarAll(255) );
printf("%d %d %d\n", idx, p.x, p.y);
}
cvNamedWindow( "DominantPoint" );
cvShowImage( "DominantPoint", img );

cvWaitKey(0);
cvReleaseMemStorage( &storage_ct );
cvReleaseMemStorage( &storage_dp );
cvReleaseImage( &img );
cvReleaseImage(&img_threshold);
cvDestroyAllWindows();

return 0;
}

技术图片

技术图片技术图片技术图片

学习opencv——习题8-6改变cvFindDominantPoints函数最后四个参数的大小对检测结果的影响

标签:函数   find   release   vco   include   cal   eof   lib   gray   

原文地址:https://www.cnblogs.com/yanzhixue/p/11362848.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!