Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/285.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 如何修复Raspberry pi 4摄像头,该摄像头只能读取二维条码,不能读取一维或二维条码_Python_Computer Vision_Raspberry Pi4 - Fatal编程技术网

Python 如何修复Raspberry pi 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

我想建立一个条码和二维扫描仪的树莓皮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 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()
二维码一切正常,但不读取条形码,我不确定是相机不具备读取条形码的能力,还是我需要修复我的代码才能读取条形码。我如何解决这个问题,以便我可以一起读取二维码和条形码