2

I had went through many tutorials and guide lines and I was able to convert part of it. But I don't know how to convert last line in to javacv. So Please can some one help me to convert this code in to javacv?

img = cv2.imread('sofud.jpg')

gray = cv2.cvtColor(img,cv2.COLOR_BGR2GRAY)

ret,thresh = cv2.threshold(gray,127,255,1)

contours,hierarchy = cv2.findContours(thresh,cv2.RETR_LIST,cv2.CHAIN_APPROX_SIMPLE)

  for cnt in contours:
    x,y,w,h = cv2.boundingRect(cnt)
    if 10 < w/float(h) or w/float(h) < 0.1:
    cv2.rectangle(img,(x,y),(x+w,y+h),(0,0,255),2)
Jeru Luke
  • 20,118
  • 13
  • 80
  • 87

1 Answers1

0

You can use the last line as this in Java CV:

opencv_core.cvRectangle(image, opencv_core.cvPoint(m,n), opencv_core.cvPoint(i,j), opencv_core.cvScalar(0,0,255,0), thickness, 8, 0);

Where the parameters mean:

opencv_core.cvRectangle(CvArr* img, CvPoint , CvPoint, CvScalar color, int thickness=1, int lineType=8, int shift=0)

and look at this Link for more information.

EDIT:

This is an example of finding contours:

cvFindContours(grayImage, memory, contours, sizeof(CvContour.class) , CV_RETR_CCOMP, CV_CHAIN_APPROX_SIMPLE, cvPoint(0,0));

Where the parameter mean:

cvFindContours(CvArr* image, CvMemStorage* storage, CvSeq** first_contour, int header_size=sizeof(CvContour), int mode=CV_RETR_LIST, int method=CV_CHAIN_APPROX_SIMPLE, CvPoint offset=cvPoint(0,0) )

For more information on the parameters, take a look at this Link, under FindContours section.

You can also use the cvDrawContours function, to draw the contours in the same way as we have used cvFindContours function.

Take a look at this Link. It is a different post on this website in which the they have explained the use of finding contours in blob detection.

Hope This Helps.

Community
  • 1
  • 1
codeDEXTER
  • 1,181
  • 7
  • 14
  • Please can you also explain how to use "findContours" method in javacv. It take another 3 integer parameters what are those things ? –  Jul 07 '12 at 10:21
  • @LBNCons Please look at the "EDIT:" section in my answer above. – codeDEXTER Jul 07 '12 at 15:12