1

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?

1 Answers1

0

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