|
楼主 |
发表于 2021-12-26 15:08:36
|
显示全部楼层
还是报错 但错误类型变了:
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 |
|