This time I will bring you a detailed explanation of the use of python configuration and OpenCV. What are the precautions for python configuration and use of OpenCV. The following is a practical case, let's take a look.
After downloading opencv2.4.9 (python2.7 matching)
(1) Run OpenCV 2.4.9.exe;
(2) Configure Python: Copy the \opencv\build\python\2.7\x64 directory: cv2.pyd
to: Python27\Lib \site-packages\ directory;
(3) Test: Enter import cv2. If an error is reported, it means the installation is not successful
1. The version of opencv must match the version of python, otherwise python will not be able to call the cv2 module.Error message:ImportError DLL load failed: %1 is not a valid Win32 application
This error occurred The reason is that the bits of python and opencv do not match. For example, your python2.7 is 32-bit, but opencv is 64-bit.2. Solution: If your python is 64-bit, copy cv2.pyd under \opencv\build\python\2.7\x64 Python27\Lib\site-packages\, otherwise copy \opencv\build\python\2.7\x86.
If your python has added environment variables, just enter python directly in the console and press Enter to see how many bits your python has:3. Some problems with opencv3
There are some differences between the use of opencv3 and opencv2. Take cv2.cv.CV_HAAR_SCALE_IMAGE as an example. An error will be reported in opencv3, prompting that it is in cv2. If there is no cv attribute, just switch to opencv2. I believe you have mastered the method after reading the case in this article. For more exciting information, please pay attention to other related articles on the php Chinese website! Recommended reading:Implementation of python batch reading of images and storing them in the database
Object life in Python replication How to use cycles
The above is the detailed content of Detailed explanation of python configuration and use of OpenCV. For more information, please follow other related articles on the PHP Chinese website!