469,608 Members | 2,668 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,608 developers. It's quick & easy.

Python and opencv

2
Hello,
I have just started working with opencv in python for my undergrad thesis. Im Trying to build a simple GUI which supports mouse inputs on an image. This is fairly simple in C and C++ , since there are tons of documentations for opencv funtions in that area.

Anyway here is the problem.

Im trying to create a mouse listener which is shown like this in the API
Expand|Select|Wrap|Line Numbers
  1. void cvSetMouseCallback( const char* window_name, CvMouseCallback on_mouse );
  2.  
  3. window_name
  4.     Name of the window. 
  5. on_mouse
  6.     Pointer to the function to be called every time mouse event occurs in the specified window. This function should be prototyped as
  7.  
  8.     void Foo(int event, int x, int y, int flags);
  9.  
  10.     where event is one of CV_EVENT_*
the problem in python is that there is no pointers so how can I give, the on_mouse handler function that I have written to the cvMouseHandlerCallback funtion as the param are not set.

when i give the function name I get the error:
> argument 2 of type 'CvMouseCallback'

and yes I know python is type free. Any Ideas???

Thanks.
Mar 17 '07 #1
3 10045
bartonc
6,596 Expert 4TB
Hello,
I have just started working with opencv in python for my undergrad thesis. Im Trying to build a simple GUI which supports mouse inputs on an image. This is fairly simple in C and C++ , since there are tons of documentations for opencv funtions in that area.

Anyway here is the problem.

Im trying to create a mouse listener which is shown like this in the API
Expand|Select|Wrap|Line Numbers
  1. void cvSetMouseCallback( const char* window_name, CvMouseCallback on_mouse );
  2.  
  3. window_name
  4.     Name of the window. 
  5. on_mouse
  6.     Pointer to the function to be called every time mouse event occurs in the specified window. This function should be prototyped as
  7.  
  8.     void Foo(int event, int x, int y, int flags);
  9.  
  10.     where event is one of CV_EVENT_*
the problem in python is that there is no pointers so how can I give, the on_mouse handler function that I have written to the cvMouseHandlerCallback funtion as the param are not set.

when i give the function name I get the error:
> argument 2 of type 'CvMouseCallback'

and yes I know python is type free. Any Ideas???

Thanks.
The ctypes module lets you do this freely. Some basics are here. This is standard in version 2.5 and I use it in 2.4.4.
Mar 17 '07 #2
bartonc
6,596 Expert 4TB
The ctypes module lets you do this freely. Some basics are here. This is standard in version 2.5 and I use it in 2.4.4.
SWIG (Simplified Wrapper and Interface Generator) is another very good tool for building a python interface to a C or C++ library. As long as you are comfortable with the learning curve of a new tool,
SWIG is a software development tool that connects programs written in C and C++ with a variety of high-level programming languages. SWIG is used with different types of languages including common scripting languages such as Perl, PHP, Python, Tcl, Ruby and PHP.
http://www.swig.org/
Mar 17 '07 #3
bartonc
6,596 Expert 4TB
SWIG (Simplified Wrapper and Interface Generator) is another very good tool for building a python interface to a C or C++ library. As long as you are comfortable with the learning curve of a new tool,http://www.swig.org/
For example, almost the entire wxPython package is generated from swig interface files (wxPython is the Python wrapper for wxWidgets and wxWindows, a very good crossplatform C++ Gui TooKit).
Mar 18 '07 #4

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

reply views Thread by Claudio Grondi | last post: by
2 posts views Thread by aneuryzma | last post: by
8 posts views Thread by J Kenneth King | last post: by
reply views Thread by JimPGH | last post: by
reply views Thread by katiezhu | last post: by
reply views Thread by guiromero | last post: by
reply views Thread by devrayhaan | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.