Guidance needed: Access camera in Extension

Hi everyone,

I’m working on a Python extension to take pictures at specific times using OpenCV and then further process them. Currently, my goal is just to access the camera and log information to ensure everything is functioning. However, I’m encountering an issue.

The problem: I get the following error message:

Despite this, I can successfully start a stream using GStreamer and view it on my Mac. This makes me suspect that the issue lies with the extension not having the necessary permissions or access to /dev/video0.

Environment and code:
I’m using OpenCV to interface with the camera. Below is the send() function from main.py, which is responsible for accessing the camera:

def send():
   cap_send = cv2.VideoCapture(0)

   if not cap_send.isOpened():
       print('Error: Unable to open camera input')
       return

   while True:
       try:
           # Capture a frame
           ret, frame = cap_send.read()
           if not ret:
               print('Error: Failed to read frame from camera')
               break

           # Perform any desired processing with `frame` here
           print("Captured a frame")

       except Exception as e:
           print(f"Error during frame capture: {e}")
           break


   # Release the camera resource
   cap_send.release()

What I’ve tried:

  1. Confirmed that the camera works using GStreamer, and the stream is viewable on my Mac.
  2. Confirmed that other parts of the extension are functioning as expected.
  3. Tested processing images directly on my Mac without using the extension. However, since the extension needs access to USB ports (e.g., /dev/...) to directly control hardware like an XYZ table in the future, I still need to resolve this issue.

What I suspect:

This could be a permissions issue where the extension doesn’t have access to /dev/video0.

Questions:

  1. Could this be related to running the script in an environment that doesn’t have camera access permissions?
  2. Any suggestions for debugging or resolving the problem?
  3. Any suggestions on what else I can do to implement this kind of functionality?

Thank you for your help!

1 Like

Hi @niklasebner -
Have you disabled Mavlink Camera manager, or killed this process in BlueOS? It is likely using the camera at /dev/video0, and thus preventing you from attaching to it.
Head to the video streams page, and delete any entries for an existing stream. Then give it another go with your script!

If it still doesn’t work, make sure you are taking the red-pill … (see instructions at top of Terminal)

1 Like

Thank you so much for your response! Your support means a great deal to me, and I truly appreciate your time and effort in helping me out.

Unfortunately, I’m still encountering some issues, but I’m glad to say I’ve made a bit of progress!

Firstly, I’ve never been able to get the built-in video streams in BlueOS to work, no matter how many times I’ve tried, so I don’t think the Mavlink camera manager should be using the camera.

When I attempt to set up a camera stream in BlueOS (this time using a Raspberry Pi camera, but I’ve also tried with various USB cameras), I get the following error:

As soon as I try creating the video stream, it crashes and gives the message that it couldn’t fetch video devices:


could not create video stream error

I’ve tested this on several versions of BlueOS and different Raspberry Pi models (3B+, 4B, and 5), but the issue persists. Since this isn’t the main focus of my original post, I won’t go into further detail on that aspect.

However, I did manage to make a bit more headway and received a different error message when trying to start the stream in my extension this time. By using red-pill, I was able to configure the Docker container to access /dev/video0.

At this point, the error changes to indicate that /dev/video0 is busy, which I suspect is due to the Mavlink camera manager. However, I’m unsure how to kill this process, especially since no video-stream is currently active in BlueOS(as it still isn’t working). Could there be another process that’s using /dev/video0? If so, how can I identify and stop it?

Additionally, if you have any advice on how to get a normal video stream working in BlueOS, I would be extremely grateful.

Once again, thank you so much for your help!! I really appreciate it and am looking forward to hearing from you!

Hi @niklasebner -
It’s worth checking if the camera your using is affected by technical bulletin 12.

The error you see on the video streams page is normal - you should add a video stream (video2, h264), in order to get things working. It also seems as if you’ve changed the default IP address of your BlueOS device?

BlueOS is not supported, at least in conjunction with the current version of the Navigator on the Pi 5 yet…

If you’re using video0- this may be the issue, as this is not a H264 stream, but mjpg! This is not supported for use in QGroundControl or Cockpit…

You can kill the video process by navigating to the terminal, and pressing cntrl-B followed by the “s” key (as detailed here.) Scroll in the list with the arrow key to the top, select Video and press enter. Then push cntrl-C to kill the Mavlink Camera Manager process.

Thank you so much for your help!

Disabling the MAVLink camera manager did indeed resolve the issue of the camera being busy, and my extension is now able to capture frames successfully.

I’m also incredibly grateful for the additional information you provided. Without your guidance, this project would have taken significantly more time, and I’m not sure I would have been able to get it working as I originally intended.

It’s incredibly reassuring to know that help like yours is available. Thank you once again for your quick responses and invaluable support!

1 Like