Python and opencv

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • jlark
    New Member
    • Mar 2007
    • 2

    Python and opencv

    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
    Code:
    void cvSetMouseCallback( const char* window_name, CvMouseCallback on_mouse );
    
    window_name
        Name of the window. 
    on_mouse
        Pointer to the function to be called every time mouse event occurs in the specified window. This function should be prototyped as
    
        void Foo(int event, int x, int y, int flags);
    
        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 cvMouseHandlerC allback funtion as the param are not set.

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

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

    Thanks.
  • bartonc
    Recognized Expert Expert
    • Sep 2006
    • 6478

    #2
    Originally posted by jlark
    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
    Code:
    void cvSetMouseCallback( const char* window_name, CvMouseCallback on_mouse );
    
    window_name
        Name of the window. 
    on_mouse
        Pointer to the function to be called every time mouse event occurs in the specified window. This function should be prototyped as
    
        void Foo(int event, int x, int y, int flags);
    
        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 cvMouseHandlerC allback funtion as the param are not set.

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

    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.

    Comment

    • bartonc
      Recognized Expert Expert
      • Sep 2006
      • 6478

      #3
      Originally posted by bartonc
      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,
      Originally posted by swig.org
      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/

      Comment

      • bartonc
        Recognized Expert Expert
        • Sep 2006
        • 6478

        #4
        Originally posted by bartonc
        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).

        Comment

        Working...