Currently I am developing image processing project and I’m using javacv to develop image processing components. I was able to extract some interesting parts of a image and now I need to read the x and y coordinates of those objects.
This is the image that I haveextracted

And I need to identify those objects and draw square around those objects. I went through some tutorials and try to identify objects using following code.
IplImage img="sourceimage";
CvSize sz = cvSize(img.width(), img.height());
IplImage gry=cvCreateImage(sz, img.depth(), 1);
cvCvtColor(img, gry, CV_BGR2GRAY);
cvThreshold(gry, gry, 200, 250, CV_THRESH_BINARY);
CvMemStorage mem = CvMemStorage.create();
CvSeq contours = new CvSeq();
CvSeq ptr = new CvSeq();
cvFindContours(gry, mem, contours, Loader.sizeof(CvContour.class) , CV_RETR_CCOMP, CV_CHAIN_APPROX_SIMPLE, cvPoint(0,0));
CvRect boundbox;
for (ptr = contours; ptr != null; ptr = ptr.h_next()) {
boundbox = cvBoundingRect(ptr, 0);
if(boundbox.height()>10||boundbox.height()>10){
cvRectangle( gry, cvPoint( boundbox.x(), boundbox.y() ), cvPoint( boundbox.x() + boundbox.width(), boundbox.y() + boundbox.height()),CvScalar.BLUE, 0, 0, 0 );
System.out.println(boundbox.x()+", "+boundbox.y());
}
}
cvShowImage("contures", gry);
cvWaitKey(0);
But it doesn’t draw as rectangle around the objects. I would like to know whether I can use cvFindContours method to identify those objects ? Please can some one explain how to archive my objective using javacv/opencv?
Try to go through following code and it will give answer for your question.
This is the output that I got for your given image.