Ask Your Question

jaka87's profile - activity

2020-09-24 14:42:38 -0500 received badge  Notable Question (source)
2020-05-27 01:39:01 -0500 received badge  Popular Question (source)
2016-12-12 01:41:48 -0500 commented question read arrow orientation from image

I updated the question.

2016-12-12 01:40:40 -0500 received badge  Editor (source)
2016-12-09 13:43:30 -0500 commented question read arrow orientation from image

i tried template matching with so so results. With the script above the shape is detected just fine. I think it would solve my problem if i would draw bowning rectangle around arrow, split it to two sides by width and then calculate how which one is more filled with contour. The only problem is i don't know how to do it.

2016-12-09 05:11:20 -0500 asked a question read arrow orientation from image

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 image description

original image

image description

UPDATE 12.12.2016: i manage to get it somewhat working by blurring the picture more to get better contour. I then create bounding rectangle and split it in two parts and calculate surface area of each to get if arrows are facing up or down. Then I chose two points on bounding rectangle and calculate degrees from it. From degrees i then get wind direction.

Now bounding rectangle can sometimes be strangely oriented and giving slightly wrong directions. I think bounding ellipse is more appropriate but the results of degrees are not always correct since i cant set in which direction to check for the angle like i did in rectangle. How could i do the same with ellipse or just mathematically invert degree value based on arrow direction ?

import cv2
import numpy as np
from matplotlib import pyplot as plt
import math
import matplotlib.path as mplPath
from math import atan2, degrees, pi

def direction2(img):

    height, width, channels = img.shape 
    img = cv2.resize(img, (width*8, height*8))                    
    img = cv2.medianBlur(img,9)
    imgray = cv2.cvtColor(img,cv2.COLOR_BGR2GRAY)

    ret,th1 = cv2.threshold(imgray,150,255,cv2.THRESH_BINARY)
    #return edged

    (img2,cnts, _) = cv2.findContours(edged.copy(), cv2.RETR_TREE, cv2.CHAIN_APPROX_SIMPLE)


    for c in cnts:
        area = cv2.contourArea(c)
        #print area
        if area > 500 and area < 1650:  
            (x,y),radius = cv2.minEnclosingCircle(c)
            center = (int(x),int(y))

            ellipse = cv2.fitEllipse(c)
            (x,y),(MA,ma),angle = cv2.fitEllipse(c)

            rect = cv2.minAreaRect(c)
            box = cv2.boxPoints(rect)
            box = np.int0(box)
            #print box

            a= math.hypot(box[1][0] - box[0][0], box[1][1] - box[0][1])
            b= math.hypot(box[3][0] - box[0][0], box[3][1] - box[0][1])

            if a>b: 


                bbPath = mplPath.Path(np.array([[box[0][0], box[0][1]],[xos, yos],[xos2, yos2],[box[3 ...