2 python ocr opencv machine-learning
因此,我正在尝试创建一个车牌检测程序,并且我一直在遵循该指南(https://github.com/nicknochnack/ANPRwithPython/blob/main/ANPR%20-%20Tutorial.ipynb),但是我我目前遇到了问题。
img = cv2.imread('image4.jpg')
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
bfilter = cv2.bilateralFilter(gray, 11, 17, 17) #Noise reduction
edged = cv2.Canny(bfilter, 30, 200) #Edge detection
keypoints = cv2.findContours(edged.copy(), cv2.RETR_TREE, cv2.CHAIN_APPROX_SIMPLE)
contours = imutils.grab_contours(keypoints)
contours = sorted(contours, key=cv2.contourArea, reverse=True)[:10]
location = None
for contour in contours:
approx = cv2.approxPolyDP(contour, 10, True)
if len(approx) == 4:
location = approx
break
mask = np.zeros(gray.shape, np.uint8)
new_image = cv2.drawContours(mask, [location], 0,255, -1)
new_image = cv2.bitwise_and(img, img, mask=mask)
Run Code Online (Sandbox Code Playgroud)
我也尝试将“位置”更改为 0 或 [0] 但没有成功。
小智 6
找到了这个问题的“解决方案”,尽管它并不是一个解决方案。这种情况不断发生的原因是因为我一直在测试的图像中没有任何可识别的形状,因此由于它无法设置“位置”,所以它也无法正确调用该函数。希望遇到此问题的人能够看到此内容并检查他们的数据。