The
The
pointer
, null when the outline was detected. Other outlines can be connected to H_next and v_next to reach the first_contour.
gray image
The function of the second -value image is:
cvThreshold
, CVADAPTIVETHRSHOLD and
cvCanny
。
The
chain code
The
method outputs outline, and all other methods output polygon (sequence of the vertex).
One of
, used to move all outline points. When the contour is from
image
The
ROI extraction and need to be analyzed in the entire image. This parameter will be useful.
The type of
#include “cv.h”
#include “cxcore.h”
#include “highgui.h”
int main( int argc, char** argv )
{
// State the iPLIMAGE pointer
IplImage* pImg = NULL;
IplImage* pContourImg = NULL;
CVMEMSTORAGE * Storage = cvcreateMemstorage (0); // Create memory block size is 64K
CvSeq * contour = 0;
int mode = CV_RETR_EXTERNAL;
if( argc == 3)
if(strcmp(argv[2], “all”) == 0)
mode = cv_retr_ccomp; // Internal and external outlines are detected
// Create a window
cvNamedWindow(“src”, 1);
cvNamedWindow(“contour”,1);
// Load the image and force the transformation to Gray
if( (pImg = cvLoadImage( “E:\\Lena.jpg”, 0)) != 0 )
{
cvShowImage( “src”, pImg );
// For the outline display image application space
// 3 channel images in order to display in color
pContourImg = cvCreateImage(cvGetSize(pImg),IPL_DEPTH_8U,3);
// Copy the original image and convert it to BGR image
cvCvtColor(pImg, pContourImg, CV_GRAY2BGR);
// Find Contour
cvFindContours( pImg, storage, &contour, sizeof(CvContour),
mode, CV_CHAIN_APPROX_SIMPLE, cvPoint(0,0));
}
else
{
// Destruction window
cvDestroyWindow( “src” );
cvDestroyWindow( “contour” );
cvReleaseMemStorage(&storage);
return -1;
}
// Draw out outline
CVDRAWCONTOURS (PContourimg, Contour, // The former is an image, the latter is a pointer pointed to the first outline
CV_RGB (0,0,255), CV_RGB (255, 0, 0), // outer contour blue, inner contour red
2, 2, 8, CVPOINT (0,0)); // All the same layer and low -level outline after drawing contour, so on, the line width is 2, the line segment type is 8, the offset coordinates are (the offset coordinates ( 0, 0)
// Display images
cvShowImage( “contour”, pContourImg );
cvWaitKey(0);
// Destruction window
cvDestroyWindow( “src” );
cvDestroyWindow( “contour” );
// Release images
cvReleaseImage( &pImg );
cvReleaseImage( &pContourImg );
cvReleaseMemStorage(&storage);
return 0;
}