Tag Archives: OpenCV

[Solved] ERROR: Unable to find the development tool `cc`

ERROR: Unable to find the development tool cc in your path; please make sure that you have the package ‘gcc’ installed. If gcc is installed on your system, then please check that cc is in your PATH.

Solution:
You probably don’t have build-essential installed, and NVIDIA needs the compiler bits to actually install and handle the driver. Run sudo apt install build-essential and install the GCC compiler and such via that package.

[Solved] OpenCV Error: AttributeError: module ‘cv2‘ has no attribute ‘data‘

Opencv error: attributeerror: module ‘CV2’ has no attribute ‘data’
the following error will appear when running the face detection code:

face_detector = cv.CascadeClassifier(cv.data.haarcascades + "haarcascade_frontalface_alt2.xml")
eye_detector = cv.CascadeClassifier(cv.data.haarcascades + "haarcascade_eye.xml")
smile_detector = cv.CascadeClassifier(cv.data.haarcascades + "haarcascade_smile.xml")


AttributeError: module 'cv2' has no attribute 'data'

Solution: uninstall your existing opencv Python and install my version of OpenCV

1. Open Anaconda prompt and enter

pip uninstall opencv-python

2. Re input

pip install opencv-python -i http://mirrors.aliyun.com/pypi/simple --trusted-host mirrors.aliyun.com

Note: when uninstalling opencv, select y, and don’t worry about red explosion

[Solved] Ubuntu 18.04 Install opencv3.2.0 and opencv_contrib Error

After configuring the ROS melody environment for Jetson nano B01 and planning to install the turtle BOT, you need to install opencv3.2.0 and add GPU acceleration support to the compilation of OpenCV. There is a problem when installing opencv from the source code:

CMake Error at cmake/OpenCVModule.cmake:286 (add_subdirectory):
  The binary directory

    /home/fdse/tools/opencv-3.2.0/release/modules/cudaarithm/.cudaarithm

  is already used to build a source directory.  It cannot be used to build
  source directory

    /home/fdse/tools/opencv_contrib/modules/cudaarithm

  Specify a unique binary directory name.
Call Stack (most recent call first):
  modules/CMakeLists.txt:7 (ocv_glob_modules)


CMake Error at cmake/OpenCVModule.cmake:286 (add_subdirectory):
  The binary directory

    /home/fdse/tools/opencv-3.2.0/release/modules/cudabgsegm/.cudabgsegm

  is already used to build a source directory.  It cannot be used to build
  source directory

    /home/fdse/tools/opencv_contrib/modules/cudabgsegm

  Specify a unique binary directory name.
Call Stack (most recent call first):
  modules/CMakeLists.txt:7 (ocv_glob_modules)


CMake Error at cmake/OpenCVModule.cmake:286 (add_subdirectory):
  The binary directory

    /home/fdse/tools/opencv-3.2.0/release/modules/cudacodec/.cudacodec

  is already used to build a source directory.  It cannot be used to build
  source directory

    /home/fdse/tools/opencv_contrib/modules/cudacodec

  Specify a unique binary directory name.
Call Stack (most recent call first):
  modules/CMakeLists.txt:7 (ocv_glob_modules)


CMake Error at cmake/OpenCVModule.cmake:286 (add_subdirectory):
  The binary directory

    /home/fdse/tools/opencv-3.2.0/release/modules/cudafeatures2d/.cudafeatures2d

  is already used to build a source directory.  It cannot be used to build
  source directory

    /home/fdse/tools/opencv_contrib/modules/cudafeatures2d

  Specify a unique binary directory name.
Call Stack (most recent call first):
  modules/CMakeLists.txt:7 (ocv_glob_modules)

The reason is that the version of opencv_conteib is inconsistent with that of opencv. When cloning opencv, add -b 3.2.0. Similarly, when cloning opencv_contrib, clone version 3.2.0 and add -b 3.2.0, then no error will be reported.

How to Solve Opencv Error: CPP: 1557 error

Opencv Error:
ret2, th2 = cv.threshold(img, 0, 255, cv.THRESH_BINARY + cv.THRESH_OTSU)
cv2.error: OpenCV(4.5.3) C:\Users\runneradmin\AppData\Local\Temp\pip-req-build-c2l3r8zm\opencv\modules\imgproc\src\thresh.cpp:1557: error: (-2:Unspecified error) in function ‘double __cdecl cv::threshold(const class cv::_InputArray &,const class cv::_OutputArray &,double,double,int)’

THRESH_OTSU mode:
‘src_type == CV_8UC1 || src_type == CV_16UC1’
where
‘src_type’ is 16 (CV_8UC3)

Original Codes:

img = cv.imread('noisy.jpg')  
  
# Fixed threshold method
ret1, th1 = cv.threshold(img, 105, 255, cv.THRESH_BINARY)
# Otsu threshold method
ret2, th2 = cv.threshold(img, 0, 255, cv.THRESH_BINARY + cv.THRESH_OTSU)
# Perform Gaussian filtering first, and then use Otsu threshold method  
blur = cv.GaussianBlur(img, (5, 5), 0)  
ret3, th3 = cv.threshold(blur, 105, 255, cv.THRESH_BINARY)  
ret4, th4 = cv.threshold(blur, 0, 255, cv.THRESH_BINARY + cv.THRESH_OTSU) 

Problem analysis

The CV2.Threshold() function inputs graphics in the form of single channel, while the image in the above code is input in the form of color three channels, resulting in an error.

Solution:

Convert the color image into a single channel gray image for input.

img = cv.imread('noisy.jpg',0)

Rerun the program

Run successfully

[Solved] Pyinstaller package opencv error: ImportError: OpenCV loader: missing configuration file: [‘config.py’]. Check OpenCV installation.

Before packaging, it was OK. After upgrading pyinstaller and opencv, an error will be reported. I looked up a circle of information and found the answer on GitHub.

ImportError: OpenCV loader: missing configuration file: [‘config.py’]. Check OpenCV installation.

In

Pyinstaller 4.6
opencv Python 4.5.3.58
encountered a problem

 

Solution:

Solution 1

Reduce the opencv Python version to 4.5.3.56. This small version iteration actually changed something, resulting in packaging failure.

Solution 2

PS: I tried this method several times and failed

import cv2
print(cv2.__file__)

Execute these two sentences to find the path where CV2 is located:

D:\anaconda\64\lib\site-packages\cv2\cv2.cp38-win_ AMD64. PYD
this is my path
when packaging:

pyinstaller -F -w --key '12345678' --clean main.py --paths="D:\anaconda\64\lib\site-packages\cv2"

Remove the last file name from the path and keep the whole folder.

I suggest using the second scheme, because it is not constrained by the version, and this problem can be solved in a similar way in other packages in the future.

Import CV2 & Numpy report red Warning and Error [How to Solve]

Usually the red report after import is because there is no module, use pip install cv2 to download the module, it will appear:
Could not find a version that satisfies the requirement cv2 (from versions: )
No matching distribution found for cv2
You are using pip version 18.1, however version 19.0.2 is available.
You should consider upgrading via the ‘python -m pip install –upgrade pip’ command.

At this point you need to type python -m pip install –upgrade pip
When the installation is complete, run this line “pip install opencv-python”, this line is to install the cv2 module, wait until the download is complete
To install the numpy module, you only need to pip install numpy
The summary is as follows:

python -m pip install --upgrade pip
pip install opencv-python
pip install numpy

Raspberry pie startup self startup opencv program script and error analysis

1. Make test script

First, we need to make a script to test whether the self startup is effective.

pi@raspberry :~ $ nano /home/pi/start.sh

The contents of start.sh are as follows:

/usr/bin/python3 /home/pi/GeometryOperations.py

Here, you must pay attention to the use of absolute paths, otherwise there is a probability that the load will fail.

Then add an execution file to the script file

pi@raspberry :~ $ chmod 777 start.sh

Test the script function

pi@raspberry :~ $ ./start.sh

If you observe that the program is running normally, you can continue to the next step

2. Add self start

Modify rc.local file

pi@raspberry :~ $ sudo nano /etc/rc.local

Find exit 0 in the text. The code added before will be executed at startup. Add a line of code before exit 0:

su pi -c “exec /home/pi/start.sh &”

CTRL + O to save, Ctrl + X to exit and restart.

pi@raspberry :~ $ sudo reboot

After restart, the program can run.

3.DEBUG

If the raspberry pie does not respond after restart, you can check the status of RC local through systemctl

pi@raspberry :~ $ sudo systemctl status rc-local

After you go in, you can see the status of each step after you start up and check where the error will be reported.

4. Possible error reports

Process:454 ExecStart=/etc/rc.local start (code=exited,status=1/FAILURE)

This error is probably due to the script file
if you just start, you must write the file path as an absolute path, otherwise an error will be reported.

error: (-2:Unspecified error) Can’t initialize GTK backend in function ‘cvInitSystem’

This error will be reported if the self startup program contains code with window operation such as OpenCV

The reason is caused by the following sentence

su pi -c “exec /home/pi/start.sh &”

If your command needs to run for a long time (such as an endless loop) or cannot exit after running, you must ensure that the “& amp;” symbol is added at the end of the command to make the command run in its background

If the code contains window interface operations similar to the following

cv2.namedWindow(‘Cap’)
cv2.imshow(‘Cap’, frame)

It will conflict with the background operation, so that the back end of GTK cannot be initialized and an error will be caused
the solution is to delete all the operations related to the interface and window, and the program can run well!

cv2.error: OpenCV(4.5.1) C:\Users\appveyor\AppData\Local\Temp\1\pip-req-buil

catalogue

The following operations are carried out under the windows environment.  

one   Change single slash to double slash

2. The modified path is in English

3. Delete CV2. Imshow ()


When I use CV2 to save pictures to a new price asking folder, I report an error CV2. Error: opencv (4.5.1) C: \ users \ appveyor \ appdata \ local \ temp \ 1 \ PIP req build

The solution is as follows:

The following operations are carried out under the windows environment.  

one   Change single slash to double slash

Some people on the Internet say that the path reading error is caused by the number in the path. Correction method: change the single slash in the path into double slash.

For example:

cv2.imwrite(save_dir + '\\' + img_name, img)

However, the same error is reported later, so read the following comments for 2 operations:  

2. The modified path is in English

I reported a similar error here because Chinese appears in the quoted picture path. If you change the picture path to an all English path, there will be no problem.   

for i in ori_imgs_single:
    img_name = i.split('\\')[-1]
    img = cv2.imread(i)
    cv2.imwrite(save_dir + '\\' + img_name, img)
print('save OK!')

OK:

3. Delete CV2. Imshow ()

Maybe there is something wrong with my environment. If you still report an error, try deleting CV2. Imshow (). If I delete it, it will be OK:  

 

  OK:

 

Opencv453 drawing rectangle function error reporting solution

# draw gt
cv2.rectangle(img, (gt[0], gt[1]), (gt[2], gt[3]), (0,255,0), 1)

The following error occurred while running:

The rectangle function in opencv453 is incompatible with floating-point data  

terms of settlement:

It is OK to convert the two coordinate data types in the rectangle function to int

cv2.rectangle(img, (int(gt[0]), int(gt[1])), (int(gt[2]), int(gt[3])),(0,255,0), 1)

[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