Tag Archives: OpenCV

Error configuration process, project files may be invalid

Error configuration process, project files may be invalid

1. Problem description

OpenCV3.2.0 + OpenCV_contrib +VS2015: Error in CMAKE compilation

2. Cause of the problem
Most of the reasons for this problem are because the version of opencv_contrib does not match the version of opencv_contrib, so this kind of problem occurs, download the corresponding version of opencv_contrib to solve the problem.
3. Solutions
Here is a GitHub site where you can download the various versions of OpenCV_Contrib for personal testing.
https://github.com/opencv/opencv_contrib/tree/master

Finally, the screenshot of the compiled version with the new version is as follows:

4. The appendix
In addition, provide a good tutorial, the website:
https://blog.csdn.net/huachao1001/article/details/76595549

Opencv: 0xc0000005: an access conflict occurred while reading location 0x0000000010

In the use of OpenCV hog + SVM for pedestrian detection reference when the big ideas and programs: https://blog.csdn.net/u011263315/article/details/41447545, is very much, but will be treated as positive and negative samples is good, the file path is still have after modification for their error as shown in the figure below:

Basically the error location is shown here:

For a long time, I did not know why it was wrong, and I consulted a lot of information but failed to solve it, which troubled me for a whole week. Finally, I solved the problem with the help of another big man, as follows:
At first, if we trace the alpha parameter, we find that it is not identified. Basically, there is no value assigned at all. At first, we thought that the problem was integrated from the ml.hpp file, and neither the existing.xml file nor the self-trained one had the value. Then the following a program about generating classifier and test files are commented out, to step through the part of sample training, found from the file name where you are to become very strange, basically to imread position could not read from the file image, then we do not have the right to read from the file to wrong image, according to this train of thought to make themselves the way in which to read file, specific procedures reference of the below: https://www.cnblogs.com/zhuwei1988/p/5746637.html, after the application is running through the test can also be trained classifier.
My environment is VS2013+OpenCV2.4.9, if other users have other errors, it is probably a version problem…
The programmer patiently read through the error line by line until he found the reason for the error… Record the process in order to avoid later have similar mistakes do not know how to debug……

Opencv: the application can’t start normally

Compiling environment:
Operating system: Win8.1 64-bit
IDE Platform: Visual Studio 2013 Ultimate

Today on opening the.exe file generated by VS: The application cannot start properly 0xc000007b solution
It seems that the configured x86 OpenCV file may not run under x64 system (I am not sure whether this is the reason, because I have been doing this before without any problems).
Finally, it is possible to run the generated executable with the following method:
(1) Change x86 in the previously configured OpenCV path to x64
Debug:
1. Project ->; Configure properties ->; Conventional – & gt; Use of MFC: Use MFC in static libraries.
2. Project ->; Configure properties ->; C/C++-> Code generation ->; Runtime: Select multithreaded debugging (/MT).
3. When compiling, select Release, x64
Release:

1. Project ->; Configure properties ->; Conventional – & gt; Use of MFC: Use MFC in static libraries
2. Project ->; Configure properties ->; C/C++-> Code generation ->; Runtime: Select multi-threaded debugging (/ MTD).
3. When compiling, select Debug and Win32

Modulenotfounderror: no module named ‘CV2’ – (version problem)

Ubuntu Running OpenCV project tip: ModuleNotFoundError: No Module Named ‘Cv2’
Haha, that was the problem when it was first installed. Just throw me up.
1. Reason: the versions are inconsistent
The problem is that when installing OpencV-Python, the detailed version number is appended, which makes it different from the Python environment. In addition, there will be other problems, I can’t remember exactly.
2. Solutions

    first use the instruction: PIP install opencv-python to execute once, if the .py file or so to see the next one; Just do not append the version number when installing OpencV-Python.

Opencv error: insufficient memory

Recently, I have been using the function Haartraining provided by Opencv to train the classifier. The previous picture used was 20*20, which could train the classifier. Later, when it was changed to 80*86, the error was reported, which was due to insufficient memory. Here is a screenshot of the error report:

So, I looked it up on the Internet and found a solution: change the debugging platform from 32 to 64, because there seems to be a problem with 32 bits, no matter how big your actual memory is, it only works around 2 or 3 gs. Another solution is to make your training pictures smaller.

Python synthesizes multiple pictures into one video

Reference python + opencv to save the picture as video – 2016 update,
code example is:

def imgs2video(imgs_dir, save_name):
    fps = 24
    fourcc = cv2.VideoWriter_fourcc(*'MJPG')
    video_writer = cv2.VideoWriter(save_name, fourcc, fps, (1920, 1080))
    # no glob, need number-index increasing
    imgs = glob.glob(os.path.join(imgs_dir, '*.png'))

    for i in range(len(imgs)):
        imgname = os.path.join(imgs_dir, 'core-{:02d}.png'.format(i))
        frame = cv2.imread(imgname)
        video_writer.write(frame)

    video_writer.release()

Reference python opencv VideoWriter: opencv:frame size mismatched video size,

    1. Error
"mMovieWriter.status: 3. Error: Cannot Save"

Because I already have a file with the same name, I can’t overwrite it, so just delete it and convert it.

      1. Warning:
OpenCV: Frame size does not match video size.
      1. warning:
WARNING: -finishWriting should not be called on the main thread.

error(-215) !empty() in function detectMultiScale solution

error(-215) ! Empty () In function detectMultiScale solution
Errors like this can occur when building a cascading classifier using OpenCV Python

error: (-215:Assertion failed) !empty() in function 'detectMultiScale'

Any discussion about this question on Stack Overflow at https://stackoverflow.com/questions/30508922/error-215-empty-in-function-detectmultiscale
The common perception is that XML or other files are missing or incorrectly routed.
The correct path would look like this:

cascade_fn = args.get('--cascade', "../../data/haarcascades/haarcascade_frontalface_alt.xml")
nested_fn  = args.get('--nested-cascade', "../../data/haarcascades/haarcascade_eye.xml")

cam = create_capture(video_src, fallback='synth:bg=../data/lena.jpg:noise=0.05')

There are also some references to this answer:
http://answers.opencv.org/question/52340/opencv-error-assertion-failed-empty-in-detectmultiscale/

About the solution of ERROR: Failed building wheel for dlib

Error reporting in some dependency libraries with dlib and Face_recognition installed

(face_recognition) C:\Users\FlynnLi>pip install dlib -i http://pypi.douban.com/simple --trusted-host pypi.douban.com
Looking in indexes: http://pypi.douban.com/simple
Collecting dlib
  Downloading http://pypi.doubanio.com/packages/63/92/05c3b98636661cb80d190a5a777dd94effcc14c0f6893222e5ca81e74fbc/dlib-19.19.0.tar.gz (3.2 MB)
     |████████████████████████████████| 3.2 MB 2.2 MB/s
Building wheels for collected packages: dlib
  Building wheel for dlib (setup.py) ... error
  ERROR: Command errored out with exit status 1:
   command: 'D:\Python\Virtual\face_recognition\Scripts\python.exe' -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'C:\\Users\\FlynnLi\\AppData\\Local\\Temp\\pip-install-ywrf5o_o\\dlib\\setup.py'"'"'; __file__='"'"'C:\\Users\\FlynnLi\\AppData\\Local\\Temp\\pip-install-ywrf5o_o\\dlib\\setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' bdist_wheel -d 'C:\Users\FlynnLi\AppData\Local\Temp\pip-wheel-4oqer9mq'
       cwd: C:\Users\FlynnLi\AppData\Local\Temp\pip-install-ywrf5o_o\dlib\
  Complete output (55 lines):
  running bdist_wheel
  running build
  running build_py
  package init file 'dlib\__init__.py' not found (or not a regular file)
  running build_ext
  Building extension for Python 3.7.5 (tags/v3.7.5:5c02a39a0b, Oct 15 2019, 00:11:34) [MSC v.1916 64 bit (AMD64)]
  Invoking CMake setup: 'cmake C:\Users\FlynnLi\AppData\Local\Temp\pip-install-ywrf5o_o\dlib\tools\python -DCMAKE_LIBRARY_OUTPUT_DIRECTORY=C:\Users\FlynnLi\AppData\Local\Temp\pip-install-ywrf5o_o\dlib\build\lib.win-amd64-3.7 -DPYTHON_EXECUTABLE=D:\Python\Virtual\face_recognition\Scripts\python.exe -DCMAKE_LIBRARY_OUTPUT_DIRECTORY_RELEASE=C:\Users\FlynnLi\AppData\Local\Temp\pip-install-ywrf5o_o\dlib\build\lib.win-amd64-3.7 -A x64'
  -- Building for: NMake Makefiles
  CMake Error at CMakeLists.txt:3 (project):
    Generator

      NMake Makefiles

    does not support platform specification, but platform

      x64

    was specified.


  CMake Error: CMAKE_C_COMPILER not set, after EnableLanguage
  CMake Error: CMAKE_CXX_COMPILER not set, after EnableLanguage
  -- Configuring incomplete, errors occurred!
  See also "C:/Users/FlynnLi/AppData/Local/Temp/pip-install-ywrf5o_o/dlib/build/temp.win-amd64-3.7/Release/CMakeFiles/CMakeOutput.log".
  Traceback (most recent call last):
    File "<string>", line 1, in <module>
    File "C:\Users\FlynnLi\AppData\Local\Temp\pip-install-ywrf5o_o\dlib\setup.py", line 261, in <module>
      'Topic :: Software Development',
    File "D:\Python\Virtual\face_recognition\lib\site-packages\setuptools\__init__.py", line 144, in setup
      return distutils.core.setup(**attrs)
    File "d:\python\lib\distutils\core.py", line 148, in setup
      dist.run_commands()
    File "d:\python\lib\distutils\dist.py", line 966, in run_commands
      self.run_command(cmd)
    File "d:\python\lib\distutils\dist.py", line 985, in run_command
      cmd_obj.run()
    File "D:\Python\Virtual\face_recognition\lib\site-packages\wheel\bdist_wheel.py", line 223, in run
      self.run_command('build')
    File "d:\python\lib\distutils\cmd.py", line 313, in run_command
      self.distribution.run_command(command)
    File "d:\python\lib\distutils\dist.py", line 985, in run_command
      cmd_obj.run()
    File "d:\python\lib\distutils\command\build.py", line 135, in run
      self.run_command(cmd_name)
    File "d:\python\lib\distutils\cmd.py", line 313, in run_command
      self.distribution.run_command(command)
    File "d:\python\lib\distutils\dist.py", line 985, in run_command
      cmd_obj.run()
    File "C:\Users\FlynnLi\AppData\Local\Temp\pip-install-ywrf5o_o\dlib\setup.py", line 135, in run
      self.build_extension(ext)
    File "C:\Users\FlynnLi\AppData\Local\Temp\pip-install-ywrf5o_o\dlib\setup.py", line 172, in build_extension
      subprocess.check_call(cmake_setup, cwd=build_folder)
    File "d:\python\lib\subprocess.py", line 363, in check_call
      raise CalledProcessError(retcode, cmd)
  subprocess.CalledProcessError: Command '['cmake', 'C:\\Users\\FlynnLi\\AppData\\Local\\Temp\\pip-install-ywrf5o_o\\dlib\\tools\\python', '-DCMAKE_LIBRARY_OUTPUT_DIRECTORY=C:\\Users\\FlynnLi\\AppData\\Local\\Temp\\pip-install-ywrf5o_o\\dlib\\build\\lib.win-amd64-3.7', '-DPYTHON_EXECUTABLE=D:\\Python\\Virtual\\face_recognition\\Scripts\\python.exe', '-DCMAKE_LIBRARY_OUTPUT_DIRECTORY_RELEASE=C:\\Users\\FlynnLi\\AppData\\Local\\Temp\\pip-install-ywrf5o_o\\dlib\\build\\lib.win-amd64-3.7', '-A', 'x64']' returned non-zero exit status 1.
  ----------------------------------------
  ERROR: Failed building wheel for dlib
  Running setup.py clean for dlib
Failed to build dlib
Installing collected packages: dlib
    Running setup.py install for dlib ... error
    ERROR: Command errored out with exit status 1:
     command: 'D:\Python\Virtual\face_recognition\Scripts\python.exe' -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'C:\\Users\\FlynnLi\\AppData\\Local\\Temp\\pip-install-ywrf5o_o\\dlib\\setup.py'"'"'; __file__='"'"'C:\\Users\\FlynnLi\\AppData\\Local\\Temp\\pip-install-ywrf5o_o\\dlib\\setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' install --record 'C:\Users\FlynnLi\AppData\Local\Temp\pip-record-vngiiz8h\install-record.txt' --single-version-externally-managed --compile --install-headers 'D:\Python\Virtual\face_recognition\include\site\python3.7\dlib'
         cwd: C:\Users\FlynnLi\AppData\Local\Temp\pip-install-ywrf5o_o\dlib\
    Complete output (57 lines):
    running install
    running build
    running build_py
    package init file 'dlib\__init__.py' not found (or not a regular file)
    running build_ext
    Building extension for Python 3.7.5 (tags/v3.7.5:5c02a39a0b, Oct 15 2019, 00:11:34) [MSC v.1916 64 bit (AMD64)]
    Invoking CMake setup: 'cmake C:\Users\FlynnLi\AppData\Local\Temp\pip-install-ywrf5o_o\dlib\tools\python -DCMAKE_LIBRARY_OUTPUT_DIRECTORY=C:\Users\FlynnLi\AppData\Local\Temp\pip-install-ywrf5o_o\dlib\build\lib.win-amd64-3.7 -DPYTHON_EXECUTABLE=D:\Python\Virtual\face_recognition\Scripts\python.exe -DCMAKE_LIBRARY_OUTPUT_DIRECTORY_RELEASE=C:\Users\FlynnLi\AppData\Local\Temp\pip-install-ywrf5o_o\dlib\build\lib.win-amd64-3.7 -A x64'
    -- Building for: NMake Makefiles
    CMake Error at CMakeLists.txt:3 (project):
      Generator

        NMake Makefiles

      does not support platform specification, but platform

        x64

      was specified.


    CMake Error: CMAKE_C_COMPILER not set, after EnableLanguage
    CMake Error: CMAKE_CXX_COMPILER not set, after EnableLanguage
    -- Configuring incomplete, errors occurred!
    See also "C:/Users/FlynnLi/AppData/Local/Temp/pip-install-ywrf5o_o/dlib/build/temp.win-amd64-3.7/Release/CMakeFiles/CMakeOutput.log".
    Traceback (most recent call last):
      File "<string>", line 1, in <module>
      File "C:\Users\FlynnLi\AppData\Local\Temp\pip-install-ywrf5o_o\dlib\setup.py", line 261, in <module>
        'Topic :: Software Development',
      File "D:\Python\Virtual\face_recognition\lib\site-packages\setuptools\__init__.py", line 144, in setup
        return distutils.core.setup(**attrs)
      File "d:\python\lib\distutils\core.py", line 148, in setup
        dist.run_commands()
      File "d:\python\lib\distutils\dist.py", line 966, in run_commands
        self.run_command(cmd)
      File "d:\python\lib\distutils\dist.py", line 985, in run_command
        cmd_obj.run()
      File "D:\Python\Virtual\face_recognition\lib\site-packages\setuptools\command\install.py", line 61, in run
        return orig.install.run(self)
      File "d:\python\lib\distutils\command\install.py", line 545, in run
        self.run_command('build')
      File "d:\python\lib\distutils\cmd.py", line 313, in run_command
        self.distribution.run_command(command)
      File "d:\python\lib\distutils\dist.py", line 985, in run_command
        cmd_obj.run()
      File "d:\python\lib\distutils\command\build.py", line 135, in run
        self.run_command(cmd_name)
      File "d:\python\lib\distutils\cmd.py", line 313, in run_command
        self.distribution.run_command(command)
      File "d:\python\lib\distutils\dist.py", line 985, in run_command
        cmd_obj.run()
      File "C:\Users\FlynnLi\AppData\Local\Temp\pip-install-ywrf5o_o\dlib\setup.py", line 135, in run
        self.build_extension(ext)
      File "C:\Users\FlynnLi\AppData\Local\Temp\pip-install-ywrf5o_o\dlib\setup.py", line 172, in build_extension
        subprocess.check_call(cmake_setup, cwd=build_folder)
      File "d:\python\lib\subprocess.py", line 363, in check_call
        raise CalledProcessError(retcode, cmd)
    subprocess.CalledProcessError: Command '['cmake', 'C:\\Users\\FlynnLi\\AppData\\Local\\Temp\\pip-install-ywrf5o_o\\dlib\\tools\\python', '-DCMAKE_LIBRARY_OUTPUT_DIRECTORY=C:\\Users\\FlynnLi\\AppData\\Local\\Temp\\pip-install-ywrf5o_o\\dlib\\build\\lib.win-amd64-3.7', '-DPYTHON_EXECUTABLE=D:\\Python\\Virtual\\face_recognition\\Scripts\\python.exe', '-DCMAKE_LIBRARY_OUTPUT_DIRECTORY_RELEASE=C:\\Users\\FlynnLi\\AppData\\Local\\Temp\\pip-install-ywrf5o_o\\dlib\\build\\lib.win-amd64-3.7', '-A', 'x64']' returned non-zero exit status 1.
    ----------------------------------------
ERROR: Command errored out with exit status 1: 'D:\Python\Virtual\face_recognition\Scripts\python.exe' -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'C:\\Users\\FlynnLi\\AppData\\Local\\Temp\\pip-install-ywrf5o_o\\dlib\\setup.py'"'"'; __file__='"'"'C:\\Users\\FlynnLi\\AppData\\Local\\Temp\\pip-install-ywrf5o_o\\dlib\\setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' install --record 'C:\Users\FlynnLi\AppData\Local\Temp\pip-record-vngiiz8h\install-record.txt' --single-version-externally-managed --compile --install-headers 'D:\Python\Virtual\face_recognition\include\site\python3.7\dlib' Check the logs for full command output.

Anaconda is downloaded according to the Suggestions on the Internet, conda is used to download, and the virtual environment is created before downloading

conda create -n face python=3.7 #Python3.7
activate face 

Installing Opencv has reported another error… Don’t recurse…

 D:\Anaconda\envs>conda install opencv-python
Collecting package metadata (current_repodata.json): done
Solving environment: failed with initial frozen solve. Retrying with flexible solve.
Collecting package metadata (repodata.json): done
Solving environment: failed with initial frozen solve. Retrying with flexible solve.

Actually, the name of the package under Python is OpencV-Python, and Anaconda is Opencv

conda install -c conda-forge opencv

Error reporting also occurred when installing the face_recognition library, and the solution is to use

pip install --no-dependencies face_recognition

And then I can introduce usage and write code normally.

OpenCV3.1 + Python2.7 error “DLL load failed: The specified module could not be found”

According to the web site [http://docs.opencv.org/3.1.0/d5/de5/tutorial_py_setup_in_windows.html] method 2 manual compiled OpenCV3.1.0 and install python.
but error “DLL load failed: The specified module could not be found” appears when importing cv2.
I looked for the following reasons online, the possible reason is that
1) opencv and python corresponding versions are different, such as one is 32bit and one is 64bit. Pyd
2) did not add cv2.pyd to C:/Python27/lib/site-packages
3) system environment variable could not be found cv2.pyd
the final solution to my computer problem was:
add [C:\ opencv-3.1.0 \build\bin\Release] to system environment variable.

Opencv problem: opencv error: assertion failed (! Empty()) in detectmultiscale

Problem description:

in the process of using OpenCV on ROS to realize face detection, the following problems are encountered:

:

OpenCV Error: Assertion failed (! Empty ()) in detectMultiScale, the file/TMP/binarydeb/ros – kinetic – opencv3-3.3.1/modules/objdetect/SRC/cascadedetect CPP, Line 1698
the terminate called after throwing an instance of ‘CV: : Exception’
I () :/TMP/binarydeb/ros – kinetic – opencv3-3.3.1/modules/objdetect/SRC/cascadedetect CPP: 1698: error: (215). empty() in function detectMultiScale

Aborted (core dumped)

OpenCV cascade detector, Cascadedetect error, XML path reading error, found in the original code face_cascade did not read. XML file. As follows:

cv::CascadeClassifier face_cascade;

solution:

Find the location of the XML file related to face recognition and add the XML file to face_cascade. As follows:

cv::CascadeClassifier face_cascade = cv::CascadeClassifier("/home/opencv/opencv-3.4.4/data/haarcascades/haarcascade_frontalface_default.xml");

after modification, code debugging passed, problem solved.

The XML file here is also optional, with haarcascade_eye.xml for eye recognition, and so on.

Mac installation opencv brew tap homebrew / Science

MAC use brew to install opencv, look up information when a blog said the need to add the command:

brew tap homebrew/science

always gives an error when trying:

Error: homebrew/science was deprecated. This tap is now empty as all its formulae were migrated.

, meaning homebrew/science has been removed, meaning that the brew tap step is not required.


solution: remove this step, directly brew install xx, xx refers to your package.

above.

[solved] Python: opencv: error: (- 215) size.width >0 && size.height >0 in function cv::imshow

when using cv2.imread(),
when this error occurs, please check the following information:
is spelling error
is this picture
is added suffix
is 0 absolute path 1
2 what system is this?Consider changing the single slash to and double slash . In general, a backslash
is already supported

image_data = cv2.imread('D:\\lab\\AgriculturalDisease_trainingset\\images\\00c5c908-fc25-4710-a109-db143da23112___RS_Erly.B 7778.JPG')

in Windows how to check the address is correct, especially in the loop
can be copied directly in the Windows window, to see if you can read and display the picture.
then checks the address of the program, prints it out, and compares whether the two are the same.

if you encounter Chinese name can’t read, please refer to this website: Chinese path error problem
simply, is to directly rewrite the cv2.imread function, replace it with another function cv_imread:

def cv_imread(filePath):
    cv_img=cv2.imdecode(np.fromfile(filePath,dtype=np.uint8),-1)
    return cv_img

# The main citation section is as follows: (img_path needs to be given by yourself)
image_data = cv_imread(img_path)