Close

03.10.2019 - installating OpenCV on RPI3B with ubuntu

A project log for VT-01 - robotic project

a Versatile robotic platform for various tasks.

nj1337nj1337 10/02/2019 at 23:250 Comments

today i was checking some website for computer vision. And i think i will use an intel D415 or D435 cam depth camera. But it's not supported in raspbian. So i decided to install ubuntu on my Raspberry Pi 3. 


Here is how to to do this.

First, grab the archive from ubuntu, then write it to your SD car. I'm using rufus for this operation.

When done, put your SDcard in the RPi3 and boot. Make the first configuration ... keyboard, location ... 

Once this done, install SSHd : 

apt remove openssh-server

apt install openssh-server

systemctl disable sshguard

systemctl enable openssh-server

Go to your main computer and connect with SSH, then purge some useless packages

sudo su

apt-get remove --purge libreoffice*

apt-get clean

apt-get autoremove

Update the OS : 

sudo apt update && sudo apt upgrade -y

sudo apt update && sudo apt upgrade -y

I'm the current version (beta), there is a bug with the firmeware, you need to force it

sudo dpkg -i --force-all /var/cache/apt/archives/linux-firmware-raspi2_1.20190215-0ubuntu0.18.04.1_armhf.deb

I need screen, cause i'm working with SSH and i dont want to loose my session : 

apt install screen

 Then install RDP, so you can connect from windows easly : 

sudo apt install xrdp

sudo systemctl enable xrdp

Now we can start OpenCV 4.X installation :

First, make the swap bigger : 

swapoff /swapfile

rm  /swapfile

dd if=/dev/zero of=/swapfile bs=1M count=2048

chmod 600 /swapfile

mkswap /swapfile

swapon /swapfile

Then, install some needed packages :  

apt install build-essential cmake git pkg-config libgtk-3-dev "libcanberra-gtk*"

apt install libavcodec-dev libavformat-dev libswscale-dev libv4l-dev libxvidcore-dev libx264-dev

apt install libjpeg-dev libpng-dev libtiff-dev gfortran openexr libatlas-base-dev opencl-headers

apt install python3-dev python3-numpy libtbb2 libtbb-dev libdc1394-22-dev

 Go back to your user and download openCV with git : 

exit

mkdir ~/opencv_build && cd ~/opencv_build

git clone https://github.com/opencv/opencv.git

git clone https://github.com/opencv/opencv_contrib.git

mkdir -p ~/opencv_build/opencv/build && cd ~/opencv_build/opencv/build

screen a new session : 

screen

 hit space

then cmake the thing : 

cmake -D CMAKE_BUILD_TYPE=RELEASE \
    -D CMAKE_INSTALL_PREFIX=/usr/local \
    -D INSTALL_C_EXAMPLES=OFF \
    -D INSTALL_PYTHON_EXAMPLES=OFF \
    -D OPENCV_GENERATE_PKGCONFIG=ON \
    -D ENABLE_NEON=ON \
    -D OPENCV_EXTRA_EXE_LINKER_FLAGS=-latomic \
    -D ENABLE_VFPV3=ON \
    -D BUILD_TESTS=OFF \
    -D OPENCV_ENABLE_NONFREE=ON \
    -D OPENCV_EXTRA_MODULES_PATH=~/opencv_build/opencv_contrib/modules \
    -D BUILD_EXAMPLES=OFF ..

then compile the monster : 

make -j4

if make stop or hang, just restart it without the -j4 

Make a coffee, grab a good netflix film, and stay relax for 2/3 hours.

Once done, install the compiled thing :

sudo make install

DONE

Check if it's working :

for C++ : 

pkg-config --modversion opencv4

For python : 

python3 -c "import cv2; print(cv2.__version__)"

lets get back to previous swap file : 

 sudo su

swapoff /swapfile

rm  /swapfile

dd if=/dev/zero of=/swapfile bs=1M count=1024

chmod 600 /swapfile

mkswap /swapfile

swapon /swapfile

Have fun =)

Discussions