Tuesday, July 3, 2018

Help frustration Python and OpenCV on OS X

Help frustration Python and OpenCV on OS X



One of the most frustrating moments is when Im almost sure I cannot do something. And in general I know I can solve anything, really. Just not now. I have to wait til I learn a certain material. Or I need to wait for help. Or I just need to realize whats the problem. Yeah, I often ask the wrong question.


I realized that moment when I had problems with web servers. I never learned proper Unix or networks. And with the internet its not too hard to solve anything when you know what you want to solve. Please give me this Apache mod name. Please tell me how to install a mail server. Please show me how to install an SVN server. But then you have questions like - Ive seen that cool server architecture my colleague is using, and hes pretty happy with that, who can I install it? Haha, slap, *ts*.

This story is about video input. I have an idea that I would like to make and I need to use the video input. Now the easiest would be to use Flash. But thats proprietary (about that another time). There is the free Adobe Flex SDK - but Im pretty angry at them to charge for Flash Builder. Anyways. I can use Objective C and Mac libraries - meh, me no gusta. I need something more dynamic. Google didnt give me any HTML5 solution either. Then I checked Python and it said he has a library: ctypes opencv. Brilliant, I know 2 commands in Python so I will figure out the rest somehow. And then shit hit the fan.

I managed to install the library (*clap*^2), run the first demo and crash:

Traceback (most recent call last):
File "delaunay.py", line 13, in <module>
from ctypes_opencv import *
File "/Library/Python/2.7/site-packages/ctypes_opencv/__init__.py", line 18, in <module>
from ctypes_opencv.cxcore import *
File "/Library/Python/2.7/site-packages/ctypes_opencv/cxcore.py", line 80, in <module>
_cxDLL, _cvDLL, _hgDLL = detect_opencv()
File "/Library/Python/2.7/site-packages/ctypes_opencv/cxcore.py", line 58, in detect_opencv
cxDLL = cdll.LoadLibrary(find_lib(cxcore))
File "/Library/Python/2.7/site-packages/ctypes_opencv/cxcore.py", line 54, in find_lib
raise ImportError("OpenCVs shared library %s is not found. Make sure you have its path included in your PATH variable." % name)
ImportError: OpenCVs shared library cxcore is not found. Make sure you have its path included in your PATH variable.


Splendid, thank you, really. Got a hat and a whip and opened google. Everybody was suggesting to install macports. Im not saying its bad, I just dont feel comfortable using it. I tried once and it collided with other binaries - and Im using hombrew anyway (which do not install opencv).

Then Ive found that I need to add the local variables to the shell profile - which I did in all the possible permutation and variation. No luck. As many times (often on *.so hunt) I was looking for silly professors websites who uploaded their libraries (dylib or so). There was some - which partially solved my problem - generating new ones. (Btw Im sure a proper infosec admin would have died by seeing my negligence.)

Then you go to the source and try to act as ones in the "hacker" movies. Seemed it requires some files in the library source - which was interesting. Some existed, some didnt. I pulled up a Lubuntu and did the same install. Same issues.

That was several days of desperate self torture when I joined to the #python IRC room. A guy their mentioned he had to change distribution in order to make cv work. Marvelous. Then another guy (@Brend) was extremely helpful and took a look at the code and mentioned its really not likely I can make it work.

Thats the point when you close your eyes and kick a last one. And ... Ive met OpenCVWiki. You know the moment after dozen of circles in the dark forest you spot a new tree. I downloaded their package. It uses cmake, so I checked out what is that. Compile, copy the libs to /usr/lib. Nothing works. import cv says no module found. On my way out I tried one of their demo - and Jesus Christ it was running with my camera led turned on. Tada.wav.


What actually happened is that cv seems to be old-ish. And the latter I installed is using cv2. Which works just fine.

---

What is the lesson? I dont know, honestly. I aged 10 years thanks to my lack of knowledge. How could you get the answer the quickest? What would be your path to success in that case?

Peter

go to link download