opencv mac os environment initialization
general reference
http://www.cnblogs.com/freeweb/p/5794447.html
But I encountered some mac os problems during the process and recorded it
The following describes the combined installation process of Python and OpenCV under Linux. To use the OpenCV module, Python must import the packages provided by OpenCV. Therefore, to provide Python support, first install the necessary components before installing OpenCV. The general list is as follows:
1, gcc g++ general system comes with
2, cmake is used when compiling OpenCV, it needs to be installed manually
3. The pkg-config command is usually provided with the system. If it is missing, use yum -y install pkg-config to install it
4, Python 2.x, the system comes with
5. NumPy A library for large matrix processing, this is a must! If it is not installed, the Python module cannot be compiled after OpenCV is installed, and other libraries can be installed later
The last step is to install OpenCV
Since my mac os gcc, python2.7 already has it.
The first step is to install pk-config
http://pkgconfig.freedesktop.org/releases/pkg-config-0.28.tar.gz Download and unzip
./configure --with-internal-glib
make
sudo make install
Finish
The second step, install cmake
First go to cmake, the official website, and download the installation package corresponding to the Mac operating system https://cmake.org/download/
The 3.10.1 I downloaded directly downloads the .dmg.
After the installation is complete, run the cmake graphical interface program, select Tools in the options bar in the upper left corner, and click How to install for Command Line Use. Then a message box pops up:
One may add CMake to the PATH:
PATH="/Applications/CMake.app/Contents/bin":"$PATH"
Or, to install symlinks to '/usr/local/bin', run:
sudo "/Applications/CMake.app/Contents/bin/cmake-gui" --install
Or, to install symlinks to another directory, run:
sudo "/Applications/CMake.app/Contents/bin/cmake-gui" --install=/path/to/bin
Officially, there are three ways to install the cmake command line tool, that is, the way the terminal can recognize the cmake command. I chose the second method given by the official, that is, copy the sudo "/Applications/CMake.app/Contents/bin/cmake-gui" --install command to the terminal, then run it, and then type the cmake command in the terminal, just There will be no more errors such as command not found, and the installation is successful.
Finish
The third step, NumPy installation
https://sourceforge.net/projects/numpy/?source=typ_redirect download
After decompression, under the source code path
python setup.py install
The installation is complete.
The fourth step, install OpenCV,
The official website is: http://opencv.org/ Download the source code I downloaded 3.4.0, unzip it
cd opencv-3.4.0/
mkdir build
cd build
cmake ..
make -j 4
sudo make install
ll /usr/local/lib/python2.7/site-packages/
root admin 3276452 12 30 21:19 cv2.so
See sv2.so that the installation is successful
If you start the python interactive command line at this time, import cv2
Error, ImportError: No module named cv2
The fifth step, solve the problem of ImportError: No module named cv2
>>> import site
>>> site.getsitepackages()
['/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python', '/Library/Python/2.7/site-packages']
Copy /usr/local/lib/python2.7/site-packages/cv2.so to the corresponding directory of site.getsitepackages().
I only copied to /Library/Python/2.7/site-packages.
The sixth step, hello word
#!/usr/bin/python
# -*- coding:utf-8 -*-
import cv2
image = cv2.imread("/Users/rachelluo/Downloads/IMG_4432.JPG")
print image
cv2.imwrite("./a.jpg", image)