cv2.error:未知的 C++ easyOCR reader.readtext() 函数中 OpenCV 代码的异常

发布于 2025-01-15 19:53:00 字数 3510 浏览 0 评论 0原文

我尝试在车牌检测模型中使用easyOCR读取文本。但有时会出现错误

  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])

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

I have tried to read the text using easyOCR in the number plate detection model.but some times there is a error called

  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

but sometimes it works properly. after running two or three times this error occurred.
This is the code that gives the error.

   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])

Looking for a solution to fix this issue.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

空宴 2025-01-22 19:53:00

尝试使用早期版本的 opencv-python。我在其他地方看到它,它解决了我像你一样的持续错误。我认为 4.5.4.60 有效。

Try an earlier version of opencv-python. I saw it elsewhere and it solved my constant error like yours. I think 4.5.4.60 worked.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文