opencv4 python mac_Install OpenCV 3 With Python 3 (Mac OSX)

Install FFmpegFFmpeg is used to encode and decode multimedia data. It

is very important to complete this step before moving on to step 8. You

will be able to install OpenCV without FFmpeg, but some functions will

not compile properly without it and trying to install FFmpeg post OpenCV

installation is tricky.

Run the following line in your terminal shell.

$ brew install ffmpeg

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

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

I have installed python3 using homebrew. I recommend using it. In this case,

you should only install python3:

brew install python3

If you already have python3, skip this step. You can also install openCV 2.4.9, but at the time of writing there is

no option for openCV 3 with python3.

You should also install numpy. For that you can use pip (already installed), a python packet manager:

pip3 install numpy

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 install

as 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 download

Select 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 them

as they are shown.

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 click

generate.

If any problem should happen, you can try to detect it by reading the

output 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:

cd /Users/[username]/Downloads/opencv-3.0.0-alpha/build

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

make -j8

For the next command you need super user privileges:

sudo make install

Checking it all works

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

python3

import cv2

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

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:

sudo make uninstall

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

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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值