• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C++ cvFindContours函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C++中cvFindContours函数的典型用法代码示例。如果您正苦于以下问题:C++ cvFindContours函数的具体用法?C++ cvFindContours怎么用?C++ cvFindContours使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了cvFindContours函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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);
}
开发者ID:JoakimSoderberg,项目名称:catcierge,代码行数:55,代码来源:catcierge_haar_matcher.c


示例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;
}
开发者ID:madalinaMdl,项目名称:Disertatie,代码行数:53,代码来源:mainwindow.cpp


示例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;
}
开发者ID:songshine,项目名称:DigitReco,代码行数:31,代码来源:img_sc.cpp


示例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;
		}
	////}
}
开发者ID:FranoTech,项目名称:ws-workflow,代码行数:32,代码来源:scancell.cpp


示例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;
}
开发者ID:hgk333,项目名称:Capston_numberDetecting,代码行数:60,代码来源:findNumber.cpp


示例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);
}
开发者ID:gimlids,项目名称:LTPM,代码行数:28,代码来源:Segment.cpp


示例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);
}
开发者ID:Mystfit,项目名称:Sonoromancer,代码行数:28,代码来源:ofxCvBlobFinder.cpp


示例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);
    }
}
开发者ID:ROUISSI,项目名称:tinkerland,代码行数:31,代码来源:contours.cpp


示例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;
}
开发者ID:mattdawkins,项目名称:scallop-tk,代码行数:35,代码来源:AdaptiveThresholding.cpp


示例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);  
}
开发者ID:andrew-nguyen,项目名称:clj-tesseract,代码行数:27,代码来源:image.cpp


示例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;
}
开发者ID:Multicia,项目名称:lj,代码行数:35,代码来源:feature.cpp


示例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(&reg_vision);
    cvReleaseImage(&temp);
}
开发者ID:shenerguang,项目名称:ZyboRobot,代码行数:60,代码来源:sign.c


示例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;
	}
}
开发者ID:shenerguang,项目名称:ZyboRobot,代码行数:60,代码来源:eye.c


示例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;
}
开发者ID:godfery,项目名称:skew,代码行数:26,代码来源:contours.c


示例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);
}
开发者ID:shenerguang,项目名称:ZyboRobot,代码行数:26,代码来源:sign.c


示例16: FindWormBoundary

/*
 * Smooths, thresholds and finds the worms contour.
 * The original image must already be loaded into Worm.ImgOrig
 * The Smoothed image is deposited into Worm.ImgSmooth
 * The thresholded image is deposited into Worm.ImgThresh
 * The Boundary is placed in Worm.Boundary
 *
 */
void FindWormBoundary(WormAnalysisData* Worm, WormAnalysisParam* Params){
	/** This function currently takes around 5-7 ms **/
	/**
	 * Before I forget.. plan to make this faster by:
	 *  a) using region of interest
	 *  b) decimating to make it smaller (maybe?)
	 *  c) resize
	 *  d) not using CV_GAUSSIAN for smoothing
	 */
	TICTOC::timer().tic("cvSmooth");
	cvSmooth(Worm->ImgOrig,Worm->ImgSmooth,CV_GAUSSIAN,Params->GaussSize*2+1);
	//cvSmooth(Worm->ImgOrig,Worm->ImgSmooth,CV_MEDIAN,Params->GaussSize*2+1);
	//cvSmooth(Worm->ImgOrig,Worm->ImgSmooth,CV_BLUR,Params->GaussSize*2+1,Params->GaussSize*2+1);
	TICTOC::timer().toc("cvSmooth");
	TICTOC::timer().tic("cvThreshold");
	cvThreshold(Worm->ImgSmooth,Worm->ImgThresh,Params->BinThresh,255,CV_THRESH_BINARY );
	TICTOC::timer().toc("cvThreshold");
	CvSeq* contours;
	IplImage* TempImage=cvCreateImage(cvGetSize(Worm->ImgThresh),IPL_DEPTH_8U,1);
	cvCopy(Worm->ImgThresh,TempImage);
	TICTOC::timer().tic("cvFindContours");
	cvFindContours(TempImage,Worm->MemStorage, &contours,sizeof(CvContour),CV_RETR_EXTERNAL,CV_CHAIN_APPROX_NONE,cvPoint(0,0));
	TICTOC::timer().toc("cvFindContours");
	TICTOC::timer().tic("cvLongestContour");
	if (contours) LongestContour(contours,&(Worm->Boundary));
	TICTOC::timer().toc("cvLongestContour");
	cvReleaseImage(&TempImage);

}
开发者ID:MaxMillion,项目名称:mindcontrol,代码行数:37,代码来源:WormAnalysis.c


示例17: cvCreateImage

void ControlWidget::ContourImage()
{
    if(this->m_storage == NULL) {
        this->contour_image = cvCreateImage(cvGetSize(this->imagerd), IPL_DEPTH_8U, 1);
        this->m_storage = cvCreateMemStorage(0);
    }
    else {
        this->contour_image = cvCreateImage(cvGetSize(this->imagerd), IPL_DEPTH_8U, 1);
        cvClearMemStorage(this->m_storage);
    }

    CvSeq* contours = 0;

    cvCvtColor(this->imagerd, this->contour_image, CV_BGR2GRAY);
    cvCanny(this->contour_image, this->contour_image, this->contour_Low, this->contour_High);
    cvFindContours(this->contour_image, this->m_storage, &contours, sizeof(CvContour), CV_RETR_TREE);

    cvZero(this->contour_image);

    if(contours) {
        cvDrawContours(this->contour_image, contours, cvScalarAll(255), cvScalarAll(128), 5);

        QImage ContourImage = QImage((const unsigned char*)(this->contour_image->imageData),
                                     this->contour_image->width, this->contour_image->height,
                                     QImage::Format_Indexed8).rgbSwapped();

         this->bufferContourImage = new QPixmap();
        *bufferContourImage = QPixmap::fromImage(ContourImage);
        *bufferContourImage = bufferContourImage->scaled(250, 200);
    }

    cvClearSeq(contours);
    cvZero(this->contour_image);
}
开发者ID:GreenSimulation,项目名称:OpenCV,代码行数:34,代码来源:controlwidget.cpp


示例18: find_contour

void find_contour(struct ctx *ctx)
{
	double area, max_area = 0.0;
	CvSeq *contours, *tmp, *contour = NULL;

	/* cvFindContours modifies input image, so make a copy */
	cvCopy(ctx->thr_image, ctx->temp_image1, NULL);
	cvFindContours(ctx->temp_image1, ctx->temp_st, &contours,
		       sizeof(CvContour), CV_RETR_EXTERNAL,
		       CV_CHAIN_APPROX_SIMPLE, cvPoint(0, 0));

	/* Select contour having greatest area */
	for (tmp = contours; tmp; tmp = tmp->h_next) {
		area = fabs(cvContourArea(tmp, CV_WHOLE_SEQ, 0));
		if (area > max_area) {
			max_area = area;
			contour = tmp;
		}
	}

	/* Approximate contour with poly-line */
	if (contour) {
		contour = cvApproxPoly(contour, sizeof(CvContour),
				       ctx->contour_st, CV_POLY_APPROX_DP, 2,
				       1);
		ctx->contour = contour;
	}
}
开发者ID:ylmeng,项目名称:grab_box,代码行数:28,代码来源:hand.c


示例19: findContours

void findContours( IplImage* img, CvMemStorage* storage, CvSeq **contours)
{
    //for findContour function
    IplImage* timg  =NULL;
    IplImage* gray  =NULL;
    IplImage* tgray =NULL;

    CvSize sz = cvSize( img->width, img->height );

	// make a copy of input image
	gray = cvCreateImage( sz, img->depth, 1 );
	timg = cvCreateImage( sz, img->depth, 1 );
	tgray = cvCreateImage( sz, img->depth, 1 );

	cvSetImageCOI(img,1);
    cvCopy( img, timg,NULL );
	cvSetImageCOI(img,0);

    cvCopy( timg, tgray, 0 );

    cvCanny( tgray, gray, ct1, ct2, 5 );
    // holes between edge segments
    cvDilate( gray, gray, 0, 2 );

    cvFindContours( gray, storage, contours,
                    sizeof(CvContour),CV_RETR_LIST,
                    CV_CHAIN_APPROX_NONE, cvPoint(0,0) );

    //release all the temporary images
    cvReleaseImage( &gray );
    cvReleaseImage( &tgray );
    cvReleaseImage( &timg );

}
开发者ID:ntavish,项目名称:tri,代码行数:34,代码来源:main.c


示例20: get_connected_components

/*	The function will return the connected components in 'comp', 
	as well as the number of connected components 'nc'.
	At this point, we have to determine whether the components are eye pair or not.
	We'll use experimentally derived heuristics for this, based on the width, 
	height, vertical distance, and horizontal distance of the components. 
	To make things simple, we only proceed if the number of the connected components is 2.*/
int get_connected_components(IplImage* img, IplImage* prev, CvRect window, CvSeq** comp)
{
		IplImage* _diff;
 
		cvZero(diff);
 
    /* apply search window to images */
		cvSetImageROI(img, window);
		cvSetImageROI(prev, window);
		cvSetImageROI(diff, window);
 
    /* motion analysis */
		cvSub(img, prev, diff, NULL);
		cvThreshold(diff, diff, 5, 255, CV_THRESH_BINARY);
		cvMorphologyEx(diff, diff, NULL, kernel, CV_MOP_OPEN, 1);
 
    /* reset search window */
		cvResetImageROI(img);
		cvResetImageROI(prev);
		cvResetImageROI(diff);
 
		_diff = (IplImage*)cvClone(diff);
 
    /* get connected components */
		int nc = cvFindContours(_diff, storage, comp, sizeof(CvContour),
                            CV_RETR_CCOMP, CV_CHAIN_APPROX_SIMPLE, cvPoint(0,0));
 
		cvClearMemStorage(storage);		
		cvReleaseImage(&_diff);
	
		return nc;
}
开发者ID:madhurjain,项目名称:TrackNoseBlinkEye,代码行数:38,代码来源:TrackNoseBlinkEye.cpp



注:本文中的cvFindContours函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C++ cvFindCornerSubPix函数代码示例发布时间:2022-05-30
下一篇:
C++ cvErode函数代码示例发布时间:2022-05-30
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap