yuxiaoyuan0406 / JetsonInstruction

An instraction for coding and other shit on Jetson nano
3 stars 0 forks source link

Instructions for installing OpenCV for conda enviorment #1

Closed yuxiaoyuan0406 closed 3 years ago

yuxiaoyuan0406 commented 3 years ago

Instructions in README does not install OpenCV for your conda envioement.
May cause some problems.
For example, when install OpenCV via conda-forge and using the CSI camera in python, gives this.

>>> window = cv2.namedWindow("CSI")
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
cv2.error: OpenCV(4.5.2) ../modules/highgui/src/window.cpp:662: error: (-2:Unspecified error) The function is not implemented. Rebuild the library with Windows, GTK+ 2.x or Cocoa support. If you are on Ubuntu or Debian, install libgtk2.0-dev and pkg-config, then re-run cmake or configure script in function 'cvNamedWindow'

When try to use test script, cannot open camera.

$ python simple_camera.py 
nvarguscamerasrc ! video/x-raw(memory:NVMM), width=(int)1280, height=(int)720, format=(string)NV12, framerate=(fraction)60/1 ! nvvidconv flip-method=0 ! video/x-raw, width=(int)1280, height=(int)720, format=(string)BGRx ! videoconvert ! video/x-raw, format=(string)BGR ! appsink
Unable to open camera

Try to fix this by build OpenCV from source for conda.
Ref: https://jayrobwilliams.com/files/html/OpenCV_Install.html

Using cmake command:
Note that my opencv dir is under /home/vip

# set which env to install
CONDA_ENV=~/archiconda3/envs/cv4
# run cmake
cmake -D CMAKE_BUILD_TYPE=RELEASE \
-D CMAKE_INSTALL_PREFIX=/usr \
-D OPENCV_EXTRA_MODULES_PATH=~/opencv_contrib/modules \
-D EIGEN_INCLUDE_PATH=/usr/include/eigen3 \
-D PYTHON_DEFAULT_EXECUTABLE=${CONDA_ENV}/bin/python \
-D PYTHON3_LIBRARY=${CONDA_ENV}/lib/python3.6m.dylib \
-D PYTHON3_INCLUDE_DIR=${CONDA_ENV}/include/python3.6m \
-D PYTHON3_EXECUTABLE=${CONDA_ENV}/bin/python \
-D PYTHON3_PACKAGES_PATH=${CONDA_ENV}/lib/python3.6/site-packages \
-D BUILD_opencv_python2=OFF \
-D BUILD_opencv_python3=ON \
-D WITH_OPENCL=OFF \
-D WITH_CUDA=ON \
-D CUDA_ARCH_BIN=5.3 \
-D CUDA_ARCH_PTX="" \
-D WITH_CUDNN=ON \
-D WITH_CUBLAS=ON \
-D ENABLE_FAST_MATH=ON \
-D CUDA_FAST_MATH=ON \
-D OPENCV_DNN_CUDA=ON \
-D ENABLE_NEON=ON \
-D WITH_QT=OFF \
-D WITH_OPENMP=ON \
-D WITH_OPENGL=ON \
-D BUILD_TIFF=ON \
-D WITH_FFMPEG=ON \
-D WITH_GSTREAMER=ON \
-D WITH_TBB=ON \
-D BUILD_TBB=ON \
-D BUILD_TESTS=OFF \
-D WITH_EIGEN=ON \
-D WITH_V4L=ON \
-D WITH_LIBV4L=ON \
-D OPENCV_ENABLE_NONFREE=ON \
-D INSTALL_C_EXAMPLES=OFF \
-D INSTALL_PYTHON_EXAMPLES=ON \
-D OPENCV_GENERATE_PKGCONFIG=ON \
-D BUILD_EXAMPLES=ON ..
yuxiaoyuan0406 commented 3 years ago

Run that give this

-- General configuration for OpenCV 4.5.2 =====================================
--   Version control:               unknown
-- 
--   Extra modules:
--     Location (extra):            /home/vip/opencv_contrib/modules
--     Version control (extra):     unknown
-- 
--   Platform:
--     Timestamp:                   2021-07-06T11:51:40Z
--     Host:                        Linux 4.9.201-tegra aarch64
--     CMake:                       3.10.2
--     CMake generator:             Unix Makefiles
--     CMake build tool:            /usr/bin/make
--     Configuration:               RELEASE
-- 
--   CPU/HW features:
--     Baseline:                    NEON FP16
--       required:                  NEON
-- 
--   C/C++:
--     Built as dynamic libs?:      YES
--     C++ standard:                11
--     C++ Compiler:                /usr/bin/c++  (ver 7.5.0)
--     C++ flags (Release):         -fsigned-char -ffast-math -W -Wall -Werror=return-type -Werror=non-virtual-dtor -Werror=address -Werror=sequence-point -Wformat -Werror=format-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 -fopenmp -O3 -DNDEBUG  -DNDEBUG
--     C++ flags (Debug):           -fsigned-char -ffast-math -W -Wall -Werror=return-type -Werror=non-virtual-dtor -Werror=address -Werror=sequence-point -Wformat -Werror=format-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 -fopenmp -g  -O0 -DDEBUG -D_DEBUG
--     C Compiler:                  /usr/bin/cc
--     C flags (Release):           -fsigned-char -ffast-math -W -Wall -Werror=return-type -Werror=address -Werror=sequence-point -Wformat -Werror=format-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 -fopenmp -O3 -DNDEBUG  -DNDEBUG
--     C flags (Debug):             -fsigned-char -ffast-math -W -Wall -Werror=return-type -Werror=address -Werror=sequence-point -Wformat -Werror=format-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 -fopenmp -g  -O0 -DDEBUG -D_DEBUG
--     Linker flags (Release):      -Wl,--gc-sections -Wl,--as-needed  
--     Linker flags (Debug):        -Wl,--gc-sections -Wl,--as-needed  
--     ccache:                      NO
--     Precompiled headers:         NO
--     Extra dependencies:          m pthread cudart_static dl rt nppc nppial nppicc nppicom nppidei nppif nppig nppim nppist nppisu nppitc npps cublas cudnn cufft -L/usr/local/cuda/lib64 -L/usr/lib/aarch64-linux-gnu
--     3rdparty dependencies:
-- 
--   OpenCV modules:
--     To be built:                 alphamat aruco bgsegm bioinspired calib3d ccalib core cudaarithm cudabgsegm cudacodec cudafeatures2d cudafilters cudaimgproc cudalegacy cudaobjdetect cudaoptflow cudastereo cudawarping cudev datasets dnn dnn_objdetect dnn_superres dpm face features2d flann freetype fuzzy gapi hdf hfs highgui img_hash imgcodecs imgproc intensity_transform line_descriptor mcc ml objdetect optflow phase_unwrapping photo plot python3 quality rapid reg rgbd saliency sfm shape stereo stitching structured_light superres surface_matching text tracking ts video videoio videostab wechat_qrcode xfeatures2d ximgproc xobjdetect xphoto
--     Disabled:                    python2 world
--     Disabled by dependency:      -
--     Unavailable:                 cnn_3dobj cvv java julia matlab ovis viz
--     Applications:                perf_tests examples apps
--     Documentation:               NO
--     Non-free algorithms:         YES
-- 
--   GUI: 
--     GTK+:                        YES (ver 3.22.30)
--       GThread :                  YES (ver 2.56.4)
--       GtkGlExt:                  NO
--     OpenGL support:              NO
--     VTK support:                 NO
-- 
--   Media I/O: 
--     ZLib:                        /usr/lib/aarch64-linux-gnu/libz.so (ver 1.2.11)
--     JPEG:                        /usr/lib/aarch64-linux-gnu/libjpeg.so (ver 80)
--     WEBP:                        build (ver encoder: 0x020f)
--     PNG:                         /usr/lib/aarch64-linux-gnu/libpng.so (ver 1.6.34)
--     TIFF:                        build (ver 42 - 4.2.0)
--     JPEG 2000:                   build (ver 2.4.0)
--     OpenEXR:                     build (ver 2.3.0)
--     HDR:                         YES
--     SUNRASTER:                   YES
--     PXM:                         YES
--     PFM:                         YES
-- 
--   Video I/O:
--     DC1394:                      YES (2.2.5)
--     FFMPEG:                      YES
--       avcodec:                   YES (57.107.100)
--       avformat:                  YES (57.83.100)
--       avutil:                    YES (55.78.100)
--       swscale:                   YES (4.8.100)
--       avresample:                YES (3.7.0)
--     GStreamer:                   YES (1.14.5)
--     v4l/v4l2:                    YES (linux/videodev2.h)
-- 
--   Parallel framework:            TBB (ver 2020.2 interface 11102)
-- 
--   Trace:                         YES (with Intel ITT)
-- 
--   Other third-party libraries:
--     Lapack:                      NO
--     Eigen:                       YES (ver 3.3.4)
--     Custom HAL:                  YES (carotene (ver 0.0.1))
--     Protobuf:                    build (3.5.1)
-- 
--   NVIDIA CUDA:                   YES (ver 10.2, CUFFT CUBLAS FAST_MATH)
--     NVIDIA GPU arch:             53
--     NVIDIA PTX archs:
-- 
--   cuDNN:                         YES (ver 8.0.0)
-- 
--   Python 3:
--     Interpreter:                 /home/vip/archiconda3/envs/cv4/bin/python (ver 3.6.7)
--     Libraries:                   /home/vip/archiconda3/envs/cv4/lib/python3.6m.dylib (ver 3.6.7)
--     numpy:                       /home/vip/archiconda3/envs/cv4/lib/python3.6/site-packages/numpy/core/include (ver 1.19.4)
--     install path:                /home/vip/archiconda3/envs/cv4/lib/python3.6/site-packages/cv2/python-3.6
-- 
--   Python (for build):            /home/vip/archiconda3/envs/cv4/bin/python
-- 
--   Java:                          
--     ant:                         NO
--     JNI:                         NO
--     Java wrappers:               NO
--     Java tests:                  NO
-- 
--   Install to:                    /usr
-- -----------------------------------------------------------------
-- 
-- Configuring done
-- Generating done
-- Build files have been written to: /home/vip/opencv/build
yuxiaoyuan0406 commented 3 years ago

Use this script to make and install

#!/bin/bash
cd ~/opencv
cd build

CONDA_ENV=~/archiconda3/envs/cv4

FREE_MEM="$(free -m | awk '/^Swap/ {print $2}')"
# Use "-j 4" only swap space is larger than 5.5GB
if [[ "FREE_MEM" -gt "5500" ]]; then
  NO_JOB=4
else
  NO_JOB=1
fi
make -j ${NO_JOB} 

sudo rm -r /usr/include/opencv4/opencv2
sudo make install
cd ${CONDA_ENV}/lib/python3.6
ln -s /usr/local/python/cv2 cv2

After installation, run the test script again. Everything works perfectly.

yuxiaoyuan0406 commented 3 years ago

Note: I cannot see opencv when I run conda list

$ conda list
# packages in environment at /home/vip/archiconda3/envs/cv4:
#
# Name                    Version                   Build  Channel
_openmp_mutex             4.5                       1_gnu    conda-forge
ca-certificates           2018.03.07                    0    c4aarch64
certifi                   2021.5.30        py36h704843e_0    conda-forge
ld_impl_linux-aarch64     2.36.1               h02ad14f_0    conda-forge
libblas                   3.8.0               17_openblas    conda-forge
libcblas                  3.8.0               17_openblas    conda-forge
libffi                    3.2.1                h71b71f5_5    c4aarch64
libgcc-ng                 9.3.0               he1ea209_19    conda-forge
libgfortran-ng            7.3.0                h6bc79d0_0    c4aarch64
libgomp                   9.3.0               he1ea209_19    conda-forge
liblapack                 3.8.0               17_openblas    conda-forge
libopenblas               0.3.10          pthreads_hb3c22a3_4    conda-forge
libstdcxx-ng              9.3.0               h1ed1776_19    conda-forge
ncurses                   6.2                  h7fd3ca4_4    conda-forge
numpy                     1.19.4           py36hdc1b780_2    conda-forge
openssl                   1.0.2p               h7b6447c_0    c4aarch64
pip                       21.1.3             pyhd8ed1ab_0    conda-forge
python                    3.6.7             hd21baee_1002    conda-forge
python_abi                3.6                     2_cp36m    conda-forge
readline                  7.0                  h7ce4240_5    c4aarch64
setuptools                49.6.0           py36h704843e_3    conda-forge
sqlite                    3.28.0               hb527c52_0    conda-forge
tk                        8.6.10               ha99a2a3_1    conda-forge
wheel                     0.36.2             pyhd3deb0d_0    conda-forge
xz                        5.2.5                h6dd45c4_1    conda-forge
zlib                      1.2.11               h7b6447c_2    c4aarch64

But using python to import opencv works fine.

$ python -c 'import cv2;print(cv2.__version__)'
4.5.2
yuxiaoyuan0406 commented 3 years ago

Some warning

When I rebuild OpenCV for another env, this occured.

-- General configuration for OpenCV 4.5.2 =====================================
--   Version control:               unknown
--
--   Extra modules:
--     Location (extra):            /home/vip/opencv_contrib/modules
--     Version control (extra):     unknown
--
--   Platform:
--     Timestamp:                   2021-08-23T08:15:30Z
--     Host:                        Linux 4.9.201-tegra aarch64
--     CMake:                       3.10.2
--     CMake generator:             Unix Makefiles
--     CMake build tool:            /usr/bin/make
--     Configuration:               RELEASE
--
--   CPU/HW features:
--     Baseline:                    NEON FP16
--       required:                  NEON
--
--   C/C++:
--     Built as dynamic libs?:      YES
--     C++ standard:                11
--     C++ Compiler:                /usr/bin/c++  (ver 7.5.0)
--     C++ flags (Release):         -fsigned-char -ffast-math -W -Wall -Werror=return-type -Werror=non-virtual-dtor -Werror=address -Werror=sequence-point -Wformat -Werror=format-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 -fopenmp -O3 -DNDEBUG  -DNDEBUG
--     C++ flags (Debug):           -fsigned-char -ffast-math -W -Wall -Werror=return-type -Werror=non-virtual-dtor -Werror=address -Werror=sequence-point -Wformat -Werror=format-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 -fopenmp -g  -O0 -DDEBUG -D_DEBUG
--     C Compiler:                  /usr/bin/cc
--     C flags (Release):           -fsigned-char -ffast-math -W -Wall -Werror=return-type -Werror=address -Werror=sequence-point -Wformat -Werror=format-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 -fopenmp -O3 -DNDEBUG  -DNDEBUG
--     C flags (Debug):             -fsigned-char -ffast-math -W -Wall -Werror=return-type -Werror=address -Werror=sequence-point -Wformat -Werror=format-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 -fopenmp -g  -O0 -DDEBUG -D_DEBUG
--     Linker flags (Release):      -Wl,--gc-sections -Wl,--as-needed
--     Linker flags (Debug):        -Wl,--gc-sections -Wl,--as-needed
--     ccache:                      NO
--     Precompiled headers:         NO
--     Extra dependencies:          m pthread cudart_static -lpthread dl rt nppc nppial nppicc nppicom nppidei nppif nppig nppim nppist nppisu nppitc npps cublas cudnn cufft -L/usr/local/cuda/lib64 -L/usr/lib/aarch64-linux-gnu
--     3rdparty dependencies:
--
--   OpenCV modules:
--     To be built:                 alphamat aruco bgsegm bioinspired calib3d ccalib core cudaarithm cudabgsegm cudacodec cudafeatures2d cudafilters cudaimgproc cudalegacy cudaobjdetect cudaoptflow cudastereo cudawarping cudev datasets dnn dnn_objdetect dnn_superres dpm face features2d flann freetype fuzzy gapi hdf hfs highgui img_hash imgcodecs imgproc intensity_transform line_descriptor mcc ml objdetect optflow phase_unwrapping photo plot python3 quality rapid reg rgbd saliency sfm shape stereo stitching structured_light superres surface_matching text tracking ts video videoio videostab wechat_qrcode xfeatures2d ximgproc xobjdetect xphoto
--     Disabled:                    python2 world
--     Disabled by dependency:      -
--     Unavailable:                 cnn_3dobj cvv java julia matlab ovis viz
--     Applications:                perf_tests examples apps
--     Documentation:               NO
--     Non-free algorithms:         YES
--
--   GUI:
--     GTK+:                        YES (ver 3.22.30)
--       GThread :                  YES (ver 2.56.4)
--       GtkGlExt:                  NO
--     OpenGL support:              NO
--     VTK support:                 NO
--
--   Media I/O:
--     ZLib:                        /usr/lib/aarch64-linux-gnu/libz.so (ver 1.2.11)
--     JPEG:                        /usr/lib/aarch64-linux-gnu/libjpeg.so (ver 80)
--     WEBP:                        build (ver encoder: 0x020f)
--     PNG:                         /usr/lib/aarch64-linux-gnu/libpng.so (ver 1.6.34)
--     TIFF:                        build (ver 42 - 4.2.0)
--     JPEG 2000:                   OpenJPEG (ver 2.4.0)
--     OpenEXR:                     build (ver 2.3.0)
--     HDR:                         YES
--     SUNRASTER:                   YES
--     PXM:                         YES
--     PFM:                         YES
--
--   Video I/O:
--     DC1394:                      YES (2.2.5)
--     FFMPEG:                      YES
--       avcodec:                   YES (57.107.100)
--       avformat:                  YES (57.83.100)
--       avutil:                    YES (55.78.100)
--       swscale:                   YES (4.8.100)
--       avresample:                YES (3.7.0)
--     GStreamer:                   YES (1.14.5)
--     v4l/v4l2:                    YES (linux/videodev2.h)
--
--   Parallel framework:            TBB (ver 2020.2 interface 11102)
--
--   Trace:                         YES (with Intel ITT)
--
--   Other third-party libraries:
--     Lapack:                      NO
--     Eigen:                       YES (ver 3.3.4)
--     Custom HAL:                  YES (carotene (ver 0.0.1))
--     Protobuf:                    build (3.5.1)
--
--   NVIDIA CUDA:                   YES (ver 10.2, CUFFT CUBLAS FAST_MATH)
--     NVIDIA GPU arch:             53
--     NVIDIA PTX archs:
--
--   cuDNN:                         YES (ver 8.0.0)
--
--   Python 3:
--     Interpreter:                 /home/vip/archiconda3/envs/torch/bin/python (ver 3.6.7)
--     Libraries:                   /home/vip/archiconda3/envs/torch/lib/python3.6m.dylib (ver 3.6.7)
--     numpy:                       /home/vip/archiconda3/envs/torch/lib/python3.6/site-packages/numpy/core/include (ver 1.19.4)
--     install path:                /home/vip/archiconda3/envs/torch/lib/python3.6/site-packages/cv2/python-3.6
--
--   Python (for build):            /home/vip/archiconda3/envs/torch/bin/python
--
--   Java:
--     ant:                         NO
--     JNI:                         NO
--     Java wrappers:               NO
--     Java tests:                  NO
--
--   Install to:                    /usr
-- -----------------------------------------------------------------
--
-- Configuring done
WARNING: Target "tbb" has EXCLUDE_FROM_ALL set and will not be built by default but an install rule has been provided for it.  CMake does not define behavior for this case.
CMake Warning at cmake/OpenCVUtils.cmake:1545 (add_library):
  Cannot generate a safe runtime search path for target opencv_imgcodecs
  because files in some directories may conflict with libraries in implicit
  directories:

    runtime library [libpng16.so.16] in /usr/lib/aarch64-linux-gnu may be hidden by files in:
      /home/vip/archiconda3/envs/torch/lib
    runtime library [libz.so.1] in /usr/lib/aarch64-linux-gnu may be hidden by files in:
      /home/vip/archiconda3/envs/torch/lib

  Some of these libraries may not be found correctly.
Call Stack (most recent call first):
  cmake/OpenCVModule.cmake:933 (ocv_add_library)
  cmake/OpenCVModule.cmake:852 (_ocv_create_module)
  modules/imgcodecs/CMakeLists.txt:148 (ocv_create_module)

CMake Warning at cmake/OpenCVUtils.cmake:1545 (add_library):
  Cannot generate a safe runtime search path for target opencv_videoio
  because files in some directories may conflict with libraries in implicit
  directories:

    runtime library [libgobject-2.0.so.0] in /usr/lib/aarch64-linux-gnu may be hidden by files in:
      /home/vip/archiconda3/envs/torch/lib
    runtime library [libglib-2.0.so.0] in /usr/lib/aarch64-linux-gnu may be hidden by files in:
      /home/vip/archiconda3/envs/torch/lib

  Some of these libraries may not be found correctly.
Call Stack (most recent call first):
  cmake/OpenCVModule.cmake:933 (ocv_add_library)
  cmake/OpenCVModule.cmake:852 (_ocv_create_module)
  modules/videoio/CMakeLists.txt:212 (ocv_create_module)

CMake Warning at cmake/OpenCVUtils.cmake:1534 (add_executable):
  Cannot generate a safe runtime search path for target opencv_perf_videoio
  because files in some directories may conflict with libraries in implicit
  directories:

    runtime library [libgobject-2.0.so.0] in /usr/lib/aarch64-linux-gnu may be hidden by files in:
      /home/vip/archiconda3/envs/torch/lib
    runtime library [libglib-2.0.so.0] in /usr/lib/aarch64-linux-gnu may be hidden by files in:
      /home/vip/archiconda3/envs/torch/lib

  Some of these libraries may not be found correctly.
Call Stack (most recent call first):
  cmake/OpenCVModule.cmake:1176 (ocv_add_executable)
  modules/videoio/CMakeLists.txt:214 (ocv_add_perf_tests)

CMake Warning at cmake/OpenCVUtils.cmake:1545 (add_library):
  Cannot generate a safe runtime search path for target opencv_highgui
  because files in some directories may conflict with libraries in implicit
  directories:

    runtime library [libcairo-gobject.so.2] in /usr/lib/aarch64-linux-gnu may be hidden by files in:
      /home/vip/archiconda3/envs/torch/lib
    runtime library [libcairo.so.2] in /usr/lib/aarch64-linux-gnu may be hidden by files in:
      /home/vip/archiconda3/envs/torch/lib
    runtime library [libgio-2.0.so.0] in /usr/lib/aarch64-linux-gnu may be hidden by files in:
      /home/vip/archiconda3/envs/torch/lib
    runtime library [libgobject-2.0.so.0] in /usr/lib/aarch64-linux-gnu may be hidden by files in:
      /home/vip/archiconda3/envs/torch/lib
    runtime library [libglib-2.0.so.0] in /usr/lib/aarch64-linux-gnu may be hidden by files in:
      /home/vip/archiconda3/envs/torch/lib
    runtime library [libgthread-2.0.so.0] in /usr/lib/aarch64-linux-gnu may be hidden by files in:
      /home/vip/archiconda3/envs/torch/lib

  Some of these libraries may not be found correctly.
Call Stack (most recent call first):
  cmake/OpenCVModule.cmake:933 (ocv_add_library)
  cmake/OpenCVModule.cmake:852 (_ocv_create_module)
  modules/highgui/CMakeLists.txt:147 (ocv_create_module)

-- Generating done
-- Build files have been written to: /home/vip/opencv/build

I ignored the warning at the first time as any programmer would do.
But when I run make, it failed.

$ make -j4
...
[ 41%] Built target example_text_textdetection_swt
[ 42%] Built target example_text_cropped_word_recognition
[ 42%] Built target example_text_end_to_end_recognition
[ 42%] Built target example_text_character_recognition
[ 42%] Built target example_text_textdetection
[ 42%] Built target example_text_textbox_demo
[ 42%] Built target example_text_segmented_word_recognition
[ 42%] Built target example_text_webcam_demo
[ 42%] Built target example_text_dictnet_demo
[ 42%] Linking CXX executable ../../bin/opencv_perf_videoio
/home/vip/archiconda3/envs/torch/lib/libgio-2.0.so.0: undefined reference to `g_spawn_async_with_fds'
/home/vip/archiconda3/envs/torch/lib/libgio-2.0.so.0: undefined reference to `g_utf8_validate_len'
/home/vip/archiconda3/envs/torch/lib/libgio-2.0.so.0: undefined reference to `g_source_set_dispose_function'
/home/vip/archiconda3/envs/torch/lib/libgio-2.0.so.0: undefined reference to `g_ref_count_dec'
/home/vip/archiconda3/envs/torch/lib/libgio-2.0.so.0: undefined reference to `g_unix_get_passwd_entry'
/home/vip/archiconda3/envs/torch/lib/libgio-2.0.so.0: undefined reference to `g_uri_join'
/home/vip/archiconda3/envs/torch/lib/libgio-2.0.so.0: undefined reference to `g_uri_split_with_user'
/home/vip/archiconda3/envs/torch/lib/libgio-2.0.so.0: undefined reference to `g_canonicalize_filename'
/home/vip/archiconda3/envs/torch/lib/libgio-2.0.so.0: undefined reference to `g_uri_split_network'
/home/vip/archiconda3/envs/torch/lib/libgio-2.0.so.0: undefined reference to `g_uri_is_valid'
/home/vip/archiconda3/envs/torch/lib/libgio-2.0.so.0: undefined reference to `g_file_set_contents_full'
/home/vip/archiconda3/envs/torch/lib/libgio-2.0.so.0: undefined reference to `g_atomic_ref_count_init'
/home/vip/archiconda3/envs/torch/lib/libgio-2.0.so.0: undefined reference to `g_atomic_ref_count_dec'
/home/vip/archiconda3/envs/torch/lib/libgio-2.0.so.0: undefined reference to `g_ref_count_init'
/home/vip/archiconda3/envs/torch/lib/libgio-2.0.so.0: undefined reference to `g_atomic_ref_count_inc'
/home/vip/archiconda3/envs/torch/lib/libgio-2.0.so.0: undefined reference to `g_ref_count_inc'
collect2: error: ld returned 1 exit status
modules/videoio/CMakeFiles/opencv_perf_videoio.dir/build.make:178: recipe for target 'bin/opencv_perf_videoio' failed
make[2]: *** [bin/opencv_perf_videoio] Error 1
CMakeFiles/Makefile2:7850: recipe for target 'modules/videoio/CMakeFiles/opencv_perf_videoio.dir/all' failed
make[1]: *** [modules/videoio/CMakeFiles/opencv_perf_videoio.dir/all] Error 2
Makefile:162: recipe for target 'all' failed
make: *** [all] Error 2

This error was warned by cmake.
System libs was hidden by conda env.
Block conda from PATH to fix this.ref

$ echo $PATH
/home/vip/archiconda3/envs/torch/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin
$ export PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin"

Then remove CMakeCache.txt and re-cmake.
No warnings now.