1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75
|
#include <cv.h>
#include <cvaux.h>
#include <highgui.h>
#include <stdio.h>
int main()
{
IplImage* test=0;
CvCapture* capture = 0;
//capture = cvCaptureFromAVI("ab.avi");
capture = cvCaptureFromCAM(0);
CvMemStorage* storage = cvCreateMemStorage(0);
IplImage* frame;
IplImage* Image_Contour_1channel;
IplImage* Image_Contour_3channel;
CvSeq * contour = 0;
int press_key;
int slider_pos=70;
if(capture)
{
test = cvQueryFrame(capture);
int width = (int)cvGetCaptureProperty( capture, CV_CAP_PROP_FRAME_WIDTH );
int height= (int)cvGetCaptureProperty( capture, CV_CAP_PROP_FRAME_HEIGHT);
printf("width %d height %d\n",width,height);
frame = cvCreateImage(cvSize(width,height), 8 ,3);
Image_Contour_3channel = cvCreateImage(cvSize(width,height), 8 ,3);
Image_Contour_1channel= cvCreateImage(cvSize(width,height), 8 ,1);
//cvNamedWindow( "Imerir_Seuil", 0 );
cvNamedWindow( "Imerir_Tracker", 0 );
while(cvGrabFrame(capture))
{
frame = cvRetrieveFrame(capture);
cvConvertImage(frame,Image_Contour_1channel,1);
Image_Contour_3channel=cvCloneImage(frame);
cvCreateTrackbar( "Bar", "Imerir_Tracker", &slider_pos, 255,NULL);
cvThreshold( Image_Contour_1channel,Image_Contour_1channel, slider_pos, 255, CV_THRESH_TOZERO );
cvFindContours( Image_Contour_1channel, storage, &contour, sizeof(CvContour),CV_RETR_EXTERNAL, CV_CHAIN_APPROX_SIMPLE);//CV_CHAIN_APPROX_NONE //CV_CHAIN_APPROX_SIMPLE
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( FrameContour, contour, color, color, -1, 1, 8 );
cvDrawContours(Image_Contour_3channel, contour,CV_RGB(0,0,255), CV_RGB(255, 0, 0),2, 2, 8);
}
cvShowImage( "Imerir_Tracker", Image_Contour_3channel );
//cvShowImage( "Imerir_Seuil", Image_Contour_1channel );
press_key = cvWaitKey(5);
if( (char)press_key == 27 )
break;
}
}
else printf("Video stream not found\n\n");
cvReleaseImage( &Image_Contour_3channel );
cvReleaseImage( &Image_Contour_1channel );
cvDestroyWindow("Imerir_Tracker");
return 0;
} |
Partager