I am currently running ubuntu 18.04 and I have a picamera connected to my rpi. When I use the main display and connect the rpi to my screen via HDMI, I can access the camera using the opencv library using cv2.videoCapture(0) with the code included below.

However, when I do the same using a remote virtual desktop (using xfce4 desktop environment, tightvnc, port 5901) I cannot access my picamera. When I run a check using the same code, it does not detect my camera, hence it does not display the video. When I enter "ls /dev" while connected remotely, I see the /dev/video0 device in the terminal on my remote desktop, which is my camera. What is causing my picamera to not work on the remote desktop and how do I solve this?

Also a keyboard and mouse connected directly to my rpi does affect anything on my remote screen, perhaps that has something to do with why my camera is not detected? Perhaps someone could help me with using devices attached directly to my rpi while accessing it remotely. Thank you for any help.

Code used to test camera

import cv2

cams_test = 3
for i in range(0, cams_test):
    cap = cv2.VideoCapture(i)
    test, frame = cap.read()
    print("i : "+str(i)+" /// result: "+str(test))

cap = cv2.VideoCapture(0)

while True:  
    ret, frame = cap.read()

    if ret == True:
        rect, frame = cap.read()
        cv2.imshow('camera', frame)

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

    if ret == False:

  • You might want to look into raspberrypi.stackexchange.com to see if they have an answer. – NomadMaker Jun 8 '20 at 18:56

The camera preview most likely writes directly to the frame buffer. This is not captured by the VNC server application.

you can solve this issue using fbcp in order to capture the HDMI output; adafruit used this method to run mine-craft pi using their TFT hat.

  • Hi Jake, thanks for your help but could you elaborate on this, I found this: github.com/tasanakorn/rpi-fbcp I cloned it to my home directory and then did "mkdir build" inside the rpi-fbcp directory and followed the rest of the instructions. But when I got to "make" I got a "fatal error: bcm_host.h: No such file or directory". Did I do something wrong here? I looked up the error as well and found a solution asking me to "sudo apt-get install libraspberrypi-dev raspberrypi-kernel-headers" but upon doing so it says that it is unable to locate those packages. – JKEL Jun 8 '20 at 15:31
  • I'm sure i used sudo apt-get install fbcp on raspbian. does this work on ubuntu? – Jake Jun 9 '20 at 7:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.