Try   HackMD

opencv3.3.0 on raspberry pi3

plateform: raspberry pi3 model B
storage: 32GB SD card
OS: ubuntuMATE for pi3

check have enough space
df -h
like mine 3.8G Available


/dev/root should have more than 2GB
if no see here to enlarge space

my environment base on duckietown-bunny image
here
https://hackmd.io/p/SJbHPc-p#/2

dependency

sudo apt-get install python3.5-dev

sudo apt-get install \ pkg-config \ libjpeg-dev \ libtiff5-dev \ libjasper-dev \ libpng12-dev \ libavcodec-dev \ libavformat-dev \ libswscale-dev \ libeigen3-dev \ libxvidcore-dev \ libx264-dev \ libgtk2.0-dev \ libatlas-base-dev gfortran

vl4
Check prerequisites (with sudo raspi-config):
in terminal type sudo raspi-config

  • Enable the camera
  • Set large memory for gpu_mem (In Advance Options > Memmory Split set 128 min)

install stuff for v4l
sudo apt-get -y install libv4l-dev v4l-utils

Enable the kernel module:
sudo modprobe bcm2835-v4l2

test module
v4l2-ctl --list-devices

you would see


I'm using ps3eye webcam

build opencv3.3.0 from source

dowload .zip source here

I put opencv-3.3.0.zip.zip under /home/user/
unzip opencv-3.3.0.zip

cd opencv-3.3.0 mkdir build cd build

config cmake with NEON,TBB, v4l enable

cmake -D CMAKE_BUILD_TYPE=RELEASE \ -D CMAKE_INSTALL_PREFIX=/usr/local \ -D BUILD_WITH_DEBUG_INFO=OFF \ -D BUILD_DOCS=OFF \ -D BUILD_EXAMPLES=OFF \ -D BUILD_TESTS=OFF \ -D BUILD_opencv_ts=OFF \ -D BUILD_PERF_TESTS=OFF \ -D INSTALL_C_EXAMPLES=OFF \ -D INSTALL_PYTHON_EXAMPLES=ON \ -D ENABLE_NEON=ON \ -D WITH_TBB=ON \ -D WITH_LIBV4L=ON \ -D PYTHON_EXECUTABLE=/usr/bin/python3.5\ ..

check no error with generation complete

then

make -j4
this step took about 40mins
(future may cross compile)

after make without error
sudo make install

opencv stuff would move to these path

/usr/local/lib/libcv*
/usr/local/lib/python3.5/dist-packages/cv*
/usr/local/include/opencv2/
/usr/local/bin/opencv_*
/usr/local/share/OpenCV/

config pkg-config

mostly we utilize pkg-config to compile openCV code

configure OpenCV. open the opencv.conf file with the command

sudo vim /etc/ld.so.conf.d/opencv.conf

/usr/local/lib

This set the .so (dynamic link library) searching path.
it will search opencv___.so from the path
Remember we alread copy .so to /usr/local/lib when typing sudo make install in previous stage.

sudo ldconfig
now, edit ~/.bashrc
this would auto load terminal environment for pkg-config

sudo vim ~/.bashrc

add at the bottom

export PKG_CONFIG_PATH=$PKG_CONFIG_PATH:/usr/local/lib/pkgconfig export PYTHONPATH=/usr/local/bin/python3.5:$PYTHONPATH

Horay! we've got opencv-3.3.0 on pi3!


Test

$ python3
>>> import cv2
>>> print (cv2.__version__)
3.3.0
>>>

compile ssd_mobileNet

Inside ~/opencv-3.3.0/samples/
have dnn sample

copy it to ~/

cd ~/opencv-3.3.0/samples/
cp -r dnn ~/

cd dnn

now build the examble with pkg-config

g++ ssd_mobilenet_object_detection.cpp `pkg-config --cflags opencv` `pkg-config --libs opencv` -o ssd_mobilenet_object_detection

Now download data set(opencv-dl-data) and put your executable into correspondent folder

data set:
.caffemodel, .prototxt
https://drive.google.com/open?id=0BwY-lpO6tzxHVUZqN1pXc0xZdDQ

we are in dnn folder

inside ~/dnn/opencv-dl-data/ssd_mobilenet_object_detection/

connect your webcam to pi3 first run it
./ssd_mobilenet_object_detection -video=/dev/video0 -model=MobileNetSSD_train.caffemodel -proto=MobileNetSSD_300x300.prototxt

Have fun!


protobuf use for serialization
means to put parameter original store in hard disk in to memory

reference:
https://hackmd.io/s/S1gWq7BwW#
http://pklab.net/?id=392&lang=EN
sudo apt-get install ros-kinetic-perception
cv_bridge depends on opencv-3.2.0

https://github.com/ros-perception/vision_opencv/issues/162

make opencv run fast
https://www.slideshare.net/embeddedvision/making-opencv-code-run-fast-a-presentation-from-intel

opencv3.3.0 with deep learning

issue
https://hackmd.io/s/H1tfSqYv-#

opencv2.x opencv3.x mix
https://hackmd.io/EwVgxgnApghjYFoBsATMMEBYkEYMA5MQUEAGGUsYJAZimADMB2EIA===

tags: opencv3.3.0 pi3