PaddlePaddle / PaddleOCR

Awesome multilingual OCR toolkits based on PaddlePaddle (practical ultra lightweight OCR system, support 80+ languages recognition, provide data annotation and synthesis tools, support training and deployment among server, mobile, embedded and IoT devices)
https://paddlepaddle.github.io/PaddleOCR/
Apache License 2.0
43.91k stars 7.8k forks source link

用opencv把图像变为灰度图后传入ocr报错not enough values to unpack (expected 3, got 2) #1314

Closed PUZZER closed 3 years ago

PUZZER commented 3 years ago

D:\anaconda3\envs\OCR\python.exe F:/PaddleOCR/det-rec.py Namespace(cls=False, cls_batch_num=30, cls_image_shape='3, 48, 192', cls_model_dir='C:\Users\PUZZER/.paddleocr/cls', cls_thresh=0.9, det=True, det_algorithm='DB', det_db_box_thresh=0.5, det_db_thresh=0.3, det_db_unclip_ratio=2.0, det_east_cover_thresh=0.1, det_east_nms_thresh=0.2, det_east_score_thresh=0.8, det_max_side_len=960, det_model_dir='C:\Users\PUZZER/.paddleocr/det', enable_mkldnn=False, gpu_mem=3000, image_dir=None, ir_optim=True, label_list=['0', '180'], lang='ch', max_text_length=25, rec=True, rec_algorithm='CRNN', rec_batch_num=30, rec_char_dict_path='./ppocr/utils/ppocr_keys_v1.txt', rec_char_type='ch', rec_image_shape='3, 32, 320', rec_model_dir='C:\Users\PUZZER/.paddleocr/rec/ch', use_angle_cls=False, use_gpu=True, use_pdserving=False, use_space_char=True, use_tensorrt=True, use_zero_copy_run=False) [[ 3 3 3 ... 2 2 2] [ 3 3 3 ... 2 2 2] [ 3 3 3 ... 2 2 2] ... [22 22 23 ... 30 29 28] [25 25 25 ... 31 31 31] [26 26 25 ... 32 32 32]] Traceback (most recent call last): File "F:/PaddleOCR/det-rec.py", line 34, in result = ocr.ocr(img, det=True, rec=True, cls=False) File "F:\PaddleOCR\paddleocr.py", line 247, in ocr dt_boxes, rec_res = self.call(img) File "F:\PaddleOCR\tools\infer\predict_system.py", line 88, in call dt_boxes, elapse = self.text_detector(img) File "F:\PaddleOCR\tools\infer\predict_det.py", line 137, in call im, ratio_list = self.preprocess_op(img) File "F:\PaddleOCR\ppocr\data\det\db_process.py", line 250, in call im, (ratio_h, ratio_w) = self.resize_image_type0(im) File "F:\PaddleOCR\ppocr\data\det\db_process.py", line 177, in resize_imagetype0 h, w, = im.shape ValueError: not enough values to unpack (expected 3, got 2)

原图没问题,灰度图试过operncv3和opencv4.2都不行读入代码如下: from paddleocr import PaddleOCR

ocr = PaddleOCR(gpu_mem=3000, use_angle_cls=False, use_tensorrt=True,) # need to run only once to download and load model into memory img_path = os.listdir('./imagetest/') img_path.sort(key=lambda x: int(x[:-4])) # 倒着数第四位'.'为分界线,按照‘.’左边的数字从小到大排序,读入文件名后排序 t1 = time.time() for file in img_path:

读取灰度图像

img = cv2.imread('./imagetest/' + file, cv2.IMREAD_GRAYSCALE)
print(img)
t0 = time.time()
result = ocr.ocr(img, det=True, rec=True, cls=False)
print('单张耗时:', (time.time() - t0))
for line in result:
    print(line)

print("识别总耗时:", time.time() - t1)

WenmuZhou commented 3 years ago

图片需要Gray2BGR,paddleocr包内部没有对灰度图做支持

PUZZER commented 3 years ago

图片需要Gray2BGR,paddleocr包内部没有对灰度图做支持

谢谢回复,有机会可以支持下,新手很容易掉坑,此问题closed