473,499 Members | 1,672 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Python and opencv

2 New Member
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 10407
bartonc
6,596 Recognized Expert Expert
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 Recognized Expert Expert
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 Recognized Expert Expert
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

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

Similar topics

0
4645
by: Claudio Grondi | last post by:
What is the current status of Python OpenCV interface i.e. the opencv module? \OpenCV\samples\python\contours.py gives following ERROR: OpenCV Python version of contours Traceback (most recent...
1
2803
by: Claudio Grondi | last post by:
OpenCV means Intel® Open Source Computer Vision Library. It is a collection of C functions and a few C++ classes that implement some popular Image Processing and Computer Vision algorithms. OpenCV...
0
1278
by: Peter Otten | last post by:
QOTW: "If you can find a workable solution not involving metaclasses and decorators, don't use them" - Michele Simionato "Newest Beautiful Soup beta solves everyone's problems that I know of." -...
0
3315
by: mkd | last post by:
Hi there To compile opencv I need to use: g++ `pkg-config --cflags opencv` -o face face.c `pkg-config --libs opencv` Now I want to compile in KDevelop, but it chooses gcc instead Does...
1
1617
by: Mark Asbach | last post by:
Hi pythonians, I'm one of the maintainers of an open source image processing toolkit (OpenCV) and responsible for parts of the autotools setup. The package mainly consists of four shared...
2
2356
by: aneuryzma | last post by:
Hi guys, I'm doing a project with both ogre3d and openCV and now I have to merge the code. I have 2 Visual C++ solutions and either of them has his own configuration. Can you give me some...
8
1671
by: J Kenneth King | last post by:
Hey everyone, I'm working on a python extension wrapper around Rob Hess' implementation of a SIFT feature detector. I'm working on a computer-vision based project that requires interfacing with...
0
2048
by: JimPGH | last post by:
I am trying to use the OpenCV cvFitLine() function using the Python SWIG interface to OpenCV. My problem has to do with the fact that the last argument is a pointer to an array of four floats (to...
0
3078
by: katiezhu | last post by:
I'm working a project. It's about screen control. I write the program using c/c++ in visual studio 2008. I just use my hand to replace mouse to control screen. The code is given below: //Must...
0
7131
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7007
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7174
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
5470
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
4919
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4600
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3099
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
1
665
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
297
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.