车牌识别出现的问题
出现问题的源代码:img = cv2.imread('D:/pycharm/cv-cnn-lpr-main/data/testset/set1/19.jpg')
resize_img = img_resize(img)
# 预处理
pred_img = pre_process(resize_img)
# 车牌定位
car_plate_list = locate_plate(resize_img, pred_img)
# CNN车牌过滤
ret,cnn_plate = cnn_select_plate(car_plate_list, plate_model_path)
if not ret:
print("未检测到车牌")
cv2.imshow('cnn_plate_img', cnn_plate)
cv2.imwrite('./data/output/plate_cnn.jpg', cnn_plate)
问题:
Traceback (most recent call last):
File "D:/pycharm/cv-cnn-lpr-main/lpr_main.py", line 457, in <module>
cv2.imshow('cnn_plate_img', cnn_plate)
cv2.error: OpenCV(4.5.4) :-1: error: (-5:Bad argument) in function 'imshow'
> Overload resolution failed:
>- mat is not a numpy array, neither a scalar
>- Expected Ptr<cv::cuda::GpuMat> for argument 'mat'
>- Expected Ptr<cv::UMat> for argument 'mat' 请问一下各位该怎么解决
else:
cv2.imshow('cnn_plate_img', cnn_plate)
cv2.imwrite('./data/output/plate_cnn.jpg', cnn_plate) hrpzcf 发表于 2021-12-23 21:01
else:
cv2.imshow('cnn_plate_img', cnn_plate)
cv2.imwrite('./data/output/plate_cnn.jpg', cn ...
还是报错 但错误类型变了:
Traceback (most recent call last):
File "D:/pycharm/cv-cnn-lpr-main/lpr_main.py", line 470, in <module>
char_img_list = extract_char(cnn_plate)
File "D:/pycharm/cv-cnn-lpr-main/lpr_main.py", line 370, in extract_char
gray_plate = cv2.cvtColor(car_plate_extract, cv2.COLOR_BGR2GRAY)
cv2.error: OpenCV(4.5.4) :-1: error: (-5:Bad argument) in function 'cvtColor'
> Overload resolution failed:
>- src is not a numpy array, neither a scalar
>- Expected Ptr<cv::UMat> for argument 'src'
错误的两个地方代码:
1.
# 车牌定位
car_plate_list = locate_plate(resize_img, pred_img)
# CNN车牌过滤
ret, cnn_plate = cnn_select_plate(car_plate_list, plate_model_path)
if not ret:
print("未检测到车牌")
else:
cv2.imshow('cnn_plate_img', cnn_plate)
cv2.waitKey(0)
cv2.imwrite('./data/output/plate_cnn.jpg', cnn_plate)
# 字符提取
char_img_list = extract_char(cnn_plate)
# CNN字符识别
text = cnn_recognize_char(char_img_list, char_model_path)
print(text)
cv2.waitKey(0)
2.
# 识别字符并排列
def extract_char(car_plate_extract):
gray_plate = cv2.cvtColor(car_plate_extract, cv2.COLOR_BGR2GRAY)
# retn, binary_plate = cv2.threshold(gray_plate, 0, 255, cv2.THRESH_BINARY | cv2.THRESH_OTSU)
binary_plate = cv2.adaptiveThreshold(gray_plate, 255, cv2.ADAPTIVE_THRESH_GAUSSIAN_C, cv2.THRESH_BINARY, 17, -5)
char_img_lists = get_chars(binary_plate)
return char_img_lists
页:
[1]