Setting Up Raspberry Pi Camera on Ubuntu 20.04 64 bit for Raspberry Pi 4

Preamble

This was a pig for no good reason, so hopefully someone else doesn’t have to go through the same pain I did.

For clarity I was using a Raspberry Pi 4 running Ubuntu 20.04 64 bit with a Pi Zero camera connected using an adapter ribbon cable. Ensure everything is properly connected before starting.

How To

  1. Edit your /boot/firmware/config.txt, adding the following…
start_x=1
gpu_mem=512
disable_camera_led=1
start_file=start_4x.elf
fixup_file=fixup_4x.dat
sudo apt-get update
sudo apt-get upgrade
sudo reboot

When your system comes back up you should now have your camera listed as a video device. You can check this using…

ls /dev/video*

…check you have /dev/video0

  1. Edit your /etc/modules file, adding bcm2835-v4l2.

  2. Modify your user’s priveleges…

sudo usermod -aG video $USER
  1. We’ll need the frame size for the next step, we can find this using v4l-utils.
sudo apt-get install v4l-utils
sudo v4l2-ctl --device=/dev/video0 --all | grep Width/Height
  1. Test the camera with Python and Open CV.
sudo apt-get install python3-opencv

Create a Python script, camera_test.py, and add the following, swapping out your cameras frame width and height…

import cv2

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

# set dimensions
cap.set(cv2.CAP_PROP_FRAME_WIDTH, 2560)
cap.set(cv2.CAP_PROP_FRAME_HEIGHT, 1440)

# take frame
ret, frame = cap.read()
# write frame to file
cv2.imwrite('image.jpg', frame)
# release camera
cap.release()

Then run it…

python3 camera_test.py

…and check the output in image.jpeg.

Refs and Further Reading

A big thanks to the many posts that got me to where I needed to be.

Hey you!

Found this useful or interesting?

Consider donating to support.

Any question, comments, corrections or suggestions?

Reach out on the social links below through the buttons.