本文整理汇总了C++中cvContourArea函数的典型用法代码示例。如果您正苦于以下问题:C++ cvContourArea函数的具体用法?C++ cvContourArea怎么用?C++ cvContourArea使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了cvContourArea函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。
示例1: 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
示例2: ratioCheck
static char ratioCheck(CvSeq* c1, CvSeq* c2, double areaRatioMax, double heightRatioMax){
double area1, area2;
double height1, height2;
double areaRatio, heightRatio;
CvRect r1, r2;
area1=fabs(cvContourArea(c1, CV_WHOLE_SEQ,0));
area2=fabs(cvContourArea(c2, CV_WHOLE_SEQ,0));
r1 = ((CvContour *) c1)->rect;
r2 = ((CvContour *) c2)->rect;
height1 = r1.height;
height2 = r2.height;
if(height1 > height2) areaRatio = height1/height2;
else areaRatio = height2/height1;
if(area1 > area2) areaRatio = area1/area2;
else areaRatio = area2/area1;
if(areaRatio <= areaRatioMax && heightRatio <= heightRatioMax) {
return 1;
}
return 0;
}
开发者ID:Zazcallabah,项目名称:dotdetector,代码行数:27,代码来源:shapedetector.c
示例3: sort_carea_compare
//--------------------------------------------------------------------------------
bool sort_carea_compare( const CvSeq* a, const CvSeq* b) {
// use opencv to calc size, then sort based on size
float areaa = fabs(cvContourArea(a, CV_WHOLE_SEQ));
float areab = fabs(cvContourArea(b, CV_WHOLE_SEQ));
//return 0;
return (areaa > areab);
}
开发者ID:Akira-Hayasaka,项目名称:ofxOpenCV22,代码行数:9,代码来源:ofxCvContourFinder.cpp
示例4: qsort_carea_compare
//--------------------------------------------------------------------------------
static int qsort_carea_compare( const void* _a, const void* _b) {
int out = 0;
// pointers, ugh.... sorry about this
CvSeq* a = *((CvSeq **)_a);
CvSeq* b = *((CvSeq **)_b);
// use opencv to calc size, then sort based on size
float areaa = fabs(cvContourArea(a, CV_WHOLE_SEQ));
float areab = fabs(cvContourArea(b, CV_WHOLE_SEQ));
// note, based on the -1 / 1 flip
// we sort biggest to smallest, not smallest to biggest
if( areaa > areab ) { out = -1; }
else { out = 1; }
return out;
}
开发者ID:Ahmedn1,项目名称:ccv-hand,代码行数:15,代码来源:ContourFinder.cpp
示例5: areaFilter
int Contours::areaFilter(double min_area,double max_area){
double area;
area=fabs(cvContourArea(this->c,CV_WHOLE_SEQ));
return area> min_area && area<max_area;
}
开发者ID:margguo,项目名称:tpf-robotica,代码行数:7,代码来源:Contours.cpp
示例6: onMouse
//When the user clicks in the window...
void onMouse(int event, int x, int y, int flags, void *params){
//params points to the contour sequence. Here we cast the pointer to CvContour instead of CvSeq.
//CvContour is in fact an extension of CvSeq and is the structure used by cvFindContours, if we cast
//to CvSeq, we won't be able to access the fields specific to CvContour.
CvContour *contours = *(CvContour **)params;
CvContour *ctr; //This will point to the specific contour the user clicked in.
double area; //This will hold the area of the contour the user clicked in.
if(!contours)return; //If there are no contours, we don't bother doing anything.
//"event" tells us what occured
switch(event){
case CV_EVENT_LBUTTONDOWN: //single click
case CV_EVENT_LBUTTONDBLCLK: //double click
printf("Click: %d %d\n",x,y); //Write out where the user clicked.
//Here we retrieve the inner-most contour the user clicked in. If there is no such contour,
//the function returns a null pointer, which we need to check against.
ctr = contourFromPosition(contours, x, y);
if(ctr){ //The user did click inside something
//Calculate the area of the contour using cvContourArea. CV_WHOLE_SEQ means we want the area of the whole contour.
//Important: we need to calculate the absolute value of the result using fabs because cvContourArea can return negative values.
area = fabs(cvContourArea(ctr, CV_WHOLE_SEQ,0));
printf("Area: %f\n",area); //and print the result out.
}
break;
case CV_EVENT_LBUTTONUP: //single click up
case 10: //double-click up? (not documented)
break;
}
}
开发者ID:biotrump,项目名称:mip,代码行数:33,代码来源:findContour.c
示例7: catcierge_haar_matcher_count_contours
size_t catcierge_haar_matcher_count_contours(catcierge_haar_matcher_t *ctx, CvSeq *contours)
{
size_t contour_count = 0;
double area;
int big_enough = 0;
CvSeq *it = NULL;
assert(ctx);
assert(ctx->args);
if (!contours)
return 0;
it = contours;
while (it)
{
area = cvContourArea(it, CV_WHOLE_SEQ, 0);
big_enough = (area > 10.0);
if (ctx->super.debug) printf("Area: %f %s\n", area, big_enough ? "" : "(too small)");
if (big_enough)
{
contour_count++;
}
it = it->h_next;
}
return contour_count;
}
开发者ID:JoakimSoderberg,项目名称:catcierge,代码行数:29,代码来源:catcierge_haar_matcher.c
示例8: 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
示例9: 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
示例10: 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
示例11: 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
示例12: 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
示例13: getArea
/*retuns Area of the contour*/
double Contours::getArea(){
if(this->area==-1){
this->area=fabs(cvContourArea(this->c,CV_WHOLE_SEQ));
}
return this->area;
}
开发者ID:margguo,项目名称:tpf-robotica,代码行数:9,代码来源:Contours.cpp
示例14: cvConvexHull2
double CBlobGetHullArea::operator()(const CBlob &blob) const
{
if(blob.Edges() != NULL && blob.Edges()->total > 0)
{
CvSeq *hull = cvConvexHull2( blob.Edges(), 0, CV_CLOCKWISE, 1 );
return fabs(cvContourArea(hull));
}
return blob.Perimeter();
}
开发者ID:Karma-Revolutions,项目名称:icub-main,代码行数:9,代码来源:Blob.cpp
示例15: THROW_EXCEPTION
/**
* @internal
* @brief Find the blobs in the received image.
* What it looks for in an image is bright areas, so typically
* the image result of a background subtraction is a good input.
*
* @param[in] inImage image where the blobs will be searched
*/
void BlobFinder::update( const Image& inImage )
{
// Check valid
if ( !isValid() )
THROW_EXCEPTION( "Trying to compute blobs, with the BlobFinder not initialized. Init method should be called" );
// Check blob area... and if it has not been set, set it to the max and min (no lower than 10, to avoid opencv issues)
if ( (m_minBlobArea < 0) || (m_maxBlobArea < 0) )
{
m_minBlobArea = 10;
m_maxBlobArea = (float)inImage.getWidth() * (float)inImage.getHeight();
}
// Check both images have same size and it is the same than the filter size
if( (inImage.getNChannels() != 1) && (inImage.getNChannels() != 3) )
THROW_EXCEPTION( "Trying to compute blobs on images with non supporte format -> only RGB or GRAYSCALE images supported" );
// Request temp image to work with
IplImage* cvTempImage = ImageResourceManager::getSingleton().getImage( inImage.getWidth(), inImage.getHeight(), 1 );
// If they have different number of channels -> convert them
if ( inImage.getNChannels() == 3 )
cvConvertImage( &inImage.getCVImage(), cvTempImage );
// just one channel -> Copy the input image
else
cvCopy( &inImage.getCVImage(), cvTempImage );
// Find blobs (openCV contours)
int retrivalMode = CV_RETR_EXTERNAL; // CV_RETR_CCOMP
cvFindContours( cvTempImage, m_findContoursStorage, &m_contour, sizeof(CvContour), retrivalMode, CV_CHAIN_APPROX_SIMPLE );
// Extract found contours
// Iterate through found contours and store them..
m_blobs.clear();
for( ; m_contour != 0; m_contour = m_contour->h_next )
{
// Get contour area
double area = fabs( cvContourArea( m_contour, CV_WHOLE_SEQ ) );
// If it has a good size (between min and max)
if ( ( area > m_maxBlobArea ) || ( area < m_minBlobArea ) )
continue;
// Store new Blob
m_blobs.push_back( Blob( area, m_contour ) );
}
// Release temp image
ImageResourceManager::getSingleton().releaseImage( cvTempImage );
// Extract information of found blobs
extractBlobsInformation();
// Clear OpenCV contours storage
cvClearMemStorage( m_findContoursStorage );
}
开发者ID:space150,项目名称:space150-Cing,代码行数:65,代码来源:BlobFinder.cpp
示例16: find_connected_components
static void
find_connected_components (IplImage * mask, int poly1_hull0, float perimScale,
CvMemStorage * mem_storage, CvSeq * contours)
{
CvContourScanner scanner;
CvSeq *c;
int numCont = 0;
/* Just some convenience variables */
const CvScalar CVX_WHITE = CV_RGB (0xff, 0xff, 0xff);
const CvScalar CVX_BLACK = CV_RGB (0x00, 0x00, 0x00);
/* CLEAN UP RAW MASK */
cvMorphologyEx (mask, mask, 0, 0, CV_MOP_OPEN, CVCLOSE_ITR);
cvMorphologyEx (mask, mask, 0, 0, CV_MOP_CLOSE, CVCLOSE_ITR);
/* FIND CONTOURS AROUND ONLY BIGGER REGIONS */
if (mem_storage == NULL) {
mem_storage = cvCreateMemStorage (0);
} else {
cvClearMemStorage (mem_storage);
}
scanner = cvStartFindContours (mask, mem_storage, sizeof (CvContour),
CV_RETR_TREE, CV_CHAIN_APPROX_SIMPLE, cvPoint (0, 0));
while ((c = cvFindNextContour (scanner)) != NULL) {
double len = cvContourArea (c, CV_WHOLE_SEQ, 0);
/* calculate perimeter len threshold: */
double q = (mask->height + mask->width) / perimScale;
/* Get rid of blob if its perimeter is too small: */
if (len < q) {
cvSubstituteContour (scanner, NULL);
} else {
/* Smooth its edges if its large enough */
CvSeq *c_new;
if (poly1_hull0) {
/* Polygonal approximation */
c_new =
cvApproxPoly (c, sizeof (CvContour), mem_storage, CV_POLY_APPROX_DP,
CVCONTOUR_APPROX_LEVEL, 0);
} else {
/* Convex Hull of the segmentation */
c_new = cvConvexHull2 (c, mem_storage, CV_CLOCKWISE, 1);
}
cvSubstituteContour (scanner, c_new);
numCont++;
}
}
contours = cvEndFindContours (&scanner);
/* PAINT THE FOUND REGIONS BACK INTO THE IMAGE */
cvZero (mask);
/* DRAW PROCESSED CONTOURS INTO THE MASK */
for (c = contours; c != NULL; c = c->h_next)
cvDrawContours (mask, c, CVX_WHITE, CVX_BLACK, -1, CV_FILLED, 8, cvPoint (0,
0));
}
开发者ID:PeterXu,项目名称:gst-mobile,代码行数:56,代码来源:gstsegmentation.cpp
示例17: areaFilter
int Contours::areaFilter(double min_area,double max_area){
double area;
area=fabs(cvContourArea(this->c,CV_WHOLE_SEQ));
int zone=getPointZone(this->x,this->y);
double minAreaByZone[]={0,200,150,65,50};
//double maxAreaByZone[]={0,800,400,200,100};
double maxAreaByZone[]={0,1000,550,350,250};
return area>minAreaByZone[zone] && area<maxAreaByZone[zone];
}
开发者ID:margguo,项目名称:tpf-robotica,代码行数:13,代码来源:Contours.cpp
示例18: LargestContour
//This boolean function returns whether the (x,y) point is inside the given contour.
CvContour * LargestContour(void *contours){
//We know that a point is inside a contour if we can find one point in the contour that is immediately to the left,
//one that is immediately on top, one that is immediately to the right and one that is immediately below the (x,y) point.
//We will update the boolean variables below when these are found:
char found_left=0, found_top=0, found_right=0, found_bottom=0;
int count, i; //Variables used for iteration
if(!contours)return 0; //Don't bother doing anything if there is no contour.
CvContour *output=NULL, *contour = *(CvContour **)contours;
float maxArea=0.0f;
while(contour){ //We loop through the list of contours...
float area=0.0;
area = fabs(cvContourArea(contour, CV_WHOLE_SEQ,0));
if(maxArea < area){
maxArea = area;
output = contour;
}
count = contour->total; //The total field holds the number of points in the contour.
printf("outside contour : area=%f, points=%d\n",area, count);
CvContour *inside=(CvContour *)contour->v_next;
while(inside){ //Check to see if the point the user clicked on is inside the current contour, if yes...
//output = contour; //Since the point is inside the contour, set the output accordingly.
area = fabs(cvContourArea(inside, CV_WHOLE_SEQ,0));
count = inside->total; //The total field holds the number of points in the contour.
printf(" inside Area: area=%f, points=%d\n", area, count); //and print the result out.
//We now need to check all the contours inside the one we are processing. We go down one level by following the v_next (vertical next) pointer in the
//CvSeq/CvContour structure. From then, we recurse into this function to go through all the contours.
inside = (CvContour *)inside->v_next;
}
//Once we're done with this contour, we need to move to the following contour that's not included in the one we just processed.
//This is pointed to by the h_next (horizontal next) pointer.
contour = (CvContour *)(contour->h_next);
}
printf("max contour %p, area=%f\n",output, maxArea);
return output;
}
开发者ID:biotrump,项目名称:mip,代码行数:39,代码来源:findContour.c
示例19: COMMAND_FUNC
static COMMAND_FUNC( do_ocv_area )
{
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_ocv_area: sequence is NULL.\n");
WARN(ERROR_STRING);
return;
}
/* Not sure when this change took effect... */
//#if CV_VERSION_INT > MAKE_VERSION_INT(1,1,0)
#if CV_VERSION_INT > MAKE_VERSION_INT(2,0,0)
float area = fabs(cvContourArea(ocv_seq_p->ocv_seq, CV_WHOLE_SEQ, 0 ));
#else
float area = fabs(cvContourArea(ocv_seq_p->ocv_seq, CV_WHOLE_SEQ ));
#endif
char area_string[30];
sprintf(area_string, "%f", area);
ASSIGN_VAR("contour_area", area_string);
}
开发者ID:E-LLP,项目名称:QuIP,代码行数:23,代码来源:opencv_menu.c
示例20: while
CvSeq* BallIdentification::findLargerBlob(CvSeq* contours){
double largestArea = 0; //Const. for the largest area
CvSeq* largest_contour = NULL; //Contour for the largest area
while (contours != NULL){ //If the current contour available
double area = fabs(cvContourArea(contours,CV_WHOLE_SEQ, false)); //Get the current contour's area as "area"
if(area > largestArea){ //If "area" is larger than the previous largest area
largestArea = area;
largest_contour = contours;
}
contours = contours->h_next; //Search for the next contour
}
return largest_contour;
}
开发者ID:unball,项目名称:vision,代码行数:14,代码来源:ball_identification.cpp
注:本文中的cvContourArea函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论