本文整理汇总了C++中cvFindContours函数的典型用法代码示例。如果您正苦于以下问题:C++ cvFindContours函数的具体用法?C++ cvFindContours怎么用?C++ cvFindContours使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了cvFindContours函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: catcierge_haar_matcher_find_prey
int catcierge_haar_matcher_find_prey(catcierge_haar_matcher_t *ctx,
IplImage *img, IplImage *thr_img,
match_result_t *result, int save_steps)
{
catcierge_haar_matcher_args_t *args = ctx->args;
IplImage *thr_img2 = NULL;
CvSeq *contours = NULL;
size_t contour_count = 0;
assert(ctx);
assert(img);
assert(ctx->args);
// thr_img is modified by FindContours so we clone it first.
thr_img2 = cvCloneImage(thr_img);
cvFindContours(thr_img, ctx->storage, &contours,
sizeof(CvContour), CV_RETR_LIST, CV_CHAIN_APPROX_NONE, cvPoint(0, 0));
// If we get more than 1 contour we count it as a prey. At least something
// is intersecting the white are to split up the image.
contour_count = catcierge_haar_matcher_count_contours(ctx, contours);
// If we don't find any prey
if ((args->prey_steps >= 2) && (contour_count == 1))
{
IplImage *erod_img = NULL;
IplImage *open_img = NULL;
CvSeq *contours2 = NULL;
erod_img = cvCreateImage(cvGetSize(thr_img2), 8, 1);
cvErode(thr_img2, erod_img, ctx->kernel3x3, 3);
if (ctx->super.debug) cvShowImage("haar eroded img", erod_img);
open_img = cvCreateImage(cvGetSize(thr_img2), 8, 1);
cvMorphologyEx(erod_img, open_img, NULL, ctx->kernel5x1, CV_MOP_OPEN, 1);
if (ctx->super.debug) cvShowImage("haar opened img", erod_img);
cvFindContours(erod_img, ctx->storage, &contours2,
sizeof(CvContour), CV_RETR_LIST, CV_CHAIN_APPROX_NONE, cvPoint(0, 0));
cvReleaseImage(&erod_img);
cvReleaseImage(&open_img);
contour_count = catcierge_haar_matcher_count_contours(ctx, contours2);
}
if (ctx->super.debug)
{
cvDrawContours(img, contours, cvScalarAll(0), cvScalarAll(0), 1, 1, 8, cvPoint(0, 0));
cvShowImage("Haar Contours", img);
}
cvReleaseImage(&thr_img2);
return (contour_count > 1);
}
示例2: cvCreateImage
float MainWindow::matchTwoShapes(IplImage* image1, IplImage* image2)
{
double matchresult = 100;
double mincontour = 200; // taille mimale du contour qu il faut le detecter
int CVCONTOUR_APPROX_LEVEL;
IplImage* img1_edge = cvCreateImage(cvGetSize(image1), 8, 1);
IplImage* img2_edge = cvCreateImage(cvGetSize(image2), 8, 1);
cvThreshold(image1, img1_edge, 128, 255, CV_THRESH_BINARY);
cvThreshold(image2, img2_edge, 128, 255, CV_THRESH_BINARY);
CvMemStorage* storage = cvCreateMemStorage();
CvMemStorage* storage2 = cvCreateMemStorage();
CvSeq* premier_contour_img1 = NULL;
CvSeq* premier_contour_img2 = NULL;
CvSeq* newseq = NULL;
CvSeq* newseq2 = NULL;
//first Border extraction
cvFindContours(img1_edge, storage, &premier_contour_img1, sizeof(CvContour), CV_RETR_LIST);
//second border extraction
cvFindContours(img2_edge, storage2, &premier_contour_img2, sizeof(CvContour), CV_RETR_LIST);
CVCONTOUR_APPROX_LEVEL = m_ui->tolerance_lvl->value();
//extract aprox polu
for (CvSeq* c = premier_contour_img1; c != NULL; c = c->h_next)
{
if (cvContourPerimeter(c) > mincontour)
{
newseq = cvApproxPoly(c, sizeof(CvContour), storage, CV_POLY_APPROX_DP, CVCONTOUR_APPROX_LEVEL, 0); //pprox
}
}
for(CvSeq* c = premier_contour_img2; c != NULL; c = c->h_next)
{
if (cvContourPerimeter(c) > mincontour)
{
newseq2 = cvApproxPoly(c, sizeof(CvContour), storage2, CV_POLY_APPROX_DP, CVCONTOUR_APPROX_LEVEL, 0); //pprox
}
}
//match the two contours
if(newseq && newseq2)
{
matchresult = cvMatchShapes(newseq2, newseq, 1, 0.0); // inainte era cvMatchContours
}
cvReleaseImage(&img1_edge);
cvReleaseImage(&img2_edge);
cvReleaseMemStorage(&storage);
cvReleaseMemStorage(&storage2);
return matchresult;
}
示例3: GetContourPointRandom
point* GetContourPointRandom(const IplImage* img,int npoints)
{
point* pts = NULL;
IplImage* img_bw = cvCloneImage(img);
// 2 . 轮廓提取
CvMemStorage * storage = cvCreateMemStorage();
CvSeq * contour = NULL;
/*cvShowImage("song",img_bw);
cvWaitKey(0);*/
int tatal = cvFindContours(img_bw,storage,&contour,sizeof(CvContour),
CV_RETR_LIST,CV_CHAIN_APPROX_NONE );
CvPoint *samplearray = (CvPoint *)malloc(npoints * sizeof(CvPoint));
if(contoursample(contour,samplearray,npoints))
{//随机点生成成功
pts = (point *)malloc(npoints * sizeof(point));
for(int i=0;i<npoints;i++)
{
pts[i].x = samplearray[i].x;
pts[i].y = samplearray[i].y;
}
}
cvReleaseMemStorage(&storage);
free(samplearray);
return pts;
}
示例4: main
int main (int argv, char** argc[])
{
int ncell = 0, prev_ncontour = 0, same_count = 0;
////while (!worker->CancellationPending) {
////worker->ReportProgress(50, String::Format(rm->GetString("Progress_Analyze_FoundNCell"), title, ncell));
cvConvert(input_morph, tmp8UC1);
cvClearMemStorage(storage);
int ncontour = cvFindContours(tmp8UC1, storage, &first_con, sizeof(CvContour), CV_RETR_EXTERNAL);
if (ncontour == 0)
break; // finish extract cell
if (ncontour == prev_ncontour) {
cvErode(input_morph, input_morph);
same_count++;
} else
same_count = 0;
prev_ncontour = ncontour;
cur = first_con;
while (cur != nullptr) {
double area = fabs(cvContourArea(cur));
if ((area < 3000.0) || (same_count > 10)) {
int npts = cur->total;
CvPoint *p = new CvPoint[npts];
cvCvtSeqToArray(cur, p);
cvFillPoly(out_single, &p, &npts, 1, cvScalar(255.0)); // move to single
cvFillPoly(input_morph, &p, &npts, 1, cvScalar(0.0)); // remove from input
delete[] p;
ncell++;
}
cur = cur->h_next;
}
////}
}
示例5: rotationTest
double rotationTest(IplImage *thresholdImage, IplImage* contourPicture, vector<ContourData> contourData){
int returnValue = 0;
// create storate for contour
CvMemStorage* storage = cvCreateMemStorage(0);
CvSeq *first_contour = 0;
//decide a interesting area (center)
int imageMinX = cvGetSize(thresholdImage).width/4 , imageMaxX = cvGetSize(thresholdImage).width - imageMinX, imageMinY = cvGetSize(thresholdImage).height/4, imageMaxY = cvGetSize(thresholdImage).height - imageMinY;
//find the contour
int nContour = cvFindContours(thresholdImage, storage, &first_contour, sizeof(CvContour), CV_RETR_LIST,CV_CHAIN_APPROX_SIMPLE);
// cout<<"nContour = "<< nContour<< "\n";
CvSeq *contour; //for saving the contour
for (contour = first_contour ; contour != 0 ; contour = contour->h_next) {
int tmp_maxX = 0 , tmp_maxY = 0 , tmp_minX = 1000000, tmp_minY = 1000000, tmp_width = 0, tmp_height = 0;
// Draw the contour
cvDrawContours(contourPicture, contour, CV_RGB(0,0,255), CV_RGB(255, 0, 0), 2, 1);
//draw the rectangle on the picture outside of contour
for (int i = 0 ; i < contour->total ; i++) {
// find the area of contour
CvPoint* ContourPoint = (CvPoint*)cvGetSeqElem(contour, i);
if (tmp_maxX < ContourPoint->x)
tmp_maxX = ContourPoint->x;
if (tmp_maxY < ContourPoint->y)
tmp_maxY = ContourPoint->y;
if (tmp_minX > ContourPoint->x)
tmp_minX = ContourPoint->x;
if (tmp_minY > ContourPoint->y)
tmp_minY = ContourPoint->y;
}
//calculate width and height
tmp_width = tmp_maxX - tmp_minX; tmp_height = tmp_maxY - tmp_minY;
//if rate of fiture is right, input data in vector
if((double)tmp_width/(double)tmp_height < 1 && tmp_height > 20 && tmp_maxX < imageMaxX && tmp_minX > imageMinX && tmp_minY > imageMinY && tmp_maxY < imageMaxY ){
//cvRectangle(contourPicture, CvPoint(tmp_maxX,tmp_maxY), CvPoint(tmp_minX,tmp_minY), CV_RGB(0, 255, 0));
ContourData tmp_contour;
tmp_contour.setMaxX(tmp_maxX); tmp_contour.setMaxY(tmp_maxY); tmp_contour.setMinX(tmp_minX); tmp_contour.setMinY(tmp_minY); tmp_contour.setHeight(tmp_height); tmp_contour.setWidth(tmp_width);
tmp_contour.setCenter();
contourData.push_back(tmp_contour);
//confirm the value stored at vector
// cout<<"max ( "<<tmp_maxX<<","<<tmp_maxY<<")\n";
// cout<<"min ( "<<tmp_minX<<","<<tmp_minY<<")\n";
// cout<<"width : "<<tmp_width<< " height : "<<tmp_height<<"\n";
}
}
returnValue = arrangeContourData(contourData, contourPicture);
//find the number area.
cvReleaseMemStorage(&storage);
return returnValue;
}
示例6: cvFindContours
void Segment::updateContour()
{
contour = 0;
cvFindContours(iplMask, storage, &contour, sizeof(CvContour), CV_RETR_LIST, CV_CHAIN_APPROX_NONE);
CvMoments moments;
// CvSeq* c = contour;
//cerr << "-------------------------- " << c << endl;
/*for( CvSeq* c = contour; c!=NULL; c=c->h_next ){
for(int i = 0; i < c->total; i++){
CvPoint* p = CV_GET_SEQ_ELEM( CvPoint, c, i );
cerr << p->x << "," << p->y << endl;
}
}
*/
cvMoments(contour, &moments);
double m00, m10, m01;
m00 = cvGetSpatialMoment(&moments, 0,0);
m10 = cvGetSpatialMoment(&moments, 1,0);
m01 = cvGetSpatialMoment(&moments, 0,1);
// TBD check that m00 != 0
float center_x = m10/m00;
float center_y = m01/m00;
centroid = cvPoint(center_x, center_y);
}
示例7: cvCreateMemStorage
//----------------------------------------------------------------------------------
void ofxCvBlobFinder::findBlobs(ofxCvGrayscaleImage image, bool find_holes) {
CvMemStorage *stor = cvCreateMemStorage();
IplImage *img = image.getCvImage();
CvSeq *contours;
_width = img->width;
_height = img->height;
// CV_RETR_EXTERNAL to not find holes
int mode = (find_holes)?CV_RETR_LIST:CV_RETR_EXTERNAL;
cvFindContours(img, stor, &contours, sizeof(CvContour), mode, CV_CHAIN_APPROX_SIMPLE);
blobz.clear();
while (contours) {
ofxCvComplexBlob b = ofxCvComplexBlob(contours);
b.setApproxFactor(approxFactor);
b.getApproxPoints();
b.getHullPoints();
blobz.push_back( b );
contours = contours->h_next;
}
// sort blobs
sort(blobz.begin(), blobz.end(), sort_blob_func);
}
示例8: main
int main( int argc, char** argv )
{
IplImage* src;
// the first command line parameter must be file name of binary
// (black-n-white) image
if( argc == 2 && (src=cvLoadImage(argv[1], 0))!= 0)
{
IplImage* dst = cvCreateImage( cvGetSize(src), 8, 3 );
CvMemStorage* storage = cvCreateMemStorage(0);
CvSeq* contour = 0;
cvThreshold( src, src, 50, 255, CV_THRESH_BINARY );
cvNamedWindow( "Source", 1 );
cvShowImage( "Source", src );
cvFindContours( src, storage, &contour, sizeof(CvContour),
CV_RETR_CCOMP, CV_CHAIN_CODE );
cvZero( dst );
for( ; contour != 0; contour = contour->h_next )
{
CvScalar color = CV_RGB( rand()&255, rand()&255, rand()&255 );
/* replace CV_FILLED with 1 to see the outlines */
cvDrawContours( dst, contour, color, color, 0, 1, CV_AA );
}
cvNamedWindow( "Components", 1 );
cvShowImage( "Components", dst );
cvWaitKey(0);
}
}
示例9: hfBinaryClassify
int hfBinaryClassify(IplImage *bin, float minRad, float maxRad, CandidatePtrVector& kps ) {
// Create OpenCV storage block
CvMemStorage *mem = cvCreateMemStorage(0);
CvSeq *Contours = NULL, *ptr = NULL;
// Identify Contours in binary image
cvFindContours( bin, mem, &Contours, sizeof(CvContour),
CV_RETR_CCOMP, CV_CHAIN_APPROX_SIMPLE, cvPoint(0,0) );
//Process
int highcount = 0;
int lowcount = 0;
for( ptr = Contours; ptr != NULL; ptr = ptr->h_next ) {
int ret = findStableMatches( ptr, minRad, maxRad, kps, bin );
if( ret == -1 )
lowcount++;
if( ret == 1 )
highcount++;
}
//Create return
int retval = 0x0;
if( lowcount > 100000 )
retval = retval | AT_LOWER;
if( highcount > 0 )
retval = retval | AT_RAISE;
//Deallocate
if(Contours)
{
cvReleaseMemStorage( &Contours->storage );
}
return 0;
}
示例10: toIplImage
void Image::drawContours() {
IplImage* src = this -> toIplImage();
IplImage* dst = this -> cloneEmpty() -> toIplImage();
CvMemStorage* storage = cvCreateMemStorage(0);
CvSeq* contour = 0;
cvThreshold( src, src, 1, 255, CV_THRESH_BINARY );
cvNamedWindow( "Source", 1 );
cvShowImage( "Source", src );
cvFindContours( src, storage, &contour, sizeof(CvContour),
CV_RETR_CCOMP, CV_CHAIN_APPROX_SIMPLE );
cvZero( dst );
for( ; contour != 0; contour = contour->h_next )
{
CvScalar color = CV_RGB( rand()&255, rand()&255, rand()&255 );
/* replace CV_FILLED with 1 to see the outlines */
cvDrawContours( dst, contour, color, color, -1, CV_FILLED, 8 );
}
cvNamedWindow( "Components", 1 );
cvShowImage( "Components", dst );
cvWaitKey(0);
}
示例11: cvCreateMemStorage
vector<float> feature::getPAR(IplImage *src, int mask)
{
float perimeter, area, rc, i;
perimeter = area = i = 0;
CvMemStorage* storage = cvCreateMemStorage(0);
CvSeq* contours = 0;
cvFindContours(src, storage, &contours, sizeof(CvContour), CV_RETR_LIST);
if (contours) {
CvSeq* c = contours;
for (; c != NULL; c = c->h_next) {
if (cvContourArea(c) < 1000) continue;
perimeter += cvArcLength(c);
area += cvContourArea(c);
// perimeter = perimeter > cvArcLength(c) ? perimeter : cvArcLength(c);
// area = area > cvContourArea(c) ? area : cvContourArea(c);
i++;
//qDebug("\tmask = %d, i = %d, perimeter = %f, area = %f", mask, i, perimeter, area);
}
}
if (area == 0)
rc = -1;
else
rc = perimeter * perimeter / (4 * 3.14 * area);
//form feature based on mask
vector<float> PAR({perimeter, area, rc});
if (mask == 2) {
PAR.push_back(i);
}
cvReleaseMemStorage(&storage);
return PAR;
}
示例12: reg_sign
void reg_sign()
{
int counter_num=0;
IplImage * temp;
temp= cvCreateImage(cvSize(sign_rect.width,sign_rect.height),8,1);
cvCvtColor(reg_vision,temp,CV_BGR2GRAY);
//Gauss smooth
cvSmooth(temp,temp,CV_GAUSSIAN,3,3,0,0);
//Canny edge detect
cvCanny(temp,temp,120,150,3);
//Threshold
CvSeq * sc;
CvSeq * c;
cvThreshold(temp,temp,0,255,CV_THRESH_BINARY);
counter_num=cvFindContours(temp,mem,&sc,sizeof(CvContour),CV_RETR_LIST,CV_CHAIN_APPROX_NONE,cvPoint(0,0));
double rmin=-1;
double r;
c=sc;
CvBox2D minrect;
while(c!=NULL)
{
CvBox2D rect = cvMinAreaRect2(c,mem);
r=((double)(rect.size.width*rect.size.height))/(sign_rect.width*sign_rect.height);
if(r>0.1)
{
if(r<rmin||rmin<0)
{
rmin=r;
minrect=rect;
}
}
c=c->h_next;
}
//printf("counter:%d rate:%f\n",counter_num,rmin);
//cvShowImage("reg_vision",reg_vision);
if(rmin<0.2)
{
cur_sign=GO_AHEAD;
printf("GO_AHEAD!\n");
}
else if(rmin<0.5)
{
cur_sign=TURN_RIGHT;
printf("TURN_RIGHT!\n");
}
else if(rmin<0.7)
{
cur_sign=STOP;
printf("STOP!\n");
}
else
{
cur_sign=NONE;
printf("NONE!\n");
}
cvReleaseImage(®_vision);
cvReleaseImage(&temp);
}
示例13: sharingan
void sharingan()
{
int lowtherd =120;
int hightherd=130;
int small_size=500;
int contour_num;
cvCvtColor(vision,gray_vision,CV_BGR2GRAY);
//Gauss smooth
cvSmooth( gray_vision,gray_vision,CV_GAUSSIAN,3,3,0,0);
//Canny edge detect
cvCanny(gray_vision,gray_vision,lowtherd,hightherd,3);
//Threshold
cvThreshold(gray_vision,gray_vision,0,255,CV_THRESH_BINARY);
//picture used to display
//find countor
CvSeq * fc=NULL;
CvSeq * c;
cvClearMemStorage(mem);
contour_num=cvFindContours(gray_vision,mem,&fc,sizeof(CvContour),CV_RETR_LIST,CV_CHAIN_APPROX_NONE,cvPoint(0,0));
// printf("find counters:%d\n",contour_num);
c=fc;
cvCopyImage(blank,road_vision);
cvCopyImage(blank,sign_vision);
sign_flag=0;
line_num=0;
corn_num=0;
while(c!=NULL)
{
CvBox2D rect = cvMinAreaRect2(c,mem);
double width=rect.size.height>rect.size.width?rect.size.height:rect.size.width;
double height=rect.size.height<=rect.size.width?rect.size.height:rect.size.width;
if(height*width>small_size)
{
double s;
s=cvContourArea(c,CV_WHOLE_SEQ,0);
if(s>500)
{
sign_flag=1;
cvDrawContours(sign_vision,c,cvScalar(255,255,255,0), cvScalar(255,255,255,0),0, 1,8,cvPoint(0,0));
}
else if(s<=500)
{
if(width>50&&height<15)
{
line_box[line_num]=rect;
line_num++;
}
else
{
corn_box[line_num]=rect;
corn_num++;
}
cvDrawContours(road_vision,c,cvScalar(255,255,255,0), cvScalar(255,255,255,0),0, 1,8,cvPoint(0,0));
}
}
c=c->h_next;
}
}
示例14: contorsFindBox
int contorsFindBox(IplImage *src, CvMemStorage* storage, CvBox2D *box)
{
CvSeq *contours;
int ret;
double area;
assert((area = src->width * src->height) > 0);
ret = cvFindContours(src, storage,
&contours, sizeof(CvContour), CV_RETR_LIST, CV_CHAIN_APPROX_SIMPLE, cvPoint(0, 0));
if (ret == 0) return 1;
for (CvSeq *c = contours; c != NULL; c = c->h_next) {
c = cvApproxPoly(c, sizeof(CvContour), storage, CV_POLY_APPROX_DP, 5, 1);
double contour_area = fabs(cvContourArea(c, CV_WHOLE_SEQ, 0));
double ratio = area / contour_area;
if (ratio > 1.5 && ratio < 6.0) {
CvBox2D b = cvMinAreaRect2(c, NULL);
memcpy(box, &b, sizeof(CvBox2D));
return 0;
}
}
return 1;
}
示例15: split_sign
void split_sign()
{
CvSeq * sc;
CvSeq * c;
CvSeq * cmax;
cvClearMemStorage(mem);
cvFindContours(sign_vision,mem,&sc,sizeof(CvContour),CV_RETR_LIST,CV_CHAIN_APPROX_NONE,cvPoint(0,0));
double smax=0;
double s;
c=sc;
while(c!=NULL)
{
s=cvContourArea(c,CV_WHOLE_SEQ,0);
if(s>smax)
{
smax=s;
cmax=c;
}
c=c->h_next;
}
sign_rect=cvBoundingRect(cmax,0);
cvSetImageROI(vision,sign_rect);
reg_vision= cvCreateImage(cvSize(sign_rect.width,sign_rect.height),8,3);
cvCopyImage(vision,reg_vision);
cvResetImageROI(vision);
}