Search code examples
opencvhaar-classifier

Is there a way get all coordinates from the detected object using haar cascade?


I have used below tutorial to detect object and get coordinates of rectangles that contain object https://docs.opencv.org/3.3.1/d2/d99/tutorial_js_face_detection.html

But I want to get all coordinates of object (not vector of rectangular coordinates) for object extraction.How can I do that?Is there any function can do that?

For example: enter image description here


Solution

  • Haar-cascades has been trained to return only the rectangular coordinates of the detected object and not the contour.

    But try the following:

    1) Create a mask with the rectangular coordinates

    2) Mask out just the object region using the Mask image(check cv2.bitwise_and)

    3) Edge detection using canny or threshold if it is applicable.

    4) Find contours. You can use cv2.findcontours function, where you can set cv2.findcontours(..,..,method =CHAIN_APPROX_NONE) to get all the points lying on the contour.