Quantcast
Channel: OpenCV Q&A Forum - Latest question feed
Viewing all articles
Browse latest Browse all 19555

read arrow orientation from image

$
0
0
Hello. I created script to get arrows from the image. Im trying to detect orientation for each arrow. With my script i manage to get somewhat accurate results. The problem is that Im getting same results if arrows are oriented up or down, to the left or to the right. How to know if the arrow is pointing to left or to the right? In both cases of the pictures below i get same result around 90 deg. ![image description](/upfiles/1481278360776499.png) ![image description](/upfiles/1481278407811398.png) the script is folowing import numpy as np import cv2 import math img = cv2.imread('sample7.png') height, width, channels = img.shape img = cv2.resize(img, (width*8, height*8)) img = cv2.medianBlur(img,5) imgray = cv2.cvtColor(img,cv2.COLOR_BGR2GRAY) ret,th1 = cv2.threshold(imgray,100,255,cv2.THRESH_BINARY) edged=cv2.Canny(th1,127,200) im2,contours,h = cv2.findContours(edged.copy(),cv2.RETR_TREE,cv2.CHAIN_APPROX_SIMPLE) (img2,cnts, _) = cv2.findContours(edged.copy(), cv2.RETR_TREE, cv2.CHAIN_APPROX_SIMPLE) screenCnt=None flag_t=False flag_s=False kot=[] for c in cnts: approx = cv2.approxPolyDP( c, 0.01*cv2.arcLength(c,True), True ) area = cv2.contourArea(c) #print area if int(len(approx)) > 8 and area > 600 and area < 1100: anglelist=[] cv2.drawContours(img, [approx], -1, (0, 255, 255), 1) (x,y),(MA,ma),angle = cv2.fitEllipse(c) print round(angle,-1) kot.append(round(angle,-1)) d = {} for elm in kot: d[elm] = d.get(elm, 0) + 1 counts = [(j,i) for i,j in d.items()] count, max_elm = max(counts) print 'most common:' print max_elm cv2.imshow('img',img) cv2.waitKey(0) cv2.destroyAllWindows()

Viewing all articles
Browse latest Browse all 19555

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>