I'm trying to identify the contour area of a german vehicle registration. I followed some tutorials and had the idea to use cv2 findContours in combination with HoughLinesP . The challenge is that the registration is held by human that sits inside a car.
- The hands breaks the contour of the registration
- The car has other contours like the registration e.g. a car radio
- The registration reaches over the boundary of the image.
When I crop the image based on the line that i created I get something from the radio instead of the registration. Because the lines of the registration are not connected.
I would would really appreciate if someone could point me into the right direction.
def crop_image(dilated):
binary = cv2.threshold(dilated, 150, 255, cv2.THRESH_BINARY)[1]
cv2.imshow("binary", binary)
edges = cv2.Canny(binary, 150, 84, apertureSize=3)
cv2.imshow("canny", edges)
dilted_lines = dilated
lines = cv2.HoughLinesP(edges, 1, 3.14 / 180, 100, minLineLength=15, maxLineGap=500)
for line in lines:
l = line[0]
cv2.line(dilted_lines, (l[0], l[1]), (l[2], l[3]),
(0, 255, 0), 4)
cv2.imshow("lines", dilted_lines)
contours, _ = cv2.findContours(edges, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)
sortedCnt = sorted(contours, key=lambda x: cv2.contourArea(x))
x, y, w, h = cv2.boundingRect(sortedCnt[-1])
cv2.imshow("crop", dilated[y:y + h, x:x + w])



