I tried to detect vehicle axles in an image. Here are the steps that I followed.
- Read the image and changed to grayscale.
- Applied median.
- Applied canny edge detection.
- Applied Hough circles.
For canny the threshold1, threshold2 parameters are varied using track bar and for Hough circles param1, param2, minDist are varied. By param1 and param2 has no impact on detection.
Problem : As you can see in the last image, it detects the circles and it is little away from the original axle. Is there any other parameters that I need to change or consider ?
Code
import cv2
import numpy as np
def readAndResize(image,a):
imag = cv2.imread(image,a)
org = cv2.imread(image)
#resixe the image
small = cv2.resize(imag, (0,0), fx=0.3, fy=0.3)
small2 = cv2.resize(org, (0,0), fx=0.3, fy=0.3)
height, width = small.shape
img = small[height - height/3:height,0:width]
org2 = small2[height - height/3:height,0:width]
return img, org2
img,org2 = readAndResize('5.jpg',0)
cv2.imshow('Original',org2)
gray = cv2.cvtColor(org2, cv2.COLOR_BGR2GRAY)
med = cv2.medianBlur(gray,5)
canny = cv2.Canny(med,100,50)
circles = cv2.HoughCircles(canny,cv2.HOUGH_GRADIENT,1,92,20,10,minRadius=4,maxRadius=0)
circles = np.uint16(np.around(circles))
for i in circles[0,:]:
cv2.circle(org2,(i[0],i[1]),i[2],(0,255,0),2)
cv2.circle(org2,(i[0],i[1]),2,(0,50,255),3)
cv2.imshow('Median',med)
cv2.imshow('canny',canny)
cv2.imshow('Detected',org2)
cv2.waitKey(0)
cv2.destroyAllWindows()