My Pi 3 Install Log (6): OpenCV (part 2) on Raspberry Jessie (Lite)
(4 hours)
# in part 1 after creating a virtual env for python 2.7, i changed my mind.
# thought like redo in python3 because my physical env is python2 and has numpy installed already.
$ deactivate # leave env
$ rm -rf .virtualenvs/cv
$ mkvirtualenv cv -p python3
Already in, have (cv) before prompt
If not in (cv) yet
$ source .profile
$ workon cv
pip list # show what has been installed
pip install numpy # took quite long time ~10mins!!
# version 1.11.1
$ cd ~/opencv-3.1.0/
$ mkdir build
$ cd build
$ cmake -D CMAKE_BUILD_TYPE=RELEASE \
-D CMAKE_INSTALL_PREFIX=/usr/local \
-D INSTALL_PYTHON_EXAMPLES=ON \
-D OPENCV_EXTRA_MODULES_PATH=~/opencv_contrib-3.1.0/modules \
-D BUILD_EXAMPLES=ON ..
# I want to see cmake output so startx and ran from lxterminal.
# it was a mistake to also call ‘make’ there took me 102mins while the instruction said 75mins.
$ make -j4
# but it completed successfully. :) 2.7GB was generated within the build folder
# install to system
$ make install
$ ldconfig
## step 6
$ cd /usr/local/lib/python3.4/site-packages/
$ ls -l
total 1852
-rw-r--r-- 1 root staff 1896140 Aug 22 21:43 cv2.cpython-34m.so
$ sudo mv cv2.cpython-34m.so cv2.so
$ cd ~/.virtualenvs/cv/lib/python3.4/site-packages/
$ ln -s /usr/local/lib/python3.4/site-packages/cv2.so cv2.so
* * *
congrats, installation completed
* * *
## step 7 verify installation
# open a new terminal
$ source ~/.profile
$ workon cv
$ python
>>> import cv2
>>> cv2.__version__
'3.1.0'
>>>
## my step 8 (optional)
The two opencv folders at ~ no longer necessary for python code.
Before moving on, I want to back up the 'build' folder for what have been compiled and generated during 102 mins wait.
Before moving on, I want to back up the 'build' folder for what have been compiled and generated during 102 mins wait.
# plug in a big enough USB disk, say have a label myusbdisk
$ tar cvf /media/pi/myusbdrive/opencv-3.1.1_build.tar /home/pi/opencv-3.1.0/build/
(edited)
built samples and examples in ~/opencv-3.1.1/build/bin
to try them, first start the gui
open a terminal, and enter
sudo modprobe bcm2835-v4l2 # see ref below
sometimes example stuck won't quit
kill that process
1. ctrl-shift-n for a new terminal
2. ps ax | grep facedetect
3. (note the pid, eg. 12345)
4. kill 12345
* * *
ref:
I think the difference is that he is not using the Raspberry Pi camera but a USB webcam - at 4:40 guvcview is reporting using driver uvcvideo. I've just tried it and guvcvideo fails immediately for me complaining about the contents of /proc/cpuinfo (no CPU frequency, although I don't know why it needs to know that!).
I haven't listened through all of the tutorial, but I think the bit you need is
CODE: sudo modprobe bcm2835-v4l2
to load the RaspiCam V4L2 driver. raspistill and raspivid talk to the MMAL service directly, whereas most applications (including OpenCV) use V4L2.
* * *
# to build cpp examples myself https://www.learnopencv.com/how-to-compile-opencv-sample-code/
CODE: sudo modprobe bcm2835-v4l2
to load the RaspiCam V4L2 driver. raspistill and raspivid talk to the MMAL service directly, whereas most applications (including OpenCV) use V4L2.
* * *
# to build cpp examples myself https://www.learnopencv.com/how-to-compile-opencv-sample-code/
# Gcc using opencv
You can use pkg-config command to get the compiler/linker options. Like this
gcc `pkg-config --cflags opencv` `pkg-config --libs opencv` new.c
Please note the above punctuation is ` not '.
Or you can use CMake. Write a CMakeLists.txt like this
cmake_minimum_required (VERSION 2.6)
project (new1)
find_package (OpenCV REQUIRED)
include_directories (${OpenCV_INCLUDE_DIRS})
add_executable (new1 new.c)
target_link_libraries (new1 ${OpenCV_LIBS})
then you can build like this
mkdir build
cd build
cmake -DOpenCV_DIR=<the-directory-contating-OpenCVConfig.cmake> ..
make
gcc `pkg-config --cflags opencv` `pkg-config --libs opencv` new.c
Please note the above punctuation is ` not '.
Or you can use CMake. Write a CMakeLists.txt like this
cmake_minimum_required (VERSION 2.6)
project (new1)
find_package (OpenCV REQUIRED)
include_directories (${OpenCV_INCLUDE_DIRS})
add_executable (new1 new.c)
target_link_libraries (new1 ${OpenCV_LIBS})
then you can build like this
mkdir build
cd build
cmake -DOpenCV_DIR=<the-directory-contating-OpenCVConfig.cmake> ..
make
Labels: Jessie, OpenCV, Raspberry Pi
0 Comments:
Post a Comment
<< Home