# Python code to detect an arrow (seven-sided) in an image. import numpy as np import cv2 # Read image img2 = cv2.imread ( ’arrow.jpg’ , cv2.IMREAD_COLOR) # Read the same image in a different variable and # converted not gray scale. img = cv2.imread ( ’arrow.jpg’ , cv2.IMREAD_GRAYSCALE) # Convert image to binary # (black only -white image). _, threshold = cv2.threshold (img, 110 , 255 , cv2.THRESH_BINARY) # Detect shapes in the image by region selection # with the same colors or intensities. contours, _ = cv2.findContours (threshold, cv2.RETR_TREE, cv2.CHAIN_APPROX_SIMPLE) # Search in each region selected for # find the desired polygon. for cnt in contours: area = cv2.contourArea (cnt) # List regions based on their region. if area" 400 : approx = cv2.approxPolyDP (cnt, 0.009 * cv2. arcLength (cnt, True ), True ) # Check if not. sides of the selected region is 7. if ( len (approx) = = 7 ): cv2.drawContours (img2, [approx], 0 , ( 0 , 0 , 255 ), 5 ) # Show the image along with the arrowhead . cv2.imshow ( ’image2’ , img2) # Exit the window if "q" is pressed on the keyboard. if cv2.waitKey ( 0 ) & amp ; 0xFF = = ord ( ’q’ ): cv2.destroyAllWindows () |