up主开发环境:python3.6、OpenCV3.4.4、tensorflow1.12
my开发环境:Python 3.7.0、cv2 4.2.0、tensorflow1.15.0
跑一个车牌识别的脚本
https://blog.youkuaiyun.com/GK_2014/article/details/84779166
就知道开发环境不同会出幺蛾子,果然就出了,
Traceback (most recent call last):
File "d:/AI_program/CarPlateIdentity/code/carPlateIdentity.py", line 455, in <module>
car_plate_list = locate_carPlate(img,pred_img)
File "d:/AI_program/CarPlateIdentity/code/carPlateIdentity.py", line 249, in locate_carPlate
cloneImg,contours,heriachy = cv2.findContours(pred_image,cv2.RETR_EXTERNAL,cv2.CHAIN_APPROX_SIMPLE)
ValueError: not enough values to unpack (expected 3, got 2)
原因:(版本)
OpenCV 在3.4.3.18 以前findContours输出3个参数如下
im2, contours, hierarchy = cv2.findContours(mask, cv2.RETR_TREE, cv2.CHAIN_APPROX_SIMPLE)
如果不改代码则需要把opencv版本降级pip install opencv-python==3.4.3.18
在3.4.3.18 之后输出2个参数,故只要去掉cloneImg,即可
contours, hierarchy = cv2.findContours(mask, cv2.RETR_TREE, cv2.CHAIN_APPROX_SIMPLE)
修改:
#修改前
#cloneImg,contours,heriachy = cv2.findContours(pred_image,cv2.RETR_EXTERNAL,cv2.CHAIN_APPROX_SIMPLE)
#修改后
contours,heriachy = cv2.findContours(pred_image,cv2.RETR_EXTERNAL,cv2.CHAIN_APPROX_SIMPLE)
文件解决,车票识别成功