title: How to find the direction of triangles in an image using OpenCV
body: <p>I am trying to find the direction of triangles in an image. below is the image:</p>
  <p><a href="https://i.stack.imgur.com/JCiDs.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/JCiDs.png" alt="enter image description here" /></a></p>
  <p>These triangles are pointing upward/downward/leftward/rightward. This is not the actual image. I have already used canny edge detection to find edges then contours and then the dilated image is shown below.</p>
  <p><strong>My logic to find the direction:</strong></p>
  <p>The logic I am thinking to use is that among the three corner coordinates If I can identify the base coordinates of the triangle (having the same abscissa or ordinates values coordinates), I can make a base vector. Then angle between unit vectors and base vectors can be used to identify the direction. But this method can only determine if it is up/down or left/right but cannot differentiate between up and down or right and left. I tried to find the corners using <code>cv2.goodFeaturesToTrack</code> but as I know it's giving only the 3 most effective points in the entire image.  So I am wondering if there is other way to find the direction of triangles.</p>
  <p>Here is my code in python to differentiate between the triangle/square and circle:</p>
  <pre><code>#blue_masking
  mask_blue=np.copy(img1)
  row,columns=mask_blue.shape
  for i in range(0,row):
      for j in range(0,columns):
          if (mask_blue[i][j]==25):
              mask_blue[i][j]=255
          else: 
              mask_blue[i][j]=0
  blue_edges = cv2.Canny(mask_blue,10,10)
  kernel_blue = cv2.getStructuringElement(cv2.MORPH_ELLIPSE,(2,2))
  dilated_blue = cv2.dilate(blue_edges, kernel)
  blue_contours,hierarchy = 
  cv2.findContours(dilated_blue,cv2.RETR_TREE,cv2.CHAIN_APPROX_SIMPLE)
  for cnt in blue_contours:
      area = cv2.contourArea(cnt)
      perimeter = cv2.arcLength(cnt,True)
      M = cv2.moments(cnt)
      cx = int(M['m10']/M['m00'])
      cy = int(M['m01']/M['m00'])
      if(12&lt;(perimeter*perimeter)/area&lt;14.8):
          shape=&quot;circle&quot;
      elif(14.8&lt;(perimeter*perimeter)/area&lt;18):
          shape=&quot;squarer&quot;
      elif(18&lt;(perimeter*perimeter)/area and area&gt;200):
          shape=&quot;triangle&quot;
      print(shape) 
      print(area)
      print((perimeter*perimeter)/area,&quot;\n&quot;)
      
  cv2.imshow('mask_blue',dilated_blue)
  cv2.waitKey(0)
  cv2.destroyAllWindows()
  
    
  </code></pre>
  <p>Source image can be found here: <a href="https://github.com/UJ5/Deep-learning-/blob/main/gray.png" rel="nofollow noreferrer"><code>img1</code></a></p>
  <p>Please help, how can I found the direction of triangles?<br />
  Thank you.</p>