[Python] When trying to use Opencv to take a picture on a webcam connected to a raspberry pi I...

Discussão em 'Python' iniciado por Stack, Fevereiro 6, 2025.

  1. Stack

    Stack Membro Participativo

    I'm trying to use a raspberry pi 3 to act as a baby monitor using an ssh to connect remotely on my main Pc. I installed OpenCV and tried to run this code in order to take a picture on the usb web camera I have plugged into the raspberry pi;

    import cv2
    cap = cv2.VideoCapture(0) # Access the first connected webcam [2, 5, 7]

    while True:
    ret, frame = cap.read()
    # Process the frame here (display, save, etc.)
    cv2.imshow('Webcam', frame)
    if cv2.waitKey(1) & 0xFF == ord('q'): # Press 'q' to quit
    break


    After trying to run this code I get an error that says:

    qt.qpa.xcb: could not connect to display
    qt.qpa.plugin: Could not load the Qt platform plugin "xcb" in "/home/colin/env/lib/python3.11/site-packages/cv2/qt/plugins" even though it was found.
    This application failed to start because no Qt platform plugin could be initialized. Reinstalling the application may fix this problem.

    Available platform plugins are: xcb.

    Aborted


    After getting this error I tried to look it up and someone said to run this code in the terminal to install xcb.

    sudo apt-get install --reinstall libxcb-xinerama0


    after doing so I tried to run the python code again but got the same error. After this I did more research and tried to install qt by using the line "sudo apt-get install qt4-dev-tools" but got this error message

    E: Unable to locate package qt4-dev-tools


    I'm very lost and very confused could someone please help me out I've been trying to get this to work for the better part of 4 hours and its very frustrating.

    Tried to run a python code to take a picture on the USB webcam but got an error that I was missing xcb, so I tried to install it using sudo apt-get install --reinstall libxcb-xinerama0, after doing this and running the python code again I got the same error code So i tried to download qt using the line sudo apt-get install qt4-dev-tools but got a new error code that says the program cant locate package qt4-dev-tools.

    Continue reading...

Compartilhe esta Página