本文整理汇总了C++中cvDrawContours函数的典型用法代码示例。如果您正苦于以下问题:C++ cvDrawContours函数的具体用法?C++ cvDrawContours怎么用?C++ cvDrawContours使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了cvDrawContours函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: preprocess
IplImage* preprocess(IplImage* img){ //creates a Image with the contours in the picture
CvMemStorage* g_storage = NULL;
IplImage* gray;
gray = cvCreateImage( cvGetSize( img ), 8, 1 ); //creates the immage, allocating memory for the pixel values
g_storage = cvCreateMemStorage(0);
cvClearMemStorage( g_storage );
CvSeq* contours = 0;
cvCvtColor( img, gray, CV_BGR2GRAY );
cvThreshold( gray, gray, 100, 255, CV_THRESH_BINARY );
cvFindContours( gray, g_storage, &contours ); //find the contours with the thresholdimmage
cvZero( gray );
if( contours )
{
cvDrawContours(gray,contours,cvScalarAll(255),cvScalarAll(255),100 ); //paint the contours on immage contours
}
return gray;
}
示例2: main
int main(int argc, char **argv)
{
int thresh = 128;
int erode = 0;
int dilate = 0;
int do_contour = 0;
IplImage *image_bw = cvCreateImage(SIZE, 8, 1);
IplImage *image_thresh = cvCreateImage(SIZE, 8, 1);
IplImage *image_temp = cvCreateImage(SIZE, 8, 1);
cvNamedWindow("config", CV_WINDOW_AUTOSIZE);
cvCreateTrackbar("threshold", "config", &thresh, 255, NULL);
cvCreateTrackbar("erode", "config", &erode, 10, NULL);
cvCreateTrackbar("dilate", "config", &dilate, 10, NULL);
cvCreateTrackbar("contour", "config", &do_contour, 1, NULL);
CvMemStorage *storage = cvCreateMemStorage();
while (cvWaitKey(10) < 0) {
IplImage *image = freenect_sync_get_rgb_cv(0);
if (!image) {
printf("Error: Kinect not connected?\n");
return -1;
}
cvCvtColor(image, image, CV_RGB2BGR);
cvCvtColor(image, image_bw, CV_RGB2GRAY);
cvThreshold(image_bw, image_thresh, thresh, 255, CV_THRESH_BINARY);
cvErode(image_thresh, image_thresh, NULL, erode);
cvDilate(image_thresh, image_thresh, NULL, dilate);
if (do_contour) {
CvSeq *contours;
cvCopy(image_thresh, image_temp);
cvFindContours(image_temp, storage, &contours);
cvDrawContours(image, contours, CV_RGB(0, 255, 0), CV_RGB(0, 255, 255), 1);
}
cvShowImage("RGB", image);
cvShowImage("BW", image_bw);
cvShowImage("THRESH", image_thresh);
}
return 0;
}
示例3: node_composit_exec_cvDrawContour
static void node_composit_exec_cvDrawContour(void *data, bNode *node, bNodeStack **in, bNodeStack **out)
{
IplImage *img, *dst, *img1, *img2, *img3,*imgRed, *umbral;
CvMemStorage* storage = cvCreateMemStorage(0);
CvSeq* contour = 0;
//TODO: Use atach buffers
if(out[0]->hasoutput==0) return;
img=in[0]->data;
dst = cvCreateImage( cvGetSize(img), 8, 3 );
img1=cvCreateImage(cvGetSize(img),IPL_DEPTH_8U,1);
img2=cvCreateImage(cvGetSize(img),IPL_DEPTH_8U,1);
img3=cvCreateImage(cvGetSize(img),IPL_DEPTH_8U,1);
imgRed=cvCreateImage(cvGetSize(img),IPL_DEPTH_8U,1);
umbral=cvCreateImage(cvGetSize(img),IPL_DEPTH_8U,1);
cvSplit(img, img1, img2, imgRed, img3);
cvThreshold( umbral,imgRed,210,255, CV_THRESH_BINARY );
cvFindContours( img, storage, &contour, sizeof(CvContour),CV_RETR_CCOMP, CV_CHAIN_APPROX_SIMPLE,cvPoint(0, 0) );
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, cvPoint(0,0) );
}
out[0]->data= dst;
/*CvSeq* contour = in[1]->data;
if(in[0]->data && in[1]->data){
IplImage* dst = cvCreateImage( cvGetSize(image), 8, 3 );
cvZero(dst);
//cvDrawContours( dst, contour, CV_RGB(255,0,0),CV_RGB(0,255,0), -1,3, CV_AA,cvPoint(0,0));
CvSeq* c=contour;
for( ; c != 0; c = c->h_next )
{
CvScalar color = CV_RGB( rand()&255, rand()&255, rand()&255 );
cvDrawContours( dst, c, color, color, -1, 1, 8 ,cvPoint(0,0));
}
out[0]->data= dst;
}*/
}
示例4: cvGetMat
CvSeq*cvSegmentFGMask(CvArr* _mask, int poly1Hull0, float perimScale, CvMemStorage* storage, CvPoint offset)
{
CvMat mstub, *mask = cvGetMat(_mask, &mstub);
CvMemStorage* tempStorage = storage ? storage : cvCreateMemStorage();
CvSeq *contours, *c;
int nContours = 0;
CvContourScanner scanner;
// clean up raw mask
cvMorphologyEx(mask, mask, 0, 0, CV_MOP_OPEN, 1);
cvMorphologyEx(mask, mask, 0, 0, CV_MOP_CLOSE, 1);
// find contours around only bigger regions
scanner = cvStartFindContours(mask, tempStorage,
sizeof(CvContour), CV_RETR_EXTERNAL, CV_CHAIN_APPROX_SIMPLE, offset);
while ((c = cvFindNextContour(scanner)) != 0)
{
double len = cvContourPerimeter(c);
double q = (mask->rows + mask->cols) / perimScale; // calculate perimeter len threshold
if (len < q) //Get rid of blob if it's perimeter is too small
cvSubstituteContour(scanner, 0);
else //Smooth it's edges if it's large enough
{
CvSeq* newC;
if (poly1Hull0) //Polygonal approximation of the segmentation
newC = cvApproxPoly(c, sizeof(CvContour), tempStorage, CV_POLY_APPROX_DP, 2, 0);
else //Convex Hull of the segmentation
newC = cvConvexHull2(c, tempStorage, CV_CLOCKWISE, 1);
cvSubstituteContour(scanner, newC);
nContours++;
}
}
contours = cvEndFindContours(&scanner);
// paint the found regions back into the image
cvZero(mask);
for (c = contours; c != 0; c = c->h_next)
cvDrawContours(mask, c, cvScalarAll(255), cvScalarAll(0), -1, CV_FILLED, 8,
cvPoint(-offset.x, -offset.y));
if (tempStorage != storage)
{
cvReleaseMemStorage(&tempStorage);
contours = 0;
}
return contours;
}
示例5: cvCreateMemStorage
void moBlobFinderModule::applyFilter(IplImage *src) {
this->storage = cvCreateMemStorage(0);
this->clearBlobs();
this->storage = cvCreateMemStorage(0);
cvCopy(src, this->output_buffer);
CvSeq *contours = 0;
cvFindContours(this->output_buffer, this->storage, &contours, sizeof(CvContour), CV_RETR_CCOMP);
cvDrawContours(this->output_buffer, contours, cvScalarAll(255), cvScalarAll(255), 100);
// Consider each contour a blob and extract the blob infos from it.
int size;
int ratio;
int min_size = this->property("min_size").asInteger();
int max_size = this->property("max_size").asInteger();
CvSeq *cur_cont = contours;
while (cur_cont != 0) {
CvRect rect = cvBoundingRect(cur_cont, 0);
size = rect.width * rect.height;
// Check ratio to make sure blob can physically represent a finger
// magic number 6 is used for now to represent maximum ratio of
// Length/thickness of finger
if (rect.width < rect.height) {
ratio = rect.height / (double)rect.width;
} else {
ratio = rect.width / (double)rect.height;
}
if ((ratio <= 6) && (size >= min_size) && (size <= max_size)) {
moDataGenericContainer *blob = new moDataGenericContainer();
blob->properties["implements"] = new moProperty("pos,size");
blob->properties["x"] = new moProperty((rect.x + rect.width / 2) / (double) src->width);
blob->properties["y"] = new moProperty((rect.y + rect.height / 2) / (double) src->height);
blob->properties["width"] = new moProperty(rect.width);
blob->properties["height"] = new moProperty(rect.height);
this->blobs->push_back(blob);
cvRectangle(this->output_buffer, cvPoint(rect.x,rect.y), cvPoint(rect.x + rect.width,rect.x + rect.height), cvScalar(250,10,10), 1);
}
cur_cont = cur_cont->h_next;
}
cvReleaseMemStorage(&this->storage);
this->output_data->push(this->blobs);
}
示例6: main
int main()
{
const int imgHeight = 500;
const int imgWidth = 500;
IplImage* pImgSrc = cvCreateImage(cvSize(imgWidth, imgHeight), IPL_DEPTH_8U, 1); // Ôʼͼ
IplImage* pImgContour = NULL; // ÂÖÀªÍ¼
CvMemStorage* pMemStorage = cvCreateMemStorage(0); // ÁÙʱ´æ´¢Çø
CvSeq* pContour = 0; // ´æ´¢ÂÖÀªµã
// »æÖÆÔʼͼƬ
DrawImage(pImgSrc);
// ÏÔʾÔʼͼ
cvNamedWindow("Source", CV_WINDOW_AUTOSIZE);
cvShowImage("Source", pImgSrc);
// ΪÂÖÀªÍ¼ÉêÇë¿Õ¼ä, 3ͨµÀͼÏñ
pImgContour = cvCreateImage(cvGetSize(pImgSrc), IPL_DEPTH_8U, 3);
// ½«µ¥Í¨µÀ»Ò¶Èͼת»¯Îª3ͨµÀ»Ò¶Èͼ
//cvCvtColor(pImgSrc, pImgContour, CV_GRAY2BGR);
cvZero(pImgContour);
// ²éÕÒÂÖÀª
cvFindContours(pImgSrc, pMemStorage, &pContour, sizeof(CvContour), CV_RETR_TREE, CV_CHAIN_APPROX_SIMPLE, cvPoint(0, 0));
// ½«ÂÖÀª»³ö
cvDrawContours(pImgContour, pContour, CV_RGB(0, 0, 255), CV_RGB(255, 0, 0), 2, 2, 8, cvPoint(0, 0));
// ÏÔʾÂÖÀªÍ¼
cvNamedWindow("Contour", CV_WINDOW_AUTOSIZE);
cvShowImage("Contour", pImgContour);
cvWaitKey(0);
cvDestroyWindow("Contour");
cvDestroyWindow("Source");
cvReleaseImage(&pImgSrc);
cvReleaseImage(&pImgContour);
cvReleaseMemStorage(&pMemStorage);
return 0;
}
示例7: startTracking
void MeanShift::startTracking(const Image* image, const CvConnectedComp* cComp)
{
if (!cComp->contour) /* Not really connected component */
return startTracking(image, cComp->rect);
Image* mask = new Image(image->size(), UByte, 1);
cvDrawContours(mask->cvImage(),
cComp->contour,
cvScalar(255),
cvScalar(255),
-1,
CV_FILLED,
8);
delete m_trackingHist;
m_trackingHist = Histogram::createHSHistogram(image, mask);
m_lastPostition = cComp->rect;
delete mask;
}
示例8: contour
IplImage* contour(IplImage* img)
{
static int i;
char fileName[20];
CvMemStorage* store;
IplImage* aux=NULL;
if(aux == NULL)
{
aux = cvCreateImage(cvGetSize(img),8,1);
store = cvCreateMemStorage(0);
}
CvSeq * contours =0;
cvFindContours(img,store,&contours); //finding contours in an image
cvZero(aux);
//if(contours->total)
{
cvDrawContours(aux,contours,cvScalarAll(255),cvScalarAll(255),100);
}
CvMoments *moments = (CvMoments*)malloc(sizeof(CvMoments));
double M00, M01, M10;
fruitCount=0;
while(contours!=NULL) //detects the moments means coords of individual contours
{
if( cvContourArea(contours,CV_WHOLE_SEQ) < 5 ) //detects only sizable objects
{
contours = contours->h_next;
continue;
}
cvMoments(contours, moments);
M00 = cvGetSpatialMoment(moments,0,0);
M10 = cvGetSpatialMoment(moments,1,0);
M01 = cvGetSpatialMoment(moments,0,1);
centers[fruitCount].x = (int)(M10/M00); //global variable, stores the centre coords of an object
centers[fruitCount].y = (int)(M01/M00);
fruitCount++; //important global variable, it represents the total no. of objects detected in the image if it is zero the no action :)
contours = contours->h_next;
}
cvClearMemStorage(store);
return aux;
}
示例9: malloc
/*
* Prints a contour on a dst Image. Used for debugging.
* prints text at the side of a contour.
* depthLevel sets the level in the contour tree(to include/exclue holes)
*/
void Contours::printContour(int depthLevel, CvScalar color,IplImage * dst){
CvFont font;
int line_type=CV_AA;
char * a=(char *) malloc(20);
char * b=(char *) malloc(20);
char * c=(char *) malloc(20);
char * d=(char *) malloc(20);
char * e=(char *) malloc(20);
cvDrawContours( dst, this->c, CV_RGB(255,0,0), CV_RGB(0,255,0),
depthLevel, 3, CV_AA, cvPoint(0,0) );
CvMemStorage* mem = cvCreateMemStorage(0);
CvBox2D box=cvMinAreaRect2(this->c,mem);
//~ traversePoints(this->c);
std::vector<int> centroid=this->getCentroid();
CvPoint pt2=cvPoint(centroid[0]+5,centroid[1]+5);
CvPoint pt3=cvPoint(centroid[0]+5,centroid[1]+15);
CvPoint pt4=cvPoint(centroid[0]+5,centroid[1]+25);
CvPoint pt5=cvPoint(centroid[0]+5,centroid[1]+35);
CvPoint pt6=cvPoint(centroid[0]+5,centroid[1]+45);
sprintf(a,"per: %g",this->getPerimeter());
sprintf(b,"zone: %d",getPointZone(this->x,this->y));
sprintf(c,"area: %g",this->getArea());
sprintf(d,"ecc: %g",this->getPerimeter()*this->getPerimeter()/this->getArea());
//~ sprintf(d,"boxArea: %g",(double) this->getArea()/(box.size.width*box.size.height));
cvInitFont( &font, CV_FONT_HERSHEY_COMPLEX, 0.5, 0.5, 0.0,0.5, line_type );
cvPutText( dst, a, pt2, &font, CV_RGB(255,255,0));
cvPutText( dst, c, pt3, &font, CV_RGB(255,255,0));
cvPutText( dst, b, pt4, &font, CV_RGB(255,255,0));
cvPutText( dst, d, pt5, &font, CV_RGB(255,255,0));
//~ free(a);
cvReleaseMemStorage(&mem);
}
示例10: _tmain
int _tmain(int argc, _TCHAR* argv[])
{
CvSeq* contours = NULL;
CvMemStorage* storage = cvCreateMemStorage(0);
IplImage* img = cvLoadImage("answer_reveal.png");
cvNamedWindow("win");
IplImage* grayImg = cvCreateImage(cvGetSize(img), 8, 1);
cvCvtColor(img, grayImg, CV_RGB2GRAY);
cvThreshold(grayImg, grayImg, 160, 255, CV_THRESH_BINARY);
cvFindContours(grayImg, storage, &contours);
// cvZero(grayImg); -- if we were displaying the gray image with the contours, in only black and white
if (contours) {
cvDrawContours(img, contours,
cvScalar(255, 0, 0), // ext color (red)
cvScalar(0, 255, 0), // hole color (green)
100, // max level of contours to draw
5); // thickness
}
cvShowImage("win", img);
// experiment to read a frame from an image
CvCapture* capture = cvCaptureFromFile("C:\\Projects\\meancat\\misc\\100Bot\\1v100_translated.mpeg");
if (capture == NULL) {
printf("capture is null");
} else {
cvSetCaptureProperty(capture, CV_CAP_PROP_POS_FRAMES, 0);
IplImage* oneFrame = cvQueryFrame(capture);
cvShowImage("win", oneFrame);
}
cvWaitKey(0);
cvReleaseImage(&img);
cvReleaseImage(&grayImg);
return 0;
}
示例11: connected_components
CvSeq* connected_components( IplImage* source, IplImage* result )
{
IplImage* binary_image = cvCreateImage( cvGetSize(source), 8, 1 );
cvConvertImage( source, binary_image );
CvMemStorage* storage = cvCreateMemStorage(0);
CvSeq* contours = 0;
cvThreshold( binary_image, binary_image, 1, 255, CV_THRESH_BINARY );
cvFindContours( binary_image, storage, &contours, sizeof(CvContour), CV_RETR_CCOMP, CV_CHAIN_APPROX_SIMPLE );
if (result)
{
cvZero( result );
for(CvSeq* contour = contours ; 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( result, contour, color, color, -1, CV_FILLED, 8 );
}
}
return contours;
}
示例12: cvZero
void ShapeClassifier::UpdateContourImage() {
cvZero(filterImage);
// first, determine how many template contours we need to draw by counting the length of the sequence
int numContours = 0;
for (CvSeq *contour = templateContours; contour != NULL; contour = contour->h_next) {
numContours++;
}
if (numContours > 0) {
int gridSize = (int) ceil(sqrt((double)numContours));
int gridX = 0;
int gridY = 0;
int gridSampleW = FILTERIMAGE_WIDTH / gridSize;
int gridSampleH = FILTERIMAGE_HEIGHT / gridSize;
int contourNum = 0;
for (CvSeq *contour = templateContours; contour != NULL; contour = contour->h_next) {
cvSetImageROI(filterImage, cvRect(gridX*gridSampleW, gridY*gridSampleH, gridSampleW, gridSampleH));
CvRect bounds = cvBoundingRect(contour, 1);
int contourSize = max(bounds.width, bounds.height);
IplImage *contourImg = cvCreateImage(cvSize(contourSize, contourSize), filterImage->depth, filterImage->nChannels);
cvZero(contourImg);
cvDrawContours(contourImg, contour, colorSwatch[contourNum], CV_RGB(255,255,255), 0, 2, CV_AA, cvPoint(-bounds.x, -bounds.y));
cvResize(contourImg, filterImage);
cvReleaseImage(&contourImg);
cvResetImageROI(filterImage);
contourNum = (contourNum+1) % COLOR_SWATCH_SIZE;
gridX++;
if (gridX >= gridSize) {
gridX = 0;
gridY++;
}
}
}
IplToBitmap(filterImage, filterBitmap);
}
示例13: cvCreateImage
void Frame::fill()
{
IplImage *mor = cvCreateImage(cvGetSize(this->image), 8, 1);
CvMemStorage* storage = cvCreateMemStorage(0);
CvSeq* contour = 0;
if(this->image->nChannels > 1) this->grayScale();
cvFindContours(this->image, storage, &contour, sizeof(CvContour), CV_RETR_CCOMP, CV_CHAIN_APPROX_SIMPLE );
cvZero(mor);
for( ; contour != 0; contour = contour->h_next )
{
CvScalar color = CV_RGB( 255, 255, 255 );
cvDrawContours( mor, contour, color, color, 0, CV_FILLED, 8 );
}
cvConvertImage(mor, this->image, 0);
cvClearMemStorage(storage);
cvReleaseImage(&mor);
}
示例14: on_trackbar
void on_trackbar(int) {
if( g_storage==NULL ) {
g_gray = cvCreateImage( cvGetSize(g_image), 8, 1 );
g_storage = cvCreateMemStorage(0);
} else {
cvClearMemStorage( g_storage );
}
CvSeq* contours = 0;
cvCvtColor( g_image, g_gray, CV_BGR2GRAY );
cvThreshold( g_gray, g_gray, g_thresh, 255, CV_THRESH_BINARY );
cvFindContours( g_gray, g_storage, &contours );
cvZero( g_gray );
if( contours )
cvDrawContours(
g_gray,
contours,
cvScalarAll(255),
cvScalarAll(255),
100
);
cvShowImage( "Contours", g_gray );
}
示例15: cvFindContours
void BlobDetectionEngine::findBlobs(IplImage *grayImg, bool drawBlobs)
{
cvFindContours(grayImg, mem, &contours, sizeof(CvContour), CV_RETR_EXTERNAL, CV_CHAIN_APPROX_SIMPLE, cvPoint(0,0));
int i = 0;
for (ptr = contours; ptr != NULL; ptr = ptr->h_next) {
//Filter small contours
CvRect rect = cvBoundingRect(ptr);
if ( rect.height * rect.width < minAreaFilter ){
continue;
}
filtCont[i] = ptr;
//CvScalar color = CV_RGB( rand()&255, rand()&255, rand()&255 );
CvScalar color = CV_RGB( 255, 255, 255 );
cvDrawContours(visualImg, ptr, color, CV_RGB(0,0,0), 0, CV_FILLED, 8, cvPoint(0,0));
cvRectangle(visualImg, cvPoint(rect.x +3, rect.y +3), cvPoint(rect.x + rect.width, rect.y + rect.height), color, 1);
//sprintf(text, "B%d [%d,%d]", i, rect.x, rect.y);
sprintf(text, "Blob %d", i);
//cvPutText(visualImg, text, cvPoint(rect.x, rect.y), &font, color);
i++;
}
numOfFiltCont = i;
}