Tag Archives: OpenCV

[Solved] Opencv Compile Error: (CMake Error: The following variables are used in this project, but they are set to not)

report errors

On Jetson NX, an error occurred while compiling opencv4.1.1. The error is as follows

CMake Error: The following variables are used in this project, but they are set to NOTFOUND.
Please set them or make sure they are set and tested correctly in the CMake files:
CUDA_cublas_LIBRARY (ADVANCED)
    linked by target "opencv_cudev" in directory /opt/opencv4/opencv_contrib-4.1.1/modules/cudev
    linked by target "opencv_test_cudev" in directory /opt/opencv4/opencv_contrib-4.1.1/modules/cudev/test
    linked by target "opencv_test_core" in directory /opt/opencv4/opencv-4.1.1/modules/core
    linked by target "opencv_perf_core" in directory /opt/opencv4/opencv-4.1.1/modules/core
    linked by target "opencv_core" in directory /opt/opencv4/opencv-4.1.1/modules/core
    linked by target "opencv_test_cudaarithm" in directory /opt/opencv4/opencv_contrib-4.1.1/modules/cudaarithm
    linked by target "opencv_cudaarithm" in directory /opt/opencv4/opencv_contrib-4.1.1/modules/cudaarithm
    linked by target "opencv_cudaarithm" in directory /opt/opencv4/opencv_contrib-4.1.1/modules/cudaarithm
    linked by target "opencv_perf_cudaarithm" in directory /opt/opencv4/opencv_contrib-4.1.1/modules/cudaarithm
    linked by target "opencv_flann" in directory /opt/opencv4/opencv-4.1.1/modules/flann
    linked by target "opencv_test_flann" in directory /opt/opencv4/opencv-4.1.1/modules/flann
    linked by target "opencv_perf_imgproc" in directory /opt/opencv4/opencv-4.1.1/modules/imgproc
    linked by target "opencv_test_imgproc" in directory /opt/opencv4/opencv-4.1.1/modules/imgproc
    linked by target "opencv_imgproc" in directory /opt/opencv4/opencv-4.1.1/modules/imgproc
    linked by target "opencv_test_ml" in directory /opt/opencv4/opencv-4.1.1/modules/ml
    linked by target "opencv_ml" in directory /opt/opencv4/opencv-4.1.1/modules/ml
    linked by target "opencv_test_phase_unwrapping" in directory /opt/opencv4/opencv_contrib-4.1.1/modules/phase_unwrapping
    linked by target "opencv_phase_unwrapping" in directory /opt/opencv4/opencv_contrib-4.1.1/modules/phase_unwrapping
    linked by target "opencv_plot" in directory /opt/opencv4/opencv_contrib-4.1.1/modules/plot
    linked by target "opencv_test_quality" in directory /opt/opencv4/opencv_contrib-4.1.1/modules/quality
    linked by target "opencv_quality" in directory /opt/opencv4/opencv_contrib-4.1.1/modules/quality
    linked by target "opencv_test_reg" in directory /opt/opencv4/opencv_contrib-4.1.1/modules/reg
    linked by target "opencv_reg" in directory /opt/opencv4/opencv_contrib-4.1.1/modules/reg
    linked by target "opencv_perf_reg" in directory /opt/opencv4/opencv_contrib-4.1.1/modules/reg
    linked by target "opencv_surface_matching" in directory /opt/opencv4/opencv_contrib-4.1.1/modules/surface_matching
    linked by target "opencv_test_cudafilters" in directory /opt/opencv4/opencv_contrib-4.1.1/modules/cudafilters
    linked by target "opencv_perf_cudafilters" in directory /opt/opencv4/opencv_contrib-4.1.1/modules/cudafilters
    linked by target "opencv_cudafilters" in directory /opt/opencv4/opencv_contrib-4.1.1/modules/cudafilters
    linked by target "opencv_test_cudaimgproc" in directory /opt/opencv4/opencv_contrib-4.1.1/modules/cudaimgproc
    linked by target "opencv_cudaimgproc" in directory /opt/opencv4/opencv_contrib-4.1.1/modules/cudaimgproc
    linked by target "opencv_perf_cudaimgproc" in directory /opt/opencv4/opencv_contrib-4.1.1/modules/cudaimgproc
    linked by target "opencv_test_cudawarping" in directory /opt/opencv4/opencv_contrib-4.1.1/modules/cudawarping
    linked by target "opencv_cudawarping" in directory /opt/opencv4/opencv_contrib-4.1.1/modules/cudawarping
    linked by target "opencv_perf_cudawarping" in directory /opt/opencv4/opencv_contrib-4.1.1/modules/cudawarping
    linked by target "opencv_dnn" in directory /opt/opencv4/opencv-4.1.1/modules/dnn
    linked by target "opencv_perf_dnn" in directory /opt/opencv4/opencv-4.1.1/modules/dnn
    linked by target "opencv_test_dnn" in directory /opt/opencv4/opencv-4.1.1/modules/dnn
    linked by target "opencv_features2d" in directory /opt/opencv4/opencv-4.1.1/modules/features2d
    linked by target "opencv_perf_features2d" in directory /opt/opencv4/opencv-4.1.1/modules/features2d
    linked by target "opencv_test_features2d" in directory /opt/opencv4/opencv-4.1.1/modules/features2d
    linked by target "opencv_test_fuzzy" in directory /opt/opencv4/opencv_contrib-4.1.1/modules/fuzzy
    linked by target "opencv_fuzzy" in directory /opt/opencv4/opencv_contrib-4.1.1/modules/fuzzy
    linked by target "opencv_hfs" in directory /opt/opencv4/opencv_contrib-4.1.1/modules/hfs
    linked by target "opencv_test_img_hash" in directory /opt/opencv4/opencv_contrib-4.1.1/modules/img_hash
    linked by target "opencv_img_hash" in directory /opt/opencv4/opencv_contrib-4.1.1/modules/img_hash
    linked by target "opencv_imgcodecs" in directory /opt/opencv4/opencv-4.1.1/modules/imgcodecs
    linked by target "opencv_perf_imgcodecs" in directory /opt/opencv4/opencv-4.1.1/modules/imgcodecs
    linked by target "opencv_test_imgcodecs" in directory /opt/opencv4/opencv-4.1.1/modules/imgcodecs
    linked by target "opencv_test_line_descriptor" in directory /opt/opencv4/opencv_contrib-4.1.1/modules/line_descriptor
    linked by target "opencv_perf_line_descriptor" in directory /opt/opencv4/opencv_contrib-4.1.1/modules/line_descriptor
    linked by target "opencv_line_descriptor" in directory /opt/opencv4/opencv_contrib-4.1.1/modules/line_descriptor
    linked by target "opencv_test_photo" in directory /opt/opencv4/opencv-4.1.1/modules/photo
    linked by target "opencv_photo" in directory /opt/opencv4/opencv-4.1.1/modules/photo
    linked by target "opencv_perf_photo" in directory /opt/opencv4/opencv-4.1.1/modules/photo
    linked by target "opencv_test_saliency" in directory /opt/opencv4/opencv_contrib-4.1.1/modules/saliency
    linked by target "opencv_saliency" in directory /opt/opencv4/opencv_contrib-4.1.1/modules/saliency
    linked by target "opencv_test_videoio" in directory /opt/opencv4/opencv-4.1.1/modules/videoio
    linked by target "opencv_videoio" in directory /opt/opencv4/opencv-4.1.1/modules/videoio
    linked by target "opencv_perf_videoio" in directory /opt/opencv4/opencv-4.1.1/modules/videoio
    linked by target "opencv_test_xphoto" in directory /opt/opencv4/opencv_contrib-4.1.1/modules/xphoto
    linked by target "opencv_perf_xphoto" in directory /opt/opencv4/opencv_contrib-4.1.1/modules/xphoto
    linked by target "opencv_xphoto" in directory /opt/opencv4/opencv_contrib-4.1.1/modules/xphoto
    linked by target "opencv_calib3d" in directory /opt/opencv4/opencv-4.1.1/modules/calib3d
    linked by target "opencv_perf_calib3d" in directory /opt/opencv4/opencv-4.1.1/modules/calib3d
    linked by target "opencv_test_calib3d" in directory /opt/opencv4/opencv-4.1.1/modules/calib3d
    linked by target "opencv_test_cudacodec" in directory /opt/opencv4/opencv_contrib-4.1.1/modules/cudacodec
    linked by target "opencv_cudacodec" in directory /opt/opencv4/opencv_contrib-4.1.1/modules/cudacodec
    linked by target "opencv_perf_cudacodec" in directory /opt/opencv4/opencv_contrib-4.1.1/modules/cudacodec
    linked by target "opencv_test_cudafeatures2d" in directory /opt/opencv4/opencv_contrib-4.1.1/modules/cudafeatures2d
    linked by target "opencv_cudafeatures2d" in directory /opt/opencv4/opencv_contrib-4.1.1/modules/cudafeatures2d
    linked by target "opencv_perf_cudafeatures2d" in directory /opt/opencv4/opencv_contrib-4.1.1/modules/cudafeatures2d
    linked by target "opencv_test_cudastereo" in directory /opt/opencv4/opencv_contrib-4.1.1/modules/cudastereo
    linked by target "opencv_cudastereo" in directory /opt/opencv4/opencv_contrib-4.1.1/modules/cudastereo
    linked by target "opencv_perf_cudastereo" in directory /opt/opencv4/opencv_contrib-4.1.1/modules/cudastereo
    linked by target "opencv_test_highgui" in directory /opt/opencv4/opencv-4.1.1/modules/highgui
    linked by target "opencv_highgui" in directory /opt/opencv4/opencv-4.1.1/modules/highgui
    linked by target "opencv_test_objdetect" in directory /opt/opencv4/opencv-4.1.1/modules/objdetect
    linked by target "opencv_objdetect" in directory /opt/opencv4/opencv-4.1.1/modules/objdetect
    linked by target "opencv_perf_objdetect" in directory /opt/opencv4/opencv-4.1.1/modules/objdetect
    linked by target "opencv_rgbd" in directory /opt/opencv4/opencv_contrib-4.1.1/modules/rgbd
    linked by target "opencv_test_rgbd" in directory /opt/opencv4/opencv_contrib-4.1.1/modules/rgbd
    linked by target "opencv_test_shape" in directory /opt/opencv4/opencv_contrib-4.1.1/modules/shape
    linked by target "opencv_shape" in directory /opt/opencv4/opencv_contrib-4.1.1/modules/shape
    linked by target "opencv_test_structured_light" in directory /opt/opencv4/opencv_contrib-4.1.1/modules/structured_light
    linked by target "opencv_structured_light" in directory /opt/opencv4/opencv_contrib-4.1.1/modules/structured_light
    linked by target "opencv_text" in directory /opt/opencv4/opencv_contrib-4.1.1/modules/text
    linked by target "opencv_test_text" in directory /opt/opencv4/opencv_contrib-4.1.1/modules/text
    linked by target "opencv_ts" in directory /opt/opencv4/opencv-4.1.1/modules/ts
    linked by target "opencv_video" in directory /opt/opencv4/opencv-4.1.1/modules/video
    linked by target "opencv_perf_video" in directory /opt/opencv4/opencv-4.1.1/modules/video
    linked by target "opencv_test_video" in directory /opt/opencv4/opencv-4.1.1/modules/video
    linked by target "opencv_xfeatures2d" in directory /opt/opencv4/opencv_contrib-4.1.1/modules/xfeatures2d
    linked by target "opencv_perf_xfeatures2d" in directory /opt/opencv4/opencv_contrib-4.1.1/modules/xfeatures2d
    linked by target "opencv_test_xfeatures2d" in directory /opt/opencv4/opencv_contrib-4.1.1/modules/xfeatures2d
    linked by target "opencv_perf_ximgproc" in directory /opt/opencv4/opencv_contrib-4.1.1/modules/ximgproc
    linked by target "opencv_ximgproc" in directory /opt/opencv4/opencv_contrib-4.1.1/modules/ximgproc
    linked by target "opencv_test_ximgproc" in directory /opt/opencv4/opencv_contrib-4.1.1/modules/ximgproc
    linked by target "opencv_xobjdetect" in directory /opt/opencv4/opencv_contrib-4.1.1/modules/xobjdetect
    linked by target "opencv_test_aruco" in directory /opt/opencv4/opencv_contrib-4.1.1/modules/aruco
    linked by target "opencv_aruco" in directory /opt/opencv4/opencv_contrib-4.1.1/modules/aruco
    linked by target "opencv_bgsegm" in directory /opt/opencv4/opencv_contrib-4.1.1/modules/bgsegm
    linked by target "opencv_test_bgsegm" in directory /opt/opencv4/opencv_contrib-4.1.1/modules/bgsegm
    linked by target "opencv_test_bioinspired" in directory /opt/opencv4/opencv_contrib-4.1.1/modules/bioinspired
    linked by target "opencv_perf_bioinspired" in directory /opt/opencv4/opencv_contrib-4.1.1/modules/bioinspired
    linked by target "opencv_bioinspired" in directory /opt/opencv4/opencv_contrib-4.1.1/modules/bioinspired
    linked by target "opencv_ccalib" in directory /opt/opencv4/opencv_contrib-4.1.1/modules/ccalib
    linked by target "opencv_test_cudabgsegm" in directory /opt/opencv4/opencv_contrib-4.1.1/modules/cudabgsegm
    linked by target "opencv_cudabgsegm" in directory /opt/opencv4/opencv_contrib-4.1.1/modules/cudabgsegm
    linked by target "opencv_perf_cudabgsegm" in directory /opt/opencv4/opencv_contrib-4.1.1/modules/cudabgsegm
    linked by target "opencv_test_cudalegacy" in directory /opt/opencv4/opencv_contrib-4.1.1/modules/cudalegacy
    linked by target "opencv_cudalegacy" in directory /opt/opencv4/opencv_contrib-4.1.1/modules/cudalegacy
    linked by target "opencv_perf_cudalegacy" in directory /opt/opencv4/opencv_contrib-4.1.1/modules/cudalegacy
    linked by target "opencv_test_cudaobjdetect" in directory /opt/opencv4/opencv_contrib-4.1.1/modules/cudaobjdetect
    linked by target "opencv_perf_cudaobjdetect" in directory /opt/opencv4/opencv_contrib-4.1.1/modules/cudaobjdetect
    linked by target "opencv_cudaobjdetect" in directory /opt/opencv4/opencv_contrib-4.1.1/modules/cudaobjdetect
    linked by target "opencv_datasets" in directory /opt/opencv4/opencv_contrib-4.1.1/modules/datasets
    linked by target "opencv_dnn_objdetect" in directory /opt/opencv4/opencv_contrib-4.1.1/modules/dnn_objdetect
    linked by target "opencv_dpm" in directory /opt/opencv4/opencv_contrib-4.1.1/modules/dpm
    linked by target "opencv_test_face" in directory /opt/opencv4/opencv_contrib-4.1.1/modules/face
    linked by target "opencv_face" in directory /opt/opencv4/opencv_contrib-4.1.1/modules/face
    linked by target "opencv_test_optflow" in directory /opt/opencv4/opencv_contrib-4.1.1/modules/optflow
    linked by target "opencv_optflow" in directory /opt/opencv4/opencv_contrib-4.1.1/modules/optflow
    linked by target "opencv_perf_optflow" in directory /opt/opencv4/opencv_contrib-4.1.1/modules/optflow
    linked by target "opencv_stitching" in directory /opt/opencv4/opencv-4.1.1/modules/stitching
    linked by target "opencv_test_tracking" in directory /opt/opencv4/opencv_contrib-4.1.1/modules/tracking
    linked by target "opencv_tracking" in directory /opt/opencv4/opencv_contrib-4.1.1/modules/tracking
    linked by target "opencv_perf_tracking" in directory /opt/opencv4/opencv_contrib-4.1.1/modules/tracking
    linked by target "opencv_cudaoptflow" in directory /opt/opencv4/opencv_contrib-4.1.1/modules/cudaoptflow
    linked by target "opencv_perf_cudaoptflow" in directory /opt/opencv4/opencv_contrib-4.1.1/modules/cudaoptflow
    linked by target "opencv_test_cudaoptflow" in directory /opt/opencv4/opencv_contrib-4.1.1/modules/cudaoptflow
    linked by target "opencv_test_stereo" in directory /opt/opencv4/opencv_contrib-4.1.1/modules/stereo
    linked by target "opencv_stereo" in directory /opt/opencv4/opencv_contrib-4.1.1/modules/stereo
    linked by target "opencv_perf_stereo" in directory /opt/opencv4/opencv_contrib-4.1.1/modules/stereo
    linked by target "opencv_test_superres" in directory /opt/opencv4/opencv_contrib-4.1.1/modules/superres
    linked by target "opencv_superres" in directory /opt/opencv4/opencv_contrib-4.1.1/modules/superres
    linked by target "opencv_perf_superres" in directory /opt/opencv4/opencv_contrib-4.1.1/modules/superres
    linked by target "opencv_test_videostab" in directory /opt/opencv4/opencv_contrib-4.1.1/modules/videostab
    linked by target "opencv_videostab" in directory /opt/opencv4/opencv_contrib-4.1.1/modules/videostab
    linked by target "opencv_annotation" in directory /opt/opencv4/opencv-4.1.1/apps/annotation
    linked by target "opencv_visualisation" in directory /opt/opencv4/opencv-4.1.1/apps/visualisation
    linked by target "opencv_interactive-calibration" in directory /opt/opencv4/opencv-4.1.1/apps/interactive-calibration
    linked by target "opencv_version" in directory /opt/opencv4/opencv-4.1.1/apps/version

-- Configuring incomplete, errors occurred!
See also "/opt/opencv4/opencv-4.1.1/build/CMakeFiles/CMakeOutput.log".
See also "/opt/opencv4/opencv-4.1.1/build/CMakeFiles/CMakeError.log".

Solution

This is due to the lack of CUDA files.

Since I am CUDA 10.2, I choose cuda-toolkit-10-2 and the corresponding cuda-toolkit-x-x according to CUDA version. We install it directly, and the missing files will be downloaded and installed automatically,

sudo apt-get update
sudo apt-get install cuda-toolkit-10-2

After installation, recompile opnecv.

[Solved] opencv-python: recipe for target ‘modules/python3/CMakeFiles/opencv_python3.dir/all‘ failed

1. Question.
Python3.8 environment
When using pip3 to install opencv-python, there is a
[modules/python3/CMakeFiles/opencv_python3.dir/__/src2/cv2.cpp.o] Error 1
recipe for target ‘modules/python3/CMakeFiles/opencv_python3.dir/all’ failed

2. Cause.
When compiling in opencv-python, it cannot call python3.8 properly
3. Solution:
sudo apt-get install python3.8-dev
4. Successful installation

[Solved] OpenCv5 error: (-215:Assertion failed) !_descriptors.empty() in function ‘add‘

OpenCv5——error: (-215:Assertion failed) !_ Descriptors. Empty() in function ‘Add’ problem solved

    1. the path of Chinese pictures cannot be included in the path of pictures. Format: D:/qqfiles/Web/Xiaomi/images/1.JPG

 

    1. the path of Windows cannot be copied directly. On the contrary, there is no qualified dataset in the path

[Solved] cv2.error: (-215:Assertion failed) encoder->isFormatSupported(CV_8U) in function ‘imwrite_‘

OpenCV Error:
cv2.error: OpenCV(4.5.1) /private/var/folders/nz/vv4_9tw56nv9k3tkvyszvwg80000gn/T/pip-req-build-39p1qqfs/opencv/modules/imgcodecs/src/loadsave.cpp:694: error: (-215:Assertion failed) encoder->isFormatSupported(CV_8U) in function ‘imwrite_’

    1. First check if the path is wrong check the image type, for example, for exr suffix images, float64 can not be saved

Solution:

img = img.astype(np.float32)

[Solved] Python opencv imshow Error: Assertion failed (size.width>0 && size.height>0) in cv::imshow

The result of error reporting is believed to be the same:

There is no Chinese in the path, but this error occurs. It feels very outrageous.

I couldn’t find the problem. Later, I wrote all the paths of the picture and found it\ F is a string formatting code. People are stupid, so friends write all the paths and find the problem.

This is the modified path:

In fact, when you see the formatting code, python will display it in another color, so I thought of it here! The path cannot be found until it is written!

OpenCV4 Error: imread(argv[1], CV_LOAD_IMAGE_COLOR);

Imread (argv [1], cv_load_image_color) in opencv4 reports an error
view the imread() function description. The second parameter

enum ImreadModes {
       IMREAD_UNCHANGED            = -1, //!< If set, return the loaded image as is (with alpha channel, otherwise it gets cropped). Ignore EXIF orientation.
       IMREAD_GRAYSCALE            = 0,  //!< If set, always convert image to the single channel grayscale image (codec internal conversion).
       IMREAD_COLOR                = 1,  //!< If set, always convert image to the 3 channel BGR color image.
       IMREAD_ANYDEPTH             = 2,  //!< If set, return 16-bit/32-bit image when the input has the corresponding depth, otherwise convert it to 8-bit.
       IMREAD_ANYCOLOR             = 4,  //!< If set, the image is read in any possible color format.
       IMREAD_LOAD_GDAL            = 8,  //!< If set, use the gdal driver for loading the image.
       IMREAD_REDUCED_GRAYSCALE_2  = 16, //!< If set, always convert image to the single channel grayscale image and the image size reduced 1/2.
       IMREAD_REDUCED_COLOR_2      = 17, //!< If set, always convert image to the 3 channel BGR color image and the image size reduced 1/2.
       IMREAD_REDUCED_GRAYSCALE_4  = 32, //!< If set, always convert image to the single channel grayscale image and the image size reduced 1/4.
       IMREAD_REDUCED_COLOR_4      = 33, //!< If set, always convert image to the 3 channel BGR color image and the image size reduced 1/4.
       IMREAD_REDUCED_GRAYSCALE_8  = 64, //!< If set, always convert image to the single channel grayscale image and the image size reduced 1/8.
       IMREAD_REDUCED_COLOR_8      = 65, //!< If set, always convert image to the 3 channel BGR color image and the image size reduced 1/8.
       IMREAD_IGNORE_ORIENTATION   = 128 //!< If set, do not rotate the image according to EXIF's orientation flag.
     };

Change the second parameter to imread_Grayscale is enough.

The second method:
Add header file:

#include <opencv2/imgcodecs/legacy/constants_c.h>

At this time, the parameter CV_LOAD_IMAGE_Color will not report an error.

Error reporting of OpenCV and Darknet under Python 2.7

Error reporting of OpenCV and Darknet under Python 2.7

Python 2.7 is run by default during the whole ROS. I don’t know how to adjust it, so Yolo can’t run. The following error is reported

Gtk-ERROR **: GTK+ 2.x symbols detected. Using GTK+ 2.x and GTK+ 3 in the same process is not supported

The solution is to recompile opencv in the following order

cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local -D WITH_TBB=ON -D BUILD_NEW_PYTHON_SUPPORT=ON -D WITH_V4L=ON -D INSTALL_C_EXAMPLES=ON -D INSTALL_PYTHON_EXAMPLES=ON -D BUILD_EXAMPLES=ON -D WITH_QT=ON -D WITH_GTK=ON -D WITH_OPENGL=ON ..

sudo make install

Ubuntu 18.04 installation of opencv2.4.13 encountered fatal error. Possible solutions

Ubuntu 18.04 installation of opencv2.4.13 encountered fatal error. Possible solutions

During the installation process, some fatal errors may occur. I haven’t found a method for a long time. I happened to see an article that the installation can be successful according to the following methods. Although the errors reported are not consistent, they can be used in this way.

Ubuntu installation opencv step pit

1、 Installation process

apt-get update
apt-get install build-essential
apt-get install cmake git libgtk2.0-dev pkg-config libavcodec-dev libavformat-dev libswscale-dev
apt-get install python-dev python-numpy libtbb2 libtbb-dev libjpeg-dev libpng-dev libtiff-dev libjasper-dev libdc1394-22-dev
     
     
cd opencv-2.4.13
mkdir release
cd release/

cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local ..
make -j4
sudo make install

[UNK]ह_;;

CMake Error at cmake/OpenCVDetectCXXCompiler.cmake:85 (list):

CMake Error at cmake/OpenCVDetectCXXCompiler.cmake:85 (list):
  list GET given empty list
Call Stack (most recent call first):
  CMakeLists.txt:77 (include)


CMake Error at cmake/OpenCVDetectCXXCompiler.cmake:86 (list):
  list GET given empty list
Call Stack (most recent call first):
  CMakeLists.txt:77 (include)




CMake Error at cmake/OpenCVDetectCXXCompiler.cmake:89 (math):
  math cannot parse the expression: "*100 + ": syntax error, unexpected
  exp_TIMES, expecting exp_PLUS or exp_MINUS or exp_OPENPARENT or exp_NUMBER
  (1)
Call Stack (most recent call first):
  CMakeLists.txt:77 (include)

Solution
replace the contents of opencvdetectcxxcompiler.cmake with the following:

# ----------------------------------------------------------------------------
# Detect Microsoft compiler:
# ----------------------------------------------------------------------------
if(CMAKE_CL_64)
    set(MSVC64 1)
endif()

if(CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
  set(CMAKE_COMPILER_IS_GNUCXX 1)
  set(CMAKE_COMPILER_IS_CLANGCXX 1)
endif()
if(CMAKE_C_COMPILER_ID STREQUAL "Clang")
  set(CMAKE_COMPILER_IS_GNUCC 1)
  set(CMAKE_COMPILER_IS_CLANGCC 1)
endif()
if("${CMAKE_CXX_COMPILER};${CMAKE_C_COMPILER}" MATCHES "ccache")
  set(CMAKE_COMPILER_IS_CCACHE 1)
endif()

# ----------------------------------------------------------------------------
# Detect Intel ICC compiler -- for -fPIC in 3rdparty ( UNIX ONLY ):
#  see  include/opencv/cxtypes.h file for related   ICC & CV_ICC defines.
# NOTE: The system needs to determine if the '-fPIC' option needs to be added
#  for the 3rdparty static libs being compiled.  The CMakeLists.txt files
#  in 3rdparty use the CV_ICC definition being set here to determine if
#  the -fPIC flag should be used.
# ----------------------------------------------------------------------------
if(UNIX)
  if  (__ICL)
    set(CV_ICC   __ICL)
  elseif(__ICC)
    set(CV_ICC   __ICC)
  elseif(__ECL)
    set(CV_ICC   __ECL)
  elseif(__ECC)
    set(CV_ICC   __ECC)
  elseif(__INTEL_COMPILER)
    set(CV_ICC   __INTEL_COMPILER)
  elseif(CMAKE_C_COMPILER MATCHES "icc")
    set(CV_ICC   icc_matches_c_compiler)
  endif()
endif()

if(MSVC AND CMAKE_C_COMPILER MATCHES "icc|icl")
  set(CV_ICC   __INTEL_COMPILER_FOR_WINDOWS)
endif()

# ----------------------------------------------------------------------------
# Detect GNU version:
# ----------------------------------------------------------------------------
if(CMAKE_COMPILER_IS_CLANGCXX)
  set(CMAKE_GCC_REGEX_VERSION "4.2.1")
  set(CMAKE_OPENCV_GCC_VERSION_MAJOR 4)
  set(CMAKE_OPENCV_GCC_VERSION_MINOR 2)
  set(CMAKE_OPENCV_GCC_VERSION 42)
  set(CMAKE_OPENCV_GCC_VERSION_NUM 402)

  execute_process(COMMAND ${CMAKE_CXX_COMPILER} ${CMAKE_CXX_COMPILER_ARG1} -v
                  ERROR_VARIABLE CMAKE_OPENCV_CLANG_VERSION_FULL
                  ERROR_STRIP_TRAILING_WHITESPACE)

  string(REGEX MATCH "version.*$" CMAKE_OPENCV_CLANG_VERSION_FULL "${CMAKE_OPENCV_CLANG_VERSION_FULL}")
  string(REGEX MATCH "[0-9]+\\.[0-9]+" CMAKE_CLANG_REGEX_VERSION "${CMAKE_OPENCV_CLANG_VERSION_FULL}")

elseif(CMAKE_COMPILER_IS_GNUCXX)
  execute_process(COMMAND ${CMAKE_CXX_COMPILER} ${CMAKE_CXX_COMPILER_ARG1} -dumpversion
                OUTPUT_VARIABLE CMAKE_OPENCV_GCC_VERSION_FULL
                OUTPUT_STRIP_TRAILING_WHITESPACE)

  execute_process(COMMAND ${CMAKE_CXX_COMPILER} ${CMAKE_CXX_COMPILER_ARG1} -v
                ERROR_VARIABLE CMAKE_OPENCV_GCC_INFO_FULL
                OUTPUT_STRIP_TRAILING_WHITESPACE)

  # Typical output in CMAKE_OPENCV_GCC_VERSION_FULL: "c+//0 (whatever) 4.2.3 (...)"
  # Look for the version number, major.minor.build
  string(REGEX MATCH "[0-9]+\\.[0-9]+\\.[0-9]+" CMAKE_GCC_REGEX_VERSION "${CMAKE_OPENCV_GCC_VERSION_FULL}")
  if(NOT CMAKE_GCC_REGEX_VERSION)#major.minor
    string(REGEX MATCH "[0-9]+\\.[0-9]+" CMAKE_GCC_REGEX_VERSION "${CMAKE_OPENCV_GCC_VERSION_FULL}")
  endif()

  if(CMAKE_GCC_REGEX_VERSION)
    # Split the parts:
    string(REGEX MATCHALL "[0-9]+" CMAKE_OPENCV_GCC_VERSIONS "${CMAKE_GCC_REGEX_VERSION}")

    list(GET CMAKE_OPENCV_GCC_VERSIONS 0 CMAKE_OPENCV_GCC_VERSION_MAJOR)
    list(GET CMAKE_OPENCV_GCC_VERSIONS 1 CMAKE_OPENCV_GCC_VERSION_MINOR)
  else()#compiler returned just the major version number
    string(REGEX MATCH "[0-9]+" CMAKE_GCC_REGEX_VERSION "${CMAKE_OPENCV_GCC_VERSION_FULL}")
    if(NOT CMAKE_GCC_REGEX_VERSION)#compiler did not return anything reasonable
      set(CMAKE_GCC_REGEX_VERSION "0")
      message(WARNING "GCC version not detected!")
    endif()
    set(CMAKE_OPENCV_GCC_VERSION_MAJOR ${CMAKE_GCC_REGEX_VERSION})
    set(CMAKE_OPENCV_GCC_VERSION_MINOR 0)
  endif()

  set(CMAKE_OPENCV_GCC_VERSION ${CMAKE_OPENCV_GCC_VERSION_MAJOR}${CMAKE_OPENCV_GCC_VERSION_MINOR})
  math(EXPR CMAKE_OPENCV_GCC_VERSION_NUM "${CMAKE_OPENCV_GCC_VERSION_MAJOR}*100 + ${CMAKE_OPENCV_GCC_VERSION_MINOR}")
  message(STATUS "Detected version of GNU GCC: ${CMAKE_OPENCV_GCC_VERSION} (${CMAKE_OPENCV_GCC_VERSION_NUM})")

  if(WIN32)
    execute_process(COMMAND ${CMAKE_CXX_COMPILER} -dumpmachine
              OUTPUT_VARIABLE OPENCV_GCC_TARGET_MACHINE
              OUTPUT_STRIP_TRAILING_WHITESPACE)
    if(OPENCV_GCC_TARGET_MACHINE MATCHES "amd64|x86_64|AMD64")
      set(MINGW64 1)
    endif()
  endif()
endif()

if(MSVC64 OR MINGW64)
  set(X86_64 1)
elseif(MINGW OR (MSVC AND NOT CMAKE_CROSSCOMPILING))
  set(X86 1)
elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "amd64.*|x86_64.*|AMD64.*")
  set(X86_64 1)
elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "i686.*|i386.*|x86.*|amd64.*|AMD64.*")
  set(X86 1)
elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "^(arm.*|ARM.*)")
  set(ARM 1)
elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "^(aarch64.*|AARCH64.*)")
  set(AARCH64 1)
endif()

# Workaround for 32-bit operating systems on 64-bit x86_64 processor
if(X86_64 AND CMAKE_SIZEOF_VOID_P EQUAL 4 AND NOT FORCE_X86_64)
  message(STATUS "sizeof(void) = 4 on x86/x86_64 processor. Assume 32-bit compilation mode (X86=1)")
  unset(X86_64)
  set(X86 1)
endif()

# Similar code exists in OpenCVConfig.cmake
if(NOT DEFINED OpenCV_STATIC)
  # look for global setting
  if(NOT DEFINED BUILD_SHARED_LIBS OR BUILD_SHARED_LIBS)
    set(OpenCV_STATIC OFF)
  else()
    set(OpenCV_STATIC ON)
  endif()
endif()

if(MSVC)
  if(CMAKE_CL_64)
    set(OpenCV_ARCH x64)
  elseif((CMAKE_GENERATOR MATCHES "ARM") OR ("${arch_hint}" STREQUAL "ARM") OR (CMAKE_VS_EFFECTIVE_PLATFORMS MATCHES "ARM|arm"))
    # see Modules/CmakeGenericSystem.cmake
    set(OpenCV_ARCH ARM)
  else()
    set(OpenCV_ARCH x86)
  endif()
  if(MSVC_VERSION EQUAL 1400)
    set(OpenCV_RUNTIME vc8)
  elseif(MSVC_VERSION EQUAL 1500)
    set(OpenCV_RUNTIME vc9)
  elseif(MSVC_VERSION EQUAL 1600)
    set(OpenCV_RUNTIME vc10)
  elseif(MSVC_VERSION EQUAL 1700)
    set(OpenCV_RUNTIME vc11)
  elseif(MSVC_VERSION EQUAL 1800)
    set(OpenCV_RUNTIME vc12)
  elseif(MSVC_VERSION EQUAL 1900)
    set(OpenCV_RUNTIME vc14)
  elseif(MSVC_VERSION EQUAL 1910)
    set(OpenCV_RUNTIME vc15)
  endif()
elseif(MINGW)
  set(OpenCV_RUNTIME mingw)

  if(MINGW64)
    set(OpenCV_ARCH x64)
  else()
    set(OpenCV_ARCH x86)
  endif()
endif()

/Usr/include/C + +/7/cstdlib: 75:15: fatal error: stdlib. H: there is no such file or directory
solution: change the cmake instruction

cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local .. -D ENABLE_PRECOMPILED_HEADERS=OFF ..

Raspberry pie compilation and installation opencv error: fatal error: bootdesc_bgm.i: No such file or directory

~/opencv_contrib/modules/xfeatures2d/src/boostdesc.cpp:673:20: fatal error: boostdesc_bgm.i: No such file or directory

Solution:
Check the /home/pi/Downloads/opencv-3.4.0/build/CMakeDownloadLog.txt log file, search for boostdesc_bgm.i keyword in the log file CMakeDownloadLog.txt, and find that the download of this file has failed.
A total of 11 files were found to be missing as follows:
boostdesc_bgm.i
boostdesc_bgm_bi.i
boostdesc_bgm_hd.i
boostdesc_lbgm.i
boostdesc_binboost_064.i
boostdesc_binboost_128.i
boostdesc_binboost_256.i
vgg_generated_120.i
vgg_generated_64.i
vgg_generated_80.i
vgg_generated_48.i

Download and upzip. put them in the path of /home/pi/Downloads/opencv_contrib3.4.0/modules/xfeatures2d/src/ is OK.
Then re-compile:

make clean
make

[Solved] OpenCV ERROR: The minSdk version should not be declared in the android manifest file

ERROR: The minSdk version should not be declared in the android manifest file. You can move the version from the manifest to the defaultConfig in the build.gradle file.
Remove minSdkVersion and sync project
Affected Modules: openCVLibrary3415


Solution: Just comment it out and run it again!!!
ERROR: The minSdk version should not be declared in the android manifest file. You can move the version from the manifest to the defaultConfig in the build.gradle file.
Remove minSdkVersion and sync project
Affected Modules: openCVLibrary3415