LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

convert mouse position to image position

Using a zoomed IMAQ image in an image control, I want to recover the position of the mouse in the co-ords of the underlying image. LastMousePositionX (and Y) give the info I want but they are one click in the past and not the current position. Amazingly, there doesn't appear to be an equivalent CurrentMousePositionX. I can't seem to find the info I need to do the conversion manually. The mousedown event returns the current mouse position and I can get the position in the image container by subtracting off its left and top position. But to convert this to the image position I need to know both the zoom and where the images origin is relative to what is displayed. I can't seem to find that origin position in the list of property nodes. The only thing I can seem to come up with is to extract the info from teh image information string, but this seems like an incredibly poor way to extract such obvious information - espeically since the info must be calculated to put in the string anyway. Can anyone help with this?
0 Kudos
Message 1 of 8
(5,299 Views)

I don't know about the IMAQ image control, but the 2D Picture control has a Mouse property, which gives the current X and Y position of the mouse. Could you place a transparent Picture on top of your image control and use the coordinates that way?

 

Robot Happy

National Instruments
LabVIEW
Certified Developer
0 Kudos
Message 2 of 8
(5,287 Views)
CurrentX and Y work if the whole image is displayed. I've used that before. The advantage (and problem) of the image control is tha you can zoom and pan arbitrarily. The CurrentX and Y give you position in the window. To convert that to co-rods in the image you need both zoom and the location of the origin of the IMAQ image relative to the origin of the image control. I don't know how to get that last piece of info.
0 Kudos
Message 3 of 8
(5,279 Views)

Hi,

 

I am confused why you get the mouse position one click in the past because it seems to work ok for me. I've had to use four of the image properties to recreate the effect using the mousemove event, but this seems to give the same values as the Last Mouse Position property so I think it does what you want. I couldn't see an origin property so I did the conversion using the position given at the image center. I wanted to post a snippet here but I'm new to posting and couldn't seem to get it to work for the whole block diagram, so I'm using a screenshot instead. I hope this helps in some way.

 

Will

 

image position.png

Message 4 of 8
(5,258 Views)

 


@Polyphemus wrote:
[...] get the mouse position one click in the past [...]


 

 

To avoid this time-lag I guess you are supposed to force the event structure do run once, without a user triggered event; therefore you can use the property node "value" and "value signalling (SGL)"

in the time-out frame of the event structure

 

 

2013-04-30_refresh.png

 

Unfortunately I can't test this with your code as I don't have IMAQ on this PC.

 

0 Kudos
Message 5 of 8
(5,251 Views)

I suspect that because you are using mouse move, which is constantly updating, last mouse position works reasonably well. I'm using mouse down, as I only want things to happen when I click and last mouse position definitely gives me where the mouse was when I last clicked. I'm marking a grid and it is definitely the previous grid point that last mouse position returns. On the plus side, image centre does seem to return the point of the larger underlying image at the display centre, so using that I could figure out where in the larger image I'm working. That's somewhat nicer than getting the co-ords from the image information string and converting them, which is what I was reduced to doing. I still don't see why there isn't a current mouse position feature that gives co-ords in terms of the underlying image as last mouse position does.

 

Another little item that isn't clear to me is why the underlying IMAQ image lists mouse operations under its events. They don't fire when you are working on the displayed image.

 

Finally, I discovered the hard way that the mouse events still fire even when you are over the ROI toolbox, so clicking to change a tool causes the mouse down event to fire. Dumb! Fortunately easy ro fix by checking whether the mouse is inside the dispaly area, but still dumb.

0 Kudos
Message 6 of 8
(5,233 Views)

@Greg_at_NI wrote:

I don't know about the IMAQ image control, but the 2D Picture control has a Mouse property, which gives the current X and Y position of the mouse. Could you place a transparent Picture on top of your image control and use the coordinates that way?

 

Robot Happy


"place a transparent Picture on top of your image control"but how?

0 Kudos
Message 7 of 8
(5,103 Views)

@cathy345 wrote:

"place a transparent Picture on top of your image control"but how?


hi,

I would do this:

 

1# right-click frontpanel>modern>graph>elements>2d picture

0.PNG

 

2# tools palette>brush-tool>transparent color

1.png

 

 

there's also this entry in the online-help

 

http://zone.ni.com/reference/en-XX/help/371361K-01/lvhowto/creating_transparent_objec/

 

 

 

Regards,
Alex

0 Kudos
Message 8 of 8
(5,071 Views)