1

Respected All,

I am using watershed algorithm in the attached image, now I want to find the size of the enclosed boundary image (irregular object in the image).

The image is attached: enter image description here

Jeru Luke
  • 20,118
  • 13
  • 80
  • 87
saeediqbal
  • 135
  • 2
  • 5
  • Is your comment to Silencer code your tried and gave error? If so post in your question. See also my other comment at Silencer. Your question is now doomed to be downvoted and closed due to lack of effort.. – ZF007 Dec 21 '17 at 07:37
  • I am using opencv3.5 – saeediqbal Dec 21 '17 at 07:42
  • That's not an answer to my question.. unless cv3.5 gives errors with below answer. Then post your trail steps and error code. Its not a problem to show your below result (comment to Silencer's answer in your question). Go edit. – ZF007 Dec 21 '17 at 07:44
  • @saeediqbal help me please, you can? https://stackoverflow.com/questions/60978380/how-to-remove-the-background-of-the-image-of-interest-using-opencv-on-android – Carlos Diego Apr 30 '20 at 17:39

1 Answers1

2

Update:

In OpenCV 3.4 , cv2.findContours returns image, contours, hierarchy

cv2.findContours(image, mode, method[, contours[, hierarchy[, offset]]]) -> image, contours, hierarchy

enter image description here

In OpenCV 4.0, cv2.findContours returns contours, hierarchy

cv2.findContours(image, mode, method[, contours[, hierarchy[, offset]]]) -> contours, hierarchy

enter image description here

So to find contours in a threshed binary image, and calculate the areas, use:

cnts= cv.findContours(threshed, cv.RETR_EXTERNAL, cv.CHAIN_APPROX_SIMPLE)[-2]
for cnt in cnts:
    area = cv2.contourArea(cnt)
    print(area)
Kinght 金
  • 17,681
  • 4
  • 60
  • 74
  • cnts = cv.findContours(thresh.copy(), cv.RETR_EXTERNAL, cv.CHAIN_APPROX_SIMPLE) print("cnts is ",cnts) like the above: output is following: cnts is (array([[255, 255, 255, ..., 255, 255, 255], [255, 255, 255, ..., 255, 255, 255], [255, 255, 255, ..., 255, 255, 255], ..., [255, 255, 255, ..., 255, 255, 255], [255, 255, 255, ..., 255, 255, 255]], dtype=uint8), [array([[[ 0, 0]], [[ 0, 131]], [[199, 131]], [[199, 0]]], dtype=int32)], array([[[-1, -1, -1, -1]]], dtype=int32)) – saeediqbal Dec 21 '17 at 07:33
  • 1
    @saeediqbal: refer with comment to your own answer.. Now its difficult to read and I've got no clue what you mean. Cheers. – ZF007 Dec 21 '17 at 07:36