Score:1

PiCamera with OpenCV 4.5.4 on Ubuntu 22.04 Server (RaspberryPi 4B) Capture Returns Empty Frame

im flag

Installed OpenCV 4.5.4 to Ubuntu 22.04 Server on Raspberry Pi4B.
( sudo apt install python3-opencv -y )

Video4Linux sees the camera:

$ v4l2-ctl --list-devices
...

unicam (platform:fe801000.csi):
    /dev/video0
    /dev/media0

Attempting to capture video from PiCamera v1.3 in OpenCV gives empty frame

#!/usr/bin/env python3

import cv2 
from datetime import datetime

# open camera

cap = cv2.VideoCapture('/dev/video0', cv2.CAP_V4L)

# set dimensions
# 16:9 - 1296x730, 1920x1080
# 4:3 - 640x480, 1296x972, 2592x1944
cap.set(cv2.CAP_PROP_FRAME_WIDTH, 2592)
cap.set(cv2.CAP_PROP_FRAME_HEIGHT, 1944)

# filename format
fname = "capture_"+datetime.now().strftime("%Y%m%d-%H%M%S")+".jpg"

# capture a frame
ret, frame = cap.read()

print("ret:",ret)
if ret:
    print("h,w: ", frame.shape[:2])

    # wirte frame to file
    cv2.imwrite(fname, frame)
else:
    print("Frame not captured")

# release camera
cap.release()
# ---

$ ./snapJPG_opencv.py 
ret: False
Frame not captured

Any ideas how to debug?

Score:0
cn flag

Did you enable the camera in the raspi-config tool?

I recently had the same problem using the camera in OpenCV on Raspberry pi 4 with Ubuntu 22.04 Server.

You need to install the raspi-config tool.

In a terminal type below command to install the tool.

sudo apt install raspi-config

Then open the tool using

sudo raspi-config

Once the tool screen is openwed, go to Interface Options and then enable "Legacy camera option".

More about raspi-config tool Raspberry Pi Documentation

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.