Find specific tip of triangle using opencv and python
13:11 29 Nov 2022

I am working with the image below. The target is to find the triangle tip with the line attached. First, I would like to explain the problem statement, and then I will tell what I have done so far.

enter image description here

I am trying to find out which tip of the triangle has the line attached to it. as shown below.

enter image description here

Then draw a point on that tip as shown below.

enter image description here

So far I am able to identify the triangle in the image with the below code.

import cv2
import numpy as np

img = cv2.imread('image_name.png')
img1 = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)

ret,thresh = cv2.threshold(img1,150,255,0)
contours,hierarchy = cv2.findContours(thresh, 1, 2)
print("Number of contours detected:",len(contours))

for cnt in contours:
   approx = cv2.approxPolyDP(cnt, 0.1*cv2.arcLength(cnt, True), True)
   if len(approx) == 3:
      img = cv2.drawContours(img, [cnt], -1, (0,255,255), 3)
      M = cv2.moments(cnt)
      if M['m00'] != 0.0:
         x = int(M['m10']/M['m00'])
         y = int(M['m01']/M['m00'])
      cv2.putText(img, 'Triangle', (x, y), cv2.FONT_HERSHEY_SIMPLEX, 0.6, (255, 255, 0), 2)

cv2.imwrite("Shapes.png", img) 

The output image is shown below.

enter image description here

I need help to detect the tip with the line. How can I do it. Thank you for your time.

python opencv image-processing computer-vision