Cameras for Raspberry Pi

  1. Home
  2. Docs
  3. Cameras for Raspberry Pi
  4. PTZ Camera
  5. How to run PTZ Cameras in Ubuntu

How to run PTZ Cameras in Ubuntu

1. Installing dependencies

sudo apt-get update && sudo apt-get upgrade
sudo apt install -y cmake
sudo apt install libyaml-dev
sudo apt install libpng-dev
sudo apt install -y libcamera-dev libepoxy-dev libjpeg-dev libtiff5-dev
sudo apt install -y python3-pip git
sudo pip3 install jinja2
sudo apt install -y libboost-dev
sudo apt install -y libgnutls28-dev openssl libtiff5-dev
sudo apt install -y qtbase5-dev libqt5core5a libqt5gui5 libqt5widgets5
sudo apt install -y meson
sudo pip3 install pyyaml ply
sudo pip3 install --upgrade meson
sudo apt install -y libglib2.0-dev libgstreamer-plugins-base1.0-dev	
sudo apt install -y cmake libboost-program-options-dev libdrm-dev libexif-dev
sudo apt-get install python-opencv
sudo apt-get install python3-smbus

2. Compiling libcamera

git clone git://linuxtv.org/libcamera.git
cd libcamera
meson build --buildtype=release -Dpipelines=raspberrypi -Dipas=raspberrypi -Dv4l2=true -Dgstreamer=enabled -Dtest=false -Dlc-compliance=disabled -Dcam=disabled -Dqcam=enabled -Ddocumentation=disabled -Dpycamera=enabled
ninja -C build   # use -j 2 on Raspberry Pi 3 or earlier devices
sudo ninja -C build install
#Adding dynamic link libraries to __int_py will not copy successfully
sudo cp -r ~/libcamera/build/src/py/libcamera/ /usr/local/lib/python3.10/dist-packages/
sudo rm /usr/local/lib/python3.10/dist-packages/libcamera/__init__.py
sudo bash -c 'cat /home/#your account name#/libcamera/build/src/py/libcamera/__init__.py >> /usr/local/lib/python3.10/dist-packages/libcamera/__init__.py'

3. Compiling libcamera-apps

git clone https://github.com/raspberrypi/libcamera-apps.git
cd libcamera-apps
mkdir build
cd build
cmake .. -DENABLE_DRM=1 -DENABLE_X11=1 -DENABLE_QT=1 -DENABLE_OPENCV=0 -DENABLE_TFLITE=0
make -j4  # use -j1 on Raspberry Pi 3 or earlier devices
sudo make install
sudo ldconfig # this is only necessary on the first build

4. Compiling python-kms++ 

git clone https://github.com/tomba/kmsxx.git
cd kmsxx
git submodule update --init
meson build
sudo ninja -C build install 
sudo cp -r ~/kmsxx/build/py/pykms/ /usr/local/lib/python3.10/dist-packages/
sudo ldconfig

5. picamera2

sudo apt install -y python3-pyqt5 python3-prctl libatlas-base-dev ffmpeg python3-pip
pip3 install numpy --upgrade
pip3 install picamera2

6. Modify configuration file

sudo vi /boot/firmware/config.txt

Find the line where camera_auto_detect is and change it to camera_auto_detect=0

add dtoverlay=<camera> at the end of the line

For example:

dtoverlay=imx477

7. Allow accessing /dev/dma_heap on Ubuntu

# add rule in /etc/udev/rules.d/raspberrypi.rules and add rule
SUBSYSTEM=="dma_heap", GROUP="video", MODE="0660"
# Add user to video group Then reboot
sudo usermod -a -G video $USER 

8. Run project

git clone https://github.com/ArduCAM/PTZ-Camera-Controller.git
cd PTZ-Camera-Controller
sudo python3 FocuserExample.py
Was this article helpful to you? Yes No