installing opencv for python issues - python

I'm running OS X Leopard. I followed this site to install it. Trying to run any demo script, I now get "No module named opencv.cv", which is obviously stopping me from doing any programming. I am running python 2.5.1 (yes, I know it's kind of old).
Why would this be, and how can I solve it?
Thanks

You need to compile openCV unfortunately. It's not that hard to do though at least.

A nice route is to use MacPorts: First, be sure to have py26-numpy installed to have support for basic functions such as cv.fromarray :
sudo port install py26-numpy
Then, opencv will compile (with no problem on my side):
sudo port install opencv +python26

Your link tells to install OpenCV with MacPorts, which currently installs version 2.2.0. The API was changed for 2.2, so that might be the reason opencv.cv doesn't exist (also your link is written for the ancient 1.0). OpenCV changelog explains it:
http://opencv.willowgarage.com/wiki/OpenCV%20Change%20Logs
It isn't clear to me how up-to-date the OpenCV documentation is nowadays but I recommend looking at it:
http://opencv.willowgarage.com/documentation/python/index.html
(Python examples there begin with import cv)

Related

OpenCV aruco not working in Python (windows)

I've been doing some work using aruco with c++ but I'll have to switch to python now.
(I'm using windows 8, 64-bit Operating System, x64-based processor)
I installed Python and the libraries I believe I'll need the following way:
Downloaded and installed Python 3.5 from this link:
https://www.python.org/downloads/
Added Python to paths
Downloaded opencv+contrib & numpy & scipy from this link:
https://www.lfd.uci.edu/~gohlke/pythonlibs/
Went to Python Scripts folder in a cmd window and with pip3.5
installed all the libraries
When I run visual studio I'm able to import numpy and cv2, it's just when I try to import aruco or import cv2.aruco that I have problems...
I honestly just started trying to use python and I must say that I don't really know what I'm doing. I don't have a lot of experience with this kind of stuff (I'm a mechanical egineer student and I'm trying to use computer vision for some stuff, so I pretty much learned everything online). I managed to do what I wanted with c++, but the guys I work with want to make everything with python (they have their reasons).
Also (and again, I'm just trying everything I can here...) when I run python on a cmd window I'm able to import numpy, scipy, cv2 and cv2.aruco.
Am I doing something wrong or do I need something else to use aruco with python?
Any help is appreciated, I'm really running out of googling power haha
maybe try pip install opencv-python
Try also installing the AruCo library through pip just in case, as the environment you have shared does not explicitly have AruCo in it.
pip install aruco
Here's the link in PyPI: https://pypi.org/project/aruco/

Installing rpy or rpy2 on mac

I'm in the process of trying to install rpy or rpy2 on my Macbook so I can use R from python. Information about rpy can be found here: http://rpy.sourceforge.net/index.html
My problem is in the installation itself. I can't seem to make python recognize Rpy using import command: I keep getting the message "No module named rpy2". Does anyone know where I can find some step-by-step instructions on how to successfully install this? I have already installed both python and R, and both are working perfectly. Thanks in advance!
Try easy_install rpy2. You need to install easy_install before that.
I took that from here
I long gave up on these issues on my Mac. Since I installed OS Lion, I found that I needed to switch to MacPorts and then installing packages like RPy2 from their repository.
I know some people like to dig into the system and learn all the idiosyncrasies of the architecture and keep a vanilla install of python on their Mac. I find that i get problems like yours too frequently and they distract me from real work.
I just download the MacPorts modules when I need them and get on with the problem at hand. Others say the same thing about HomeBrew but I have only worked with MacPorts and it makes installation of modules too easy. You may want to invest some time investigating if either of these solutions work for you.
Another approach to using package managers like MacPorts or HomeBrew is to use a virtualenv and install python and all related modules there. Again, not a solution I have tried directly, but a quick search will show you many endorsements for this approach to using a specific Python executable and packaging its modules In an isolated environment.
as long as you have pip installed on your mac, then life will be easy as:
sudo pip install rpy2
If you want rpy it isn't on macport, at least a search of their packages only showed rpy2. According to the rpy web site its in fink. However at the moment fink is down so I can't verify this. Which is irritating because I need rpy (not rpy2) because another package has a dependency on it.
I also tried pip to find rpy and it said no package, which is a shame because pip is great for python installs (provided I remember to use 'sudo' first.

Installing MatplotLib in mac osx lion

I was trying to install matplotlib in Mac OSX Lion. Tried to used the binary that is in the sourcefourge site, but I got this error: "matplotlib requires System Python 2.7 to install".
I went to the Terminal and typed python --version and its check the requirements.
After this I tried to used the pip, and while doing so é got the following error:
"src/_image.cpp:908: error: invalid use of incomplete type ‘struct png_info_def’"
Can you give me clues in how to install it?
Many thanks.
EDIT: I found a way, without having to install a new version of python:
http://the.taoofmac.com/space/blog/2011/07/24/2222
This is because of a change in the API for libpng v1.5 (which is included with Mac OSX Lion). The changes has already been pushed upstream, so you will need to compile from the upstream repository until the next release.
You can follow the instructions on http://jholewinski.wordpress.com/2011/07/21/installing-matplotlib-on-os-x-10-7-with-homebrew/
I followed this page's instructions. I got stuck at
pip install -e git+https://github.com/matplotlib/matplotlib#egg=matplotlib-dev
Then I did:
git clone https://github.com/matplotlib/matplotlib.git
cd matplotlib
python setup.py build
python setup.py install
Checked my installation by typing in terminal:
python
import matplotlib
print matplotlib.__version__
print matplotlib.__file__
I got version 0.10.0 dev (as of this writing) and path /usr/local/Cellar/...
You can try with an "official" python distribution, apple might have tweaked the supplied one. You can find the 2.7 here: http://www.python.org/download/
You might have to re-install numpy as well afterwords: http://sourceforge.net/projects/numpy/files/NumPy/1.6.1/
I would suggest to install scipy as well
Let me know if it works ;)
I would recommend using macports, it should take care of dependencies and would be indepedent of the system python version.
EDIT: Just a few clarifications, taking into account comments to this answer.
Why use macports (or another installer)? Because they take care of dependencies, provide functionality to uninstall and switch between versions (I've used the latter successfully for gcc and python). And because the default installation location is not the system executable location. Overriding the system python can break applications that rely on it (this is certainly true in many Linux distributions, maybe less so on mac OS X).
When is it particularly useful? When you want to install on top of a version of python that is different to system python, and when you have non-python extensions (C, C++, Fortran...).
What's the down side? As #Trond has mentioned in the comments, it is good if you're OK with default compilations of packages. You don't have a handle over configuration or compiler flags as you would if you built from source.
A good alternative to macports is fink, which seems to give you more control (build from source). I am not sure it is completely ready for mac OS X Lion yet.
I know it will take a lot more time, but I would reccomend installing python, numpy, and matplotlib from source to ensure that you have consistency in your system. From the error it could look like you have a problem with libPNG support. I have a written a "How to install python dev tools on Mac OSX" that you may find useful. It contains directions for how to install python, numpy, matplotlib and all necessary dependencies. I understand you are working with Python 2.7 and the directions I am listing is for Python 2.6.5, but it would be the same approach. Hope you get it to work.
You could just install the Python 2.6 version of Matplotlib, assuming that Python2.6 is included with Lion (py2.5 & 2.6 are included with Mac OS 10.6 "Snow Leopard" - try typing python2.6 to find out if that version is installed.).
On MacPorts you do this via something like:
sudo port install py26-matplotlib
where py26-... (or py25-..., py27-... etc.) indicates which python version it is meant for. (check the Pallet/ports list to get the correct package name, in case I guessed wrong)

Opencv 2.2 not recognized on Python 2.7 (Ubuntu/Windows XP)

I've been trying to connect opencv and python in both Ubuntu and Windows XP. I've failed on both.
I've read many webpages and threads about "how to install" it but none has worked (the worst part is that they all say kind of the same).
Steps (windows xp):
Installed Python 2.7 by default (works perfectly)
Installed PIL and cx_Freeze (may they
create a conflict? I don't think so
:s)
Installed Opencv 2.2 by default
(OpenCV-2.2.0-win32-vs2010.exe) and
it isn't recognized inside a py nor
as import opencv.cv nor using the
cookbook way, import cv (I skipped
the visual studio steps since I'll
use it with python)
Checked path (it's ok, it has the
Opencv2.2\bin thing)
Rechecked webpages and stuff
Steps (ubuntu):
Had python working
sudo apt-get install, cmake, make,
sudo make install, etcetc (from the
tutorials)
same thing... module not recognized
Please can you help?
Update:
I managed to install it and have it recognized by the system (I used http://www.lfd.uci.edu/~gohlke/pythonlibs/#opencv and it worked perfectly after that).
The problem now is that it crashes when I try to use CaptureFromFile. Someone else has reported it 3 days ago so now I wait.
I'll check the other wrappers, maybe one of them will work.
For windows see my web page: http://www.modernmind.org/wiki/OpenCV
For Ubuntu you should just need to apt-get install python-dev then generate the make files with Cmake, build it and then make install. In order to build the python bindings you need to have the python header files on your system and you probably don't. When you run configure in Cmake make sure that you don't see any messages at the top about PYTHON_INCLUDE not being defined.
To access a library it needs a Python library installed in the Python version you are using. From what you write above it seems to me that you install OpenCV in general, but that you don't specifically install the Python library. This is why it doesn't work.
I'm not sure how to install the Python wrappers, and the OpenCV documentation is a bit sparse on that info. But if you did build them (and that needs to be turned on explicitly, says the docs) they seem to end up in opencv/release/lib .
Look at "Testing Python wrappers" on http://opencv.willowgarage.com/wiki/InstallGuide
If there is still no luck, there is a bunch of alternative Python wrappers available: http://pypi.python.org/pypi?%3Aaction=search&term=opencv&submit=search
Maybe they are better documented.

Enable python support while installing opencv using mac ports

I installed opencv in my mac using mac ports by the following command
sudo port install opencv
It took around 2 hours and it installed properly. But the problem is that the python bindings are not enabled.
So please let me know how to install opencv in mac using ports and also enable the python bindings. Thanks
PS: I tried to manually compile opencv from source but I am getting lot of errors and I am not able to do it.
be sure to have py26-numpy installed to have support for basic functions such as cv.fromarray :
sudo port install py26-numpy
opencv will compile silently without numpy (it's not strictly a dependency).
sudo port install -v opencv +python26
there you can check that the binding to numpy is effective.
It's possible to compile opencv using cmake on macos (I'm actually doing this) but there is a problem with the videoWriter ...
Have a look there http://www.tsd.net.au/blog/opencv-python-bindings-macports
should be helpful.
I am still not able to compile opencv properly. At last, I found some pre-compiled dmg files from http://vislab.cs.vt.edu/~vislab/wiki/index.php?title=Vision which is working pretty decently.

Categories