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
|
#include <opencv/highgui.h>
#include <opencv/cv.h>
#include <tchar.h>
int _tmain(int argc, _TCHAR* argv[])
{
blobs = CBlobResult( img, NULL, 10 0, NULL ); //store detected objects
int blobnum = blobs.GetNumBlobs();
cvInitFont (&dfont, CV_FONT_HERSHEY_SIMPLEX , hscale, vscale, italicscale, thickness, CV_AA);
CBlobGetXCenter x_center;
CBlobGetYCenter y_center;
//filter object detected with central point as black pixel
for(int i = 0; i < blobnum; i++)
{ blob_current = blobs.GetBlob(i);
p3.x = x_center.operator()(blob_current);
p3.y = y_center.operator()(blob_current);
if (blob_current.ExternPerimeter()==0)
{ if (s3.val[0] != 0)
{
final_blobs.AddBlob(&blob_current);
}
}
}
int final_blobNum = final_blobs.GetNumBlobs();
for(int i = 0; i < final_blobNum; i++)
{
blob = final_blobs.GetBlob(i);
p1.x = (int)blob.MinX();
p1.y = (int)blob.MinY();
p2.x = (int)blob.MaxX();
p2.y = (int)blob.MaxY();
//draw the selected candidates
sprintf(text, "%d", i+1);
cvPutText(img2, text, cvPoint(p1.x, p2.y + 15),&dfont,CV_RGB(100,100,100));
cvRectangle( img2, p1, p2, CV_RGB( 100, 100, 100 ), 1, 8, 0 );
}
return 0;
}
|