Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error : How to fix "SystemError: <built-in function imshow> returned NULL without setting an error" in Opencv python

I am working on one project Data extraction from invoices using computer vision in this i am trying to extract data from image invoice using opencv and pytesseract and further i am using Regex for segregate that raw data into different parts like Date, Vendor name, Invoice number, item name and item quantity.at start i am trying to extract Date but stuck with error.

here is my code

import pytesseract
from pytesseract import Output
import cv2

img = cv2.imread('invoice.png')
d = pytesseract.image_to_data(img, output_type=Output.DICT)
n_boxes = len(d['level'])
for i in range(n_boxes):
    (x, y, w, h) = (d['left'][i], d['top'][i], d['width'][i], d['height'][i])
    img = cv2.rectangle(img, (x, y), (x + w, y + h), (0, 0, 255), 2)

cv2.imshow(img,'img')

but i get this error

File "testpdf3.py", line 12, in <module>
    cv2.imshow(img,'img')
SystemError: <built-in function imshow> returned NULL without setting an error
like image 499
Mayur Satav Avatar asked Mar 24 '26 03:03

Mayur Satav


1 Answers

The syntax of cv2.imshow() is cv2.imshow("windowname", image). In the program, line 12 should be cv2.imshow('img', img).

like image 197
Vaishnavi Piyush Avatar answered Mar 26 '26 15:03

Vaishnavi Piyush