<?xml version="1.0"?>
<?xml-stylesheet type="text/css" href="https://wiki.radxa.com/mw/skins/common/feed.css?303"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
		<id>https://wiki.radxa.com/mw/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Rust</id>
		<title>Radxa Wiki - User contributions [en]</title>
		<link rel="self" type="application/atom+xml" href="https://wiki.radxa.com/mw/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Rust"/>
		<link rel="alternate" type="text/html" href="https://wiki.radxa.com/Special:Contributions/Rust"/>
		<updated>2026-06-13T16:49:34Z</updated>
		<subtitle>User contributions</subtitle>
		<generator>MediaWiki 1.23.3</generator>

	<entry>
		<id>https://wiki.radxa.com/Rockpi4/dev/install-opencv</id>
		<title>Rockpi4/dev/install-opencv</title>
		<link rel="alternate" type="text/html" href="https://wiki.radxa.com/Rockpi4/dev/install-opencv"/>
				<updated>2022-07-18T07:27:59Z</updated>
		
		<summary type="html">&lt;p&gt;Rust: /* Dependencies */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{rockpi4_header}}&lt;br /&gt;
{{Languages|rockpi4/dev/install-opencv}}&lt;br /&gt;
    [[rockpi4 | ROCK Pi 4]] &amp;gt; [[rockpi4/dev | Development]] &amp;gt; [[rockpi4/dev/install-opencv | Install OpenCV]]&lt;br /&gt;
&lt;br /&gt;
This a guide to install OpenCV on your ROCK Pi 4 that running Ubuntu. All the instructions are done in terminal.&lt;br /&gt;
&lt;br /&gt;
== Compile OpenCV (4.0.1)==&lt;br /&gt;
&lt;br /&gt;
To compile OpenCV on ROCK Pi, we need at least 4GB ram and we recommend to compile on ubuntu arm64 images.&lt;br /&gt;
&lt;br /&gt;
=== Step 1: Get Ubuntu running  on ROCK Pi 4===&lt;br /&gt;
&lt;br /&gt;
To use OpenCV, an OS desktop is necessary. If your ROCK Pi 4 is running Ubuntu but without desktop, you can install Ubuntu mate desktop.&lt;br /&gt;
&lt;br /&gt;
    $ sudo apt install ubuntu-mate-core &amp;amp;&amp;amp; sudo apt install ubuntu-mate-desktop&lt;br /&gt;
&lt;br /&gt;
=== Step 2: Install all the recommended packages ===&lt;br /&gt;
&lt;br /&gt;
* Compilers: &lt;br /&gt;
&lt;br /&gt;
    $ sudo apt-get install build-essential&lt;br /&gt;
&lt;br /&gt;
* Required:&lt;br /&gt;
&lt;br /&gt;
    $ sudo apt-get install cmake git libgtk2.0-dev pkg-config libavcodec-dev libavformat-dev libswscale-dev&lt;br /&gt;
&lt;br /&gt;
* Recommended optional packages&lt;br /&gt;
&lt;br /&gt;
    $ sudo apt-get install python-dev python-numpy libtbb2 libtbb-dev libjpeg-dev libpng-dev libtiff-dev libdc1394-22-dev&lt;br /&gt;
    $ sudo apt install libgstreamer1.0-dev libgstreamer-plugins-base1.0-dev libavresample-dev&lt;br /&gt;
    $ sudo apt install tesseract-ocr cmake-data liblept5&lt;br /&gt;
&lt;br /&gt;
=== Step 3: Download OpenCV source ===&lt;br /&gt;
&lt;br /&gt;
We suggest that you are at the home folder, so that you don't  have to change the code in the next steps.&lt;br /&gt;
&lt;br /&gt;
We need to download OpenCV source. OpenCV latest release: [[https://opencv.org/releases.html here]]. As of writing this, the latest release is 4.0.1. For the newer version, just replace the link for the source code zip file. &lt;br /&gt;
&lt;br /&gt;
    $ cd ~&lt;br /&gt;
    $ wget -O opencv.zip https://github.com/opencv/opencv/archive/4.0.1.zip&lt;br /&gt;
    $ unzip opencv.zip&lt;br /&gt;
&lt;br /&gt;
And we also need to install the contribution packages of OpenCV. Here we get the latest release version:&lt;br /&gt;
&lt;br /&gt;
    $ cd ~&lt;br /&gt;
    $ wget -O opencv_contrib.zip https://github.com/opencv/opencv_contrib/archive/4.0.1.zip&lt;br /&gt;
    $ unzip opencv_contrib.zip&lt;br /&gt;
&lt;br /&gt;
=== Step 4: Configuring and compiling ===&lt;br /&gt;
&lt;br /&gt;
Confifure thte build  using cmake:&lt;br /&gt;
&lt;br /&gt;
    $ cd ~/opencv-4.0.1/&lt;br /&gt;
    $ mkdir build&lt;br /&gt;
    $ cd build&lt;br /&gt;
    $ export PY_NAME=$(python -c 'from sys import version_info as v; print(&amp;quot;python%d.%d&amp;quot; % v[:2])')&lt;br /&gt;
    $ export PY_NUMPY_DIR=$(python -c 'import os.path, numpy.core; print(os.path.dirname(numpy.core.__file__))')&lt;br /&gt;
    $ cmake -DCMAKE_BUILD_TYPE=RELEASE \&lt;br /&gt;
         -DCMAKE_INSTALL_PREFIX=/usr/local \&lt;br /&gt;
         \&lt;br /&gt;
         -DPYTHON2_EXECUTABLE=$(which python) \&lt;br /&gt;
         -DPYTHON_INCLUDE_DIR=/usr/include/$PY_NAME \&lt;br /&gt;
         -DPYTHON_INCLUDE_DIR2=/usr/include/aarch64-linux-gnu/$PY_NAME \&lt;br /&gt;
         -DPYTHON_LIBRARY=/usr/lib/aarch64-linux-gnu/lib$PY_NAME.so \&lt;br /&gt;
         -DPYTHON2_NUMPY_INCLUDE_DIRS=/usr/lib/$PY_NAME/dist-packages/numpy/core/include/ \&lt;br /&gt;
         \&lt;br /&gt;
         -DBUILD_DOCS=OFF \&lt;br /&gt;
         -DBUILD_EXAMPLES=OFF \&lt;br /&gt;
         -DBUILD_TESTS=OFF \&lt;br /&gt;
         -DBUILD_PERF_TESTS=OFF \&lt;br /&gt;
         \&lt;br /&gt;
         -DOPENCV_EXTRA_MODULES_PATH=../../opencv_contrib-4.0.1/modules \&lt;br /&gt;
         ..&lt;br /&gt;
&lt;br /&gt;
Compile OpenCV in the build folder:&lt;br /&gt;
&lt;br /&gt;
    $ make -j$(nproc --all)&lt;br /&gt;
&lt;br /&gt;
Install OpenCV in the build folder:&lt;br /&gt;
&lt;br /&gt;
    $ sudo make install&lt;br /&gt;
    $ sudo ldconfig&lt;br /&gt;
&lt;br /&gt;
=== Step 5: Test your building and installation ===&lt;br /&gt;
&lt;br /&gt;
To confirm that you have install ed OpenCV correctly , try this: &lt;br /&gt;
&lt;br /&gt;
    rock@linux:~$ python&lt;br /&gt;
    Python 2.7.15rc1 (default, Nov 12 2018, 14:31:15) &lt;br /&gt;
    [GCC 7.3.0] on linux2&lt;br /&gt;
    Type &amp;quot;help&amp;quot;, &amp;quot;copyright&amp;quot;, &amp;quot;credits&amp;quot; or &amp;quot;license&amp;quot; for more information.&lt;br /&gt;
    &amp;gt;&amp;gt;&amp;gt; import cv2&lt;br /&gt;
    &amp;gt;&amp;gt;&amp;gt; cv2.__version__&lt;br /&gt;
    '4.0.1'&lt;br /&gt;
    &amp;gt;&amp;gt;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Step6: Do the sample supported by OpenCV official ===&lt;br /&gt;
&lt;br /&gt;
    $ cd ~/opencv-4.0.1/samples/python&lt;br /&gt;
    $ python watershed.py&lt;br /&gt;
&lt;br /&gt;
Finally, if you don't need the files in opencv-4.0.1 or opencv_contrib-4.0.1. You can remove them:&lt;br /&gt;
&lt;br /&gt;
    $ cd ~&lt;br /&gt;
    $ rm -rf opencv-4.0.1 opencv_contrib-4.0.1 opencv_contrib.zip opencv.zip&lt;br /&gt;
&lt;br /&gt;
If you follow the code exactly, you will find it working just fine.&lt;br /&gt;
&lt;br /&gt;
== Compile OpenCV (4.6.0) ==&lt;br /&gt;
&lt;br /&gt;
=== Requirements ===&lt;br /&gt;
&lt;br /&gt;
RAM &amp;gt;= 2G&lt;br /&gt;
&lt;br /&gt;
Debian &amp;gt;= 10&lt;br /&gt;
&lt;br /&gt;
=== Download Source Code ===&lt;br /&gt;
&lt;br /&gt;
[https://opencv.org/releases/ Releases - OpenCV]&lt;br /&gt;
&lt;br /&gt;
=== Dependencies ===&lt;br /&gt;
&lt;br /&gt;
    apt install build-essential cmake pkg-config ccache git&lt;br /&gt;
    apt install python2 python3  python3-pip&lt;br /&gt;
    apt install qt5-default&lt;br /&gt;
    apt install libpng-dev libjpeg-dev&lt;br /&gt;
    apt install libeigen3-dev&lt;br /&gt;
    apt install ffmpeg libavcodec-dev libavformat-dev libswscale-dev libavresample-dev&lt;br /&gt;
    apt install libgstreamer1.0-dev libgstreamermm-1.0-dev&lt;br /&gt;
    apt install libgtk-3-dev libgtkglext1-dev libgtkglextmm-x11-1.2-dev&lt;br /&gt;
    &lt;br /&gt;
    pip3 install numpy&lt;br /&gt;
&lt;br /&gt;
Download `OpenBLAS` (Basic Linear Algebra Subprograms)&lt;br /&gt;
&lt;br /&gt;
[http://www.openblas.net/ OpenBLAS : An optimized BLAS library]&lt;br /&gt;
&lt;br /&gt;
    # tar &amp;amp;&amp;amp; cd project dir &lt;br /&gt;
    make&lt;br /&gt;
    sudo make install&lt;br /&gt;
&lt;br /&gt;
* `qt5-default` may not be found in many apt source but there should be substitution&lt;br /&gt;
* `build-essential` `cmake` `pkg-config` `ccache` `git` essential to build&lt;br /&gt;
* `libpng-dev` `libjpeg-dev` image files surpport&lt;br /&gt;
* `libeigen3-dev` linear algebra surpport&lt;br /&gt;
* `ffmpeg` `libavcodec-dev` `libavformat-dev` `libswscale-dev` `libavresample-dev` video files surpport&lt;br /&gt;
* `libgstreamer1.0-dev` `libgstreamermm-1.0-dev` stream media surpport&lt;br /&gt;
* `libgtk-3-dev` `libgtkglext1-dev` `libgtkglextmm-x11-1.2-dev` GUI lib&lt;br /&gt;
&lt;br /&gt;
=== Build ===&lt;br /&gt;
&lt;br /&gt;
    # tar &amp;amp;&amp;amp; cd project dir&lt;br /&gt;
    mkdir -p build &amp;amp;&amp;amp; cd build&lt;br /&gt;
    # generate makefile&lt;br /&gt;
    cmake .. -DCMAKE_BUILD_TYPE=Release -DCMAKE_VERBOSE_MAKEFILE=ON -DCMAKE_INSTALL_PREFIX=/opt/opencv -DWITH_OPENGL=ON -DOPENCV_ENABLE_NONFREE=ON -DWITH_QT=ON -DBUILD_TESTS=OFF -DBUILD_PERF_TESTS=OFF -DOPENCV_GENERATE_PKGCONFIG=ON  -DWITH_1394=OFF -DBUILD_opencv_python2=OFF -DBUILD_opencv_python3=ON -DPYTHON3_LIBRARY=$(python3 -c &amp;quot;from distutils.sysconfig import get_config_var;from os.path import dirname,join ; print(join(dirname(get_config_var('LIBPC')),get_config_var('LDLIBRARY')))&amp;quot;) -DPYTHON3_NUMPY_INCLUDE_DIRS=$(python3 -c &amp;quot;import numpy; print(numpy.get_include())&amp;quot;) -DPYTHON3_PACKAGES_PATH=$(python3 -c &amp;quot;from distutils.sysconfig import get_python_lib; print(get_python_lib())&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
* ''WITH_OPENGL''=ON : enables OpenGL hardware acceleration surpport&lt;br /&gt;
&lt;br /&gt;
* ''CMAKE_BUILD_TYPE''=Release : or Debug if you want&lt;br /&gt;
&lt;br /&gt;
* ''CMAKE_VERBOSE_MAKEFILE''=ON : easy to find errors&lt;br /&gt;
&lt;br /&gt;
* ''OPENCV_ENABLE_NONFREE''=ON : Some algorithms included in the library are known to be protected by patents and are disabled by default&lt;br /&gt;
&lt;br /&gt;
* ''CMAKE_INSTALL_PREFIX''=/opt/opencv： To install produced binaries root location&lt;br /&gt;
&lt;br /&gt;
* ''WITH_QT''=ON : use Qt to draw a window&lt;br /&gt;
&lt;br /&gt;
* ''BUILD_TESTS''=OFF，''BUILD_PERF_TESTS''=OFF：shorten the build time&lt;br /&gt;
&lt;br /&gt;
* ''OPENCV_GENERATE_PKGCONFIG''=ON： enables  `.pc`  file generation along with standard CMake package&lt;br /&gt;
&lt;br /&gt;
* For more information, [https://docs.opencv.org/4.6.0/db/d05/tutorial_config_reference.html OpenCV: OpenCV configuration options reference]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
result output may look like below：&lt;br /&gt;
&lt;br /&gt;
    -- General configuration for OpenCV 4.6.0 =====================================&lt;br /&gt;
    --   Version control:               unknown&lt;br /&gt;
    --&lt;br /&gt;
    --   Platform:&lt;br /&gt;
    --     Timestamp:                   2022-07-13T07:48:24Z&lt;br /&gt;
    --     Host:                        Linux 4.4.154-116-rockchip-g86a614bc15b3 aarch64&lt;br /&gt;
    --     CMake:                       3.13.4&lt;br /&gt;
    --     CMake generator:             Unix Makefiles&lt;br /&gt;
    --     CMake build tool:            /usr/bin/make&lt;br /&gt;
    --     Configuration:               Release&lt;br /&gt;
    --&lt;br /&gt;
    --   CPU/HW features:&lt;br /&gt;
    --     Baseline:                    NEON FP16&lt;br /&gt;
    --&lt;br /&gt;
    --   C/C++:&lt;br /&gt;
    --     Built as dynamic libs?:      YES&lt;br /&gt;
    --     C++ standard:                11&lt;br /&gt;
    --     C++ Compiler:                /usr/bin/c++  (ver 8.3.0)&lt;br /&gt;
    --     C++ flags (Release):         -fsigned-char -W -Wall -Wreturn-type -Wnon-virtual-dtor -Waddress -Wsequence-point -Wformat -Wformat-security -Wmissing-declarations -Wundef -Winit-self -Wpointer-arith -Wshadow -Wsign-promo -Wuninitialized -Wsuggest-override -Wno-delete-non-virtual-dtor -Wno-comment -Wimplicit-fallthrough=3 -Wno-strict-overflow -fdiagnostics-show-option -pthread -fomit-frame-pointer -ffunction-sections -fdata-sections    -fvisibility=hidden -fvisibility-inlines-hidden -O3 -DNDEBUG  -DNDEBUG&lt;br /&gt;
    --     C++ flags (Debug):           -fsigned-char -W -Wall -Wreturn-type -Wnon-virtual-dtor -Waddress -Wsequence-point -Wformat -Wformat-security -Wmissing-declarations -Wundef -Winit-self -Wpointer-arith -Wshadow -Wsign-promo -Wuninitialized -Wsuggest-override -Wno-delete-non-virtual-dtor -Wno-comment -Wimplicit-fallthrough=3 -Wno-strict-overflow -fdiagnostics-show-option -pthread -fomit-frame-pointer -ffunction-sections -fdata-sections    -fvisibility=hidden -fvisibility-inlines-hidden -g  -O0 -DDEBUG -D_DEBUG&lt;br /&gt;
    --     C Compiler:                  /usr/bin/cc&lt;br /&gt;
    --     C flags (Release):           -fsigned-char -W -Wall -Wreturn-type -Waddress -Wsequence-point -Wformat -Wformat-security -Wmissing-declarations -Wmissing-prototypes -Wstrict-prototypes -Wundef -Winit-self -Wpointer-arith -Wshadow -Wuninitialized -Wno-comment -Wimplicit-fallthrough=3 -Wno-strict-overflow -fdiagnostics-show-option -pthread -fomit-frame-pointer -ffunction-sections -fdata-sections    -fvisibility=hidden -O3 -DNDEBUG  -DNDEBUG&lt;br /&gt;
    --     C flags (Debug):             -fsigned-char -W -Wall -Wreturn-type -Waddress -Wsequence-point -Wformat -Wformat-security -Wmissing-declarations -Wmissing-prototypes -Wstrict-prototypes -Wundef -Winit-self -Wpointer-arith -Wshadow -Wuninitialized -Wno-comment -Wimplicit-fallthrough=3 -Wno-strict-overflow -fdiagnostics-show-option -pthread -fomit-frame-pointer -ffunction-sections -fdata-sections    -fvisibility=hidden -g  -O0 -DDEBUG -D_DEBUG&lt;br /&gt;
    --     Linker flags (Release):      -Wl,--gc-sections -Wl,--as-needed -Wl,--no-undefined&lt;br /&gt;
    --     Linker flags (Debug):        -Wl,--gc-sections -Wl,--as-needed -Wl,--no-undefined&lt;br /&gt;
    --     ccache:                      YES&lt;br /&gt;
    --     Precompiled headers:         NO&lt;br /&gt;
    --     Extra dependencies:          dl m pthread rt&lt;br /&gt;
    --     3rdparty dependencies:&lt;br /&gt;
    --&lt;br /&gt;
    --   OpenCV modules:&lt;br /&gt;
    --     To be built:                 calib3d core dnn features2d flann gapi highgui imgcodecs imgproc ml objdetect photo stitching video videoio&lt;br /&gt;
    --     Disabled:                    world&lt;br /&gt;
    --     Disabled by dependency:      -&lt;br /&gt;
    --     Unavailable:                 java python2 python3 ts&lt;br /&gt;
    --     Applications:                apps&lt;br /&gt;
    --     Documentation:               NO&lt;br /&gt;
    --     Non-free algorithms:         YES&lt;br /&gt;
    --&lt;br /&gt;
    --   GUI:                           QT5&lt;br /&gt;
    --     QT:                          YES (ver 5.11.3 )&lt;br /&gt;
    --       QT OpenGL support:         YES (Qt5::OpenGL 5.11.3)&lt;br /&gt;
    --     GTK+:                        YES (ver 3.24.5)&lt;br /&gt;
    --       GThread :                  YES (ver 2.58.3)&lt;br /&gt;
    --       GtkGlExt:                  YES (ver 1.2.0)&lt;br /&gt;
    --     OpenGL support:              YES (/usr/lib/aarch64-linux-gnu/libGL.so /usr/lib/aarch64-linux-gnu/libGLU.so)&lt;br /&gt;
    --     VTK support:                 NO&lt;br /&gt;
    --&lt;br /&gt;
    --   Media I/O:&lt;br /&gt;
    --     ZLib:                        /usr/lib/aarch64-linux-gnu/libz.so (ver 1.2.11)&lt;br /&gt;
    --     JPEG:                        /usr/lib/aarch64-linux-gnu/libjpeg.so (ver 62)&lt;br /&gt;
    --     WEBP:                        build (ver encoder: 0x020f)&lt;br /&gt;
    --     PNG:                         /usr/lib/aarch64-linux-gnu/libpng.so (ver 1.6.36)&lt;br /&gt;
    --     TIFF:                        /usr/lib/aarch64-linux-gnu/libtiff.so (ver 42 / 4.1.0)&lt;br /&gt;
    --     JPEG 2000:                   build (ver 2.4.0)&lt;br /&gt;
    --     OpenEXR:                     /usr/lib/aarch64-linux-gnu/libImath.so /usr/lib/aarch64-linux-gnu/libIlmImf.so /usr/lib/aarch64-linux-gnu/libIex.so /usr/lib/aarch64-linux-gnu/libHalf.so /usr/lib/aarch64-linux-gnu/libIlmThread.so (ver 2_2)&lt;br /&gt;
    --     HDR:                         YES&lt;br /&gt;
    --     SUNRASTER:                   YES&lt;br /&gt;
    --     PXM:                         YES&lt;br /&gt;
    --     PFM:                         YES&lt;br /&gt;
    --&lt;br /&gt;
    --   Video I/O:&lt;br /&gt;
    --     FFMPEG:                      YES&lt;br /&gt;
    --       avcodec:                   YES (58.35.100)&lt;br /&gt;
    --       avformat:                  YES (58.20.100)&lt;br /&gt;
    --       avutil:                    YES (56.22.100)&lt;br /&gt;
    --       swscale:                   YES (5.3.100)&lt;br /&gt;
    --       avresample:                YES (4.0.0)&lt;br /&gt;
    --     GStreamer:                   YES (1.14.4)&lt;br /&gt;
    --     v4l/v4l2:                    YES (linux/videodev2.h)&lt;br /&gt;
    --&lt;br /&gt;
    --   Parallel framework:            pthreads&lt;br /&gt;
    --&lt;br /&gt;
    --   Trace:                         YES (with Intel ITT)&lt;br /&gt;
    --&lt;br /&gt;
    --   Other third-party libraries:&lt;br /&gt;
    --     Lapack:                      YES (/opt/OpenBLAS/lib/libopenblas.so)&lt;br /&gt;
    --     Eigen:                       YES (ver 3.3.7)&lt;br /&gt;
    --     Custom HAL:                  YES (carotene (ver 0.0.1))&lt;br /&gt;
    --     Protobuf:                    build (3.19.1)&lt;br /&gt;
    --&lt;br /&gt;
    --   OpenCL:                        YES (no extra features)&lt;br /&gt;
    --     Include path:                /home/rock/OpenCV/opencv-4.6.0/3rdparty/include/opencl/1.2&lt;br /&gt;
    --     Link libraries:              Dynamic load&lt;br /&gt;
    --&lt;br /&gt;
    --   Python 3:&lt;br /&gt;
    --     Interpreter:                 /usr/bin/python3 (ver 3.7.3)&lt;br /&gt;
    --     Libraries:                   NO&lt;br /&gt;
    --     numpy:                       /home/rock/.local/lib/python3.7/site-packages/numpy/core/include (ver 1.16.2)&lt;br /&gt;
    --     install path:                -&lt;br /&gt;
    --&lt;br /&gt;
    --   Python (for build):            /usr/bin/python2.7&lt;br /&gt;
    --&lt;br /&gt;
    --   Java:&lt;br /&gt;
    --     ant:                         NO&lt;br /&gt;
    --     JNI:                         NO&lt;br /&gt;
    --     Java wrappers:               NO&lt;br /&gt;
    --     Java tests:                  NO&lt;br /&gt;
    --&lt;br /&gt;
    --   Install to:                    /usr/local&lt;br /&gt;
    -- -----------------------------------------------------------------&lt;br /&gt;
    --&lt;br /&gt;
    -- Configuring done&lt;br /&gt;
    -- Generating done&lt;br /&gt;
    -- Build files have been written to: /home/rock/OpenCV/opencv-4.6.0/build&lt;br /&gt;
&lt;br /&gt;
check the output，install dependencies and reuse the full `cmake` command to make item to '''YES''' if it interests you &lt;br /&gt;
&lt;br /&gt;
eg. ''OpenGL Support'' and ''OpenCL'' should be '''YES''' if you want full hardware acceleration feature&lt;br /&gt;
&lt;br /&gt;
After the generation, make :&lt;br /&gt;
&lt;br /&gt;
    make all&lt;br /&gt;
    #or make all -j$(grep -c ^processor /proc/cpuinfo)&lt;br /&gt;
    make install&lt;br /&gt;
&lt;br /&gt;
== Troubleshooting ==&lt;br /&gt;
&lt;br /&gt;
* Post your issue at the forum: https://forum.radxa.com/c/dev&lt;/div&gt;</summary>
		<author><name>Rust</name></author>	</entry>

	<entry>
		<id>https://wiki.radxa.com/Rockpi4/dev/install-opencv</id>
		<title>Rockpi4/dev/install-opencv</title>
		<link rel="alternate" type="text/html" href="https://wiki.radxa.com/Rockpi4/dev/install-opencv"/>
				<updated>2022-07-18T07:26:44Z</updated>
		
		<summary type="html">&lt;p&gt;Rust: /* Build */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{rockpi4_header}}&lt;br /&gt;
{{Languages|rockpi4/dev/install-opencv}}&lt;br /&gt;
    [[rockpi4 | ROCK Pi 4]] &amp;gt; [[rockpi4/dev | Development]] &amp;gt; [[rockpi4/dev/install-opencv | Install OpenCV]]&lt;br /&gt;
&lt;br /&gt;
This a guide to install OpenCV on your ROCK Pi 4 that running Ubuntu. All the instructions are done in terminal.&lt;br /&gt;
&lt;br /&gt;
== Compile OpenCV (4.0.1)==&lt;br /&gt;
&lt;br /&gt;
To compile OpenCV on ROCK Pi, we need at least 4GB ram and we recommend to compile on ubuntu arm64 images.&lt;br /&gt;
&lt;br /&gt;
=== Step 1: Get Ubuntu running  on ROCK Pi 4===&lt;br /&gt;
&lt;br /&gt;
To use OpenCV, an OS desktop is necessary. If your ROCK Pi 4 is running Ubuntu but without desktop, you can install Ubuntu mate desktop.&lt;br /&gt;
&lt;br /&gt;
    $ sudo apt install ubuntu-mate-core &amp;amp;&amp;amp; sudo apt install ubuntu-mate-desktop&lt;br /&gt;
&lt;br /&gt;
=== Step 2: Install all the recommended packages ===&lt;br /&gt;
&lt;br /&gt;
* Compilers: &lt;br /&gt;
&lt;br /&gt;
    $ sudo apt-get install build-essential&lt;br /&gt;
&lt;br /&gt;
* Required:&lt;br /&gt;
&lt;br /&gt;
    $ sudo apt-get install cmake git libgtk2.0-dev pkg-config libavcodec-dev libavformat-dev libswscale-dev&lt;br /&gt;
&lt;br /&gt;
* Recommended optional packages&lt;br /&gt;
&lt;br /&gt;
    $ sudo apt-get install python-dev python-numpy libtbb2 libtbb-dev libjpeg-dev libpng-dev libtiff-dev libdc1394-22-dev&lt;br /&gt;
    $ sudo apt install libgstreamer1.0-dev libgstreamer-plugins-base1.0-dev libavresample-dev&lt;br /&gt;
    $ sudo apt install tesseract-ocr cmake-data liblept5&lt;br /&gt;
&lt;br /&gt;
=== Step 3: Download OpenCV source ===&lt;br /&gt;
&lt;br /&gt;
We suggest that you are at the home folder, so that you don't  have to change the code in the next steps.&lt;br /&gt;
&lt;br /&gt;
We need to download OpenCV source. OpenCV latest release: [[https://opencv.org/releases.html here]]. As of writing this, the latest release is 4.0.1. For the newer version, just replace the link for the source code zip file. &lt;br /&gt;
&lt;br /&gt;
    $ cd ~&lt;br /&gt;
    $ wget -O opencv.zip https://github.com/opencv/opencv/archive/4.0.1.zip&lt;br /&gt;
    $ unzip opencv.zip&lt;br /&gt;
&lt;br /&gt;
And we also need to install the contribution packages of OpenCV. Here we get the latest release version:&lt;br /&gt;
&lt;br /&gt;
    $ cd ~&lt;br /&gt;
    $ wget -O opencv_contrib.zip https://github.com/opencv/opencv_contrib/archive/4.0.1.zip&lt;br /&gt;
    $ unzip opencv_contrib.zip&lt;br /&gt;
&lt;br /&gt;
=== Step 4: Configuring and compiling ===&lt;br /&gt;
&lt;br /&gt;
Confifure thte build  using cmake:&lt;br /&gt;
&lt;br /&gt;
    $ cd ~/opencv-4.0.1/&lt;br /&gt;
    $ mkdir build&lt;br /&gt;
    $ cd build&lt;br /&gt;
    $ export PY_NAME=$(python -c 'from sys import version_info as v; print(&amp;quot;python%d.%d&amp;quot; % v[:2])')&lt;br /&gt;
    $ export PY_NUMPY_DIR=$(python -c 'import os.path, numpy.core; print(os.path.dirname(numpy.core.__file__))')&lt;br /&gt;
    $ cmake -DCMAKE_BUILD_TYPE=RELEASE \&lt;br /&gt;
         -DCMAKE_INSTALL_PREFIX=/usr/local \&lt;br /&gt;
         \&lt;br /&gt;
         -DPYTHON2_EXECUTABLE=$(which python) \&lt;br /&gt;
         -DPYTHON_INCLUDE_DIR=/usr/include/$PY_NAME \&lt;br /&gt;
         -DPYTHON_INCLUDE_DIR2=/usr/include/aarch64-linux-gnu/$PY_NAME \&lt;br /&gt;
         -DPYTHON_LIBRARY=/usr/lib/aarch64-linux-gnu/lib$PY_NAME.so \&lt;br /&gt;
         -DPYTHON2_NUMPY_INCLUDE_DIRS=/usr/lib/$PY_NAME/dist-packages/numpy/core/include/ \&lt;br /&gt;
         \&lt;br /&gt;
         -DBUILD_DOCS=OFF \&lt;br /&gt;
         -DBUILD_EXAMPLES=OFF \&lt;br /&gt;
         -DBUILD_TESTS=OFF \&lt;br /&gt;
         -DBUILD_PERF_TESTS=OFF \&lt;br /&gt;
         \&lt;br /&gt;
         -DOPENCV_EXTRA_MODULES_PATH=../../opencv_contrib-4.0.1/modules \&lt;br /&gt;
         ..&lt;br /&gt;
&lt;br /&gt;
Compile OpenCV in the build folder:&lt;br /&gt;
&lt;br /&gt;
    $ make -j$(nproc --all)&lt;br /&gt;
&lt;br /&gt;
Install OpenCV in the build folder:&lt;br /&gt;
&lt;br /&gt;
    $ sudo make install&lt;br /&gt;
    $ sudo ldconfig&lt;br /&gt;
&lt;br /&gt;
=== Step 5: Test your building and installation ===&lt;br /&gt;
&lt;br /&gt;
To confirm that you have install ed OpenCV correctly , try this: &lt;br /&gt;
&lt;br /&gt;
    rock@linux:~$ python&lt;br /&gt;
    Python 2.7.15rc1 (default, Nov 12 2018, 14:31:15) &lt;br /&gt;
    [GCC 7.3.0] on linux2&lt;br /&gt;
    Type &amp;quot;help&amp;quot;, &amp;quot;copyright&amp;quot;, &amp;quot;credits&amp;quot; or &amp;quot;license&amp;quot; for more information.&lt;br /&gt;
    &amp;gt;&amp;gt;&amp;gt; import cv2&lt;br /&gt;
    &amp;gt;&amp;gt;&amp;gt; cv2.__version__&lt;br /&gt;
    '4.0.1'&lt;br /&gt;
    &amp;gt;&amp;gt;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Step6: Do the sample supported by OpenCV official ===&lt;br /&gt;
&lt;br /&gt;
    $ cd ~/opencv-4.0.1/samples/python&lt;br /&gt;
    $ python watershed.py&lt;br /&gt;
&lt;br /&gt;
Finally, if you don't need the files in opencv-4.0.1 or opencv_contrib-4.0.1. You can remove them:&lt;br /&gt;
&lt;br /&gt;
    $ cd ~&lt;br /&gt;
    $ rm -rf opencv-4.0.1 opencv_contrib-4.0.1 opencv_contrib.zip opencv.zip&lt;br /&gt;
&lt;br /&gt;
If you follow the code exactly, you will find it working just fine.&lt;br /&gt;
&lt;br /&gt;
== Compile OpenCV (4.6.0) ==&lt;br /&gt;
&lt;br /&gt;
=== Requirements ===&lt;br /&gt;
&lt;br /&gt;
RAM &amp;gt;= 2G&lt;br /&gt;
&lt;br /&gt;
Debian &amp;gt;= 10&lt;br /&gt;
&lt;br /&gt;
=== Download Source Code ===&lt;br /&gt;
&lt;br /&gt;
[https://opencv.org/releases/ Releases - OpenCV]&lt;br /&gt;
&lt;br /&gt;
=== Dependencies ===&lt;br /&gt;
&lt;br /&gt;
    apt install build-essential cmake pkg-config ccache git&lt;br /&gt;
    apt install python2 python3  python3-pip&lt;br /&gt;
    apt install qt5-default&lt;br /&gt;
    apt install libpng-dev libjpeg-dev&lt;br /&gt;
    apt install libeigen3-dev&lt;br /&gt;
    apt install ffmpeg libavcodec-dev libavformat-dev libswscale-dev libavresample-dev&lt;br /&gt;
    apt install libgstreamer1.0-dev libgstreamermm-1.0-dev&lt;br /&gt;
    apt install libgtk-3-dev libgtkglext1-dev libgtkglextmm-x11-1.2-dev&lt;br /&gt;
    &lt;br /&gt;
    pip3 install numpy&lt;br /&gt;
&lt;br /&gt;
Download `OpenBLAS` (Basic Linear Algebra Subprograms)&lt;br /&gt;
&lt;br /&gt;
[http://www.openblas.net/ OpenBLAS : An optimized BLAS library]()&lt;br /&gt;
&lt;br /&gt;
    # tar &amp;amp;&amp;amp; cd project dir &lt;br /&gt;
    make&lt;br /&gt;
    sudo make install&lt;br /&gt;
&lt;br /&gt;
* `qt5-default` may not be found in many apt source but there should be substitution&lt;br /&gt;
* `build-essential` `cmake` `pkg-config` `ccache` `git` essential to build&lt;br /&gt;
* `libpng-dev` `libjpeg-dev` image files surpport&lt;br /&gt;
* `libeigen3-dev` linear algebra surpport&lt;br /&gt;
* `ffmpeg` `libavcodec-dev` `libavformat-dev` `libswscale-dev` `libavresample-dev` video files surpport&lt;br /&gt;
* `libgstreamer1.0-dev` `libgstreamermm-1.0-dev` stream media surpport&lt;br /&gt;
* `libgtk-3-dev` `libgtkglext1-dev` `libgtkglextmm-x11-1.2-dev` GUI lib&lt;br /&gt;
&lt;br /&gt;
=== Build ===&lt;br /&gt;
&lt;br /&gt;
    # tar &amp;amp;&amp;amp; cd project dir&lt;br /&gt;
    mkdir -p build &amp;amp;&amp;amp; cd build&lt;br /&gt;
    # generate makefile&lt;br /&gt;
    cmake .. -DCMAKE_BUILD_TYPE=Release -DCMAKE_VERBOSE_MAKEFILE=ON -DCMAKE_INSTALL_PREFIX=/opt/opencv -DWITH_OPENGL=ON -DOPENCV_ENABLE_NONFREE=ON -DWITH_QT=ON -DBUILD_TESTS=OFF -DBUILD_PERF_TESTS=OFF -DOPENCV_GENERATE_PKGCONFIG=ON  -DWITH_1394=OFF -DBUILD_opencv_python2=OFF -DBUILD_opencv_python3=ON -DPYTHON3_LIBRARY=$(python3 -c &amp;quot;from distutils.sysconfig import get_config_var;from os.path import dirname,join ; print(join(dirname(get_config_var('LIBPC')),get_config_var('LDLIBRARY')))&amp;quot;) -DPYTHON3_NUMPY_INCLUDE_DIRS=$(python3 -c &amp;quot;import numpy; print(numpy.get_include())&amp;quot;) -DPYTHON3_PACKAGES_PATH=$(python3 -c &amp;quot;from distutils.sysconfig import get_python_lib; print(get_python_lib())&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
* ''WITH_OPENGL''=ON : enables OpenGL hardware acceleration surpport&lt;br /&gt;
&lt;br /&gt;
* ''CMAKE_BUILD_TYPE''=Release : or Debug if you want&lt;br /&gt;
&lt;br /&gt;
* ''CMAKE_VERBOSE_MAKEFILE''=ON : easy to find errors&lt;br /&gt;
&lt;br /&gt;
* ''OPENCV_ENABLE_NONFREE''=ON : Some algorithms included in the library are known to be protected by patents and are disabled by default&lt;br /&gt;
&lt;br /&gt;
* ''CMAKE_INSTALL_PREFIX''=/opt/opencv： To install produced binaries root location&lt;br /&gt;
&lt;br /&gt;
* ''WITH_QT''=ON : use Qt to draw a window&lt;br /&gt;
&lt;br /&gt;
* ''BUILD_TESTS''=OFF，''BUILD_PERF_TESTS''=OFF：shorten the build time&lt;br /&gt;
&lt;br /&gt;
* ''OPENCV_GENERATE_PKGCONFIG''=ON： enables  `.pc`  file generation along with standard CMake package&lt;br /&gt;
&lt;br /&gt;
* For more information, [https://docs.opencv.org/4.6.0/db/d05/tutorial_config_reference.html OpenCV: OpenCV configuration options reference]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
result output may look like below：&lt;br /&gt;
&lt;br /&gt;
    -- General configuration for OpenCV 4.6.0 =====================================&lt;br /&gt;
    --   Version control:               unknown&lt;br /&gt;
    --&lt;br /&gt;
    --   Platform:&lt;br /&gt;
    --     Timestamp:                   2022-07-13T07:48:24Z&lt;br /&gt;
    --     Host:                        Linux 4.4.154-116-rockchip-g86a614bc15b3 aarch64&lt;br /&gt;
    --     CMake:                       3.13.4&lt;br /&gt;
    --     CMake generator:             Unix Makefiles&lt;br /&gt;
    --     CMake build tool:            /usr/bin/make&lt;br /&gt;
    --     Configuration:               Release&lt;br /&gt;
    --&lt;br /&gt;
    --   CPU/HW features:&lt;br /&gt;
    --     Baseline:                    NEON FP16&lt;br /&gt;
    --&lt;br /&gt;
    --   C/C++:&lt;br /&gt;
    --     Built as dynamic libs?:      YES&lt;br /&gt;
    --     C++ standard:                11&lt;br /&gt;
    --     C++ Compiler:                /usr/bin/c++  (ver 8.3.0)&lt;br /&gt;
    --     C++ flags (Release):         -fsigned-char -W -Wall -Wreturn-type -Wnon-virtual-dtor -Waddress -Wsequence-point -Wformat -Wformat-security -Wmissing-declarations -Wundef -Winit-self -Wpointer-arith -Wshadow -Wsign-promo -Wuninitialized -Wsuggest-override -Wno-delete-non-virtual-dtor -Wno-comment -Wimplicit-fallthrough=3 -Wno-strict-overflow -fdiagnostics-show-option -pthread -fomit-frame-pointer -ffunction-sections -fdata-sections    -fvisibility=hidden -fvisibility-inlines-hidden -O3 -DNDEBUG  -DNDEBUG&lt;br /&gt;
    --     C++ flags (Debug):           -fsigned-char -W -Wall -Wreturn-type -Wnon-virtual-dtor -Waddress -Wsequence-point -Wformat -Wformat-security -Wmissing-declarations -Wundef -Winit-self -Wpointer-arith -Wshadow -Wsign-promo -Wuninitialized -Wsuggest-override -Wno-delete-non-virtual-dtor -Wno-comment -Wimplicit-fallthrough=3 -Wno-strict-overflow -fdiagnostics-show-option -pthread -fomit-frame-pointer -ffunction-sections -fdata-sections    -fvisibility=hidden -fvisibility-inlines-hidden -g  -O0 -DDEBUG -D_DEBUG&lt;br /&gt;
    --     C Compiler:                  /usr/bin/cc&lt;br /&gt;
    --     C flags (Release):           -fsigned-char -W -Wall -Wreturn-type -Waddress -Wsequence-point -Wformat -Wformat-security -Wmissing-declarations -Wmissing-prototypes -Wstrict-prototypes -Wundef -Winit-self -Wpointer-arith -Wshadow -Wuninitialized -Wno-comment -Wimplicit-fallthrough=3 -Wno-strict-overflow -fdiagnostics-show-option -pthread -fomit-frame-pointer -ffunction-sections -fdata-sections    -fvisibility=hidden -O3 -DNDEBUG  -DNDEBUG&lt;br /&gt;
    --     C flags (Debug):             -fsigned-char -W -Wall -Wreturn-type -Waddress -Wsequence-point -Wformat -Wformat-security -Wmissing-declarations -Wmissing-prototypes -Wstrict-prototypes -Wundef -Winit-self -Wpointer-arith -Wshadow -Wuninitialized -Wno-comment -Wimplicit-fallthrough=3 -Wno-strict-overflow -fdiagnostics-show-option -pthread -fomit-frame-pointer -ffunction-sections -fdata-sections    -fvisibility=hidden -g  -O0 -DDEBUG -D_DEBUG&lt;br /&gt;
    --     Linker flags (Release):      -Wl,--gc-sections -Wl,--as-needed -Wl,--no-undefined&lt;br /&gt;
    --     Linker flags (Debug):        -Wl,--gc-sections -Wl,--as-needed -Wl,--no-undefined&lt;br /&gt;
    --     ccache:                      YES&lt;br /&gt;
    --     Precompiled headers:         NO&lt;br /&gt;
    --     Extra dependencies:          dl m pthread rt&lt;br /&gt;
    --     3rdparty dependencies:&lt;br /&gt;
    --&lt;br /&gt;
    --   OpenCV modules:&lt;br /&gt;
    --     To be built:                 calib3d core dnn features2d flann gapi highgui imgcodecs imgproc ml objdetect photo stitching video videoio&lt;br /&gt;
    --     Disabled:                    world&lt;br /&gt;
    --     Disabled by dependency:      -&lt;br /&gt;
    --     Unavailable:                 java python2 python3 ts&lt;br /&gt;
    --     Applications:                apps&lt;br /&gt;
    --     Documentation:               NO&lt;br /&gt;
    --     Non-free algorithms:         YES&lt;br /&gt;
    --&lt;br /&gt;
    --   GUI:                           QT5&lt;br /&gt;
    --     QT:                          YES (ver 5.11.3 )&lt;br /&gt;
    --       QT OpenGL support:         YES (Qt5::OpenGL 5.11.3)&lt;br /&gt;
    --     GTK+:                        YES (ver 3.24.5)&lt;br /&gt;
    --       GThread :                  YES (ver 2.58.3)&lt;br /&gt;
    --       GtkGlExt:                  YES (ver 1.2.0)&lt;br /&gt;
    --     OpenGL support:              YES (/usr/lib/aarch64-linux-gnu/libGL.so /usr/lib/aarch64-linux-gnu/libGLU.so)&lt;br /&gt;
    --     VTK support:                 NO&lt;br /&gt;
    --&lt;br /&gt;
    --   Media I/O:&lt;br /&gt;
    --     ZLib:                        /usr/lib/aarch64-linux-gnu/libz.so (ver 1.2.11)&lt;br /&gt;
    --     JPEG:                        /usr/lib/aarch64-linux-gnu/libjpeg.so (ver 62)&lt;br /&gt;
    --     WEBP:                        build (ver encoder: 0x020f)&lt;br /&gt;
    --     PNG:                         /usr/lib/aarch64-linux-gnu/libpng.so (ver 1.6.36)&lt;br /&gt;
    --     TIFF:                        /usr/lib/aarch64-linux-gnu/libtiff.so (ver 42 / 4.1.0)&lt;br /&gt;
    --     JPEG 2000:                   build (ver 2.4.0)&lt;br /&gt;
    --     OpenEXR:                     /usr/lib/aarch64-linux-gnu/libImath.so /usr/lib/aarch64-linux-gnu/libIlmImf.so /usr/lib/aarch64-linux-gnu/libIex.so /usr/lib/aarch64-linux-gnu/libHalf.so /usr/lib/aarch64-linux-gnu/libIlmThread.so (ver 2_2)&lt;br /&gt;
    --     HDR:                         YES&lt;br /&gt;
    --     SUNRASTER:                   YES&lt;br /&gt;
    --     PXM:                         YES&lt;br /&gt;
    --     PFM:                         YES&lt;br /&gt;
    --&lt;br /&gt;
    --   Video I/O:&lt;br /&gt;
    --     FFMPEG:                      YES&lt;br /&gt;
    --       avcodec:                   YES (58.35.100)&lt;br /&gt;
    --       avformat:                  YES (58.20.100)&lt;br /&gt;
    --       avutil:                    YES (56.22.100)&lt;br /&gt;
    --       swscale:                   YES (5.3.100)&lt;br /&gt;
    --       avresample:                YES (4.0.0)&lt;br /&gt;
    --     GStreamer:                   YES (1.14.4)&lt;br /&gt;
    --     v4l/v4l2:                    YES (linux/videodev2.h)&lt;br /&gt;
    --&lt;br /&gt;
    --   Parallel framework:            pthreads&lt;br /&gt;
    --&lt;br /&gt;
    --   Trace:                         YES (with Intel ITT)&lt;br /&gt;
    --&lt;br /&gt;
    --   Other third-party libraries:&lt;br /&gt;
    --     Lapack:                      YES (/opt/OpenBLAS/lib/libopenblas.so)&lt;br /&gt;
    --     Eigen:                       YES (ver 3.3.7)&lt;br /&gt;
    --     Custom HAL:                  YES (carotene (ver 0.0.1))&lt;br /&gt;
    --     Protobuf:                    build (3.19.1)&lt;br /&gt;
    --&lt;br /&gt;
    --   OpenCL:                        YES (no extra features)&lt;br /&gt;
    --     Include path:                /home/rock/OpenCV/opencv-4.6.0/3rdparty/include/opencl/1.2&lt;br /&gt;
    --     Link libraries:              Dynamic load&lt;br /&gt;
    --&lt;br /&gt;
    --   Python 3:&lt;br /&gt;
    --     Interpreter:                 /usr/bin/python3 (ver 3.7.3)&lt;br /&gt;
    --     Libraries:                   NO&lt;br /&gt;
    --     numpy:                       /home/rock/.local/lib/python3.7/site-packages/numpy/core/include (ver 1.16.2)&lt;br /&gt;
    --     install path:                -&lt;br /&gt;
    --&lt;br /&gt;
    --   Python (for build):            /usr/bin/python2.7&lt;br /&gt;
    --&lt;br /&gt;
    --   Java:&lt;br /&gt;
    --     ant:                         NO&lt;br /&gt;
    --     JNI:                         NO&lt;br /&gt;
    --     Java wrappers:               NO&lt;br /&gt;
    --     Java tests:                  NO&lt;br /&gt;
    --&lt;br /&gt;
    --   Install to:                    /usr/local&lt;br /&gt;
    -- -----------------------------------------------------------------&lt;br /&gt;
    --&lt;br /&gt;
    -- Configuring done&lt;br /&gt;
    -- Generating done&lt;br /&gt;
    -- Build files have been written to: /home/rock/OpenCV/opencv-4.6.0/build&lt;br /&gt;
&lt;br /&gt;
check the output，install dependencies and reuse the full `cmake` command to make item to '''YES''' if it interests you &lt;br /&gt;
&lt;br /&gt;
eg. ''OpenGL Support'' and ''OpenCL'' should be '''YES''' if you want full hardware acceleration feature&lt;br /&gt;
&lt;br /&gt;
After the generation, make :&lt;br /&gt;
&lt;br /&gt;
    make all&lt;br /&gt;
    #or make all -j$(grep -c ^processor /proc/cpuinfo)&lt;br /&gt;
    make install&lt;br /&gt;
&lt;br /&gt;
== Troubleshooting ==&lt;br /&gt;
&lt;br /&gt;
* Post your issue at the forum: https://forum.radxa.com/c/dev&lt;/div&gt;</summary>
		<author><name>Rust</name></author>	</entry>

	<entry>
		<id>https://wiki.radxa.com/Rockpi4/dev/install-opencv</id>
		<title>Rockpi4/dev/install-opencv</title>
		<link rel="alternate" type="text/html" href="https://wiki.radxa.com/Rockpi4/dev/install-opencv"/>
				<updated>2022-07-18T07:21:22Z</updated>
		
		<summary type="html">&lt;p&gt;Rust: /* Build */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{rockpi4_header}}&lt;br /&gt;
{{Languages|rockpi4/dev/install-opencv}}&lt;br /&gt;
    [[rockpi4 | ROCK Pi 4]] &amp;gt; [[rockpi4/dev | Development]] &amp;gt; [[rockpi4/dev/install-opencv | Install OpenCV]]&lt;br /&gt;
&lt;br /&gt;
This a guide to install OpenCV on your ROCK Pi 4 that running Ubuntu. All the instructions are done in terminal.&lt;br /&gt;
&lt;br /&gt;
== Compile OpenCV (4.0.1)==&lt;br /&gt;
&lt;br /&gt;
To compile OpenCV on ROCK Pi, we need at least 4GB ram and we recommend to compile on ubuntu arm64 images.&lt;br /&gt;
&lt;br /&gt;
=== Step 1: Get Ubuntu running  on ROCK Pi 4===&lt;br /&gt;
&lt;br /&gt;
To use OpenCV, an OS desktop is necessary. If your ROCK Pi 4 is running Ubuntu but without desktop, you can install Ubuntu mate desktop.&lt;br /&gt;
&lt;br /&gt;
    $ sudo apt install ubuntu-mate-core &amp;amp;&amp;amp; sudo apt install ubuntu-mate-desktop&lt;br /&gt;
&lt;br /&gt;
=== Step 2: Install all the recommended packages ===&lt;br /&gt;
&lt;br /&gt;
* Compilers: &lt;br /&gt;
&lt;br /&gt;
    $ sudo apt-get install build-essential&lt;br /&gt;
&lt;br /&gt;
* Required:&lt;br /&gt;
&lt;br /&gt;
    $ sudo apt-get install cmake git libgtk2.0-dev pkg-config libavcodec-dev libavformat-dev libswscale-dev&lt;br /&gt;
&lt;br /&gt;
* Recommended optional packages&lt;br /&gt;
&lt;br /&gt;
    $ sudo apt-get install python-dev python-numpy libtbb2 libtbb-dev libjpeg-dev libpng-dev libtiff-dev libdc1394-22-dev&lt;br /&gt;
    $ sudo apt install libgstreamer1.0-dev libgstreamer-plugins-base1.0-dev libavresample-dev&lt;br /&gt;
    $ sudo apt install tesseract-ocr cmake-data liblept5&lt;br /&gt;
&lt;br /&gt;
=== Step 3: Download OpenCV source ===&lt;br /&gt;
&lt;br /&gt;
We suggest that you are at the home folder, so that you don't  have to change the code in the next steps.&lt;br /&gt;
&lt;br /&gt;
We need to download OpenCV source. OpenCV latest release: [[https://opencv.org/releases.html here]]. As of writing this, the latest release is 4.0.1. For the newer version, just replace the link for the source code zip file. &lt;br /&gt;
&lt;br /&gt;
    $ cd ~&lt;br /&gt;
    $ wget -O opencv.zip https://github.com/opencv/opencv/archive/4.0.1.zip&lt;br /&gt;
    $ unzip opencv.zip&lt;br /&gt;
&lt;br /&gt;
And we also need to install the contribution packages of OpenCV. Here we get the latest release version:&lt;br /&gt;
&lt;br /&gt;
    $ cd ~&lt;br /&gt;
    $ wget -O opencv_contrib.zip https://github.com/opencv/opencv_contrib/archive/4.0.1.zip&lt;br /&gt;
    $ unzip opencv_contrib.zip&lt;br /&gt;
&lt;br /&gt;
=== Step 4: Configuring and compiling ===&lt;br /&gt;
&lt;br /&gt;
Confifure thte build  using cmake:&lt;br /&gt;
&lt;br /&gt;
    $ cd ~/opencv-4.0.1/&lt;br /&gt;
    $ mkdir build&lt;br /&gt;
    $ cd build&lt;br /&gt;
    $ export PY_NAME=$(python -c 'from sys import version_info as v; print(&amp;quot;python%d.%d&amp;quot; % v[:2])')&lt;br /&gt;
    $ export PY_NUMPY_DIR=$(python -c 'import os.path, numpy.core; print(os.path.dirname(numpy.core.__file__))')&lt;br /&gt;
    $ cmake -DCMAKE_BUILD_TYPE=RELEASE \&lt;br /&gt;
         -DCMAKE_INSTALL_PREFIX=/usr/local \&lt;br /&gt;
         \&lt;br /&gt;
         -DPYTHON2_EXECUTABLE=$(which python) \&lt;br /&gt;
         -DPYTHON_INCLUDE_DIR=/usr/include/$PY_NAME \&lt;br /&gt;
         -DPYTHON_INCLUDE_DIR2=/usr/include/aarch64-linux-gnu/$PY_NAME \&lt;br /&gt;
         -DPYTHON_LIBRARY=/usr/lib/aarch64-linux-gnu/lib$PY_NAME.so \&lt;br /&gt;
         -DPYTHON2_NUMPY_INCLUDE_DIRS=/usr/lib/$PY_NAME/dist-packages/numpy/core/include/ \&lt;br /&gt;
         \&lt;br /&gt;
         -DBUILD_DOCS=OFF \&lt;br /&gt;
         -DBUILD_EXAMPLES=OFF \&lt;br /&gt;
         -DBUILD_TESTS=OFF \&lt;br /&gt;
         -DBUILD_PERF_TESTS=OFF \&lt;br /&gt;
         \&lt;br /&gt;
         -DOPENCV_EXTRA_MODULES_PATH=../../opencv_contrib-4.0.1/modules \&lt;br /&gt;
         ..&lt;br /&gt;
&lt;br /&gt;
Compile OpenCV in the build folder:&lt;br /&gt;
&lt;br /&gt;
    $ make -j$(nproc --all)&lt;br /&gt;
&lt;br /&gt;
Install OpenCV in the build folder:&lt;br /&gt;
&lt;br /&gt;
    $ sudo make install&lt;br /&gt;
    $ sudo ldconfig&lt;br /&gt;
&lt;br /&gt;
=== Step 5: Test your building and installation ===&lt;br /&gt;
&lt;br /&gt;
To confirm that you have install ed OpenCV correctly , try this: &lt;br /&gt;
&lt;br /&gt;
    rock@linux:~$ python&lt;br /&gt;
    Python 2.7.15rc1 (default, Nov 12 2018, 14:31:15) &lt;br /&gt;
    [GCC 7.3.0] on linux2&lt;br /&gt;
    Type &amp;quot;help&amp;quot;, &amp;quot;copyright&amp;quot;, &amp;quot;credits&amp;quot; or &amp;quot;license&amp;quot; for more information.&lt;br /&gt;
    &amp;gt;&amp;gt;&amp;gt; import cv2&lt;br /&gt;
    &amp;gt;&amp;gt;&amp;gt; cv2.__version__&lt;br /&gt;
    '4.0.1'&lt;br /&gt;
    &amp;gt;&amp;gt;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Step6: Do the sample supported by OpenCV official ===&lt;br /&gt;
&lt;br /&gt;
    $ cd ~/opencv-4.0.1/samples/python&lt;br /&gt;
    $ python watershed.py&lt;br /&gt;
&lt;br /&gt;
Finally, if you don't need the files in opencv-4.0.1 or opencv_contrib-4.0.1. You can remove them:&lt;br /&gt;
&lt;br /&gt;
    $ cd ~&lt;br /&gt;
    $ rm -rf opencv-4.0.1 opencv_contrib-4.0.1 opencv_contrib.zip opencv.zip&lt;br /&gt;
&lt;br /&gt;
If you follow the code exactly, you will find it working just fine.&lt;br /&gt;
&lt;br /&gt;
== Compile OpenCV (4.6.0) ==&lt;br /&gt;
&lt;br /&gt;
=== Requirements ===&lt;br /&gt;
&lt;br /&gt;
RAM &amp;gt;= 2G&lt;br /&gt;
&lt;br /&gt;
Debian &amp;gt;= 10&lt;br /&gt;
&lt;br /&gt;
=== Download Source Code ===&lt;br /&gt;
&lt;br /&gt;
[https://opencv.org/releases/ Releases - OpenCV]&lt;br /&gt;
&lt;br /&gt;
=== Dependencies ===&lt;br /&gt;
&lt;br /&gt;
    apt install build-essential cmake pkg-config ccache git&lt;br /&gt;
    apt install python2 python3  python3-pip&lt;br /&gt;
    apt install qt5-default&lt;br /&gt;
    apt install libpng-dev libjpeg-dev&lt;br /&gt;
    apt install libeigen3-dev&lt;br /&gt;
    apt install ffmpeg libavcodec-dev libavformat-dev libswscale-dev libavresample-dev&lt;br /&gt;
    apt install libgstreamer1.0-dev libgstreamermm-1.0-dev&lt;br /&gt;
    apt install libgtk-3-dev libgtkglext1-dev libgtkglextmm-x11-1.2-dev&lt;br /&gt;
    &lt;br /&gt;
    pip3 install numpy&lt;br /&gt;
&lt;br /&gt;
Download `OpenBLAS` (Basic Linear Algebra Subprograms)&lt;br /&gt;
&lt;br /&gt;
[http://www.openblas.net/ OpenBLAS : An optimized BLAS library]()&lt;br /&gt;
&lt;br /&gt;
    # tar &amp;amp;&amp;amp; cd project dir &lt;br /&gt;
    make&lt;br /&gt;
    sudo make install&lt;br /&gt;
&lt;br /&gt;
* `qt5-default` may not be found in many apt source but there should be substitution&lt;br /&gt;
* `build-essential` `cmake` `pkg-config` `ccache` `git` essential to build&lt;br /&gt;
* `libpng-dev` `libjpeg-dev` image files surpport&lt;br /&gt;
* `libeigen3-dev` linear algebra surpport&lt;br /&gt;
* `ffmpeg` `libavcodec-dev` `libavformat-dev` `libswscale-dev` `libavresample-dev` video files surpport&lt;br /&gt;
* `libgstreamer1.0-dev` `libgstreamermm-1.0-dev` stream media surpport&lt;br /&gt;
* `libgtk-3-dev` `libgtkglext1-dev` `libgtkglextmm-x11-1.2-dev` GUI lib&lt;br /&gt;
&lt;br /&gt;
=== Build ===&lt;br /&gt;
&lt;br /&gt;
    # tar &amp;amp;&amp;amp; cd project dir&lt;br /&gt;
    mkdir -p build &amp;amp;&amp;amp; cd build&lt;br /&gt;
    # generate makefile&lt;br /&gt;
    cmake .. -DCMAKE_BUILD_TYPE=Release -DCMAKE_VERBOSE_MAKEFILE=ON -DCMAKE_INSTALL_PREFIX=/opt/opencv -DWITH_OPENGL=ON -DOPENCV_ENABLE_NONFREE=ON -DWITH_QT=ON -DBUILD_TESTS=OFF -DBUILD_PERF_TESTS=OFF -DOPENCV_GENERATE_PKGCONFIG=ON  -DWITH_1394=OFF -DBUILD_opencv_python2=OFF -DBUILD_opencv_python3=ON -DPYTHON3_LIBRARY=$(python3 -c &amp;quot;from distutils.sysconfig import get_config_var;from os.path import dirname,join ; print(join(dirname(get_config_var('LIBPC')),get_config_var('LDLIBRARY')))&amp;quot;) -DPYTHON3_NUMPY_INCLUDE_DIRS=$(python3 -c &amp;quot;import numpy; print(numpy.get_include())&amp;quot;) -DPYTHON3_PACKAGES_PATH=$(python3 -c &amp;quot;from distutils.sysconfig import get_python_lib; print(get_python_lib())&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
* `WITH_OPENGL`=ON : enables OpenGL hardware acceleration surpport&lt;br /&gt;
&lt;br /&gt;
* `CMAKE_BUILD_TYPE`=Release : or Debug if you want&lt;br /&gt;
&lt;br /&gt;
* `CMAKE_VERBOSE_MAKEFILE`=ON : easy to find errors&lt;br /&gt;
&lt;br /&gt;
* `OPENCV_ENABLE_NONFREE`=ON : Some algorithms included in the library are known to be protected by patents and are disabled by default&lt;br /&gt;
&lt;br /&gt;
* `CMAKE_INSTALL_PREFIX`=/opt/opencv： To install produced binaries root location&lt;br /&gt;
&lt;br /&gt;
* `WITH_QT`=ON : use Qt to draw a window&lt;br /&gt;
&lt;br /&gt;
* `BUILD_TESTS`=OFF，`BUILD_PERF_TESTS`=OFF：shorten the build time&lt;br /&gt;
&lt;br /&gt;
* `OPENCV_GENERATE_PKGCONFIG`=ON： enables  `.pc`  file generation along with standard CMake package&lt;br /&gt;
&lt;br /&gt;
* For more information, [https://docs.opencv.org/4.6.0/db/d05/tutorial_config_reference.html OpenCV: OpenCV configuration options reference]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
result output may look like below：&lt;br /&gt;
&lt;br /&gt;
    -- General configuration for OpenCV 4.6.0 =====================================&lt;br /&gt;
    --   Version control:               unknown&lt;br /&gt;
    --&lt;br /&gt;
    --   Platform:&lt;br /&gt;
    --     Timestamp:                   2022-07-13T07:48:24Z&lt;br /&gt;
    --     Host:                        Linux 4.4.154-116-rockchip-g86a614bc15b3 aarch64&lt;br /&gt;
    --     CMake:                       3.13.4&lt;br /&gt;
    --     CMake generator:             Unix Makefiles&lt;br /&gt;
    --     CMake build tool:            /usr/bin/make&lt;br /&gt;
    --     Configuration:               Release&lt;br /&gt;
    --&lt;br /&gt;
    --   CPU/HW features:&lt;br /&gt;
    --     Baseline:                    NEON FP16&lt;br /&gt;
    --&lt;br /&gt;
    --   C/C++:&lt;br /&gt;
    --     Built as dynamic libs?:      YES&lt;br /&gt;
    --     C++ standard:                11&lt;br /&gt;
    --     C++ Compiler:                /usr/bin/c++  (ver 8.3.0)&lt;br /&gt;
    --     C++ flags (Release):         -fsigned-char -W -Wall -Wreturn-type -Wnon-virtual-dtor -Waddress -Wsequence-point -Wformat -Wformat-security -Wmissing-declarations -Wundef -Winit-self -Wpointer-arith -Wshadow -Wsign-promo -Wuninitialized -Wsuggest-override -Wno-delete-non-virtual-dtor -Wno-comment -Wimplicit-fallthrough=3 -Wno-strict-overflow -fdiagnostics-show-option -pthread -fomit-frame-pointer -ffunction-sections -fdata-sections    -fvisibility=hidden -fvisibility-inlines-hidden -O3 -DNDEBUG  -DNDEBUG&lt;br /&gt;
    --     C++ flags (Debug):           -fsigned-char -W -Wall -Wreturn-type -Wnon-virtual-dtor -Waddress -Wsequence-point -Wformat -Wformat-security -Wmissing-declarations -Wundef -Winit-self -Wpointer-arith -Wshadow -Wsign-promo -Wuninitialized -Wsuggest-override -Wno-delete-non-virtual-dtor -Wno-comment -Wimplicit-fallthrough=3 -Wno-strict-overflow -fdiagnostics-show-option -pthread -fomit-frame-pointer -ffunction-sections -fdata-sections    -fvisibility=hidden -fvisibility-inlines-hidden -g  -O0 -DDEBUG -D_DEBUG&lt;br /&gt;
    --     C Compiler:                  /usr/bin/cc&lt;br /&gt;
    --     C flags (Release):           -fsigned-char -W -Wall -Wreturn-type -Waddress -Wsequence-point -Wformat -Wformat-security -Wmissing-declarations -Wmissing-prototypes -Wstrict-prototypes -Wundef -Winit-self -Wpointer-arith -Wshadow -Wuninitialized -Wno-comment -Wimplicit-fallthrough=3 -Wno-strict-overflow -fdiagnostics-show-option -pthread -fomit-frame-pointer -ffunction-sections -fdata-sections    -fvisibility=hidden -O3 -DNDEBUG  -DNDEBUG&lt;br /&gt;
    --     C flags (Debug):             -fsigned-char -W -Wall -Wreturn-type -Waddress -Wsequence-point -Wformat -Wformat-security -Wmissing-declarations -Wmissing-prototypes -Wstrict-prototypes -Wundef -Winit-self -Wpointer-arith -Wshadow -Wuninitialized -Wno-comment -Wimplicit-fallthrough=3 -Wno-strict-overflow -fdiagnostics-show-option -pthread -fomit-frame-pointer -ffunction-sections -fdata-sections    -fvisibility=hidden -g  -O0 -DDEBUG -D_DEBUG&lt;br /&gt;
    --     Linker flags (Release):      -Wl,--gc-sections -Wl,--as-needed -Wl,--no-undefined&lt;br /&gt;
    --     Linker flags (Debug):        -Wl,--gc-sections -Wl,--as-needed -Wl,--no-undefined&lt;br /&gt;
    --     ccache:                      YES&lt;br /&gt;
    --     Precompiled headers:         NO&lt;br /&gt;
    --     Extra dependencies:          dl m pthread rt&lt;br /&gt;
    --     3rdparty dependencies:&lt;br /&gt;
    --&lt;br /&gt;
    --   OpenCV modules:&lt;br /&gt;
    --     To be built:                 calib3d core dnn features2d flann gapi highgui imgcodecs imgproc ml objdetect photo stitching video videoio&lt;br /&gt;
    --     Disabled:                    world&lt;br /&gt;
    --     Disabled by dependency:      -&lt;br /&gt;
    --     Unavailable:                 java python2 python3 ts&lt;br /&gt;
    --     Applications:                apps&lt;br /&gt;
    --     Documentation:               NO&lt;br /&gt;
    --     Non-free algorithms:         YES&lt;br /&gt;
    --&lt;br /&gt;
    --   GUI:                           QT5&lt;br /&gt;
    --     QT:                          YES (ver 5.11.3 )&lt;br /&gt;
    --       QT OpenGL support:         YES (Qt5::OpenGL 5.11.3)&lt;br /&gt;
    --     GTK+:                        YES (ver 3.24.5)&lt;br /&gt;
    --       GThread :                  YES (ver 2.58.3)&lt;br /&gt;
    --       GtkGlExt:                  YES (ver 1.2.0)&lt;br /&gt;
    --     OpenGL support:              YES (/usr/lib/aarch64-linux-gnu/libGL.so /usr/lib/aarch64-linux-gnu/libGLU.so)&lt;br /&gt;
    --     VTK support:                 NO&lt;br /&gt;
    --&lt;br /&gt;
    --   Media I/O:&lt;br /&gt;
    --     ZLib:                        /usr/lib/aarch64-linux-gnu/libz.so (ver 1.2.11)&lt;br /&gt;
    --     JPEG:                        /usr/lib/aarch64-linux-gnu/libjpeg.so (ver 62)&lt;br /&gt;
    --     WEBP:                        build (ver encoder: 0x020f)&lt;br /&gt;
    --     PNG:                         /usr/lib/aarch64-linux-gnu/libpng.so (ver 1.6.36)&lt;br /&gt;
    --     TIFF:                        /usr/lib/aarch64-linux-gnu/libtiff.so (ver 42 / 4.1.0)&lt;br /&gt;
    --     JPEG 2000:                   build (ver 2.4.0)&lt;br /&gt;
    --     OpenEXR:                     /usr/lib/aarch64-linux-gnu/libImath.so /usr/lib/aarch64-linux-gnu/libIlmImf.so /usr/lib/aarch64-linux-gnu/libIex.so /usr/lib/aarch64-linux-gnu/libHalf.so /usr/lib/aarch64-linux-gnu/libIlmThread.so (ver 2_2)&lt;br /&gt;
    --     HDR:                         YES&lt;br /&gt;
    --     SUNRASTER:                   YES&lt;br /&gt;
    --     PXM:                         YES&lt;br /&gt;
    --     PFM:                         YES&lt;br /&gt;
    --&lt;br /&gt;
    --   Video I/O:&lt;br /&gt;
    --     FFMPEG:                      YES&lt;br /&gt;
    --       avcodec:                   YES (58.35.100)&lt;br /&gt;
    --       avformat:                  YES (58.20.100)&lt;br /&gt;
    --       avutil:                    YES (56.22.100)&lt;br /&gt;
    --       swscale:                   YES (5.3.100)&lt;br /&gt;
    --       avresample:                YES (4.0.0)&lt;br /&gt;
    --     GStreamer:                   YES (1.14.4)&lt;br /&gt;
    --     v4l/v4l2:                    YES (linux/videodev2.h)&lt;br /&gt;
    --&lt;br /&gt;
    --   Parallel framework:            pthreads&lt;br /&gt;
    --&lt;br /&gt;
    --   Trace:                         YES (with Intel ITT)&lt;br /&gt;
    --&lt;br /&gt;
    --   Other third-party libraries:&lt;br /&gt;
    --     Lapack:                      YES (/opt/OpenBLAS/lib/libopenblas.so)&lt;br /&gt;
    --     Eigen:                       YES (ver 3.3.7)&lt;br /&gt;
    --     Custom HAL:                  YES (carotene (ver 0.0.1))&lt;br /&gt;
    --     Protobuf:                    build (3.19.1)&lt;br /&gt;
    --&lt;br /&gt;
    --   OpenCL:                        YES (no extra features)&lt;br /&gt;
    --     Include path:                /home/rock/OpenCV/opencv-4.6.0/3rdparty/include/opencl/1.2&lt;br /&gt;
    --     Link libraries:              Dynamic load&lt;br /&gt;
    --&lt;br /&gt;
    --   Python 3:&lt;br /&gt;
    --     Interpreter:                 /usr/bin/python3 (ver 3.7.3)&lt;br /&gt;
    --     Libraries:                   NO&lt;br /&gt;
    --     numpy:                       /home/rock/.local/lib/python3.7/site-packages/numpy/core/include (ver 1.16.2)&lt;br /&gt;
    --     install path:                -&lt;br /&gt;
    --&lt;br /&gt;
    --   Python (for build):            /usr/bin/python2.7&lt;br /&gt;
    --&lt;br /&gt;
    --   Java:&lt;br /&gt;
    --     ant:                         NO&lt;br /&gt;
    --     JNI:                         NO&lt;br /&gt;
    --     Java wrappers:               NO&lt;br /&gt;
    --     Java tests:                  NO&lt;br /&gt;
    --&lt;br /&gt;
    --   Install to:                    /usr/local&lt;br /&gt;
    -- -----------------------------------------------------------------&lt;br /&gt;
    --&lt;br /&gt;
    -- Configuring done&lt;br /&gt;
    -- Generating done&lt;br /&gt;
    -- Build files have been written to: /home/rock/OpenCV/opencv-4.6.0/build&lt;br /&gt;
&lt;br /&gt;
check the output，install dependencies and reuse the full `cmake` command to make item to '''YES''' if it interests you &lt;br /&gt;
&lt;br /&gt;
eg. `OpenGL Support` and `OpenCL` should be '''YES''' if you want full hardware acceleration feature&lt;br /&gt;
&lt;br /&gt;
After the generation, make :&lt;br /&gt;
&lt;br /&gt;
    make all&lt;br /&gt;
    #or make all -j$(grep -c ^processor /proc/cpuinfo)&lt;br /&gt;
    make install&lt;br /&gt;
&lt;br /&gt;
== Troubleshooting ==&lt;br /&gt;
&lt;br /&gt;
* Post your issue at the forum: https://forum.radxa.com/c/dev&lt;/div&gt;</summary>
		<author><name>Rust</name></author>	</entry>

	<entry>
		<id>https://wiki.radxa.com/Rockpi4/dev/install-opencv</id>
		<title>Rockpi4/dev/install-opencv</title>
		<link rel="alternate" type="text/html" href="https://wiki.radxa.com/Rockpi4/dev/install-opencv"/>
				<updated>2022-07-18T07:19:59Z</updated>
		
		<summary type="html">&lt;p&gt;Rust: /* Compile OpenCV */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{rockpi4_header}}&lt;br /&gt;
{{Languages|rockpi4/dev/install-opencv}}&lt;br /&gt;
    [[rockpi4 | ROCK Pi 4]] &amp;gt; [[rockpi4/dev | Development]] &amp;gt; [[rockpi4/dev/install-opencv | Install OpenCV]]&lt;br /&gt;
&lt;br /&gt;
This a guide to install OpenCV on your ROCK Pi 4 that running Ubuntu. All the instructions are done in terminal.&lt;br /&gt;
&lt;br /&gt;
== Compile OpenCV (4.0.1)==&lt;br /&gt;
&lt;br /&gt;
To compile OpenCV on ROCK Pi, we need at least 4GB ram and we recommend to compile on ubuntu arm64 images.&lt;br /&gt;
&lt;br /&gt;
=== Step 1: Get Ubuntu running  on ROCK Pi 4===&lt;br /&gt;
&lt;br /&gt;
To use OpenCV, an OS desktop is necessary. If your ROCK Pi 4 is running Ubuntu but without desktop, you can install Ubuntu mate desktop.&lt;br /&gt;
&lt;br /&gt;
    $ sudo apt install ubuntu-mate-core &amp;amp;&amp;amp; sudo apt install ubuntu-mate-desktop&lt;br /&gt;
&lt;br /&gt;
=== Step 2: Install all the recommended packages ===&lt;br /&gt;
&lt;br /&gt;
* Compilers: &lt;br /&gt;
&lt;br /&gt;
    $ sudo apt-get install build-essential&lt;br /&gt;
&lt;br /&gt;
* Required:&lt;br /&gt;
&lt;br /&gt;
    $ sudo apt-get install cmake git libgtk2.0-dev pkg-config libavcodec-dev libavformat-dev libswscale-dev&lt;br /&gt;
&lt;br /&gt;
* Recommended optional packages&lt;br /&gt;
&lt;br /&gt;
    $ sudo apt-get install python-dev python-numpy libtbb2 libtbb-dev libjpeg-dev libpng-dev libtiff-dev libdc1394-22-dev&lt;br /&gt;
    $ sudo apt install libgstreamer1.0-dev libgstreamer-plugins-base1.0-dev libavresample-dev&lt;br /&gt;
    $ sudo apt install tesseract-ocr cmake-data liblept5&lt;br /&gt;
&lt;br /&gt;
=== Step 3: Download OpenCV source ===&lt;br /&gt;
&lt;br /&gt;
We suggest that you are at the home folder, so that you don't  have to change the code in the next steps.&lt;br /&gt;
&lt;br /&gt;
We need to download OpenCV source. OpenCV latest release: [[https://opencv.org/releases.html here]]. As of writing this, the latest release is 4.0.1. For the newer version, just replace the link for the source code zip file. &lt;br /&gt;
&lt;br /&gt;
    $ cd ~&lt;br /&gt;
    $ wget -O opencv.zip https://github.com/opencv/opencv/archive/4.0.1.zip&lt;br /&gt;
    $ unzip opencv.zip&lt;br /&gt;
&lt;br /&gt;
And we also need to install the contribution packages of OpenCV. Here we get the latest release version:&lt;br /&gt;
&lt;br /&gt;
    $ cd ~&lt;br /&gt;
    $ wget -O opencv_contrib.zip https://github.com/opencv/opencv_contrib/archive/4.0.1.zip&lt;br /&gt;
    $ unzip opencv_contrib.zip&lt;br /&gt;
&lt;br /&gt;
=== Step 4: Configuring and compiling ===&lt;br /&gt;
&lt;br /&gt;
Confifure thte build  using cmake:&lt;br /&gt;
&lt;br /&gt;
    $ cd ~/opencv-4.0.1/&lt;br /&gt;
    $ mkdir build&lt;br /&gt;
    $ cd build&lt;br /&gt;
    $ export PY_NAME=$(python -c 'from sys import version_info as v; print(&amp;quot;python%d.%d&amp;quot; % v[:2])')&lt;br /&gt;
    $ export PY_NUMPY_DIR=$(python -c 'import os.path, numpy.core; print(os.path.dirname(numpy.core.__file__))')&lt;br /&gt;
    $ cmake -DCMAKE_BUILD_TYPE=RELEASE \&lt;br /&gt;
         -DCMAKE_INSTALL_PREFIX=/usr/local \&lt;br /&gt;
         \&lt;br /&gt;
         -DPYTHON2_EXECUTABLE=$(which python) \&lt;br /&gt;
         -DPYTHON_INCLUDE_DIR=/usr/include/$PY_NAME \&lt;br /&gt;
         -DPYTHON_INCLUDE_DIR2=/usr/include/aarch64-linux-gnu/$PY_NAME \&lt;br /&gt;
         -DPYTHON_LIBRARY=/usr/lib/aarch64-linux-gnu/lib$PY_NAME.so \&lt;br /&gt;
         -DPYTHON2_NUMPY_INCLUDE_DIRS=/usr/lib/$PY_NAME/dist-packages/numpy/core/include/ \&lt;br /&gt;
         \&lt;br /&gt;
         -DBUILD_DOCS=OFF \&lt;br /&gt;
         -DBUILD_EXAMPLES=OFF \&lt;br /&gt;
         -DBUILD_TESTS=OFF \&lt;br /&gt;
         -DBUILD_PERF_TESTS=OFF \&lt;br /&gt;
         \&lt;br /&gt;
         -DOPENCV_EXTRA_MODULES_PATH=../../opencv_contrib-4.0.1/modules \&lt;br /&gt;
         ..&lt;br /&gt;
&lt;br /&gt;
Compile OpenCV in the build folder:&lt;br /&gt;
&lt;br /&gt;
    $ make -j$(nproc --all)&lt;br /&gt;
&lt;br /&gt;
Install OpenCV in the build folder:&lt;br /&gt;
&lt;br /&gt;
    $ sudo make install&lt;br /&gt;
    $ sudo ldconfig&lt;br /&gt;
&lt;br /&gt;
=== Step 5: Test your building and installation ===&lt;br /&gt;
&lt;br /&gt;
To confirm that you have install ed OpenCV correctly , try this: &lt;br /&gt;
&lt;br /&gt;
    rock@linux:~$ python&lt;br /&gt;
    Python 2.7.15rc1 (default, Nov 12 2018, 14:31:15) &lt;br /&gt;
    [GCC 7.3.0] on linux2&lt;br /&gt;
    Type &amp;quot;help&amp;quot;, &amp;quot;copyright&amp;quot;, &amp;quot;credits&amp;quot; or &amp;quot;license&amp;quot; for more information.&lt;br /&gt;
    &amp;gt;&amp;gt;&amp;gt; import cv2&lt;br /&gt;
    &amp;gt;&amp;gt;&amp;gt; cv2.__version__&lt;br /&gt;
    '4.0.1'&lt;br /&gt;
    &amp;gt;&amp;gt;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Step6: Do the sample supported by OpenCV official ===&lt;br /&gt;
&lt;br /&gt;
    $ cd ~/opencv-4.0.1/samples/python&lt;br /&gt;
    $ python watershed.py&lt;br /&gt;
&lt;br /&gt;
Finally, if you don't need the files in opencv-4.0.1 or opencv_contrib-4.0.1. You can remove them:&lt;br /&gt;
&lt;br /&gt;
    $ cd ~&lt;br /&gt;
    $ rm -rf opencv-4.0.1 opencv_contrib-4.0.1 opencv_contrib.zip opencv.zip&lt;br /&gt;
&lt;br /&gt;
If you follow the code exactly, you will find it working just fine.&lt;br /&gt;
&lt;br /&gt;
== Compile OpenCV (4.6.0) ==&lt;br /&gt;
&lt;br /&gt;
=== Requirements ===&lt;br /&gt;
&lt;br /&gt;
RAM &amp;gt;= 2G&lt;br /&gt;
&lt;br /&gt;
Debian &amp;gt;= 10&lt;br /&gt;
&lt;br /&gt;
=== Download Source Code ===&lt;br /&gt;
&lt;br /&gt;
[https://opencv.org/releases/ Releases - OpenCV]&lt;br /&gt;
&lt;br /&gt;
=== Dependencies ===&lt;br /&gt;
&lt;br /&gt;
    apt install build-essential cmake pkg-config ccache git&lt;br /&gt;
    apt install python2 python3  python3-pip&lt;br /&gt;
    apt install qt5-default&lt;br /&gt;
    apt install libpng-dev libjpeg-dev&lt;br /&gt;
    apt install libeigen3-dev&lt;br /&gt;
    apt install ffmpeg libavcodec-dev libavformat-dev libswscale-dev libavresample-dev&lt;br /&gt;
    apt install libgstreamer1.0-dev libgstreamermm-1.0-dev&lt;br /&gt;
    apt install libgtk-3-dev libgtkglext1-dev libgtkglextmm-x11-1.2-dev&lt;br /&gt;
    &lt;br /&gt;
    pip3 install numpy&lt;br /&gt;
&lt;br /&gt;
Download `OpenBLAS` (Basic Linear Algebra Subprograms)&lt;br /&gt;
&lt;br /&gt;
[http://www.openblas.net/ OpenBLAS : An optimized BLAS library]()&lt;br /&gt;
&lt;br /&gt;
    # tar &amp;amp;&amp;amp; cd project dir &lt;br /&gt;
    make&lt;br /&gt;
    sudo make install&lt;br /&gt;
&lt;br /&gt;
* `qt5-default` may not be found in many apt source but there should be substitution&lt;br /&gt;
* `build-essential` `cmake` `pkg-config` `ccache` `git` essential to build&lt;br /&gt;
* `libpng-dev` `libjpeg-dev` image files surpport&lt;br /&gt;
* `libeigen3-dev` linear algebra surpport&lt;br /&gt;
* `ffmpeg` `libavcodec-dev` `libavformat-dev` `libswscale-dev` `libavresample-dev` video files surpport&lt;br /&gt;
* `libgstreamer1.0-dev` `libgstreamermm-1.0-dev` stream media surpport&lt;br /&gt;
* `libgtk-3-dev` `libgtkglext1-dev` `libgtkglextmm-x11-1.2-dev` GUI lib&lt;br /&gt;
&lt;br /&gt;
=== Build ===&lt;br /&gt;
&lt;br /&gt;
    # tar &amp;amp;&amp;amp; cd project dir&lt;br /&gt;
    mkdir -p build &amp;amp;&amp;amp; cd build&lt;br /&gt;
    # generate makefile&lt;br /&gt;
    cmake .. -DCMAKE_BUILD_TYPE=Release -DCMAKE_VERBOSE_MAKEFILE=ON -DCMAKE_INSTALL_PREFIX=/opt/opencv -DWITH_OPENGL=ON -DOPENCV_ENABLE_NONFREE=ON -DWITH_QT=ON -DBUILD_TESTS=OFF -DBUILD_PERF_TESTS=OFF -DOPENCV_GENERATE_PKGCONFIG=ON  -DWITH_1394=OFF -DBUILD_opencv_python2=OFF -DBUILD_opencv_python3=ON -DPYTHON3_LIBRARY=$(python3 -c &amp;quot;from distutils.sysconfig import get_config_var;from os.path import dirname,join ; print(join(dirname(get_config_var('LIBPC')),get_config_var('LDLIBRARY')))&amp;quot;) -DPYTHON3_NUMPY_INCLUDE_DIRS=$(python3 -c &amp;quot;import numpy; print(numpy.get_include())&amp;quot;) -DPYTHON3_PACKAGES_PATH=$(python3 -c &amp;quot;from distutils.sysconfig import get_python_lib; print(get_python_lib())&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
* `WITH_OPENGL`=ON : enables OpenGL hardware acceleration surpport&lt;br /&gt;
&lt;br /&gt;
* `CMAKE_BUILD_TYPE`=Release : or Debug if you want&lt;br /&gt;
&lt;br /&gt;
* `CMAKE_VERBOSE_MAKEFILE`=ON : easy to find errors&lt;br /&gt;
&lt;br /&gt;
* `OPENCV_ENABLE_NONFREE`=ON : Some algorithms included in the library are known to be protected by patents and are disabled by default&lt;br /&gt;
&lt;br /&gt;
* `CMAKE_INSTALL_PREFIX`=/opt/opencv： To install produced binaries root location&lt;br /&gt;
&lt;br /&gt;
* `WITH_QT`=ON : use Qt to draw a window&lt;br /&gt;
&lt;br /&gt;
* `BUILD_TESTS`=OFF，`BUILD_PERF_TESTS`=OFF：shorten the build time&lt;br /&gt;
&lt;br /&gt;
* `OPENCV_GENERATE_PKGCONFIG`=ON： enables  `.pc`  file generation along with standard CMake package&lt;br /&gt;
&lt;br /&gt;
* For more information, [https://docs.opencv.org/4.6.0/db/d05/tutorial_config_reference.html OpenCV: OpenCV configuration options reference]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
result output may look like below：&lt;br /&gt;
&lt;br /&gt;
    -- General configuration for OpenCV 4.6.0 =====================================&lt;br /&gt;
    --   Version control:               unknown&lt;br /&gt;
    --&lt;br /&gt;
    --   Platform:&lt;br /&gt;
    --     Timestamp:                   2022-07-13T07:48:24Z&lt;br /&gt;
    --     Host:                        Linux 4.4.154-116-rockchip-g86a614bc15b3 aarch64&lt;br /&gt;
    --     CMake:                       3.13.4&lt;br /&gt;
    --     CMake generator:             Unix Makefiles&lt;br /&gt;
    --     CMake build tool:            /usr/bin/make&lt;br /&gt;
    --     Configuration:               Release&lt;br /&gt;
    --&lt;br /&gt;
    --   CPU/HW features:&lt;br /&gt;
    --     Baseline:                    NEON FP16&lt;br /&gt;
    --&lt;br /&gt;
    --   C/C++:&lt;br /&gt;
    --     Built as dynamic libs?:      YES&lt;br /&gt;
    --     C++ standard:                11&lt;br /&gt;
    --     C++ Compiler:                /usr/bin/c++  (ver 8.3.0)&lt;br /&gt;
    --     C++ flags (Release):         -fsigned-char -W -Wall -Wreturn-type -Wnon-virtual-dtor -Waddress -Wsequence-point -Wformat -Wformat-security -Wmissing-declarations -Wundef -Winit-self -Wpointer-arith -Wshadow -Wsign-promo -Wuninitialized -Wsuggest-override -Wno-delete-non-virtual-dtor -Wno-comment -Wimplicit-fallthrough=3 -Wno-strict-overflow -fdiagnostics-show-option -pthread -fomit-frame-pointer -ffunction-sections -fdata-sections    -fvisibility=hidden -fvisibility-inlines-hidden -O3 -DNDEBUG  -DNDEBUG&lt;br /&gt;
    --     C++ flags (Debug):           -fsigned-char -W -Wall -Wreturn-type -Wnon-virtual-dtor -Waddress -Wsequence-point -Wformat -Wformat-security -Wmissing-declarations -Wundef -Winit-self -Wpointer-arith -Wshadow -Wsign-promo -Wuninitialized -Wsuggest-override -Wno-delete-non-virtual-dtor -Wno-comment -Wimplicit-fallthrough=3 -Wno-strict-overflow -fdiagnostics-show-option -pthread -fomit-frame-pointer -ffunction-sections -fdata-sections    -fvisibility=hidden -fvisibility-inlines-hidden -g  -O0 -DDEBUG -D_DEBUG&lt;br /&gt;
    --     C Compiler:                  /usr/bin/cc&lt;br /&gt;
    --     C flags (Release):           -fsigned-char -W -Wall -Wreturn-type -Waddress -Wsequence-point -Wformat -Wformat-security -Wmissing-declarations -Wmissing-prototypes -Wstrict-prototypes -Wundef -Winit-self -Wpointer-arith -Wshadow -Wuninitialized -Wno-comment -Wimplicit-fallthrough=3 -Wno-strict-overflow -fdiagnostics-show-option -pthread -fomit-frame-pointer -ffunction-sections -fdata-sections    -fvisibility=hidden -O3 -DNDEBUG  -DNDEBUG&lt;br /&gt;
    --     C flags (Debug):             -fsigned-char -W -Wall -Wreturn-type -Waddress -Wsequence-point -Wformat -Wformat-security -Wmissing-declarations -Wmissing-prototypes -Wstrict-prototypes -Wundef -Winit-self -Wpointer-arith -Wshadow -Wuninitialized -Wno-comment -Wimplicit-fallthrough=3 -Wno-strict-overflow -fdiagnostics-show-option -pthread -fomit-frame-pointer -ffunction-sections -fdata-sections    -fvisibility=hidden -g  -O0 -DDEBUG -D_DEBUG&lt;br /&gt;
    --     Linker flags (Release):      -Wl,--gc-sections -Wl,--as-needed -Wl,--no-undefined&lt;br /&gt;
    --     Linker flags (Debug):        -Wl,--gc-sections -Wl,--as-needed -Wl,--no-undefined&lt;br /&gt;
    --     ccache:                      YES&lt;br /&gt;
    --     Precompiled headers:         NO&lt;br /&gt;
    --     Extra dependencies:          dl m pthread rt&lt;br /&gt;
    --     3rdparty dependencies:&lt;br /&gt;
    --&lt;br /&gt;
    --   OpenCV modules:&lt;br /&gt;
    --     To be built:                 calib3d core dnn features2d flann gapi highgui imgcodecs imgproc ml objdetect photo stitching video videoio&lt;br /&gt;
    --     Disabled:                    world&lt;br /&gt;
    --     Disabled by dependency:      -&lt;br /&gt;
    --     Unavailable:                 java python2 python3 ts&lt;br /&gt;
    --     Applications:                apps&lt;br /&gt;
    --     Documentation:               NO&lt;br /&gt;
    --     Non-free algorithms:         YES&lt;br /&gt;
    --&lt;br /&gt;
    --   GUI:                           QT5&lt;br /&gt;
    --     QT:                          YES (ver 5.11.3 )&lt;br /&gt;
    --       QT OpenGL support:         YES (Qt5::OpenGL 5.11.3)&lt;br /&gt;
    --     GTK+:                        YES (ver 3.24.5)&lt;br /&gt;
    --       GThread :                  YES (ver 2.58.3)&lt;br /&gt;
    --       GtkGlExt:                  YES (ver 1.2.0)&lt;br /&gt;
    --     OpenGL support:              YES (/usr/lib/aarch64-linux-gnu/libGL.so /usr/lib/aarch64-linux-gnu/libGLU.so)&lt;br /&gt;
    --     VTK support:                 NO&lt;br /&gt;
    --&lt;br /&gt;
    --   Media I/O:&lt;br /&gt;
    --     ZLib:                        /usr/lib/aarch64-linux-gnu/libz.so (ver 1.2.11)&lt;br /&gt;
    --     JPEG:                        /usr/lib/aarch64-linux-gnu/libjpeg.so (ver 62)&lt;br /&gt;
    --     WEBP:                        build (ver encoder: 0x020f)&lt;br /&gt;
    --     PNG:                         /usr/lib/aarch64-linux-gnu/libpng.so (ver 1.6.36)&lt;br /&gt;
    --     TIFF:                        /usr/lib/aarch64-linux-gnu/libtiff.so (ver 42 / 4.1.0)&lt;br /&gt;
    --     JPEG 2000:                   build (ver 2.4.0)&lt;br /&gt;
    --     OpenEXR:                     /usr/lib/aarch64-linux-gnu/libImath.so /usr/lib/aarch64-linux-gnu/libIlmImf.so /usr/lib/aarch64-linux-gnu/libIex.so /usr/lib/aarch64-linux-gnu/libHalf.so /usr/lib/aarch64-linux-gnu/libIlmThread.so (ver 2_2)&lt;br /&gt;
    --     HDR:                         YES&lt;br /&gt;
    --     SUNRASTER:                   YES&lt;br /&gt;
    --     PXM:                         YES&lt;br /&gt;
    --     PFM:                         YES&lt;br /&gt;
    --&lt;br /&gt;
    --   Video I/O:&lt;br /&gt;
    --     FFMPEG:                      YES&lt;br /&gt;
    --       avcodec:                   YES (58.35.100)&lt;br /&gt;
    --       avformat:                  YES (58.20.100)&lt;br /&gt;
    --       avutil:                    YES (56.22.100)&lt;br /&gt;
    --       swscale:                   YES (5.3.100)&lt;br /&gt;
    --       avresample:                YES (4.0.0)&lt;br /&gt;
    --     GStreamer:                   YES (1.14.4)&lt;br /&gt;
    --     v4l/v4l2:                    YES (linux/videodev2.h)&lt;br /&gt;
    --&lt;br /&gt;
    --   Parallel framework:            pthreads&lt;br /&gt;
    --&lt;br /&gt;
    --   Trace:                         YES (with Intel ITT)&lt;br /&gt;
    --&lt;br /&gt;
    --   Other third-party libraries:&lt;br /&gt;
    --     Lapack:                      YES (/opt/OpenBLAS/lib/libopenblas.so)&lt;br /&gt;
    --     Eigen:                       YES (ver 3.3.7)&lt;br /&gt;
    --     Custom HAL:                  YES (carotene (ver 0.0.1))&lt;br /&gt;
    --     Protobuf:                    build (3.19.1)&lt;br /&gt;
    --&lt;br /&gt;
    --   OpenCL:                        YES (no extra features)&lt;br /&gt;
    --     Include path:                /home/rock/OpenCV/opencv-4.6.0/3rdparty/include/opencl/1.2&lt;br /&gt;
    --     Link libraries:              Dynamic load&lt;br /&gt;
    --&lt;br /&gt;
    --   Python 3:&lt;br /&gt;
    --     Interpreter:                 /usr/bin/python3 (ver 3.7.3)&lt;br /&gt;
    --     Libraries:                   NO&lt;br /&gt;
    --     numpy:                       /home/rock/.local/lib/python3.7/site-packages/numpy/core/include (ver 1.16.2)&lt;br /&gt;
    --     install path:                -&lt;br /&gt;
    --&lt;br /&gt;
    --   Python (for build):            /usr/bin/python2.7&lt;br /&gt;
    --&lt;br /&gt;
    --   Java:&lt;br /&gt;
    --     ant:                         NO&lt;br /&gt;
    --     JNI:                         NO&lt;br /&gt;
    --     Java wrappers:               NO&lt;br /&gt;
    --     Java tests:                  NO&lt;br /&gt;
    --&lt;br /&gt;
    --   Install to:                    /usr/local&lt;br /&gt;
    -- -----------------------------------------------------------------&lt;br /&gt;
    --&lt;br /&gt;
    -- Configuring done&lt;br /&gt;
    -- Generating done&lt;br /&gt;
    -- Build files have been written to: /home/rock/OpenCV/opencv-4.6.0/build&lt;br /&gt;
&lt;br /&gt;
check the output，install dependencies and reuse the full `cmake` command to make item to **YES** if it interests you &lt;br /&gt;
&lt;br /&gt;
eg. `OpenGL Support` and `OpenCL` should be **YES** if you want full hardware acceleration feature&lt;br /&gt;
&lt;br /&gt;
After the generation, make :&lt;br /&gt;
&lt;br /&gt;
    make all&lt;br /&gt;
    #or make all -j$(grep -c ^processor /proc/cpuinfo)&lt;br /&gt;
    make install&lt;br /&gt;
&lt;br /&gt;
== Troubleshooting ==&lt;br /&gt;
&lt;br /&gt;
* Post your issue at the forum: https://forum.radxa.com/c/dev&lt;/div&gt;</summary>
		<author><name>Rust</name></author>	</entry>

	</feed>