0

I did an image processing project by python 3.10.9 in pycharm IDE 2023.3 and I want to do text extraction from image witch I capture from webcam when I run this code on my pc it is ok but when I run it on PDA with windows 11 64 bit os I faced with this issue process finished with exit code -1073741795 (0xC000001D) this is my code and my PDA Config is : cpu: intel celeron 1000 GH ram : 8 gb I do not use gpu for processing
I personally think the cause of my issue is cpu but I am not certain about it

import os
import cv2
import easyocr
from tkinter import *
from PIL import Image, ImageTk

flag = 0


def recognize_text(img_path):
    render = easyocr.Reader(['en'])
    return render.readtext(img_path)    -------------------------> here is my issue and code crashed


def overlay_ocr_text(img_path, save_name):
    img = cv2.imread(img_path)
    img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)

    # dpi = 80
    # fig_width, fig_height = int(img.shape[0]/dpi), int(img.shape[1]/dpi)
    # plt.figure()
    # f, axarr = plt.subplots(1, 2, figsize=(fig_width, fig_height))
    # axarr[0].imshow(img)

    result = recognize_text(img_path)
    with open('extract.txt', 'w') as f:
        for(bbox, text, prob) in result:
            if prob >= 0.4:
                f.write(f'{text} ({prob:.2f})\n')
                # print(f'Detect Text: {text} (Probability: {prob:.2f})')

                (top_left, top_right, bottom_right, bottom_left) = bbox
                top_left = (int(top_left[0]), int(top_left[1]))
                bottom_right = (int(bottom_right[0]), int(bottom_right[1]))

                cv2.rectangle(img=img, pt1=top_left, pt2=bottom_right, color=(255, 0, 0), thickness=5)

                cv2.putText(img=img, text=text, org=(top_left[0], top_left[1] - 10), fontFace=cv2.FONT_HERSHEY_SIMPLEX,
                            fontScale=1, color=(255, 0, 0), thickness=2)

    # axarr[1].imshow(img)
    # plt.savefig(f'./output/{save_name}_overlay.jpg', bbox_inches='tight')


def take_capture():
    vid = cv2.VideoCapture(0)

    while (True):
        ret, frame = vid.read()
        cv2.imshow('frame', frame)
        if cv2.waitKey(1) & 0xFF == ord('q'):
            break
    vid.release()

    cv2.destroyAllWindows()


def center(win):
    win.update_idletasks()
    width = win.winfo_width()
    frm_width = win.winfo_rootx() - win.winfo_x()
    win_width = width + 2 * frm_width
    height = win.winfo_height()
    titlebar_height = win.winfo_rooty() - win.winfo_y()
    win_height = height + titlebar_height + frm_width
    x = win.winfo_screenwidth() // 2 - win_width // 2
    y = win.winfo_screenheight() // 2 - win_height // 2
    win.geometry('{}x{}+{}+{}'.format(width, height, x, y))
    win.deiconify()


def take_snapp():
    image1 = Image.fromarray(img1P)
    image1.save('TA.png')
    path = os.getcwd() + '/TA.png'
    overlay_ocr_text(path, os.getcwd())
    global flag
    flag = 1


flag = 0
root = Tk()
capture = cv2.VideoCapture(0)

root.geometry('600x500')
root.configure(bg='Black')
Label(root, text='Sepahan Barcode', font=('times new roman', 30, "bold"), bg='black', fg='red').pack()
f1 = LabelFrame(root, bg='red')
f1.pack()
L1 = Label(f1, bg='red')
L1.pack()
Button(root, text='Take Snapshot', font=('times new roman', 30, "bold"), bg='black', fg='red', command=take_snapp).pack(fill='x', expand=True, padx=20, pady=20)


while True:
    if flag == 1:
        capture.release()
        root.destroy()
        break
    img1 = capture.read()[1]
    img1P = cv2.cvtColor(img1, cv2.COLOR_BGR2RGB)
    img1 = cv2.resize(img1P, (500, 300))
    img1 = ImageTk.PhotoImage(image=Image.fromarray(img1))
    L1['image'] = img1
    center(root)
    root.update()
  • it is to do with the path. you should use `__file__` or `sys.argv[0]` to determine the path where the code is run from. – D.L Jan 19 '23 at 08:57

0 Answers0