WorldViz User Forum

WorldViz User Forum (https://forum.worldviz.com/index.php)
-   Vizard (https://forum.worldviz.com/forumdisplay.php?f=17)
-   -   OpenCV in WorldViz (https://forum.worldviz.com/showthread.php?t=2536)

sircedric4 02-25-2010 06:10 AM

OpenCV in WorldViz
 
I am looking to use some of the face recognition and edge detection from OpenCV and am trying to get the python version to work inside WorldViz. Has anyone been able to get OpenCV working with WorldViz?

All the install guides I can find on the internet refer to Python 2.6 or greater and I know WorldViz uses Python 2.4. I've tried to perform the install stuff anyway, but haven't successfully been able to get WorldViz to recognize the dll's. I've had some troubles getting the latest OpenCV version to build which maybe part of the problem.

I am probably doing something wrong, I just want to know if anyone else has gotten it to work. If I know its possible, I can do reinstalls and maybe get new C++ compilers to make the wrappers. If the version differences won't let it work anyway I would like to know before going on a wild goose chase.

JimC 02-26-2010 08:12 AM

Not with Vizard, but I've used OpenCV 1.0 with Python 2.4...I could post the module & dlls somewhere if you want to try that.

I tried building 1.1 on Linux once--couldn't get the Python bindings to work & ended up going with the 1.0 binaries there as well.

nige777 03-01-2010 04:56 AM

Sorry for the blatant thread hi-jack :o , but this thread caught my eye. I would be VERY interested to try your compiled OpenCV modules etc. with Vizard and while I hope that Vizard will migrate to a later version of Python sooner or later (enabling the use of OpenCV 2.0) I cannot wait for that to happen. :rolleyes:

sircedric4 03-01-2010 05:50 AM

Like the poster above, I would also be interested in your OpenCV dll's. I am still trying to get OpenCV 2.0 to work in Vizard, but in the meantime if you have something that works from previous version I am definitely interested.

JimC 03-01-2010 12:35 PM

OK, I zipped the files I could find and put them at
https://netfiles.uiuc.edu/jimc/shared/pyOpenCV_py24.zip

I may have modified/broken a few of the samples...

nige777 03-02-2010 02:52 AM

:D Thank you very much, I am busy today so will look at this tomorrow

sircedric4 03-02-2010 07:19 AM

Thank you very much. I put the files in the directories you specified, though I put them in the appropriate place in the Vizard31 folder instead of Vizard30. I am trying to get the squares.py sample to work in Vizard and I get this error:

Traceback (most recent call last):
File "", line 11, in ?
File "squares.py", line 8, in ?
from opencv.cv import *
File "C:\Program Files\WorldViz\Vizard31\bin\lib\site-packages\opencv\__init__.py", line 55, in ?
from cv import *
File "C:\Program Files\WorldViz\Vizard31\bin\lib\site-packages\opencv\cv.py", line 5, in ?
import _cv
ImportError: DLL load failed: The specified module could not be found.

Do I have to do anything special to register the DLL's or am I missing one? Has anyone encountered this error message before?

JimC 03-02-2010 09:47 AM

Is there an _cv.pyd in site-packages/opencv? What is the value of sys.path?

sircedric4 03-02-2010 09:58 AM

There is a _cv.pyd in the site-packages\opencv path. I do not know what you mean by the value of sys.path.

If you are referring to the PATH environment variable in my Windows XP operating system. That value is:

Code:

%SystemRoot%\system32;%SystemRoot%;%SystemRoot%\System32\Wbem;C:\Program Files\Common Files\Roxio Shared\DLLShared\;C:\Program Files\Common Files\Roxio Shared\9.0\DLLShared\;C:\IFOR\WIN\BIN;C:\IFOR\WIN\BIN\EN_US;C:\Program Files\QuickTime\QTSystem\;C:\Program Files\Windows Imaging\;%OSG_BIN_PATH%;%OSG_SAMPLES_PATH%;C:\WINDOWS\system32\WindowsPowerShell\v1.0;C:\Program Files\IDS\uEye\GenICam\bin\win32_i86; C:\Program Files\OpenCv\bin;C:\Program Files\CMake 2.8\bin;  C:\OpenCV2.0\VS2005\bin\debug; C:\OpenCV2.0\VS2005\bin\release; C:\OPenCv2.0\bin
I guess its possible the OpenCV2.0 installation I have is interfereing somehow with the OpenCV 1.0 download?

JimC 03-02-2010 11:04 AM

In your script (or at the Vizard Python prompt) type:

import sys
print sys.path

That will tell you where it's looking for modules.

JimC 03-02-2010 11:17 AM

Never mind. I tried it myself and got the same error. When I copied the dlls into the site-packages/opencv directory it went away.

sircedric4 03-02-2010 11:29 AM

Sweet! Thanks a lot. That did the trick. Now I can play with some of these OpenCV functions.

sircedric4 03-08-2010 08:35 AM

I just got finished trying the capture-cam.py example and got a runtime error. When I ran it, it first prompted me to select a web camera and then when it tried to run it gave the following error:

Code:

Microsoft Visual C++ Runtime Library
Runtime Error!

Program: C:\program files\WorldViz\Vizard31\bin\winviz.exe

This application has requested the Runtime to terminate it in an unusual way.  Please contact the application's support team for more information.

I would like to marry the capturing of a video camera with the square detection of squares.py. Does anyone know what runtime error it is running into. It looks like it is getting hung up on:

Code:

# get size of the frame
    frame_size = cv.cvGetSize (frame)


JimC 03-09-2010 08:01 AM

It works for me in Vizard (with a Logitech QuickCam). A camera driver issue? What do you get if you print type(frame) just before the crash?

nige777 03-09-2010 09:13 AM

:d
 
Thanks for the upload - really appreciate it & once I can work out how to use vizards window instead of highGUI's i'll be flying! :)

Just one odd thing though, when I try to run the kalman example I get this error message:

Traceback (most recent call last):
File "", line11, in ?
File "kalman.py", line 35, in ?
kalman.transition_matrix[:] = A;
File "C:\Program Files\Worldviz\Vizard30\bin\lib\site-packages\opencv\cv.py", line 1944, in __setitem__
return _cv.CvMat__setitem__(*args)
RuntimeError: openCV Error:
Status=Sizes of input arguments do not match
function name=cvConvertScale
error message=
file_name=C:\User\VP\opencv\cxcore\src\cxconvert.c pp
line=1600

Any idea's because I'm fresh out of them? :confused:

Thanks

JimC 03-09-2010 09:29 AM

Code:

return _cv.CvMat__setitem__(*args)
RuntimeError: openCV Error:
Status=Sizes of input arguments do not match

My guess would be to try looping through the two arrays and setting corresponding elements one at a time rather than trying to set the whole thing at once, e.g.:

Code:

for i in range(2):
  for j in range(2):
    transition_matrix[i][j] = A[i][j]


sircedric4 03-09-2010 10:33 AM

Quote:

Originally Posted by JimC (Post 9542)
It works for me in Vizard (with a Logitech QuickCam). A camera driver issue? What do you get if you print type(frame) just before the crash?

I get .

It would be nice if I could get the openCV camera frame capture stuff to work. I tried incorporating the Vizard (vizcapture) function into squares using the Vizard webcam capabilities and I have not found a means to convert the image from the vizcapture screen buffer into an IPLImage for openCV. I have tried a straight convert and also used adapter.py to try and convert the images, but apparantly there was an error in OpenCV 1.0 when moving from a PIL or other image type to IPLImage.

I have grown tired of going the viz cam route and am back onto trying to get the OpenCV camera handler to work, so any ideas you have I will entertain. I'll try and play with drivers and stuff and let you know how it goes. I have more than one camera plugged in right now, I'll pull those and see if they're causing conflicts.

nige777 03-10-2010 05:52 AM

Thank you
 
:) Thanks you very much that worked perfectly.

Now I, like the original poster, just need to sort a method for converting frame buffer images to IPLImage!!

Came across this -

http://www.depthfirstsearch.net/blog...cv-and-python/

- which seems to address this prob however I am unable to utilize this at the moment due to my severe lack of C or C++ know-how. Any windows/C++ wizards out there who could help?

sircedric4 03-10-2010 06:40 AM

Quote:

Originally Posted by nige777 (Post 9549)
:) Thanks you very much that worked perfectly.

Now I, like the original poster, just need to sort a method for converting frame buffer images to IPLImage!!

Came across this -

http://www.depthfirstsearch.net/blog...cv-and-python/

- which seems to address this prob however I am unable to utilize this at the moment due to my severe lack of C or C++ know-how. Any windows/C++ wizards out there who could help?

I am still trying to find a better way to do the conversion myself, but in the meantime I was able to get something to "work" using the actual screen capture and file save capability in Vizard.

I used the viztask schedule capability and basically saved each image to a bitmap and then loaded the bitmaps into the squares example. It is slow, only average 2 -3 frames per second which doesn't work for me, but might work for your application. I am attaching the code I used in squares for you to look at. Maybe it'll help you.

Like, you I found that same link that might address the problem but I couldn't figure out how to do anything with it. I do know C++, but only as a language. Getting all the plugins, modules, and runtime environments setup is beyond my capability. I'd kill for some sort of class to attend that would cover all the setup stuff that people assume you know just because you know a language.

Code:

def SquareIt():
        global img, storage

        while True:
                name = 'C:/DK Files/OpenCV Learn/test1.bmp'
                yield viz.window.screenCapture(name)
#
                # create memory storage that will contain all the dynamic data
                storage = cvCreateMemStorage(0);
                img0 = cvLoadImage( name, 1 );
                if not img0:
                        print "Couldn't load %s" % name
                img = cvCloneImage( img0 );
                # force the image processing
                on_trackbar(0);
                # Also the function cvWaitKey takes care of event processing
                cvWaitKey(5);
                        # clear memory storage - reset free space position
                cvClearMemStorage( storage );

t = viztask.schedule( SquareIt() )
vizact.onkeyup('s',t.kill)


JimC 03-10-2010 09:38 AM

Yes, figuring out how to build complex C/C++ projects is a hideous nightmare, particularly on Windows with its plethora of compilers. That's why sane people prefer Python. ;)

You might have a look at ctypes_opencv. It's not intended for Python 2.4, but as it's pure python code it might be made to work. Requires the ctypes module, and there are quite a few lines of the form:

Code:

min_val_p = c_double() if min_val is True else min_val
that need to be converted to e.g.:
Code:

if min_val is True:
  min_val_p = c_double()
else:
  min_val_p = min_val

Those are the difficulties that appear right off the bat, anyway... :p

JimC 03-10-2010 09:48 AM

Quote:

You might have a look at ctypes_opencv. It's not intended for Python 2.4, but as it's pure python code it might be made to work.
Sorry, that was perhaps not clear. It's still a wrapper around the C dlls, but ctypes allows you to write the wrapper directly in Python rather than in some C-like (SWIG) or C++-like (SIP) dialect...If the problem is in the original pyopencv wrapper code, then this might provide a workaround...

JimC 03-10-2010 10:56 AM

OK, I got interested and got it to work (at least, I got capture-cam and a couple others to run). Download. The src/ctypes_opencv folder goes in Vizard's site-packages directory, there's also a folder of modified demos (I assume the syntax is a bit different). Let me know if the PIL conversion works...

nige777 03-11-2010 04:12 AM

Wow, you really are the man :D. I'm itching to try this out - will report back as soon as I have.

JimC 03-11-2010 12:32 PM

I wrote to the author of ctypes-opencv and ended up applying the fixes to the bleeding-edge version and mailing that to him. Interestingly, it looked like there might be some code added to the bleeding-edge version relevant to exactly the problem you've been writing about, so you might want to look at that. It's here.

nige777 03-12-2010 04:54 AM

:D Thank you so much for all of your time on this.

I'm tied up playing with kalman filters for the weekend so haven't had time for a proper test - however i have quickly run a couple of the demos which while they seem to work there is a complaint:
Code:

no functools support
a module which I know made an appearance in 2.5 - so I'm presuming that this rules out this fix, or am I wrong on that?

JimC 03-12-2010 06:33 AM

That's just a warning. AFAIK, all functools is used for is to fix the docstring of a single decorated function, so just ignore it.

nige777 03-12-2010 06:42 AM

:D Thats great news, thanks for the reply.
As my background is in CAD&3d modelling not in computer science there is alot of incidental knowledge that I miss - :o


All times are GMT -7. The time now is 10:16 AM.

Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Copyright 2002-2023 WorldViz LLC