USB Webcam failed to connect to BrainyPi

I am trying to use a HP webcam as a camera device for the BrainyPi.
I am using OpenCV and Python to code.

I used the following code

import cv2
camera = cv2.VideoCapture(5)

5 is got from BrainyPi documentation, generally use 0 for Windows.

while True:
ret, frame = camera.read()
cv2.imshow(‘Frame’, frame)

if cv2.waitKey(1) & 0xFF==ord('q'):
   break

camera.release()
cv2.destroyAllWindows()

The indentation and working of the code is verified on Windows OS and works properly. But when executed on BrainyPi, gave the error visible in the image

I plan to use BrainyPi as the main controlling device for my project, so would highly appreciate some quick help on this.

@JustinPaulKolengadan

Thanks for reporting !

We will get back to you soon.

Hi @JustinPaulKolengadan,

Thanks for trying out BrainyPi.

Please try these steps on BrainyPi.

Get the Camera Device number from webcamoid

  1. Download & install webcamoid

    sudo apt install webcamoid
    
  2. Open webcamoid, it will open up webcam

  3. Go to configure sources

  4. Check the camera device number

Note: If the Media UID is /dev/video5 then the camera device number is 5.

Regarding your question

The screenshot shows that the code is using /dev/video0 i.e camera device 0. Changing the code to the correct camera device number from webcamoid should fix the issue.