473,715 Members | 2,860 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 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.
Mar 17 '07 #1
3 10422
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 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.
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
4665
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 call last): File "\OpenCV\samples\python\contours.py", line 6, in ? from opencv import cv ImportError: No module named opencv
1
2812
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 library is mainly aimed at real time computer vision. Some example areas would be Human-Computer Interaction (HCI); Object Identification, Segmentation and Recognition; Face Recognition; Gesture Recognition; Motion Tracking, Ego Motion, Motion...
0
1296
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." - Leonard Richardson Jeff Croft gives a good introduction to the Django web framework. Don't let the "for non-programmers" tag deter you. http://www2.jeffcroft.com/2006/may/02/django-non-programmers/
0
3351
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 anyone know, how to change the compiler used by KDevelop ?
1
1630
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 libraries but is accompanied by a python package containing some pure python code and of course extension modules for the four libraries. Now during the last month we were preparing a major release which means testing, fixing, testing, fixing, ... in...
2
2375
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 suggestion on how to merge the two solutions and use both libraries together ? thanks!
8
1681
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 Python at the higher layers, so I figured the best way to handle this would be in C (since my initial implementation in python was ungodly and slow). I can get distutils to compile the extension and install it in the python path, but when I go...
0
2054
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 return the fitted line parameters). My first mindless attempt looked like this: line = cv.cvFitLine(img, cv.CV_DIST_L2, 0, 0.01, 0.01, line) This produced the error: After googling around bit, I decided that ctypes would give me the array...
0
3105
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 have the following line for console mode #include "stdafx.h" #include <stdlib.h> #include <stdio.h> #include <math.h> #include <conio.h> #include <cv.h>
0
8821
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9340
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9196
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9103
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7973
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6646
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4477
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
3175
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2118
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.