cv2.error: Unknown C++ exception from OpenCV code in easyOCR reader.readtext() function

cv2.error: Unknown C++ exception from OpenCV code in easyOCR reader.readtext() function

我尝试在车牌检测中使用 easyOCR 读取文本 model.but 有时会出现一个名为

的错误
  File "C:\Users\MY-PC\AppData\Local\Programs\Python\Python39\lib\site-packages\flask\app.py", line 2073, in wsgi_app
    response = self.full_dispatch_request()
  File "C:\Users\MY-PC\AppData\Local\Programs\Python\Python39\lib\site-packages\flask\app.py", line 1518, in full_dispatch_request
    rv = self.handle_user_exception(e)
  File "C:\Users\MY-PC\AppData\Local\Programs\Python\Python39\lib\site-packages\flask\app.py", line 1516, in full_dispatch_request
    rv = self.dispatch_request()
  File "C:\Users\MY-PC\AppData\Local\Programs\Python\Python39\lib\site-packages\flask\app.py", line 1502, in dispatch_request
    return self.ensure_sync(self.view_functions[rule.endpoint])(**req.view_args)
  File "C:\Users\MY-PC\AppData\Local\Programs\Python\Python39\lib\site-packages\dash\dash.py", line 1344, in dispatch
    response.set_data(func(*args, outputs_list=outputs_list))
  File "C:\Users\MY-PC\AppData\Local\Programs\Python\Python39\lib\site-packages\dash\_callback.py", line 151, in add_context
    output_value = func(*func_args, **func_kwargs)  # %% callback invoked %%
  File "E:\Git Projects\simple-flask-webApp\index.py", line 305, in update_output
    return [[parse_contents(list_of_contents, list_of_names)], [parse_image(list_of_contents)]]
  File "E:\Git Projects\simple-flask-webApp\index.py", line 122, in parse_image
    numberplate = number_plate(original_img)
  File "E:\Git Projects\simple-flask-webApp\index.py", line 289, in number_plate
    ocr_result = reader.readtext(region)
  File "C:\Users\MY-PC\AppData\Local\Programs\Python\Python39\lib\site-packages\easyocr\easyocr.py", line 385, in readtext
    horizontal_list, free_list = self.detect(img, min_size, text_threshold,\
  File "C:\Users\MY-PC\AppData\Local\Programs\Python\Python39\lib\site-packages\easyocr\easyocr.py", line 275, in detect
    text_box_list = get_textbox(self.detector, img, canvas_size, mag_ratio,
  File "C:\Users\MY-PC\AppData\Local\Programs\Python\Python39\lib\site-packages\easyocr\detection.py", line 95, in get_textbox
    bboxes_list, polys_list = test_net(canvas_size, mag_ratio, detector,
  File "C:\Users\MY-PC\AppData\Local\Programs\Python\Python39\lib\site-packages\easyocr\detection.py", line 55, in test_net
    boxes, polys, mapper = getDetBoxes(
  File "C:\Users\MY-PC\AppData\Local\Programs\Python\Python39\lib\site-packages\easyocr\craft_utils.py", line 236, in getDetBoxes
    boxes, labels, mapper = getDetBoxes_core(textmap, linkmap, text_threshold, link_threshold, low_text, estimate_num_chars)
  File "C:\Users\MY-PC\AppData\Local\Programs\Python\Python39\lib\site-packages\easyocr\craft_utils.py", line 31, in getDetBoxes_core
    nLabels, labels, stats, centroids = cv2.connectedComponentsWithStats(text_score_comb.astype(np.uint8), connectivity=4)
cv2.error: Unknown C++ exception from OpenCV code

但有时它能正常工作。在 运行 两次或三次出现此错误后。
这是给出错误的代码。

   for idx, box in enumerate(boxes):
        print(box)
        roi = box * [height, width, height, width]
        print(roi)
        region = image[int(roi[0]):int(roi[2]), int(roi[1]):int(roi[3])]
        reader = easyocr.Reader(['en'])
        ocr_result = reader.readtext(region)
        print(ocr_result)
        plt.imshow(cv2.cvtColor(region, cv2.COLOR_BGR2RGB))
        for result in ocr_result:
            print(np.sum(np.subtract(result[0][2],result[0][1])))
            print(result[1])

正在寻找解决此问题的方法。

尝试 opencv-python 的早期版本。我在别处看到它,它解决了我经常犯的错误,就像你一样。我认为 4.5.4.60 有效。