Click here to Skip to main content
15,883,765 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Whats the best way to make a crosshair that is bounded by the size of the image box it is on top of? Its will be moved using a joystick. Its for the HUD of an ROV im working on. The crosshair needs to be able to return an x and y coordinate and its location to be determined by the joystick x and y axis value scaled to the size of the 640x480 pixel emguCV image box. Any ideas of how to approach this? I got the joystick part down but I don't know what to use as the crosshair...

PS - EmguCV is an openCV library for C# and it is used in computer vision. The EmguCV image box is optimized for video playback.
Posted
Updated 29-Sep-11 8:32am
v4

1 solution

I happened to give some answers based on my joystick experience recently. It is not very trivial matter.

Please look at them:
How to Interface Joystick to WAF[^],
How to Interface Joystick[^],
Creating A Joystick Event?[^].

Not everything is exactly relevant to your problem but very similar. Please learn my answers first and later ask me your follow-up questions if you need to.

Cheers,
—SA
 
Share this answer
 
Comments
scocioba 6-Jul-11 15:57pm    
The interfacing is not the issue, but thank you very much for the references. The main question is what should i use as a "crosshair" that can be moved around in a windows form using a joystick. All the hardware stuff was handled using direct input but im not sure if i should use a small panel, a picture box. I hope this clarifies that i need to figure out what to use as the crosshair itself.
Sergey Alexandrovich Kryukov 8-Jul-11 0:41am    
OK, what to use for this UI element is more or less clear and depends what library do you use. WPF, Forms? I don't know what's emguCV. Please make it clear. You say "picture box" -- does it mean System.Windows.Forms.PictureBox?

What exactly is the purpose of control under the cross hair? What do you want to show there? This is the most important question.

I can give you a hint in advance: it you use PictureBox -- in 99% cases you don't really need it -- it does not help. However, you need to explain what graphics you need to show. Also, is there any interaction with the regular mouse -- does it do something (such as dragging)?
--SA
scocioba 11-Jul-11 13:21pm    
Sorry for the confusion. Alright so I simply want to move a red dot from the middle of an EmguCV image box which is optimized for displaying camera capture video feed. This control is similar to a picture box from windows forms. This red dot is a crosshair which does not need to be more than a simple small red dot that is larger than a few pixels. It will be controlled by a joystick which is already coded. I just want to know what windows forms control i should use as the crosshair itself. I dont want the dot to be part of the video feed itself (like making the center pixels red). The dot will be the direction in which the four thrusters of my underwater robot will move to produce a heading in the direction and angle given by the dot. The dead zone of the joystick will be the emguCV image boxes width/2 and height/2. The coordinates I will give this control will be with respect to the main window. Another question would be how to bind the crosshair to the video feed image box. The crosshair does not need to be a control, I just think that adding an ellispe to the video feed and then having it relocate when the joystick is moved would be too time consuming as opposed to just moving a small panel via the joystick to the position indicated by the joy stick x and y axis and then setting the x and y coordinates of the crosshair to the direction of the robot via some matrix algebra. Again my apologies for the confusion and thank you for your input and patience.
Sergey Alexandrovich Kryukov 14-Jul-11 23:09pm    
Short answer is: if your have video image in some control and want to show some control in foreground, GDI (GDI+) is a very bad help: it won't show. You will need DirectX overlay manager. This is boring and more complex task. That's what happens if you use Forms. As Forms use GDI+ and not DirectX, Forms is poorly suitable for the task.

In contrast, WPF is based on ActiveX and in fact has almost nothing to do with Windows. You can overlay anything over anything, including Video without any tricks. I actually developed things this way and tested all that -- it works flawlessly.

If by some reason you cannot do WPF (again, I highly recommend it for your application; why would you torture yourself with Forms and overlays?), there is a simple and limited work-around. You can build a cross-hair as two thin panels: vertical and horizontal. I would make each panel 3-pixel wide (another one -- of 3-pixel height), like black line -- white like -- blank line (or visa versa), otherwise the line would be masked by dark or light color of the video.

--SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900