Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/opencv/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在内存存储中绘制单个轮廓 我试图用C++中的OpenCV库来检测最大的轮廓。我的算法是检测所有的轮廓并完美地绘制它们。但今天我试着只画最大的一个 这是我在C++中使用OpenCV的代码: #include <cv.h> #include <highgui.h> #include "opencv2/highgui/highgui.hpp" #include "opencv2/imgproc/imgproc.hpp" #include <iostream> #include <stdio.h> using namespace std; int main() { IplImage* img = cvLoadImage("contour.png"); //show the original image cvNamedWindow("Raw"); cvShowImage("Raw",img); //converting the original image into grayscale IplImage* imgGrayScale = cvCreateImage(cvGetSize(img), 8, 1); cvCvtColor(img,imgGrayScale,CV_BGR2GRAY); //thresholding the grayscale image to get better results cvThreshold(imgGrayScale,imgGrayScale,180,255,CV_THRESH_BINARY); CvSeq* contours; //hold the pointer to a contour in the memory block CvSeq* result; //hold sequence of points of a contour CvMemStorage *storage = cvCreateMemStorage(0); //storage area for all contours //finding all contours in the image cvFindContours(imgGrayScale, storage, &contours, sizeof(CvContour), CV_RETR_LIST, CV_CHAIN_APPROX_SIMPLE, cvPoint(0,0)); int largest_area=0; int largest_contour_index=0; for(int i = 0; i< contours->total; i++ ) // iterate through each contour. { double a = cvContourArea (contours, CV_WHOLE_SEQ); // Find the area of contour if( a > largest_area ){ largest_area = a; largest_contour_index=i; //Store the index of largest contour } } int j = 0; while (j != largest_contour_index) { if (j == largest_contour_index) { //obtain a sequence of points of contour, pointed by the variable 'contour' result = cvApproxPoly(contours, sizeof(CvContour), storage, CV_POLY_APPROX_DP, cvContourPerimeter(contours)*0.02, 0); //if there are 3 vertices in the contour(It should be a triangle) if(result->total==3 ) { //iterating through each point CvPoint *pt[3]; for(int i=0;i<3;i++){ pt[i] = (CvPoint*)cvGetSeqElem(result, i); } //drawing lines around the triangle cvLine(img, *pt[0], *pt[1], cvScalar(255,0,0),4); cvLine(img, *pt[1], *pt[2], cvScalar(255,0,0),4); cvLine(img, *pt[2], *pt[0], cvScalar(255,0,0),4); } //if there are 4 vertices in the contour(It should be a quadrilateral) else if(result->total==4 ) { //iterating through each point CvPoint *pt[4]; for(int i=0;i<4;i++){ pt[i] = (CvPoint*)cvGetSeqElem(result, i); } //drawing lines around the quadrilateral cvLine(img, *pt[0], *pt[1], cvScalar(0,255,0),4); cvLine(img, *pt[1], *pt[2], cvScalar(0,255,0),4); cvLine(img, *pt[2], *pt[3], cvScalar(0,255,0),4); cvLine(img, *pt[3], *pt[0], cvScalar(0,255,0),4); } //if there are 7 vertices in the contour(It should be a heptagon) else if(result->total ==7 ) { //iterating through each point CvPoint *pt[7]; for(int i=0;i<7;i++){ pt[i] = (CvPoint*)cvGetSeqElem(result, i); } //drawing lines around the heptagon cvLine(img, *pt[0], *pt[1], cvScalar(0,0,255),4); cvLine(img, *pt[1], *pt[2], cvScalar(0,0,255),4); cvLine(img, *pt[2], *pt[3], cvScalar(0,0,255),4); cvLine(img, *pt[3], *pt[4], cvScalar(0,0,255),4); cvLine(img, *pt[4], *pt[5], cvScalar(0,0,255),4); cvLine(img, *pt[5], *pt[6], cvScalar(0,0,255),4); cvLine(img, *pt[6], *pt[0], cvScalar(0,0,255),4); } } contours = contours -> h_next; j++; } //sow the image in which identified shapes are marked cvNamedWindow("Tracked"); cvShowImage("Tracked",img); cvWaitKey(0); //wait for a key press //cleaning up cvDestroyAllWindows(); cvReleaseMemStorage(&storage); cvReleaseImage(&img); cvReleaseImage(&imgGrayScale); return 0; } #包括 #包括 #包括“opencv2/highgui/highgui.hpp” #包括“opencv2/imgproc/imgproc.hpp” #包括 #包括 使用名称空间std; int main() { IplImage*img=cvLoadImage(“contour.png”); //显示原始图像 CVD公司(“原始”); cvShowImage(“原始”,img); //将原始图像转换为灰度 IplImage*imgGrayScale=cvCreateImage(cvGetSize(img),8,1); CVT颜色(img、imgGrayScale、CV_BGR2GRAY); //对灰度图像进行阈值化以获得更好的结果 cvThreshold(imgGrayScale,imgGrayScale,180255,CV_THRESH_二进制); CvSeq*contours;//将指针指向内存块中的轮廓 CvSeq*result;//保留轮廓点的序列 CvMemStorage*storage=cvCreateMemStorage(0);//所有轮廓的存储区域 //查找图像中的所有轮廓 cvFindContours(图像缩放、存储和等高线、尺寸(CvContour)、等高线列表、等高线链近似值、等高线点(0,0)); int最大面积=0; int最大轮廓指数=0; 对于(int i=0;itotal;i++)//迭代每个轮廓。 { double a=cvContourArea(等高线,CV_total_SEQ);//查找等高线区域 如果(a>最大面积){ 最大面积=a; 最大轮廓指数=i;//存储最大轮廓指数 } } int j=0; 而(j!=最大轮廓指数){ if(j==最大等高线指数){ //获取由变量“轮廓”指向的轮廓点序列 结果=cvApproxPoly(等高线、尺寸(CvContour)、存储、CV_POLY_近似_DP、CVContourp周长(等高线)*0.02,0); //如果轮廓中有3个顶点(应为三角形) 如果(结果->总计==3) { //迭代通过每个点 CvPoint*pt[3]; 对于(int i=0;itotal=4) { //迭代通过每个点 CvPoint*pt[4]; 对于(int i=0;itotal=7) { //迭代通过每个点 CvPoint*pt[7]; 对于(int i=0;i h_next; j++; } //sow标记已识别形状的图像 CVD(“跟踪”); cvShowImage(“跟踪”,img); cvWaitKey(0);//等待按键 //清理 cvallwindows(); cvReleaseMemStorage(&storage); cvReleaseImage(&img); cvReleaseImage(&imgGrayScale); 返回0; }_C++_Opencv_Detection - Fatal编程技术网 最大面积){ 最大面积=a; 最大轮廓指数=i;//存储最大轮廓指数 } } int j=0; 而(j!=最大轮廓指数){ if(j==最大等高线指数){ //获取由变量“轮廓”指向的轮廓点序列 结果=cvApproxPoly(等高线、尺寸(CvContour)、存储、CV_POLY_近似_DP、CVContourp周长(等高线)*0.02,0); //如果轮廓中有3个顶点(应为三角形) 如果(结果->总计==3) { //迭代通过每个点 CvPoint*pt[3]; 对于(int i=0;itotal=4) { //迭代通过每个点 CvPoint*pt[4]; 对于(int i=0;itotal=7) { //迭代通过每个点 CvPoint*pt[7]; 对于(int i=0;i h_next; j++; } //sow标记已识别形状的图像 CVD(“跟踪”); cvShowImage(“跟踪”,img); cvWaitKey(0);//等待按键 //清理 cvallwindows(); cvReleaseMemStorage(&storage); cvReleaseImage(&img); cvReleaseImage(&imgGrayScale); 返回0; },c++,opencv,detection,C++,Opencv,Detection" /> 最大面积){ 最大面积=a; 最大轮廓指数=i;//存储最大轮廓指数 } } int j=0; 而(j!=最大轮廓指数){ if(j==最大等高线指数){ //获取由变量“轮廓”指向的轮廓点序列 结果=cvApproxPoly(等高线、尺寸(CvContour)、存储、CV_POLY_近似_DP、CVContourp周长(等高线)*0.02,0); //如果轮廓中有3个顶点(应为三角形) 如果(结果->总计==3) { //迭代通过每个点 CvPoint*pt[3]; 对于(int i=0;itotal=4) { //迭代通过每个点 CvPoint*pt[4]; 对于(int i=0;itotal=7) { //迭代通过每个点 CvPoint*pt[7]; 对于(int i=0;i h_next; j++; } //sow标记已识别形状的图像 CVD(“跟踪”); cvShowImage(“跟踪”,img); cvWaitKey(0);//等待按键 //清理 cvallwindows(); cvReleaseMemStorage(&storage); cvReleaseImage(&img); cvReleaseImage(&imgGrayScale); 返回0; },c++,opencv,detection,C++,Opencv,Detection" />

如何在内存存储中绘制单个轮廓 我试图用C++中的OpenCV库来检测最大的轮廓。我的算法是检测所有的轮廓并完美地绘制它们。但今天我试着只画最大的一个 这是我在C++中使用OpenCV的代码: #include <cv.h> #include <highgui.h> #include "opencv2/highgui/highgui.hpp" #include "opencv2/imgproc/imgproc.hpp" #include <iostream> #include <stdio.h> using namespace std; int main() { IplImage* img = cvLoadImage("contour.png"); //show the original image cvNamedWindow("Raw"); cvShowImage("Raw",img); //converting the original image into grayscale IplImage* imgGrayScale = cvCreateImage(cvGetSize(img), 8, 1); cvCvtColor(img,imgGrayScale,CV_BGR2GRAY); //thresholding the grayscale image to get better results cvThreshold(imgGrayScale,imgGrayScale,180,255,CV_THRESH_BINARY); CvSeq* contours; //hold the pointer to a contour in the memory block CvSeq* result; //hold sequence of points of a contour CvMemStorage *storage = cvCreateMemStorage(0); //storage area for all contours //finding all contours in the image cvFindContours(imgGrayScale, storage, &contours, sizeof(CvContour), CV_RETR_LIST, CV_CHAIN_APPROX_SIMPLE, cvPoint(0,0)); int largest_area=0; int largest_contour_index=0; for(int i = 0; i< contours->total; i++ ) // iterate through each contour. { double a = cvContourArea (contours, CV_WHOLE_SEQ); // Find the area of contour if( a > largest_area ){ largest_area = a; largest_contour_index=i; //Store the index of largest contour } } int j = 0; while (j != largest_contour_index) { if (j == largest_contour_index) { //obtain a sequence of points of contour, pointed by the variable 'contour' result = cvApproxPoly(contours, sizeof(CvContour), storage, CV_POLY_APPROX_DP, cvContourPerimeter(contours)*0.02, 0); //if there are 3 vertices in the contour(It should be a triangle) if(result->total==3 ) { //iterating through each point CvPoint *pt[3]; for(int i=0;i<3;i++){ pt[i] = (CvPoint*)cvGetSeqElem(result, i); } //drawing lines around the triangle cvLine(img, *pt[0], *pt[1], cvScalar(255,0,0),4); cvLine(img, *pt[1], *pt[2], cvScalar(255,0,0),4); cvLine(img, *pt[2], *pt[0], cvScalar(255,0,0),4); } //if there are 4 vertices in the contour(It should be a quadrilateral) else if(result->total==4 ) { //iterating through each point CvPoint *pt[4]; for(int i=0;i<4;i++){ pt[i] = (CvPoint*)cvGetSeqElem(result, i); } //drawing lines around the quadrilateral cvLine(img, *pt[0], *pt[1], cvScalar(0,255,0),4); cvLine(img, *pt[1], *pt[2], cvScalar(0,255,0),4); cvLine(img, *pt[2], *pt[3], cvScalar(0,255,0),4); cvLine(img, *pt[3], *pt[0], cvScalar(0,255,0),4); } //if there are 7 vertices in the contour(It should be a heptagon) else if(result->total ==7 ) { //iterating through each point CvPoint *pt[7]; for(int i=0;i<7;i++){ pt[i] = (CvPoint*)cvGetSeqElem(result, i); } //drawing lines around the heptagon cvLine(img, *pt[0], *pt[1], cvScalar(0,0,255),4); cvLine(img, *pt[1], *pt[2], cvScalar(0,0,255),4); cvLine(img, *pt[2], *pt[3], cvScalar(0,0,255),4); cvLine(img, *pt[3], *pt[4], cvScalar(0,0,255),4); cvLine(img, *pt[4], *pt[5], cvScalar(0,0,255),4); cvLine(img, *pt[5], *pt[6], cvScalar(0,0,255),4); cvLine(img, *pt[6], *pt[0], cvScalar(0,0,255),4); } } contours = contours -> h_next; j++; } //sow the image in which identified shapes are marked cvNamedWindow("Tracked"); cvShowImage("Tracked",img); cvWaitKey(0); //wait for a key press //cleaning up cvDestroyAllWindows(); cvReleaseMemStorage(&storage); cvReleaseImage(&img); cvReleaseImage(&imgGrayScale); return 0; } #包括 #包括 #包括“opencv2/highgui/highgui.hpp” #包括“opencv2/imgproc/imgproc.hpp” #包括 #包括 使用名称空间std; int main() { IplImage*img=cvLoadImage(“contour.png”); //显示原始图像 CVD公司(“原始”); cvShowImage(“原始”,img); //将原始图像转换为灰度 IplImage*imgGrayScale=cvCreateImage(cvGetSize(img),8,1); CVT颜色(img、imgGrayScale、CV_BGR2GRAY); //对灰度图像进行阈值化以获得更好的结果 cvThreshold(imgGrayScale,imgGrayScale,180255,CV_THRESH_二进制); CvSeq*contours;//将指针指向内存块中的轮廓 CvSeq*result;//保留轮廓点的序列 CvMemStorage*storage=cvCreateMemStorage(0);//所有轮廓的存储区域 //查找图像中的所有轮廓 cvFindContours(图像缩放、存储和等高线、尺寸(CvContour)、等高线列表、等高线链近似值、等高线点(0,0)); int最大面积=0; int最大轮廓指数=0; 对于(int i=0;itotal;i++)//迭代每个轮廓。 { double a=cvContourArea(等高线,CV_total_SEQ);//查找等高线区域 如果(a>最大面积){ 最大面积=a; 最大轮廓指数=i;//存储最大轮廓指数 } } int j=0; 而(j!=最大轮廓指数){ if(j==最大等高线指数){ //获取由变量“轮廓”指向的轮廓点序列 结果=cvApproxPoly(等高线、尺寸(CvContour)、存储、CV_POLY_近似_DP、CVContourp周长(等高线)*0.02,0); //如果轮廓中有3个顶点(应为三角形) 如果(结果->总计==3) { //迭代通过每个点 CvPoint*pt[3]; 对于(int i=0;itotal=4) { //迭代通过每个点 CvPoint*pt[4]; 对于(int i=0;itotal=7) { //迭代通过每个点 CvPoint*pt[7]; 对于(int i=0;i h_next; j++; } //sow标记已识别形状的图像 CVD(“跟踪”); cvShowImage(“跟踪”,img); cvWaitKey(0);//等待按键 //清理 cvallwindows(); cvReleaseMemStorage(&storage); cvReleaseImage(&img); cvReleaseImage(&imgGrayScale); 返回0; }

如何在内存存储中绘制单个轮廓 我试图用C++中的OpenCV库来检测最大的轮廓。我的算法是检测所有的轮廓并完美地绘制它们。但今天我试着只画最大的一个 这是我在C++中使用OpenCV的代码: #include <cv.h> #include <highgui.h> #include "opencv2/highgui/highgui.hpp" #include "opencv2/imgproc/imgproc.hpp" #include <iostream> #include <stdio.h> using namespace std; int main() { IplImage* img = cvLoadImage("contour.png"); //show the original image cvNamedWindow("Raw"); cvShowImage("Raw",img); //converting the original image into grayscale IplImage* imgGrayScale = cvCreateImage(cvGetSize(img), 8, 1); cvCvtColor(img,imgGrayScale,CV_BGR2GRAY); //thresholding the grayscale image to get better results cvThreshold(imgGrayScale,imgGrayScale,180,255,CV_THRESH_BINARY); CvSeq* contours; //hold the pointer to a contour in the memory block CvSeq* result; //hold sequence of points of a contour CvMemStorage *storage = cvCreateMemStorage(0); //storage area for all contours //finding all contours in the image cvFindContours(imgGrayScale, storage, &contours, sizeof(CvContour), CV_RETR_LIST, CV_CHAIN_APPROX_SIMPLE, cvPoint(0,0)); int largest_area=0; int largest_contour_index=0; for(int i = 0; i< contours->total; i++ ) // iterate through each contour. { double a = cvContourArea (contours, CV_WHOLE_SEQ); // Find the area of contour if( a > largest_area ){ largest_area = a; largest_contour_index=i; //Store the index of largest contour } } int j = 0; while (j != largest_contour_index) { if (j == largest_contour_index) { //obtain a sequence of points of contour, pointed by the variable 'contour' result = cvApproxPoly(contours, sizeof(CvContour), storage, CV_POLY_APPROX_DP, cvContourPerimeter(contours)*0.02, 0); //if there are 3 vertices in the contour(It should be a triangle) if(result->total==3 ) { //iterating through each point CvPoint *pt[3]; for(int i=0;i<3;i++){ pt[i] = (CvPoint*)cvGetSeqElem(result, i); } //drawing lines around the triangle cvLine(img, *pt[0], *pt[1], cvScalar(255,0,0),4); cvLine(img, *pt[1], *pt[2], cvScalar(255,0,0),4); cvLine(img, *pt[2], *pt[0], cvScalar(255,0,0),4); } //if there are 4 vertices in the contour(It should be a quadrilateral) else if(result->total==4 ) { //iterating through each point CvPoint *pt[4]; for(int i=0;i<4;i++){ pt[i] = (CvPoint*)cvGetSeqElem(result, i); } //drawing lines around the quadrilateral cvLine(img, *pt[0], *pt[1], cvScalar(0,255,0),4); cvLine(img, *pt[1], *pt[2], cvScalar(0,255,0),4); cvLine(img, *pt[2], *pt[3], cvScalar(0,255,0),4); cvLine(img, *pt[3], *pt[0], cvScalar(0,255,0),4); } //if there are 7 vertices in the contour(It should be a heptagon) else if(result->total ==7 ) { //iterating through each point CvPoint *pt[7]; for(int i=0;i<7;i++){ pt[i] = (CvPoint*)cvGetSeqElem(result, i); } //drawing lines around the heptagon cvLine(img, *pt[0], *pt[1], cvScalar(0,0,255),4); cvLine(img, *pt[1], *pt[2], cvScalar(0,0,255),4); cvLine(img, *pt[2], *pt[3], cvScalar(0,0,255),4); cvLine(img, *pt[3], *pt[4], cvScalar(0,0,255),4); cvLine(img, *pt[4], *pt[5], cvScalar(0,0,255),4); cvLine(img, *pt[5], *pt[6], cvScalar(0,0,255),4); cvLine(img, *pt[6], *pt[0], cvScalar(0,0,255),4); } } contours = contours -> h_next; j++; } //sow the image in which identified shapes are marked cvNamedWindow("Tracked"); cvShowImage("Tracked",img); cvWaitKey(0); //wait for a key press //cleaning up cvDestroyAllWindows(); cvReleaseMemStorage(&storage); cvReleaseImage(&img); cvReleaseImage(&imgGrayScale); return 0; } #包括 #包括 #包括“opencv2/highgui/highgui.hpp” #包括“opencv2/imgproc/imgproc.hpp” #包括 #包括 使用名称空间std; int main() { IplImage*img=cvLoadImage(“contour.png”); //显示原始图像 CVD公司(“原始”); cvShowImage(“原始”,img); //将原始图像转换为灰度 IplImage*imgGrayScale=cvCreateImage(cvGetSize(img),8,1); CVT颜色(img、imgGrayScale、CV_BGR2GRAY); //对灰度图像进行阈值化以获得更好的结果 cvThreshold(imgGrayScale,imgGrayScale,180255,CV_THRESH_二进制); CvSeq*contours;//将指针指向内存块中的轮廓 CvSeq*result;//保留轮廓点的序列 CvMemStorage*storage=cvCreateMemStorage(0);//所有轮廓的存储区域 //查找图像中的所有轮廓 cvFindContours(图像缩放、存储和等高线、尺寸(CvContour)、等高线列表、等高线链近似值、等高线点(0,0)); int最大面积=0; int最大轮廓指数=0; 对于(int i=0;itotal;i++)//迭代每个轮廓。 { double a=cvContourArea(等高线,CV_total_SEQ);//查找等高线区域 如果(a>最大面积){ 最大面积=a; 最大轮廓指数=i;//存储最大轮廓指数 } } int j=0; 而(j!=最大轮廓指数){ if(j==最大等高线指数){ //获取由变量“轮廓”指向的轮廓点序列 结果=cvApproxPoly(等高线、尺寸(CvContour)、存储、CV_POLY_近似_DP、CVContourp周长(等高线)*0.02,0); //如果轮廓中有3个顶点(应为三角形) 如果(结果->总计==3) { //迭代通过每个点 CvPoint*pt[3]; 对于(int i=0;itotal=4) { //迭代通过每个点 CvPoint*pt[4]; 对于(int i=0;itotal=7) { //迭代通过每个点 CvPoint*pt[7]; 对于(int i=0;i h_next; j++; } //sow标记已识别形状的图像 CVD(“跟踪”); cvShowImage(“跟踪”,img); cvWaitKey(0);//等待按键 //清理 cvallwindows(); cvReleaseMemStorage(&storage); cvReleaseImage(&img); cvReleaseImage(&imgGrayScale); 返回0; },c++,opencv,detection,C++,Opencv,Detection,在此图像上执行程序时: 上面没有图形形状 提前感谢。在第一个循环中,我认为您并没有真正迭代所有轮廓。 您应该像在第二个循环中一样使用h_next进行迭代。 此外,在搜索最大轮廓时,可以存储其指针,以便稍后访问 CvSeq* biggestContour; double a = 0; for(int i = 0; i< contours->total; i++ ) // iterate through each contour. { a = cvContourArea (con

在此图像上执行程序时: 上面没有图形形状


提前感谢。

在第一个循环中,我认为您并没有真正迭代所有轮廓。 您应该像在第二个循环中一样使用h_next进行迭代。 此外,在搜索最大轮廓时,可以存储其指针,以便稍后访问

CvSeq* biggestContour;
double a = 0;
for(int i = 0; i< contours->total; i++ ) // iterate through each contour.
{
    a = cvContourArea (contours, CV_WHOLE_SEQ);  //  Find the area of contour

    if( a > largest_area ){
        larget_area = a;
        biggestContour = contours; // store the biggest one

    }

    contours = contours -> h_next;

}

// do your work using the above biggestContour

//obtain a sequence of points of contour, pointed by the variable 'contour'
result = cvApproxPoly(biggestContour, sizeof(CvContour), storage, CV_POLY_APPROX_DP, cvContourPerimeter(biggestContour)*0.02, 0);

[...] 
CvSeq*biggestContour;
双a=0;
对于(int i=0;itotal;i++)//迭代每个轮廓。
{
a=cvContourArea(等高线,CV_total_SEQ);//查找等高线区域
如果(a>最大面积){
大面积=a;
biggestContour=等高线;//存储最大的等高线
}
轮廓=轮廓->h_下一步;
}
//使用上述最大轮廓进行工作
//获取由变量“轮廓”指向的轮廓点序列
结果=cvApproxPoly(biggestContour,sizeof(CvContour),存储,CV_POLY_近似,CvContourPeriod(biggestContour)*0.02,0;
[...] 
编辑:我将发布一些代码,您可能会发现这些代码很有用。您不能按原样使用它,但您将看到如何迭代您的轮廓。我使用它查找图像中的所有轮廓,然后根据各种条件过滤其中的一些轮廓

// we are going to use these
CvMemStorage* strgContours;
CvSeq* seqContours;
CvSeq* seqCurrent;

// create the MemStorage
strgContours = cvCreateMemStorage(0);

// you can clone your input image and work on the new one, if you wish
IplImage* imgTemp = (IplImage*)cvClone(input);

// scan the image for contours
CvContourScanner scanner;
scanner = cvStartFindContours( imgTemp, strgContours, sizeof(CvContour), CV_RETR_LIST, CV_CHAIN_APPROX_SIMPLE, cvPoint(0,0) );

double maxContourArea = 0;
while( (seqCurrent = cvFindNextContour( scanner )) != 0 ) 
{
    // Now you can work with seqCurrent, that holds current contour

    [...] 

    //the area is computed using the Green formula, 
    //thus the returned area and the number 
    //of non-zero pixels can be different.
    double area = cvContourArea( seqCurrent );   //same as "cvContourArea( c , CV_WHOLE_SEQ );"   

    [...]                   

    // you can even discard contours that do not match your criteria
    if( area < 100 ) {
        cvSubstituteContour( scanner, 0 );
        continue;
    }

    [...]

    // This is how you draw your contour on an IplImage
    // create your image
    IplImage* imgTest = cvCreateImage( size , IPL_DEPTH_8U , 3);            
    // make it black
    cvZero( imgTest );
    // draw the contour
    cvDrawContours( imgTest, seqCurrent, cvScalarAll(255), cvScalarAll(0), -1, CV_FILLED, 8, cvPoint(0,0));                     
    // do what you want to do with your image       
    [...]       
    // and then release it
    cvReleaseImage( &imgTest);                                  
}

// seqContours will hold all contours found and were not discarded
seqContours = cvEndFindContours( &scanner );

// paint the found regions back into the image
IplImage* imgContours = cvCreateImage( size , IPL_DEPTH_8U , 3);            
cvZero( imgContours );
for( seqCurrent=seqContours; seqCurrent != 0; seqCurrent = seqCurrent->h_next ) 
{               
    cvDrawContours( imgContours, seqCurrent, cvScalarAll(255), cvScalarAll(0), -1, CV_FILLED, 8, cvPoint(0,0));
}

// do things...

// Free memory
cvReleaseImage( &imgContours);  
cvReleaseImage( &imgTemp);  
cvReleaseMemStorage(&strgContours); 
//我们将使用这些
CvMemStorage*strg轮廓;
CvSeq*seq等值线;
CvSeq*seq电流;
//创建内存存储
strgContours=cvCreateMemStorage(0);
//如果愿意,您可以克隆输入图像并处理新图像
IplImage*imgTemp=(IplImage*)cvClone(输入);
//扫描图像的轮廓
轮廓扫描仪;
扫描仪=cvStartFindContours(imgTemp、strgContours、sizeof(CvContourt)、CV_RETR_列表、CV_CHAIN_近似值、cvPoint(0,0));
双面积=0;
而((seqCurrent=cvFindNextContour(扫描仪))!=0)
{
//现在您可以使用seqCurrent,它保存当前轮廓
[...] 
//使用格林公式计算面积,
//因此,返回的区域和数量
//非零像素的数量可以不同。
double area=cvContourArea(seqCurrent);//与“cvContourArea(c,CV_整体_SEQ);”相同
[...]                   
//您甚至可以放弃不符合条件的轮廓
如果(面积<100){
CVSubstituteTour(扫描仪,0);
继续;
}
[...]
//这就是你在地图上绘制轮廓的方法
//创造你的形象
IplImage*imgTest=cvCreateImage(大小,IPL_深度_8U,3);
//把它弄黑
cvZero(imgTest);
//画轮廓
CvDraw等值线(imgTest,seqCurrent,cvScalarAll(255),cvScalarAll(0),-1,CV_填充,8,cvPoint(0,0));
//用你的形象做你想做的事
[...]       
//然后释放它
cvReleaseImage(&imgTest);
}
//seqContours将保存找到的所有轮廓,且未被丢弃
seqContours=cvEndFindContours(和扫描仪);
//将找到的区域重新绘制到图像中
IplImage*imgContours=cvCreateImage(大小,IPL\U深度\U 8U,3);
cvZero(imgContours);
对于(seqCurrent=seqCurrent;seqCurrent!=0;seqCurrent=seqCurrent->h_next)
{               
cvDraw