import cv2 from pyzbar import pyzbar import subprocess def detect_qr_code(frame): detected_barcodes = pyzbar.decode(frame) for barcode in detected_barcodes: if barcode.type == 'QRCODE': return barcode.data.decode('utf-8') return None def main(): cap = cv2.VideoCapture(0) # open default USB camera (index 0) if not cap.isOpened(): print('Error: Cannot access camera') return print('Starting camera. Press q to quit.') while True: ret, frame = cap.read() if not ret: print('Error: Cannot read frame') break qr_data = detect_qr_code(frame) if qr_data: print(f'Detected QR Code: {qr_data}') # Call the play script with this QR code data as argument subprocess.Popen(['python3', 'play_spotify.py', qr_data]) break cv2.imshow('QR Code Detector', frame) if cv2.waitKey(1) & 0xFF == ord('q'): break cap.release() cv2.destroyAllWindows() if __name__ == '__main__': main()