Record mouse position with dlib - c++

I am trying to draw a rectangle on screen with dlib. Does anyone know which object provides methods for recording mouse clicks/mouse position on a dlib window?

Take a look at drawable.h and see if it is what you are looking for, here's an example from the official documentation: http://dlib.net/dlib/gui_widgets/drawable.h.html.

Related

How to draw multiple circle shape in SFML

i really want to know how to create a multiple circle shapes in SFML.
I know we can create the circle shape with sf::CircleShape
I want to create a circle shape with the same radius everytime i click on my screen and i have no idea how to do that, please help me.
You need to use an event loop to capture mouse events and any other event for that matter. See https://www.sfml-dev.org/tutorials/2.0/window-events.php for details.
Read the documentation or search via Google for more.

Hide mouse cursor in OpenCV

I need to hide the cross-shaped cursor that OpenCV shows when moving the mouse over an image window. Does anybody know if it is possible?
I wanted to add a screenshot, but unfortunately the mouse cursor is not shown in screenshots.
Thanks!
I don't think it's possible with only OpenCV, you have to use OS API or eventually you may use QT(http://www.codeprogress.com/cpp/libraries/qt/QtHideMouseCursor.php#.UjGpZD-rGoE) - it's quite easy to use it with OpenCV.

gtk+ Image draw over image in c++

I would like to draw a simple (red) line over an image with gtkmm (in c++).
I have the image : Gtk::Image *image which is displayed in my window.
But I would like the line to change of position (I mean : draw another line) when a function is called. I need your help because I didn't find how to draw over an existing image...
Thank you for your help !
EDIT : A solution for me would be to overlay the image by an image with alpha channel... but I don't know how to to that :-/
You should not actually draw in the image, instead you draw in the window.
First put the image in the window (blitting or some other means) then draw the line.
See e.g. this link on how to draw straight lines.
Connect to the "expose-event" (GTK2) or "draw" (GTK3) signal of the GtkImage. I think you should use the C++ equivalent of g_signal_connect_after (which in in GObject), and not the g_signal_connect one, so you get a chance of drawing after the image has been drawn, so your drawing is on top of it. To draw you need to use cairomm, and Joachim already gave you a link to a cairomm tutorial.

How to control a button using motion in opencv?

I want to control a button using hand motions. For example, in a video frame I create a circle-shaped button. Then when I move my hand to that circle I want to play an mp3 file, and when I move my hand to another circle the mp3 song stops playing. How can I do this?
i am working in windows7 OS and i use microsoft visual studio 2008 for work...
You have infinite options to do that. Probably the easiest is trying to do background segmentation and then check if there's anything which is not background that overlaps with the button area. It would work with any part of your body, not only your hands, but that might not be an issue.
Another option would be to try to detect and track your hands based on skin color. For this you need to obtain an histogram of the skin color and then use it with the camshift tracker. A nice way to obtain the skin color on runtime would be running a face detector (haarcascade) and getting the color from the detected region.
I'm sure there are hundreds of additional ways to do it.
Also, if you can get your hands on a Kinect camera it could help a lot. Check OpenNI and the MS Kinect SDK to see what it enables you to do.
The first thing you will have to do is create a haar cascade xml file and train it on human hands.

Function to retrieve the size of an element

What I need is a function to retrieve the size of an element, be it a Java Applet window in a browser, text boxes in programs, applications window and so on.
Now I don't know what this kind of function is called, but I uploaded an example from an application that had that functionality.
Example (The red box)
What I need to be able to with this is get its size and its coordinates on the screen. This needs to be in C++.
So ff anyone could give an example, or atleast the name of that kind of function, I would be grateful.
I found a program that has the function I seek: It is called Scar Divi, which is a scriptable tool to perform repetitive actions, mostly uses for cheating in a game called Runescape it seems. Unfortunately it is closed source.
Are you looking for Window Geometry or desktop widget?
After getting an image of the screen (there will be somethign in Qt to do this)
You need an image processing library like openCV to find the rectangle - look for "Hough Transform"
I found the solution!
POINT p;
HWND wnd;
RECT rec;
GetCursorPos(&p);
wnd = WindowFromPoint(p);
GetWindowRect(wnd, &rec);
This will give you the coordinates for the box (extract from rec).