I am developing a method to localise license plate and ultimately apply perspective transform to straighten the plate horizontally.
Currently, my image processing pipeline is able to roughly locate the plate but I'd like to narrow it further. I have applied edge detection, morphological operations and connected component analysis to get to this stage.
My result for license plate detection currently is this
I am trying to implement HoughLinesP to find straight lines of the fonts and then find the intersection of the lines with HoughPeaks, like this
My current attempt at finding houghlines is shown at the code below. However, can anyone guide me on how to find hough peaks? I did some research online and couldn't find any reliable reference.
def findHoughLines(self, image):
from src.Line import Line
# Add 1 channel to binary image
image = image[..., np.newaxis]
vis = cv2.cvtColor(image, cv2.COLOR_GRAY2BGR)
canny = cv2.Canny(image, 100, 200)
cv2.imshow("canny", canny)
lines = cv2.HoughLinesP(canny, rho=0.01, theta=np.pi/360, threshold=10, minLineLength=100, maxLineGap=30)
print(len(lines))
linesHorizontal, linesVertical = [], []
if lines is None:
print("[Info] No Hough lines have been detected")
return image
for line in lines:
x1, y1, x2, y2 = line[0]
if abs(x1 - x2) > abs(y1 - y2):
linesHorizontal.append(Line(line[0]))
else:
linesVertical.append(Line(line[0]))
# sort lines
linesHorizontal = sorted(linesHorizontal, key=lambda l: l.d_y, reverse=True)[:10]
linesVertical = sorted(linesVertical, key=lambda l: l.d_x, reverse=True)[:10]
for line in linesHorizontal:
x1, y1, x2, y2 = line.points
cv2.line(vis, (x1, y1), (x2, y2), (0, 0, 255), 1)
for line in linesVertical:
x1, y1, x2, y2 = line.points
cv2.line(vis, (x1, y1), (x2, y2), (0, 255, 0), 1)
cv2.imshow("HoughLines", vis)
Result of HoughLinesP Detection