需要:
电脑,摄像头,打印几个测试二维码
参考:
https://blog.csdn.net/kingroc/article/details/85265215
https://blog.csdn.net/kingroc/article/details/85265215
参考文章实现了本地图片识别,其实CV对摄像头也是按帧处理的,于是略修改实现摄像头前举着一张含有二维码的纸片,输出内容。
代码改的,有些乱,回头再优化
import cv2
import numpy as np
def display(im, bbox):
n = len(bbox)
for j in range(n):
cv2.line(im, tuple(bbox[j][0]), tuple(bbox[(j + 1) % n][0]), (255, 0, 0), 3)
# Display results
cv2.imshow("Results", im)
# inputImage = cv2.imread("QR.jpg")
cap = cv2.VideoCapture(0)
qrDecoder = cv2.QRCodeDetector()
while(True):
ret, inputImage = cap.read()
# Detect and decode the qrcode
data, bbox, rectifiedImage = qrDecoder.detectAndDecode(inputImage)
if len(data) > 0:
print("Decoded Data : {}".format(data))
display(inputImage, bbox)
rectifiedImage = np.uint8(rectifiedImage);
cv2.imshow("Rectified QRCode", rectifiedImage);
else:
print("QR Code not detected")
cv2.imshow("Results", inputImage)
cv2.waitKey(0)
cv2.destroyAllWindows()