当前位置: 首页>>代码示例>>C++>>正文


C++ cvBoundingRect函数代码示例

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


在下文中一共展示了cvBoundingRect函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: is_blink

/*	Eye blink code goes here & checks for bounding rects
	to determine whether eye is blinked or not.
	*/
int is_blink(CvSeq* comp, int num, CvRect window, CvRect eye)
{
		if (comp == 0 || num != 1)
			return 0;
 
		CvRect r1 = cvBoundingRect(comp, 1);
 
		/* component is within the search window */
		if (r1.x < window.x)
			return 0;
		if (r1.y < window.y)
			return 0;
		if (r1.x + r1.width > window.x + window.width)	
			return 0;
		if (r1.y + r1.height > window.y + window.height)
			return 0;
 
		/* get the centroid of eye */
		CvPoint pt = cvPoint(
			eye.x + eye.width/2 ,
			eye.y + eye.height/2 
			);
 
		/* component is located at the eye's centroid */
		if (pt.x <= r1.x || pt.x >= r1.x + r1.width)
	        return 0;
	    if (pt.y <= r1.y || pt.y >= r1.y + r1.height)
		    return 0;

		return 1;
}
开发者ID:madhurjain,项目名称:TrackNoseBlinkEye,代码行数:34,代码来源:TrackNoseBlinkEye.cpp

示例2: 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

示例3: cvCreateMemStorage

/*
 * @src Frame image
 * @contour  contour processing
 * @testImageHistogram histogram from model image
 * @h_bins number of hue bins
 * @s_bins number of sat bins 
 * @min minimum similarity to achieve when comparing histograms
 */
int Contours::histogramMatchingFilter(IplImage * src, CvHistogram * testImageHistogram,int h_bins,int s_bins, double min){
	CvRect box;
	CvMemStorage* mem = cvCreateMemStorage(0);
	
	double val;
	
	
	//get contour bounding box
	box=cvBoundingRect(this->c,0);
	
	//printf("box x:%d y:%d \n",box.x,box.y);
	
	IplImage * src_bbox=cvCreateImage(cvSize(box.width,box.height),src->depth,src->nChannels);
	
	//gets subimage bounded by box
    cvGetSubArr( src,(CvMat*)src_bbox, box );

	//gets subimage histogram
	utils::Histogram * h = new Histogram(h_bins,s_bins);
	CvHistogram* hist = h->getHShistogramFromRGB(src_bbox);
	//compares with object histogram
	val=cvCompareHist(hist,testImageHistogram,CV_COMP_BHATTACHARYYA);
	
	cvReleaseHist(&hist);
	cvReleaseImage(&src_bbox);
	cvReleaseMemStorage(&mem);
	delete h;
	
	return (val<min);
}
开发者ID:margguo,项目名称:tpf-robotica,代码行数:38,代码来源:Contours.cpp

示例4: cvBoundingRect

void MatchTemplatePlugin::ProcessStatic
( int i, ImagePlus *img, ImagePlus *oimg,
 int method, CvSize winsize, IplImage* &map){
	CvRect orect = cvBoundingRect(oimg->contourArray[i],1);
	RestrictRectLoc(orect, cvRect(0,0,img->orig->width,img->orig->height));
	cvSetImageROI(oimg->orig, orect);
	CvRect rect = cvRect(MAX(0,orect.x-winsize.width), MAX(0,orect.y-winsize.height),orect.width+2*winsize.width, orect.height+2*winsize.height);
	rect.width = MIN(rect.width,oimg->orig->width-rect.x);
	rect.height = MIN(rect.height,oimg->orig->height-rect.y);
	cvSetImageROI(img->orig, rect);

	CvSize mapsize = MyPoint(MyPoint(rect)-MyPoint(orect)+wxPoint(1,1)).ToCvSize();
	if (map && MyPoint(cvGetSize(map))!=MyPoint(mapsize))
		cvReleaseImage(&map);
	if( !map )
        map = cvCreateImage(mapsize, IPL_DEPTH_32F, 1);

	cvMatchTemplate( img->orig, oimg->orig, map, method );
	cvResetImageROI(img->orig);
	cvResetImageROI(oimg->orig);
	CvPoint minloc;
	CvPoint maxloc;
	double minval, maxval;
	cvMinMaxLoc( map, &minval, &maxval, &minloc, &maxloc);
	bool minisbest = (method == CV_TM_SQDIFF || method==CV_TM_SQDIFF_NORMED);
	rect.x = rect.x + (minisbest ? minloc.x : maxloc.x);
	rect.y = rect.y + (minisbest ? minloc.y : maxloc.y);

	CvPoint shift = cvPoint(rect.x - orect.x, rect.y - orect.y);
	ShiftContour(oimg->contourArray[i],img->contourArray[i],shift);
	ShiftFeatPoints(oimg->feats[i], img->feats[i], cvPointTo32f(shift));
}
开发者ID:p1r4nh4,项目名称:CellTrack,代码行数:32,代码来源:MatchTemplatePlugin.cpp

示例5: is_eye_pair

/**
 * Experimentally-derived heuristics to determine whether
 * the connected components are eye pair or not.
 *
 * @param	CvSeq*  comp the connected components
 * @param	int     num  the number of connected components
 * @param   CvRect* eye  output parameter, will contain the location of the 
 *                       first component
 * @return	int          '1' if eye pair, '0' otherwise
 */
int
is_eye_pair(CvSeq* comp, int num, CvRect* eye)
{
	if (comp == 0 || num != 2)
		return 0;

	CvRect r1 = cvBoundingRect(comp, 1);
	comp = comp->h_next;

	if (comp == 0)
		return 0;

	CvRect r2 = cvBoundingRect(comp, 1);

	/* the width of the components are about the same */
	if (abs(r1.width - r2.width) >= 5)
		return 0;

	/* the height f the components are about the same */
	if (abs(r1.height - r2.height) >= 5)
		return 0;

	/* vertical distance is small */
	if (abs(r1.y - r2.y) >= 5)
		return 0;

	/* reasonable horizontal distance, based on the components' width */
	int dist_ratio = abs(r1.x - r2.x) / r1.width;
	if (dist_ratio < 2 || dist_ratio > 5)
		return 0;

	/* get the centroid of the 1st component */
	CvPoint point = cvPoint(
		r1.x + (r1.width / 2),
		r1.y + (r1.height / 2)
	);

	/* return eye boundaries */
	*eye = cvRect(
		point.x - (TPL_WIDTH / 2),
		point.y - (TPL_HEIGHT / 2),
		TPL_WIDTH,
		TPL_HEIGHT
	);

	return 1;
}
开发者ID:baselabdo,项目名称:eye-tracking-system,代码行数:57,代码来源:blink.cpp

示例6: rb_bounding_rect

/*
 * Calculates up-right bounding rectangle of point set.
 * @overload bounding_rect
 * @return [CvRect] Bounding rectangle
 * @opencv_func cvBoundingRect
 */
VALUE
rb_bounding_rect(VALUE self)
{
  CvRect rect;
  try {
    rect = cvBoundingRect(CVCONTOUR(self), 1);
  }
  catch (cv::Exception& e) {
    raise_cverror(e);
  }
  return cCvRect::new_object(rect);
}
开发者ID:HaiTo,项目名称:ruby-opencv,代码行数:18,代码来源:cvcontour.cpp

示例7: cvReleaseHist

void CamShiftPlugin::ProcessStatic
( int i, ImagePlus *img, ImagePlus *oimg, int *hsizes, CvTermCriteria criteria,
IplImage** &planes, CvHistogram* &hist, IplImage* &backproject, CvRect &orect, CvPoint &ocenter, CvRect &searchwin, CvMat* &rotation, CvMat* &shift, bool oready){
	if (hist && hist->mat.dim[0].size!=hsizes[0])
		cvReleaseHist(&hist);
	if( !hist )
        hist = cvCreateHist( 3, hsizes, CV_HIST_ARRAY, NULL, 0);
    if( !backproject )
		backproject = cvCreateImage( cvGetSize(img->orig), IPL_DEPTH_8U, 1 );
	if( !planes ){
	    planes = (IplImage**) malloc(3 * sizeof(IplImage*));
        for (int p=0; p<3; p++)
			planes[p] = cvCreateImage( cvGetSize(img->orig), 8, 1 );
	}
	if (!rotation)
		rotation = cvCreateMat(2,3,CV_32FC1);
	if (!shift)
		shift = cvCreateMat(2,1,CV_32FC1);

	if (!oready){
		orect = cvBoundingRect(oimg->contourArray[i],1);
		cvCvtPixToPlane( oimg->orig, planes[0], planes[1], planes[2], 0 );
        for (int p=0; p<3; p++)
            cvSetImageROI(planes[p],orect);
        cvCalcHist( planes, hist, 0, NULL );
		cvNormalizeHist(hist, 255);
        for (int p=0; p<3; p++)
            cvResetImageROI(planes[p]);
		searchwin = orect; //cvRect(0,0,img->orig->width, img->orig->height);
		ocenter = cvPoint(orect.x+orect.width/2, orect.y+orect.height/2);
	}
	//The following checks shouldn't be needed.
	RestrictRect(searchwin, cvRect(0,0,backproject->width,backproject->height));

	cvCvtPixToPlane( img->orig, planes[0], planes[1], planes[2], 0 );
    cvCalcBackProject( planes, backproject, hist );
	CvBox2D track_box;
	CvConnectedComp track_comp;
    cvCamShift( backproject, searchwin,
                criteria,
                &track_comp, &track_box );
	searchwin = track_comp.rect;
	cvmSet(shift,0,0,track_box.center.x - ocenter.x);
	cvmSet(shift,1,0,track_box.center.y - ocenter.y);
//	shift->data.fl[0] = track_box.center.x - ocenter.x;
//	shift->data.fl[1] = track_box.center.y - ocenter.y;
	cv2DRotationMatrix(track_box.center, track_box.angle, 1.0, rotation);
	cvTransform(oimg->contourArray[i],img->contourArray[i],rotation,shift);
//	CvMat *ofm = FeatPointsToMat(oimg->feats[i]);
//	Cvmat *fm  = FeatPointsToMat(img->feats[i]);
//	cvTransform(ofm,img->contourArray[i],rotation,shift);
	TransformFeatPoints(oimg->feats[i], img->feats[i], rotation, shift);
}
开发者ID:conanhung,项目名称:examples,代码行数:53,代码来源:CamShiftPlugin.cpp

示例8: cvZero

ClassifierOutputData ShapeClassifier::ClassifyFrame(IplImage *frame) {
	cvZero(guessMask);
	if (!isTrained) return outputData;
    if(!frame) return outputData;

    IplImage *copy = cvCreateImage( cvSize(frame->width, frame->height), IPL_DEPTH_8U, 3);
    IplImage *grayscale = cvCreateImage( cvSize(frame->width, frame->height), IPL_DEPTH_8U, 1);
    IplImage *newMask = cvCreateImage( cvSize(frame->width, frame->height), IPL_DEPTH_8U, 1);
    cvZero(newMask);

    cvCvtColor(frame, grayscale, CV_BGR2GRAY);
    cvCanny(grayscale, grayscale, SHAPE_CANNY_EDGE_LINK, SHAPE_CANNY_EDGE_FIND, SHAPE_CANNY_APERTURE);
	cvDilate(grayscale, grayscale, 0, 2);

    cvCvtColor(grayscale, copy, CV_GRAY2BGR);

    CvSeq *frameContours;
    CvMemStorage *storage = cvCreateMemStorage(0);
    cvFindContours(grayscale, storage, &frameContours, sizeof(CvContour), CV_RETR_EXTERNAL, CV_CHAIN_APPROX_TC89_KCOS);

    for (CvSeq *contour = frameContours; contour != NULL; contour = contour->h_next) {
        if ( contour->total > SHAPE_MIN_CONTOUR_POINTS) {
            int contourNum = 0;
            for (CvSeq *matchContour = templateContours; matchContour != NULL; matchContour = matchContour->h_next) {
//                double match_error = cvMatchShapes(contour, matchContour, CV_CONTOURS_MATCH_I1, 0);
                double match_error = pghMatchShapes(contour, matchContour);
				if (match_error < (0.75-threshold*.75)) {
                    cvDrawContours(copy, contour, colorSwatch[contourNum], CV_RGB(0,0,0), 0, 3, 8, cvPoint(0,0));
		            CvRect rect = cvBoundingRect(contour, 1);

                    // draw rectangle in mask image
                    cvRectangle(newMask, cvPoint(rect.x, rect.y), cvPoint(rect.x+rect.width, rect.y+rect.height), cvScalar(0xFF), CV_FILLED, 8);
                }
                contourNum = (contourNum+1) % COLOR_SWATCH_SIZE;
            }
        }
    }
    cvResize(copy, applyImage);
    IplToBitmap(applyImage, applyBitmap);

	// copy the final output mask
    cvResize(newMask, guessMask);

    cvReleaseMemStorage(&storage);
    cvReleaseImage(&copy);
    cvReleaseImage(&grayscale);
	cvReleaseImage(&newMask);

	UpdateStandardOutputData();
	return outputData;
}
开发者ID:gotomypc,项目名称:eyepatch,代码行数:51,代码来源:ShapeClassifier.cpp

示例9: cvCreateMemStorage

vector<CvRect> CImageProcess::CheckBounds(IplImage *img)
{
	CvMemStorage* storage = cvCreateMemStorage( 0 );        
	CvSeq* contours = NULL;        
	IplImage *imgTemp = cvCloneImage( img );        
	cvFindContours( imgTemp, storage, &contours, sizeof( CvContour ), CV_RETR_EXTERNAL, CV_CHAIN_APPROX_NONE );  
	vector<CvRect> rect;
	for( ; contours != NULL; contours = contours -> h_next )        
	{                
		CvRect _rect = cvBoundingRect( contours, 0 );    
		rect.push_back(_rect);
	//	cvRectangle( img, cvPoint( rect.x, rect.y ),cvPoint( rect.x + rect.width, rect.y + rect.height ), cvScalar(0,0,0), 0 );        
	}  
	return rect;
}
开发者ID:shengdewu,项目名称:repository,代码行数:15,代码来源:ImageProcess.cpp

示例10: cvBoundingRect

CvRect basicOCR::findFirstChar(CvSeq* seq, int column)
{
	CvRect rcFirst = {0};
	int y = 0;	// find first row
	int x = 0;

	for (CvSeq* c = seq; c != NULL; c = c->h_next)
	{
		CvRect rc = cvBoundingRect(c,0);
		if (rc.y > column)
		{
			if (y == 0)
				y = rc.y;
			else if (rc.y < y)
			{
				y = rc.y;
				x = rc.x;
			}
		}
	}

	for (CvSeq* c = seq; c != NULL; c = c->h_next)
	{
		CvRect rc = cvBoundingRect(c,0);
		if ((rc.y >= (y - rc.height / 2)) && (rc.y <= (y + rc.height / 2)))	// in the same row
		{
			if (rc.x < x)
			{
				x = rc.x;	// find first column
				rcFirst = cvBoundingRect(c, 0);
			}
		}
	}

	return rcFirst;	// if cannot find return 0
}
开发者ID:thunder176,项目名称:OCR_ASCII_Machine_Learning,代码行数:36,代码来源:basicOCR.cpp

示例11: main

int
main (int argc, char **argv)
{
    CvMemStorage *storage = cvCreateMemStorage( 0 );
    CvSeq *points = cvCreateSeq( CV_SEQ_ELTYPE_POINT, sizeof( CvSeq ), sizeof( CvPoint ), storage );
    cvSeqPush( points, &cvPoint( 100, 50 ) );
    cvSeqPush( points, &cvPoint( 50, 100 ) );
    cvSeqPush( points, &cvPoint( 50, 150 ) );
    cvSeqPush( points, &cvPoint( 150, 50 ) );

    CvRect rect = cvBoundingRect( points );
    cvPrintRect( rect );

    cvReleaseMemStorage( &storage );
    return 0;
}
开发者ID:andrey1227,项目名称:opencvx,代码行数:16,代码来源:cvboundingrect.cpp

示例12: GetContourFeature

//各種輪郭の特徴量の取得
void GetContourFeature(CvSeq *Contour) {
    //面積
    double Area = fabs(cvContourArea(Contour, CV_WHOLE_SEQ));
    //周囲長
    double Perimeter = cvArcLength(Contour);
    
    //円形度
    double CircleLevel = 4.0 * CV_PI * Area / (Perimeter * Perimeter);

    //傾いていない外接四角形領域(フィレ径)
    CvRect rect = cvBoundingRect(Contour);

    if(perimeter_max < Perimeter) {
        perimeter_max = Perimeter;
        max_perimeter_contor = Contour;
    }
}
开发者ID:yoshixmk,项目名称:develop-subject,代码行数:18,代码来源:production_environment_test2.cpp

示例13: cvBoundingRect

/**
 * @internal
 * Extracts the relevant information of the found blobs
 * @note when this method is called, the found blobs should be stored in m_blobs member
 */
void BlobFinder::extractBlobsInformation()
{
  // Order blobs (from bigger to smaller) -> this way the most relevant are at the beginning
  std::sort( m_blobs.begin(), m_blobs.end(), std::greater< Blob >() );

  // Discard blobs (if there is more than the max)
  // TODO

  // To store contour moments
  CvMoments moment;

  // to read contour points
	CvSeqReader contourReader;
	CvPoint		  contourNode;

  // Calculate information about contours
  for( Blobs::size_type i = 0; (i < m_blobs.size()) && (i < m_maxBlobs); ++i )
  {
      // Current blob
      Blob& blob = m_blobs[ i ];

      // Get bbox
      blob.bbox = cvBoundingRect( blob.contour );

      // Get center through moments
      cvMoments( blob.contour, &moment );
      blob.center.x = (float)(moment.m10 / moment.m00);
      blob.center.y = (float)(moment.m01 / moment.m00);

      // Invert Y coordinate because our Y 0 is at top of the image,
      // and for Opencv is at the bottom of the image
      //blob.center.Y = inImage.GetHeight() - blob.center.Y;

    // Store the contour nodes
    cvStartReadSeq( blob.contour, &contourReader );
    for( int j = 0; j < blob.contour->total; ++j )
    {
	    // Read node of the contour
	    CV_READ_SEQ_ELEM( contourNode, contourReader );
	    blob.nodes.push_back( Point( (float)contourNode.x, (float)contourNode.y , 0) );
    }
  }

	// Store number of actual blobs
	m_nBlobs = min( (int)m_blobs.size(), (int)m_maxBlobs );
}
开发者ID:space150,项目名称:space150-Cing,代码行数:51,代码来源:BlobFinder.cpp

示例14: COMMAND_FUNC

static COMMAND_FUNC( do_aspect_ratio )
{
	OpenCV_Seq *ocv_seq_p;
	ocv_seq_p=PICK_OCV_SEQ("sequence");
	if( ocv_seq_p == NO_OPENCV_SEQ ) return;
	if( ocv_seq_p->ocv_seq == NULL ) {
		sprintf(ERROR_STRING, "do_aspect_ratio: sequence is NULL.\n");
		//WARN(ERROR_STRING);
		return;
	}
	CvRect r = cvBoundingRect(ocv_seq_p->ocv_seq, 1);
	float aspectRatio = (float)(r.width)/(float)(r.height);
	char aspect[30];
	sprintf(aspect, "%f", aspectRatio);
	ASSIGN_VAR("contour_aspect", aspect);
	/*sprintf(ERROR_STRING,"Aspect ratio = %f", aspectRatio);
	WARN(ERROR_STRING);*/
}
开发者ID:E-LLP,项目名称:QuIP,代码行数:18,代码来源:opencv_menu.c

示例15: memcpy

void whu_MyHand::whu_GetFingerAngle(double &m_Angle)
{
	whu_Context.WaitNoneUpdateAll();
	//double m_Angle;
	int min_val;
	int FingerNum=0;//得到的指尖的个数//
	static int m_HandOpen=0;
	static int m_handClosed=0;
	memcpy(imgDepth16u->imageData,whu_DepthMD.Data(),640*480*2);
	cvConvertScale(imgDepth16u,depthShow,255/4096.0,0);      //转化为灰度图
	min_val = min_front(depthShow);    //取得灰度图最前端
	get_gray_hand(depthShow, min_val);

	CvRect rect = cvBoundingRect( contours, 0 );//返回一个2d矩形的点集合//得到包含轮廓的最小矩形
	for(int i = 20;i < contours->total;i++)
	{
		CvPoint *p = CV_GET_SEQ_ELEM(CvPoint,contours,i);
		CvPoint *a = CV_GET_SEQ_ELEM(CvPoint,contours,i-10);
		CvPoint *b = CV_GET_SEQ_ELEM(CvPoint,contours,i+10);
		if((double)((a->x-b->x)*(a->x-b->x)+(a->y-b->y)*(a->y-b->y))/(double)((a->x-p->x)*(a->x-p->x)+(a->y-p->y)*(a->y-p->y))<0.9)//&&cvGetReal2D(cpimg,(a->x+b->x)/2,(a->y+b->y)/2) >1)      //&&*(uchar*)(depthShow->imageData+((a->y+b->y)/2)*depthShow->widthStep)[(a->x+b->x)/2]==1
		{
			if((p->x-rect.x-(rect.width)/2)*(p->x-rect.x-(rect.width)/2)+(p->y-rect.y-(rect.height)/2)*(p->y-rect.y-(rect.height)/2) > rect.height*rect.height/10)//???
			{
				FingerNum++;
			}
		}
	}
	if (FingerNum>5)
	{
			if (m_Angle<150)
			{
				m_Angle=m_Angle+15;
			}
	} 
	else
	{
		if (m_Angle>60)
		{
			m_Angle=m_Angle-15;
		}
	}
	

}
开发者ID:ShelmyLin,项目名称:Powerful_Atom_Hand,代码行数:44,代码来源:whu_MyHand.cpp


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