OpenCV aruco not working in Python (windows) - python

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/

Related

Which components do what when using Python with OpenCV?

I'm quite puzzled about what to use or install, because there are a plethora of components old and new, and the relationship between them is quite unclear to me.
There is OpenCV, the C++ library that does the heavy lifting.
Then there are various packages that provide Python support, including:
opencv-python - Python packages for OpenCV; also installs OpenCV itself. Available with import cv2.
pyopencv - a very old library.
python-opencv - a Debian package.
libopencv, described in another question here as "only a metapackage", but its purpose remains unclear to me.
Possibly I have missed some...
For a modern Python 3 project, which of these components should be used?
Using import cv
I am trying to use OpenCV with a Django project, that expects to find the library with import cv.
That recommends installing python-opencv. It also mentions pyopencv which seems odd, given how old the latter is.
What package does make a cv module available?
System vs Python packages
It looks like python-opencv is a system-level package that also installs Python modules, whereas opencv-python is a Python package that also installs system-level modules.
Is that correct? In which case, am I right in thinking that one would install both system and Python libraries using one of these but not both?
in opencv3 the old cv or cv2.cv api was removed, to use opencv correctly in python is enough with import cv2.
another package would be opencv-contrib-python

Having trouble importing pygame module on Mac OS 10.13(High Sierra)!

I am teaching myself python, going through some lessons and reading Al Sweigart's book on programming small video games using Python. I am trying to get Pygame working on my laptop. I have tried time and time again to properly install all neccesary tools to run pygame but for some reason I am constantly unsuccessful.
I first tried to install pygame for python 3.6 and after many different attempts I decided to give my computer a factory reset so I could start clean. I understand I could've deleted all residual files using the terminal but being that I'm an amateur I felt more at ease just giving my mac a wipe. Through my research I found that Pygame works best with python v 2.7. I am running Mac OS 10.13(High Sierra).
The first thing I did upon a fresh wipe was open the terminal and process all commands to download things like python2.7, homebrew, pip, pygame. I then tried to import the pygame module but still no prevail. So I decided to go right to the pygame website and download the, pygame-1.9.2pre-py2.7-macosx10.7, file. I see the pygame folder and all of its contents but everytime I try to import the module I receive this import error:
/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pygame/base.so: no matching architecture in universal wrapper
I have read that pygame only works with 32 bit version of python but whenever I attempt to download the sole i386/PPC 32 bit version from the website I cant even get IDLE to open at all.
I apologize in advance if my explanation seems a bit choppy. I'm still learning.
Please forget about 32 Bit. Apple is in the process of phasing out support for 32 bit at all, so trying to get something to work there is a short term solution at best.
Also try to not use the shipped Python from Apple. They use it themselves, it's modified slightly from the vanilla one, and fiddling with it might break things.
Your original idea to use python3.6 is the best one. Download and install it, and use the file
https://files.pythonhosted.org/packages/48/d6/230b0d2367824cd51bc9c4baba7e42933c03e34b1ea7ba3812ad5faa4599/pygame-1.9.3-cp36-cp36m-macosx_10_9_intel.whl
to install it using pip.
python3.6 -mpip install pygame
should be enough, the above file is just for reference - it should be picked up by pip.
You should use pip install pygame to install pygame. Then try to run your code by going to proper directory and running python from command line. I tried running my sample pygame code in my IDE VISUAL STUDIO CODE. I kept getting error messages. When I ran same code from command line it worked fine. Also tried from Atom and it worked fine from there too.
No idea why anyone is still messing about with Python 2 that Apple ships. Come on! Python3 has been out for 10 years.
No idea why anyone is installing MS Office or MS Visual Studio on a Mac. Come on! Surely Mac users buy Macs because they want a proper computer.
Just install homebrew, then install Python 3, then install pygame.
Goto homebrew and install it
Then
brew install python
pip install pygame

Python compiler that can compile a program that utilises Pillow/PIL?

I've written a program that utilises the Pillow module (a PIL fork).
I would like to compile the finished program to an .exe for distribution.
I have tried compiling the program with both PyInstaller and Nuitka, however neither of these seem to support the compilation of a program that utilises this external module.
Does anyone know of any other Python compilers that support the compilation of a program that utilises the Pillow module?
Thank you
Installing Anaconda is your best bet.
Anaconda is a complete package of all python programming essentials. It also has your much needed pillow (or the so called python imaging library) built-in.
It comes with certain other python packages built-in and ready-to-use such as numpy, pandas, scipy, matplotlib, and IPython.
It also has an easy-to-use IDE namely Spyder, which is the playground. You get to do all your coding here. Spyder is just like any other text editor but with more functionality an ease of access.
If your looking out for more options in image processing, Anaconda also comes with scikit-image or skmage (also built-in)
In case you want to install OpenCV on your machine, it can be easily done using the Anaconda command prompt using this command:
conda install -c menpo opencv=3.0.0
Visit the website HERE
I decided to have another attempt at compiling my program using Pyinstaller.
Pyinstaller already worked with Pillow, however it ran into problems with programs that utilised Tix.
After a lot of trial and error, I managed to create a solution based on a comment on github.
My solution.

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.

installing opencv for python issues

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)

Categories