varun9597
Posts: 3
Joined: Sun Feb 17, 2019 4:33 am

Installing OpenCV 4.0 in RaspberryPi without virtualenvironment.

Sun Feb 17, 2019 5:00 am

I want to install OpenCV 4 in my RaspberryPi 3B+. I have tried the following links and have got respective issues.

1. https://www.pyimagesearch.com/2018/09/2 ... pberry-pi/

This link installed OpenCV 4.0 but it uses the virtual environment method which is not required by me.

2. https://www.learnopencv.com/install-ope ... pberry-pi/

This link also uses virtual environment but has a note saying -
"For system wide installation of OpenCV, change CMAKE_INSTALL_PREFIX to CMAKE_INSTALL_PREFIX=/usr/local \."

So after doing that the installed version of OpenCV is 2.4.9.1.

I want OpenCV 4 without using virtual environment. Please help me out.

User avatar
Joel_Mckay
Posts: 289
Joined: Mon Nov 12, 2012 10:22 pm
Contact: Website

Re: Installing OpenCV 4.0 in RaspberryPi without virtualenvironment.

Sun Feb 17, 2019 1:23 pm

This should get you on the right path:
https://solarianprogrammer.com/2018/12/ ... -raspbian/

Hint: run a native build on the pi, and ignore the cross-compiling part of the instructions.
;-)

varun9597
Posts: 3
Joined: Sun Feb 17, 2019 4:33 am

Re: Installing OpenCV 4.0 in RaspberryPi without virtualenvironment.

Thu Feb 21, 2019 2:38 pm

Joel_Mckay wrote: This should get you on the right path:
https://solarianprogrammer.com/2018/12/ ... -raspbian/

Hint: run a native build on the pi, and ignore the cross-compiling part of the instructions.
;-)
Hey, thanks for the reply. I have not yet started the procedure. Iw anted to know if it is necessary to perform all those commands on a separate machine. Can i execute those commands directly on my Raspberry Pi? Also, I don't know anything about running a native build on the pi. :cry:

User avatar
Joel_Mckay
Posts: 289
Joined: Mon Nov 12, 2012 10:22 pm
Contact: Website

Re: Installing OpenCV 4.0 in RaspberryPi without virtualenvironment.

Thu Feb 21, 2019 3:20 pm

Native builds on the pi are slow (must use the single instance of make), but tends to allow better environment detection of platform specific flag optimizations.

The packaged opencv versions are usually older stable generic-armhf snapshots, and your make scripts will need to account for the custom built library link locations after the build.

Note the OpenCV cmake script uses a lot of dependencies that are platform specific, version specific, and uses a separate repository for things like non-free modules. Typically, I will freeze the version of the library source I use once I begin a project, as unfortunately such active projects can undergo rapid API permutations while in use (extremely bad if you are working on a problem, and need repeatable results).

In general, OpenCV has optimized around CUDA/OpenCL and Intel CPUs... so the arm builds are not going to win any performance benchmarks...
Note, people are working on OpenCL for the Pi GPU, and It would theoretically make the pi3 over 5 times faster for some tasks... but it is nowhere near complete enough for practical application in libs like OpenCV yet.

Stigma
Posts: 19
Joined: Wed Jun 26, 2019 6:57 pm

Re: Installing OpenCV 4.0 in RaspberryPi without virtualenvironment.

Mon Jul 22, 2019 11:56 pm

Joel_Mckay wrote:
Sun Feb 17, 2019 1:23 pm
This should get you on the right path:
https://solarianprogrammer.com/2018/12/ ... -raspbian/

Hint: run a native build on the pi, and ignore the cross-compiling part of the instructions.
;-)
The guide worked for the most part except when I get down to the last bit where we change the OpenCV linking in PATH:

Code: Select all

echo 'export LD_LIBRARY_PATH=/opt/opencv-4.1.0/lib:$LD_LIBRARY_PATH' >> .bashrc
This gives me a Permission Denied. Is there a way around this to edit the library path??

User avatar
Joel_Mckay
Posts: 289
Joined: Mon Nov 12, 2012 10:22 pm
Contact: Website

Re: Installing OpenCV 4.0 in RaspberryPi without virtualenvironment.

Tue Jul 23, 2019 2:15 am

try your home dir ;-)
cd ~
ls -lAh

Also, we recently did a OpenCV 3.4.5 build for legacy Stretch based ROS:
https://sourceforge.net/projects/microm ... 2_current/

I have talked with some of the awesome devs about openCV 4, and specifically about the perils of restructuring APIs other projects relied upon. There will be a lot of code that simply not longer will build in 4.0, and you should consider this if trying something that needs documentation.

What you will find, is there are now many deprecated functions that no longer exist in 4.

The old 4.0.0.1 only build flags I used for a custom deb package set, and note QT4 with the /usr/local libs will need built as well for Stretch:

Code: Select all

 
cmake -D BUILD_TIFF=ON \
-D CPACK_PACKAGE_VERSION=4 -D EXTRA_MODULES_VCSVERSION=4 -D OPENCV_VCSVERSION=4 \
-D CMAKE_BUILD_TYPE=RELEASE -D OPENCV_EXTRA_MODULES_PATH=/home/pi/SRC/opencv_contrib/modules \
-D WITH_GSTREAMER=ON  -D WITH_GSTREAMER_0_10=OFF  -D WITH_FFMPEG=ON \
-D_GLIBCXX_USE_CXX11_ABI=0 -D WITH_UNICAP=ON -D BLAS=open \
-D WITH_MATLAB=OFF -D WITH_TESTS=OFF  -D ENABLE_PRECOMPILED_HEADERS=OFF  \
-D BUILD_opencv_gpulegacy=OFF \
	-D OPENCV_ENABLE_NONFREE=ON \
-D WITH_CAFFE=ON -D BUILD_CAFFE=OFF -D Caffe_LIBS=/usr/local/caffe/lib/libcaffe.so  -D Caffe_INCLUDE_DIR=/usr/local/caffe/include \
-D WITH_CERES=ON  -D BUILD_CERES=OFF -D CERES_LIBS=/usr/local/lib/libceres.a  -D CERES_INCLUDE_DIR=/usr/local/include \
	-D Atlas_LAPACK_LIBRARY=/usr/lib/liblapack.so \
	-D ATLAS_INCLUDE_DIR==/usr/include/atlas/ \
-D ENABLE_NEON=ON \
-D ENABLE_VFPV3=ON \
-D CMAKE_CXX_FLAGS="-DTBB_USE_GCC_BUILTINS=1 -D__TBB_64BIT_ATOMICS=0" \
-D WITH_GTK=OFF  -DWITH_GTK_2_X=OFF  -D WITH_QT=4  -D WITH_VTK=OFF \
-D WITH_OPENGL=ON  \
-D WITH_CAROTENE=ON  -D WITH_OPENCL=OFF -D WITH_OPENCLAMDFFT=OFF -D WITH_OPENCLAMDBLAS=OFF -D WITH_VA_INTEL=OFF \
-D ocv_add_testdata=OFF \
-D CPACK_BINARY_DEB=ON -D CPACK_BINARY_TZ=OFF -D CPACK_BINARY_STGZ=OFF -D CPACK_BINARY_TGZ=OFF \
 -D PROTOBUF_UPDATE_FILES=ON  \
 -D BUILD_PROTOBUF=OFF  \
 -D PROTOBUF_MIN_PROTOC_VERSION=3004000 \
 -D PROTOBUF_LIBRARY=/usr/local/lib/libprotobuf.so \
 -D PROTOBUF_LITE_LIBRARY=/usr/local/lib/libprotobuf-lite.so \
 -D PROTOBUF_PROTOC_EXECUTABLE=/usr/local/bin/protoc \
 -D Protobuf_PROTOC_EXECUTABLE=/usr/local/bin/protoc \
 -D PROTOBUF_PROTOC_LIBRARY=/usr/local/lib/libprotoc.so \
 -D Protobuf_LIBS=/usr/local/lib/libprotobuf.so \
-D PYTHON2_INCLUDE_DIR2=/usr/local/caffe/include \
-D PYTHON3_INCLUDE_DIR2=/usr/local/caffe/include \
-D PYTHON_DEFAULT_EXECUTABLE=$(which python2) \
-D BUILD_opencv_python2=ON \
-D BUILD_opencv_python3=ON \
-D INSTALL_PYTHON_EXAMPLES=ON  -D BUILD_opencv_dnn=ON \
-D BUILD_opencv_world=OFF -D BUILD_opencv_cnn_3dobj=ON \
-D WITH_EIGEN=ON  -D BUILD_opencv_gs=ON -D BUILD_opencv_ovis=ON -D BUILD_opencv_gpu=ON \
-D BUILD_opencv_gpuarithm=ON  -D BUILD_opencv_gpubgsegm=ON -D BUILD_opencv_gpucodec=ON \
-D BUILD_opencv_gpufeatures2d=ON -D BUILD_opencv_gpufilters=ON -D BUILD_opencv_gpuimgproc=ON  \
-D BUILD_opencv_gpuoptflow=ON -D BUILD_opencv_gpustereo=ON -D BUILD_opencv_gpuwarping=ON \
-D WITH_OPENMP=ON -D WITH_TBB=ON -D WITH_V4L=ON  \
-D CMAKE_INSTALL_PREFIX=/usr -D INSTALL_C_EXAMPLES=ON -D BUILD_EXAMPLES=OFF    ..
Best of luck,
J

evansusu
Posts: 21
Joined: Sat Apr 13, 2019 5:06 am

Re: Installing OpenCV 4.0 in RaspberryPi without virtualenvironment.

Tue Jul 23, 2019 8:29 am

Hi just need a raspberry pi code to use:
Basically I'm combining a motion sensor, light sensor and camera module
Light sensor causes light to light up when surrounding light intensity is low and vice versa
Motion sensor detects motion and causes light to be brighter (means light already lighted up but becomes brighter)
Camera module is for facial recognition

Return to “Automation, sensing and robotics”