How can I fix this issue raised using easyocr_Python 3.11

453 Views Asked by At

I have the following Python script that raises the error "cv2.error: OpenCV(4.5.4) D:\a\opencv-python\opencv-python\opencv\modules\highgui\src\window.cpp:1274: error: (-2:Unspecified error) The function is not implemented. Rebuild the library with Windows, GTK+ 2.x or Cocoa support. If you are on Ubuntu or Debian, install libgtk2.0-dev and pkg-config, then re-run cmake or configure script in function 'cvShowImage'

import cv2

from easyocr import Reader

import argparse

from matplotlib.image import imread

 

def cleanup_text(text):

    return "".join([c if ord(c) < 128 else "" for c in text]).strip()

 

ap = argparse.ArgumentParser()

ap.add_argument("-i", "--image", required=False, help="path to input image to be OCR'd")

ap.add_argument("-l", "--langs", type=str, default="en", help="comma separated list of languages to OCR")

ap.add_argument("-g", "--gpu", type=int, default=1, help="whether or not GPU should be used")

args = vars(ap.parse_args())

 

langs = args["langs"].split(",")

print("[INFO] OCR'ing with the following languages: {}".format(langs))

 

#image = cv2.imread(args["image"])

image = cv2.imread('Capture1.jpg')

 

print("[INFO] OCR'ing input image...")

reader = Reader(langs, gpu=args["gpu"] > 0)

results = reader.readtext(image)

 

for (bbox, text, prob) in results:

    print("[INFO] {}".format(prob, text))

 

    (tl, tr, br, bl) = bbox

    tl = (int(tl[0]), int(tl[1]))

    tr = (int(tr[0]), int(tr[1]))

    br = (int(br[0]), int(br[1]))

    bl = (int(bl[0]), int(bl[1]))

 

    text = cleanup_text(text)

    cv2.rectangle(image, tl, br, (0, 255, 0), 2)

    cv2.putText(image, text, (tl[0], tl[1] - 10),

        cv2.FONT_HERSHEY_SIMPLEX, 0.8, (0, 255, 0), 2)

   

cv2.imshow("Image", image)

cv2.waitKey(0)

Full traceback:

Traceback (most recent call last):

  File "c:\Users\1\.register\OCRin.py", line 1, in <module>

    import cv2

  File "C:\Users\1\.register\lib\site-packages\cv2\__init__.py", line 181, in <module>

    bootstrap()

  File "C:\Users\1\.register\lib\site-packages\cv2\__init__.py", line 175, in bootstrap

    if __load_extra_py_code_for_module("cv2", submodule, DEBUG):

  File "C:\Users\1\.register\lib\site-packages\cv2\__init__.py", line 28, in __load_extra_py_code_for_module

    py_module = importlib.import_module(module_name)

  File "C:\Program Files\Python310\lib\importlib\__init__.py", line 126, in import_module

    return _bootstrap._gcd_import(name[level:], package, level)

  File "C:\Users\1\.register\lib\site-packages\cv2\gapi\__init__.py", line 301, in <module>

    cv.gapi.wip.GStreamerPipeline = cv.gapi_wip_gst_GStreamerPipeline

AttributeError: partially initialized module 'cv2' has no attribute 'gapi_wip_gst_GStreamerPipeline' (most likely due to a circular import)
0

There are 0 best solutions below