我有收据的图像,其中一些有二维码。我想要在这些图像中可靠地检测二维码。二维码的位置并不重要,重要的是它是否出现在收据的图像中。
我目前的进展如下:
import cv2
uri = 'dummy-uri'
qrCodeDetector = cv2.QRCodeDetector()
image = io.imread(uri)
decodedText, points, _ = self.qrCodeDetector.detectAndDecode(image)
NoneType = type(None)
if type(points) is not NoneType:
print('There is QR code in the image')
else:
print('There is not QR code in the image')基本上,如果没有二维码,point就是None --没有边上的点。但cv2 QrCodeDetector的表现并不是很好。我可以想象,训练一个物体检测器(例如Yolo)会带来更高的准确性。目前,我拥有的大多数收据图像都被识别为没有二维码的图像,尽管它们有二维码。对如何更可靠(更准确)检测二维码有什么想法吗?
发布于 2021-08-05 16:24:15
我尝试做模板matching.It会给出相当准确的结果,如果模板和图片是相同的大小,这个代码给出了两个图像的良好结果,但在其他情况下,提供的模板和图像中的二维码是不同的大小,所以它不显示预期的结果
import numpy as np
import cv2我调整了图像的大小,以减少btw模板和完整图像的差异。qr.png是实际图像的屏幕截图
img = cv2.resize(cv2.imread('Download/full.jpg', 0), (0, 0), fx=0.2, fy=0.17)
template = cv2.imread('qr.png', 0)
h, w = template.shape方法列表描述了查找template.You的不同方法,可以通过在for循环中检查并选择一个来测试哪一个更准确。
methods = [cv2.TM_CCOEFF, cv2.TM_CCOEFF_NORMED, cv2.TM_CCORR,
cv2.TM_CCORR_NORMED, cv2.TM_SQDIFF, cv2.TM_SQDIFF_NORMED]
for method in methods:
img2 = img.copy()
result = cv2.matchTemplate(img2, template, method)
min_val, max_val, min_loc, max_loc = cv2.minMaxLoc(result)
if method in [cv2.TM_SQDIFF, cv2.TM_SQDIFF_NORMED]:
location = min_loc
else:
location = max_loc
bottom_right = (location[0] + w, location[1] + h)
cv2.rectangle(img2, location, bottom_right, 255, 5)
cv2.imshow('Match', img2)
cv2.waitKey(0)
cv2.destroyAllWindows()有关代码的更多详细信息,请参阅此link
https://stackoverflow.com/questions/68652482
复制相似问题