Skip to content

Stand Up & Wheel Count Size Location

Ciaran-OBrien edited this page Nov 8, 2018 · 3 revisions
cols = ['Wheel No.', 'X Coords', 'Y Coords','Wheel Diam']
circleLocations = []

# Working best if we take the greyscaled image as HoughCircles fxn preforms canny edge on the image anyway
img = cv2.medianBlur(greyscale_image,5)
cimg = cv2.cvtColor(img,cv2.COLOR_GRAY2BGR)
# houghCircle(src,mode,dp,min distance between centroids,param1=canny threshold , param2 = smaller means more false positives, 
# then min/max radius of the circles) 
circles = cv2.HoughCircles( img,
                            cv2.HOUGH_GRADIENT,
                            1,
                            30,
                            param1=160,
                            param2=25,
                            minRadius=10,
                            maxRadius=50)

circles = np.uint16(np.around(circles))
for index,i in enumerate(circles[0,:]):
    # draw the outer circle
    cv2.circle(cimg,(i[0],i[1]),i[2],(0,255,0),2)
    # draw the center of the circle
    cv2.circle(cimg,(i[0],i[1]),2,(0,0,255),3)
    # append to list that'll be added to the dataframe
    circleLocations.append([index+1, i[0], i[1], i[2]])

wheelData = pd.DataFrame(circleLocations, columns=cols)
plt.imshow(cimg)
print(wheelData)

# TODO There could be a point that if the circle's y coord is along the same plane, so a buffer for +- 30 pixels,
# then only include those circles
    Wheel No.  X Coords  Y Coords  Wheel Diam
0           1       488       108          44
1           2       524        78          28
2           3       558       108          29
3           4       600       188          30
4           5       634        90          49
5           6        72        90          37
6           7       668       186          30
7           8       424        48          48
8           9       226       196          13
9          10       598       118          29
10         11       362        68          29
11         12       246        78          21
12         13       528       186          29
13         14       572        64          30
14         15       300        82          28
15         16       170       196          12
16         17        62       130          17
17         18        66       196          11
18         19        90       144          22
19         20       438        76          17
actualWheels = []
biggerWheel = 0
# Using just the lower third of the image to find the wheels
lowerThirdBuffer = image.shape[0] * 0.66

for index,row in enumerate(wheelData.iterrows()):
    # Let's find the largest wheel, and take that as the vehicle's wheel size
    if(row[1][3] > biggerWheel):
        biggerWheel = row[1][3]
    # Appends the actual wheels to a new list
    if(row[1][2] > lowerThirdBuffer):
        row[1][3] = biggerWheel
        actualWheels.append(list(row[1]))

actualWheels = pd.DataFrame(actualWheels,columns=cols)
print(actualWheels)
   Wheel No.  X Coords  Y Coords  Wheel Diam
0          4       600       188          44
1          7       668       186          49
2          9       226       196          49
3         13       528       186          49
4         16       170       196          49
5         18        66       196          49

Clone this wiki locally