i'm working on detecting shape of any object.i've a binary image where background is white pixels and foreground/object is black pixel. now i need to detect the shape of the area where there are black pixels.how can i do it?the shape may be of a man/car/box etc. plz help
I'm not sure which is your final goal as amphetamachine said but a pretty common approach to detect shapes could be the use of cvFindContours which given a binary image and returns a set of 'CvContour' (which in fact is a cvSeq). Binary image can be retrieved quite simple by thresholding the image (cvThreshold). Check out the contours.c example in the sample/ of opencv src directory. Check this link as well:
this sample code will give you an general idea:
cvThreshold( g_gray, g_gray, g_thresh, 255, CV_THRESH_BINARY );
cvFindContours( g_gray, g_storage, &contours );
cvZero( g_gray );
if( contours ){
cvDrawContours(
g_gray,
contours,
cvScalarAll(255),
cvScalarAll(255),
100 );
}
cvShowImage( "Contours", g_gray );
Once you have an encoding of the contour you can use cvMatchShapes which take 2 contours and return a measure of similarity between these contours.
Hope this approach provide you a head start!
For accurate shape detection you need to use haar detection or at the least K nearest neighbor. Haar detection can be very accurate, but it takes a long time to set up. K nearest neighbor is easier to set up but is not as accurate. Check out this youtube video. This guy is using KNN to detect different hand gestures. Notice that the comparison image is basically a black blob. The bad thing about KNN is that it is that it takes a lot more resources to run the program, but with haar detection, the major processing has already been done when you create the cascade xml files with haartraining.exe