Python 如何修复Raspberry pi 4摄像头,该摄像头只能读取二维条码,不能读取一维或二维条码
我想建立一个条码和二维扫描仪的树莓皮4。所以我买了一个,用了 并使用此代码读取摄像头输入Python 如何修复Raspberry pi 4摄像头,该摄像头只能读取二维条码,不能读取一维或二维条码,python,computer-vision,raspberry-pi4,Python,Computer Vision,Raspberry Pi4,我想建立一个条码和二维扫描仪的树莓皮4。所以我买了一个,用了 并使用此代码读取摄像头输入 from gpiozero import LED, Button, Buzzer import cv2 import re led = LED(19) sw1 = Button(21) buzzer = Buzzer(26) cap = cv2.VideoCapture(0) detector = cv2.QRCodeDetector() def sw1Pressed(): global sw1
from gpiozero import LED, Button, Buzzer
import cv2
import re
led = LED(19)
sw1 = Button(21)
buzzer = Buzzer(26)
cap = cv2.VideoCapture(0)
detector = cv2.QRCodeDetector()
def sw1Pressed():
global sw1Press
sw1Press = True
sw1.when_pressed = sw1Pressed
sw1Press = False
print("Reading QR code using Raspberry Pi camera")
print("Press SW1 to scan.")
while True:
if sw1Press == True:
led.toggle()
_, img = cap.read()
data, bbox, _ = detector.detectAndDecode(img)
if bbox is not None:
for i in range(len(bbox)):
cv2.line(img, tuple(bbox[i][0]), tuple(bbox[(i+1) % len(bbox)][0]), color=(255,
0, 0), thickness=2)
cv2.putText(img, data, (int(bbox[0][0][0]), int(bbox[0][0][1]) - 10), cv2.FONT_HERSHEY_SIMPLEX,
0.5, (0, 255, 0), 2)
if data:
sw1Press = False
buzzer.beep(0.1, 0.1, 1)
print("Data found: " + data)
led.off()
data = ""
cv2.imshow("code detector", img)
else:
cap.read()
cv2.destroyAllWindows()
if cv2.waitKey(1) == ord("q"):
break
led.off()
cap.release()
cv2.destroyAllWindows()
二维码一切正常,但不读取条形码,我不确定是相机不具备读取条形码的能力,还是我需要修复我的代码才能读取条形码。我如何解决这个问题,以便我可以一起读取二维码和条形码