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

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

我正在做一个项目使用计算机视觉从发票中提取数据 在此我尝试使用 opencv 和 pytesseract 从图像发票中提取数据并且我正在使用 Regex 用于将原始数据分成不同的部分,如日期、供应商名称、发票编号、项目名称和项目 quantity.at 开始我正在尝试提取日期但出现错误。

这是我的代码

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

但是我收到这个错误

File "testpdf3.py", line 12, in <module>
    cv2.imshow(img,'img')
SystemError: <built-in function imshow> returned NULL without setting an error

cv2.imshow()的语法是 cv2.imshow("windowname", image)。 在程序中,第12行应该是cv2.imshow('img', img).