picamera2 icon indicating copy to clipboard operation
picamera2 copied to clipboard

[HOW-TO] Ubuntu 22.04 Install

Open brianabouchard opened this issue 2 years ago • 11 comments

Please only ask one question per issue!

Describe what it is that you want to accomplish I would like to use picamera2 on Ubuntu 22.04. I've been able to manually build and install the libcamera library and all of the other dependencies, but I am now stuck on python3-kms++. Ubuntu 22.04 uses Python 3.10, while this library appears to use 3.9 and it will not install. Is there any way that I can build this package from source? I've been unable to find any information on it online.

brianabouchard avatar Feb 13 '23 01:02 brianabouchard

Hi, I'm thinking it ought to be possible to build python3-kms++ on a Ubuntu system so that it has the correct Python version, would that be correct? We can't make a package for Ubuntu, but maybe it's worth asking them about it. In any case it's a relatively small package and I don't recall any particular problems building it locally, so that might be a solution. Sorry not to have a ready-made answer!

davidplowman avatar Feb 13 '23 11:02 davidplowman

That would be fantastic, I'd be happy to build it locally. Do you have a link to the docs or any info on this package? I couldn't seem to find the right repo.

brianabouchard avatar Feb 13 '23 23:02 brianabouchard

Hi, the repository in question is this one: https://github.com/tomba/kmsxx (I agree, it is a bit obscure to find!!)

davidplowman avatar Feb 14 '23 08:02 davidplowman

I would also like to build from source for a docker container on raspberry pi 4B

KhanMechAI avatar Feb 15 '23 20:02 KhanMechAI

Main issue I've run into is using the pip installler - the cmake pypi package is completely broken. Its a dependency of simplejpeg and simplejpeg is a dependency of picamera2. Love playing this game...Tried may things to resolve this including building different versions of the pypi cmake (no success).

KhanMechAI avatar Feb 15 '23 20:02 KhanMechAI

Getting picamera2 into Ubuntu is on my to-do list for the mantic release (it was on my "if there's time" list for lunar, but I wound up burning too much time on module enablement amongst other things), so I'll stick this bug in my bookmarks and try and keep people updated here.

Incidentally, the libcamera-apps package should also be making it in (that one is basically ready, but missed the feature-freeze for lunar); picamera2 looks to be a bit more complex with the extra dependencies but we'll see how it goes.

I wouldn't like to speculate on whether any work on this would get back-ported to jammy (22.04) though. Given all the dependencies, it would be a fairly major task.

waveform80 avatar Apr 25 '23 20:04 waveform80

Ubuntu 22.04 64-bit release has been for quite some time. To get ROS2, OpenCV, Pi Camera into one system is a huge challenge.

$ sudo python3 cam_cal.py Can't receive frame (stream end?). Exiting ... CV version = 4.5.4

ret, frame = cap.read() #-- Read the camera frame
# if frame is read correctly ret is True
if not ret:
	print("Can't receive frame (stream end?). Exiting ...")
	print("CV version = " + cv2.__version__)
	break

So, someone suggested to use picamera2.....

Jai-GAY avatar Jan 12 '24 09:01 Jai-GAY

Someone from this group might already be on it, but it looks like there's a prerelease version of python-libcamera. https://pypi.org/project/rpi-libcamera/. I'm testing it out now and will report back

nbaldy avatar Mar 05 '24 22:03 nbaldy

In case you haven't spotted it, there is information on rpi-libcamera here.

davidplowman avatar Mar 06 '24 09:03 davidplowman

Following up - those instructions above worked for me. It took some install twiddling to get all the right versions installed, but I got there. This was my total process, I think.

Install libcamera

Primary source: https://www.raspberrypi.com/documentation/computers/camera_software.html#building-libcamera

sudo apt install -y libcamera-dev libepoxy-dev libjpeg-dev libtiff5-dev libpng-dev python3 python3-dev
sudo apt install libcamera-tools g++
sudo apt install -y python3-pip git python3-jinja2
sudo apt install -y libboost-dev
sudo apt install -y libgnutls28-dev openssl libtiff5-dev pybind11-dev liblttng-ust-dev
sudo apt install -y qtbase5-dev libqt5core5a libqt5gui5 libqt5widgets5
# NOTE - for Ubuntu 22.04, need to install meson via pip because the version apt gets is too old
sudo apt install -y cmake ninja-build 
sudo apt install -y python3-yaml python3-ply python3-pip libyaml-dev
sudo pip3 install --user meson # needs sudo to be on sudo pythonpath
PATH=$PATH:/home/$USER/.local/bin/
sudo apt install -y libglib2.0-dev libgstreamer-plugins-base1.0-dev

cd 
git clone https://github.com/raspberrypi/libcamera.git
cd libcamera

meson setup build --buildtype=release -Dpipelines=rpi/vc4,rpi/pisp -Dipas=rpi/vc4,rpi/pisp -Dv4l2=true -Dgstreamer=enabled -Dtest=false -Dlc-compliance=disabled -Dcam=disabled -Dqcam=disabled -Ddocumentation=disabled -Dpycamera=enabled

ninja -C build   # use -j 2 on Raspberry Pi 3 or earlier devices
sudo ninja -C build install

Install rpicam-apps

Primary source: https://www.raspberrypi.com/documentation/computers/camera_software.html#building-libcamera

sudo apt install -y libboost-program-options-dev libdrm-dev libexif-dev
cd 
git clone https://github.com/raspberrypi/rpicam-apps.git --branch v1.4.3
cd rpicam-apps

# Choose the 'lite' option
meson setup build -Denable_libav=false -Denable_drm=true -Denable_egl=false -Denable_qt=false -Denable_opencv=false -Denable_tflite=false

meson compile -C build # use -j1 on Raspberry Pi 3 or earlier devices
sudo /home/$USER/.local/bin/meson install -C build
sudo ldconfig # this is only necessary on the first build

Install libkms dependencies

Primary sources: https://forums.raspberrypi.com/viewtopic.php?t=351579, https://forums.raspberrypi.com/viewtopic.php?t=361758

sudo apt update && sudo apt upgrade
sudo apt install -y  libfmt-dev libdrm-dev libfmt-dev
# Install kmsxx
git clone https://github.com/tomba/kmsxx.git
cd kmsxx/
git submodule update --init
meson build -Dpykms=enabled
sudo ninja -C build install

Install picamera

https://forums.raspberrypi.com/viewtopic.php?t=361758

 pip install rpi-libcamera rpi-kms picamera2

From there, I could import and use picamera.

~Note, I'm still having some minor issues with my camera which are at the libcamera driver layer (and possibly hardware) so I cannot 100% say it works to completion... but this is my best set of installs at the moment, (before falling back to RPI OS to test if my assumedly unrelated issue with the camera is a driver issue)~ I was able to get this working to the point of collecting images when I ran this on an Ubuntu docker on a Raspbian host

nbaldy avatar Mar 06 '24 19:03 nbaldy