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
| #include <stdio.h>
#include <stdlib.h>
#include <cv.h>
#include <highgui.h>
#include <cxcore.h>
#include <cvaux.h>
IplImage* pic= NULL;
IplImage* g_gray = NULL;
int g_thresh = 100;
CvMemStorage* g_storage = NULL;
CvPoint centre(IplImage* pic)
{
CvSeq* contours=0;
CvPoint offset=cvPoint(0,0);
if( g_storage == NULL )
{g_gray = cvCreateImage( cvGetSize( pic), 8, 1 );
g_storage = cvCreateMemStorage(0);}
else {cvClearMemStorage( g_storage );}
cvCvtColor( pic, g_gray, CV_BGR2GRAY );
cvThreshold( g_gray, g_gray, g_thresh, 255, CV_THRESH_BINARY );
cvFindContours ( g_gray , g_storage, &contours, sizeof (CvContour), CV_RETR_LIST, CV_CHAIN_APPROX_SIMPLE,offset);
cvZero( g_gray );
if(contours)
{
CvScalar external_color = CV_RGB( rand()&0, rand()&0, rand()&255 );
CvScalar hole_color=CV_RGB( rand()&0, rand()&255, rand()&0 );
cvDrawContours ( g_gray, contours,external_color,hole_color, -1, 1, 8, cvPoint(0,0));}
cvShowImage( "Contours", g_gray );
cvMinAreaRect2(contours,g_storage);
}
int main(int argc, _TCHAR* argv[])
{
pic=cvLoadImage("C:/Users/ATHMANE/Desktop/hob.bmp",CV_LOAD_IMAGE_COLOR);// on charge en couleur pr qu'on puisse dessiner la BE et le CG en couleur sur l'image
cvNamedWindow("image BE&CG", CV_WINDOW_AUTOSIZE);
centre(pic);
cvShowImage("image BE&CG", pic);
cvWaitKey(0);
cvDestroyWindow("image BE&CG");
cvReleaseImage(&pic);
printf("Hello world!\n");
return 0;
} |
Partager