views:

189

answers:

2

I'm trying to get OpenCV working with Python 3. A friend showed me ctypes-opencv that appears to work with Python 3. The problem is I totally can not figure out how to "install" or get any code working. I've followed all instructions I could find from a few people mentioning installs on google and none of those seemed to work or I couldn't even get through the basics that they mentioned.

I am just hacking around with the version of IDLE that came with Python 3. No IDE.

Start with OpenCV:

The only windows installer for OpenCV 2.1 is a visual studio installer. I assume that means that it installs files that make it easier to use in Visual Studio. However, does it also mean that I can't use that installer with Python 3? I tried the vs installer together with ctypes-opencv as below, and I got errors that the dlls were not in my path (but my path variable did include the OpenCV bin folder with dlls). Is this the wrong direction?

The apparent alternative is to build OpenCV myself. I tried following the directions here and all I get is "project files may be invalid" from the CMake gui application when pressing the "Configure" button. Same when following these hints from Stack Overflow. I'm suspicious that this is also the wrong direction since I am not currently using any of the tools that are listed in the CMake configure. Is this also the wrong direction?

Next ctypes-opencv:

I installed this and the installer recognizes Python3.1 and puts itself into the site-packages folder. If I try to run demos, it tells me the dlls are not in the path although they are, as mentioned above.

Summary:

I think I generally understand each piece here (code, compile, dll, imports, ...) but I do not know how all the pieces fit together and where I am going wrong. Can someone please tell me what steps or understanding I am missing here?

I get the feeling that I need to be reading a book or two to fill in the holes in my understanding of how all these pieces fit together. I wouldn't even know what area of books to get though so any suggestions there would be appreciated as well.

+1  A: 

Python's ctypes is a wrapper around the opencv dll files, as long as you can point to the compiled libraries it doesn't matter what the source code is set up to be edited in. For windows I would simply run the installer, then try to load the dll with ctypes. If you can get that far, any other errors can be fixed by looking at the ctypes wrapper file and editing the load section to look like your test file.

Ian Wetherbee
Thanks for the comment. That got me going in the right direction. If I understand you correctly, there is no fundamental difference between dlls for visual studio or self-compiled. I finally realized when looking as you said in the ctypes-opencv load libary code that it only supports OpenCV 1. That's why it wasn't finding the dlls.
yakiimo
To anyone else looking for the answer, as of the time of this comment, you can just use the dlls included with the windows installer, but you have to use the OpenCV 1 instead of 2.
yakiimo
A: 

Yakiimo san, OpenCV 2.1 DLL can be loaded with ctypes. I have tested it.

p.s. I have set the C;\OpenCV2.1\bin in Env Path.

Russell Wong