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
![](https://i.imgur.com/xnt5ZLF.png)
**/dev/root** should have more than 2GB
if no see [here](http://pklab.net/?id=392&lang=EN) 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`
```bash=
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`
![](https://i.imgur.com/V9bHIzG.png)
* 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
![](https://i.imgur.com/URO4tAe.png)
I'm using ps3eye webcam
#### build opencv3.3.0 from source
dowload .zip source [here](https://github.com/opencv/opencv/releases/tag/3.3.0)
I put opencv-3.3.0.zip.zip under /home/user/
`unzip opencv-3.3.0.zip`
```cmake=
cd opencv-3.3.0
mkdir build
cd build
```
config cmake with NEON,TBB, v4l enable
```cmake=
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/
```
![](https://i.imgur.com/L3RHRXe.png)
#### config pkg-config
>mostly we utilize pkg-config to compile openCV code
>configure OpenCV. open the opencv.conf file with the command
```bash=
sudo vim /etc/ld.so.conf.d/opencv.conf
```
>/usr/local/lib
![](https://i.imgur.com/9XYGrvN.png)
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
```bash=
sudo vim ~/.bashrc
```
add at the bottom
```bash=
export PKG_CONFIG_PATH=$PKG_CONFIG_PATH:/usr/local/lib/pkgconfig
export PYTHONPATH=/usr/local/bin/python3.5:$PYTHONPATH
```
![](https://i.imgur.com/cnUlBEX.png)
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`
![](https://i.imgur.com/1RULH4L.png)
*now build the examble with pkg-config*
```bash=
g++ ssd_mobilenet_object_detection.cpp `pkg-config --cflags opencv` `pkg-config --libs opencv` -o ssd_mobilenet_object_detection
```
![](https://i.imgur.com/psu1AeE.png)
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
![](https://i.imgur.com/xpIlmzK.png)
![](https://i.imgur.com/7kwsrmq.png)
![](https://i.imgur.com/QLbb4Zg.png)
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!**
![](https://i.imgur.com/w4NTbCv.png)
![](https://i.imgur.com/0CYafYt.png)
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](
https://hackmd.io/s/S1gWq7BwW#)
issue
https://hackmd.io/s/H1tfSqYv-#
opencv2.x opencv3.x mix
https://hackmd.io/EwVgxgnApghjYFoBsATMMEBYkEYMA5MQUEAGGUsYJAZimADMB2EIA===
###### tags: `opencv3.3.0` `pi3`