So I’m trying to create a license plate detection program and I have been following a guide for that, (https://github.com/nicknochnack/ANPRwithPython/blob/main/ANPR%20-%20Tutorial.ipynb) however I am currently running into a problem.
JavaScript
21
1
img = cv2.imread('image4.jpg')
2
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
3
4
bfilter = cv2.bilateralFilter(gray, 11, 17, 17) #Noise reduction
5
edged = cv2.Canny(bfilter, 30, 200) #Edge detection
6
7
keypoints = cv2.findContours(edged.copy(), cv2.RETR_TREE, cv2.CHAIN_APPROX_SIMPLE)
8
contours = imutils.grab_contours(keypoints)
9
contours = sorted(contours, key=cv2.contourArea, reverse=True)[:10]
10
11
location = None
12
for contour in contours:
13
approx = cv2.approxPolyDP(contour, 10, True)
14
if len(approx) == 4:
15
location = approx
16
break
17
18
mask = np.zeros(gray.shape, np.uint8)
19
new_image = cv2.drawContours(mask, [location], 0,255, -1)
20
new_image = cv2.bitwise_and(img, img, mask=mask)
21
I have also tried to change “location” to 0 or [0] but to no success.
Advertisement
Answer
Found the “solution” to this, although it’s not much an Solution. The reason this kept happening is because the images I have been testing with, didn’t have any recognizable shapes in it, so since it was not able to set “location”, it also wasn’t able to call the function properly. Hopefully someone who runs into this issue sees this and checks their data.