【发布时间】:2021-12-16 03:29:55
【问题描述】:
所以我正在尝试使用来自this S.O. answer 的代码解码二维码图像。这是修改后的代码:
import cv2
# Name of the QR Code Image file
filename = r"C:\temp\2021-12-14_162414.png"
# read the QRCODE image
image = cv2.imread(filename)
# initialize the cv2 QRCode detector
detector = cv2.QRCodeDetector()
# detect and decode
data, vertices_array, binary_qrcode = detector.detectAndDecode(image)
# if there is a QR code
# print the data
if vertices_array is not None:
print("QRCode data:")
print(data)
else:
print("There was some error")
(这是整个程序;我还在试验。)
PNG 文件本身非常小,只有 43 KB 大小,分辨率为 290x290 (24 bpp),包含只是二维码。
但是,我不断收到错误消息:
Traceback (most recent call last):
File "C:/Repos/tesqr/decod-cv2.py", line 10, in <module>
data, vertices_array, binary_qrcode = detector.detectAndDecode(image)
cv2.error: OpenCV(4.5.4) D:\a\opencv-python\opencv-python\opencv\modules\core\src\alloc.cpp:73: error: (-4:Insufficient memory) Failed to allocate 54056250000 bytes in function 'cv::OutOfMemoryError'
为什么 alloc.cpp 要求 54 GB 的 RAM ???
我是 OpenCV 新手,所以请帮我解决问题所在。
我正在使用的库是:
$ pip3 freeze | grep opencv
opencv-contrib-python-headless==4.5.4.60
输入图像:
【问题讨论】:
-
另外,请分享输入图像。
-
@stateMachine 给你:drive.google.com/file/d/1zgZ5VH_Cqt1xPo3WMmYQ3zvQLl1de-Hd/…
-
@ChristophRackwitz 好吧,二维码应该包含一个 Zip 文件(原始文件,不是 baseXX 编码的)。使用 node.js 库
zbar.wasm或jsqr可以完美解码。不幸的是,我无法生成其他二维码,但 Zip 文件中的信息是虚拟信息,因此可以公开。 -
我刚刚创建了一个问题:github.com/opencv/opencv/issues/21287