How to reliably detect a barcode's 4 corners in real time video capture

送分小仙女□ 提交于 2020-12-15 05:26:37

问题


I found a Stackoverflow answer for detecting barcode in an image. I am trying to apply the method in the Stackoverflow answer to realtime video capture because my current solution only detect barcodes on clean large surface. How can I apply the method to video capture Here is my code.

import cv2
import numpy as np
from pyzbar.pyzbar import decode

cap = cv2.VideoCapture(0)
cap.set(3,640)
cap.set(4,480)


while True:

success, img = cap.read()
for barcode in decode(img):
myData = barcode.data.decode('utf-8')
print(myData)

if myData in myDataList:
    myOutput = 'Authorized'
    myColor = (0,255,0)
else:
    myOutput = 'Un-Authorized'
    myColor = (0, 0, 255)

pts = np.array([barcode.polygon],np.int32)
pts = pts.reshape((-1,1,2))
cv2.polylines(img,[pts],True,myColor,5)
pts2 = barcode.rect
cv2.putText(img,myOutput,(pts2[0],pts2[1]),cv2.FONT_HERSHEY_SIMPLEX,
            0.9,myColor,2)

cv2.imshow('Result',img)
cv2.waitKey(1)

来源:https://stackoverflow.com/questions/65078167/how-to-reliably-detect-a-barcodes-4-corners-in-real-time-video-capture

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!