I have various contours extracted by cv2.findContours(cv2.CHAINE_APPROX_NONE). After that I also extracted the extreme points. Now I´d like to find the point in the contour opposite to the leftmost/rightmost. The point in the contour with the same y-coordinates as the leftmost/rightmost point, so to say. As the format of the coordinates is hardly readable by most functions, maybe the trick is to reorder them.
Any idea how to solve that?
###contour extraction
cnts = cv2.findContours(img_thresh, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_NONE)
cnts = cnts[0]
(cnts, _) = contours.sort_contours(cnts)
cnt_number = 0
for cnt in cnts:
if cv2.contourArea(cnt) > 500:
contour_lenght = cv2.arcLength(cnt, True)
approx = cv2.approxPolyDP(cnt, 0.005 * contour_lenght, True)
obj_cor = len(approx)
if obj_cor > 4:
cv2.drawContours(blank_image, cnt, -1, (0, 0, 0), 2)
leftmost = tuple(cnt[cnt[:, :, 0].argmin()][0])
rightmost = tuple(cnt[cnt[:, :, 0].argmax()][0])
Also thaught about doing a line-contour-intersection (like suggested by mathematical.coffee here Line intersecting contour in openCv) but not sure how...
###bounding box
x, y, w, h = cv2.boundingRect(approx)
###end of line from leftmost
left_y = leftmost[1]
left_x = leftmost[0] + w
left_line_endpoint = (left_x, left_y)
###line intersect function suggested by mathematical.coffee
numpy.logical_and(...)