Download Opencv Python For Mac

Install FFmpeg

  1. Python Download Mac Os
  2. Opencv For Mac
  3. Opencv Python Tutorial

Mar 24, 2018.

  • FFmpeg is used to encode and decode multimedia data. Itis very important to complete this step before moving on to step 8. Youwill be able to install OpenCV without FFmpeg, but some functions willnot compile properly without it and trying to install FFmpeg post OpenCVinstallation is tricky.
  • Run the following line in your terminal shell.





###############################################################


It took me a while, but I did it. I want to migrate my final project to python 3, so I had to use Opencv 3.0.At the moment of writing, the opencv 3.0 is still alpha, but seems stable enough.So, we’ll be using python 3.4 + Opencv 3.0 alpha on OSX 10.9.4. Let’s start.

Installing python3.4

Python

I have installed python3 using homebrew. I recommend using it. In this case,you should only install python3:

Python Download Mac Os

If you already have python3, skip this step. You can also install openCV 2.4.9, but at the time of writing there isno option for openCV 3 with python3.You should also install numpy. For that you can use pip (already installed), a python packet manager:

Installing Cmake

You can also install Cmake with homebrew, but instead, I downloaded it directly from its homepage.This way you have cmake gui, a graphical user interface that makes it easier to manage. So, download and installas any program (dmg): cmake download (look for the Mac OSX 64/32-bit Universal dmg).If you have problems opening, read this

Installing opencv 3.0

First download it from the opencv homepage: opencv3.0 downloadSelect the OpenCV 3.0 (at the time of writing, alpha) for Linux/Mac.We should now unzip it.It’s time to use cmake. Open it from your applications.It asks you to select where the source code is. Navigate to your opencv3.0 folder, previously unzipped.You should also select the build directory (usually you can make a build folder inside the opencv3.0 folder)

This image shows my configuration. You can filter the configuration parameters so it is easier to find.The important ones are those with “python3” prefix.You should set yours depending on your system installation, but if you followed this guide you should set themas they are shown.

Opencv For Mac

So remember to:

  • Set the BUILD_opencv_python3. If it is not present, you can add it with the Add Entry button. (这里设置成bool 的值即可, 记得check上)
  • In my case, the parameters I had to set manually were PYTHON3_INCLUDE_DIR and PYTHON3_LIBRARY. (这里自己也要设置,路径同上图。 同时,要注意PYTHON3_NUMPY_INCLUDE_DIRS的路径也是和图里一样的。如果不一样,就看另一个帖子)
  • If the others parameters are not set automatically, it may help to run brew linkapps command before configuring. In any case, you can set them manually.
  • Your Current Generator is Unix Makefiles

Now, click configure. If everything goes fine, now you clickgenerate.If any problem should happen, you can try to detect it by reading theoutput in the bottom of CMAKE. Look for problems related with Python. It would be easier if you copy the text into textedit so you can find words.

All right, time to open a terminal.In the terminal, navigate to the folder where you have your build folder, something like:

Download Opencv Python For Mac

Now execute the make command (-jX where X is the number of cores of your CPU, to make compilation faster):

For the next command you need super user privileges:

Checking it all works

If there were no errors, you should be able to import it. Execute this in the terminal:

If there is no Error, congratulations, you have opencv3 with python 3.

Opencv Python Tutorial

Now go out for a beer, you earned it.

What? It didn’t work? No time for beer yet then…

UPDATE:If you got problems like import error, I recommend that you look careful at the outputs in every step.Actually, you should always do that for everything. Looking for words like ERROR.If you had made it to last step, you can try to uninstall and try configuring and installeing it all again.To uninstall your recently installed openCV you should go to the build directory from the terminal and run this command:

I usually do this for installing newer versions of OpenCV too (OpenCV 3.0 - beta is out now).

Download Opencv Python For Mac

If you keep having problems, post them in the comments and I’ll try to help ;)

***************************安装完毕后,可以在ipython3路径中import cv2了。但是还不能在python3中导入cv2----------

经过查询后,发现cv2.so位置是:/usr/local/lib/python3.4/site-packages

因此,在~/.bash_profile中加入了语句

PYTHONPATH='${PYTHONPATH}:/usr/local/lib/python3.4/site-packages”
export PYTHONPATH

即可 --------上面的结果还是不行,结果是Python 3.4.2和 3.4.3冲突所致。

因此我们的解决方案是: 全部删除Python3,然后再brew 安装最新的Python,最终link之即可

----------------------------------------------------

要处理avi数据,我们还需要brew install ffmpeg