Quickly install OpenCV 2.4 (+ python) on OS X and try the sample

When I hunted the net and books, I found that 1.x articles and 2.x articles were messed up. I'm confused, so I've summarized the steps that are easy to set up.

Installation procedure


Follow the steps below to install OpenCV 2.4 and the library to use it from python. sudo port -v install opencv +python27

#Check OS X standard python
$ which python 
/usr/bin/python

$ sudo port -v install opencv +python27 
・ ・ ・ The result is omitted.I was able to install it in about 10 minutes in my environment ...

#Make sure OS X standard python hasn't changed
$ which python
/usr/bin/python
$ python --version
Python 2.7.2

#Check the installed python.MacPorts directory( /opt/local/bin )Under
$ which python2.7
/opt/local/bin/python2.7

#Apparently python2.It seems that the command is passing by the name of 7. 
$ python2.7 --version
Python 2.7.5

#Check the OpenCV library path
#python2 installed by port.It seems that it is installed under the influence of 7
$ ls -l /opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/cv2.so
-rwxr-xr-x  1 root  wheel  1579428  9 16 23:36 /opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/cv2.so

Operation check


It is confirmed that the library can be referenced from python2.7.

$ python2.7
Python 2.7.5 (default, Aug  1 2013, 01:01:17) 
[GCC 4.2.1 Compatible Apple Clang 4.1 ((tags/Apple/clang-421.11.66))] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import cv2
>>> 
#Judging that the installation was successful because there was no error when importing the cv2 library

#Try running the sample program distributed by the developer official
#   http://sourceforge.net/projects/opencvlibrary/files/
$ python2.7 opencv-2.4.6/samples/python2/find_obj.py

Feature-based image matching sample.

USAGE
  find_obj.py [--feature=<sift|surf|orb>[-flann]] [ <image1> <image2> ]

  --feature  - Feature to use. Can be sift, surf of orb. Append '-flann' to feature name
                to use Flann-based matcher instead bruteforce.

  Press left mouse button on a feature point to see its mathcing point.

using sift
img1 - 604 features, img2 - 969 features
matching...
75 / 80  inliers/matched

Here is a capture of the window displayed at this time. opencvSample.jpg

Summary


Now you can run the OpenCV program. That annoying Cmake seems to be done in port install.

Reference link


The installation command used is based on "1.Build via MacPorts" described in Developer Official.

Recommended Posts

Quickly install OpenCV 2.4 (+ python) on OS X and try the sample
Install lp_solve on Mac OS X and call it with python.
Install OpenCV 4.0 and Python 3.7 on Windows 10 with Anaconda
Install selenium on Mac and try it with python
Install OpenCV on Ubuntu + python
Install django on python + anaconda and start the server
Test Python with Miniconda on OS X and Linux with travis-ci
Install Python 3.8 on Ubuntu 18.04 (OS standard)
Install OpenCV and Chainer on Ubuntu
Install Python 3.8 on Ubuntu 20.04 (OS standard)
Install Sphinx on Mac OS X
Build and install OpenCV on Windows
Install mitmproxy on Mac OS X
Install fabric on Ubuntu and try
Install Python 3.9 on Ubuntu 20.04 (OS standard?)
Install Python 2.7 on Ubuntu 20.04 (OS standard?)
Install pgmagick on Mac OS X 10.9
Steps to install the latest version of OpenCV on OS X El Capitan without Homebrew
How to install OpenCV on Cloud9 and run it in Python
Get started with the Python framework Django on Mac OS X
Continuation ・ Notes on preparing the Python development environment on Mac OS X
Install matplotlib on OS X El Capitan
Build Python3 and OpenCV environment on Ubuntu 18.04
Install pyenv and Python 3.6.8 on Ubuntu 18.04 LTS
Put OpenCV in OS X with Homebrew and input / output video with python
Install and run Python3.5 + NumPy + SciPy on Windows 10
Until you install Caffe and run the sample
Python: Try using the UI on Pythonista 3 on iPad
Run Zookeeper x python (kazoo) on Mac OS X
Try CIing the pushed python code on GitHub.
Install shogun with python modular (OS X Yosemite)
[Python] How to install OpenCV on Anaconda [Windows]
Shpinx (Python documentation builder) on Mac OS X
Try importing MLB data on Mac and Python
Install MongoDB on Ubuntu 16.04 and operate via python
Install Python and libraries for Python on MacOS Catalina
Install ZIP version Python and pip on Windows 10
I installed Pygame with Python 3.5.1 in the environment of pyenv on OS X
Install the Python API of the autonomous driving simulator LGSVL and execute the sample program
(CMake) Gently install official OpenCV on WSL (C / C ++, Python2, Python3)
Install Python3 on Mac and build environment [Definitive Edition]
Install Python on Pidora.
Install Scrapy on python3
Steps to install the latest Python on your Mac
Very easy to install SciPy on Mac OS X
Install Python on Mac
How to install caffe on OS X with macports
Install Python 3 on Mac
Install Python3.4 on CentOS 6.6
Try using E-Cell 4 on Windows 7 or Mac OS X
Install the 3rd party python library on Cinema 4D
Install PyCall on Raspberry PI and try using GPIO's library for Python from Ruby
Until you install Gauge and run the official sample
Build a Python development environment on Mac OS X
[Windows] [Python3] Install python3 and Jupyter Notebook (formerly ipython notebook) on Windows
Install and develop Git, VSCode, Docker on Chrome OS
Install python on windows
mac OS X 10.15.x pyenv Python If you can't install
Install PyQt5 with homebrew on Mac OS X Marvericks (10.9.2)
Install the latest stable Python with pyenv (both 2 and 3)
Ubuntu 20.04 on raspberry pi 4 with OpenCV and use with python