Home > Enterprise >  Find edge points of this shape using opencv python
Find edge points of this shape using opencv python

Time:08-19

Everyone I have used contours to find out the endpoints as shown in the image but I'm not getting my expected output what these points (p1,p2,p3,p4). Can you please help me to find it out? I have also attached my input image below. Thank you.

import cv2
cropped_image=cv2.imread('croped_img.png')
# cropped_image=cv2.resize(cropped_image,(512,615))
original_ccropped_image=cropped_image.copy()
cnt= contours(cropped_image)

#####take points bbox for stright line
x_new,y_new,w_new,h_new = cv2.boundingRect(cnt)

#####take points bbox for rotated
rect = cv2.minAreaRect(cnt)
box = cv2.boxPoints(rect)
box = np.int0(box)
print(box)
cropped_image=cv2.drawContours(cropped_image,[box],0,(0,0,255),2)

My input image

enter image description here

CodePudding user response:

As mentioned in the comments you need to use convexity defects. OpenCV tutorial on this can be found enter image description here

  • Related