LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Using mouse click to return image coordinates.

Solved!
Go to solution

Ok so I've been trying to figure out how to do this and it seems very complicated for something that really seems straightforward.

 

Anyway. I have a camera that updates an image object on the front panel using a while loop. I have another image object that is updated with a still image when the "snap" button is pressed. Now what I want to do is to click on a point in the snapped image and have the VI return the coordinates of that pixel in the image coordinate frame.

 

What I've got so far is an event structure in the while loop with the following to occur in the event "image object -> mouse down":

 

Server reference (reference to the image object) -> Property node (last mouse position) -> output screen coordinates.

 

I've got two errors that don't make a whole lot of sense to me (I haven't worked with event structures before): "event data node contains unwired or bad terminal" and "event structure one or more event cases have no events defined". This second one seems strange since I don't actually want anything to happen if there's no mouse click. The first one seems to refer to the element box on the left hand side of the event structure.

 

The above is my lastest attmpt at sorting this problem and as far as I can see it should work. whatever about the errors, am I even taking the right approach with this? I'd have thought image cordinates would be a common enough thing but search the boards here, it would appear not...

 

Kinda stumped here. Any help is much appreciated.

Message Edited by RoBoTzRaWsUm on 04-14-2009 08:34 AM
0 Kudos
Message 1 of 10
(12,182 Views)

Hi RoBoTzRaW...,

are there any empty event cases? Do you have some inputs on the right hand side? Are some terminals on the left hand side black?

It would be easier to help if you upload your vi.

 

Mike

0 Kudos
Message 2 of 10
(12,170 Views)

I've just got the one event. IE. if the mouse is clicked do this, otherwies do nothing...

 

I've attached the VI anyway. By the way, I lied. I actually have 2 cameras but if I can get this working for one I can do it for the other.

 

Thanks.

0 Kudos
Message 3 of 10
(12,167 Views)
Solution
Accepted by topic author RoBoTzRaWsUm

Hello RoBoTzRaWsUm,

 

I have taken a look at your VI, which has been taking a correct approach to the data you are looking for.  As you are using and event structure, you should be looking for an event to occur.  When using a Property Node, you are trying read an attribute of a control.  However, in an Event Structure, I believe you should be using an Invoke Node.  An Invoke Node allows your to read an event or write a method with the Control Class in LabVIEW. 

 

1. Place down and Invoke Node from the Functions Palette in 'Programming'->'Application Control'

2. Wire your Image Control reference to it

3. Click Method, and select 'Get Last Event'

4. Right click on 'Which Events' and 'Create Constant'.  Make the constant '1' in the array

5. Read the 'Coordinates' Cluster from the left hand side of the Event Case by right clicking  and 'Create Indicator'

 

You will find a piece of example code attached.

 

Regards

George T.
Senior Applications Engineer
National Instruments UK and Ireland
Message 4 of 10
(12,129 Views)

OK so I'm almost there. I developed this on a bit further and got it working with the property node. I just tried it with an invoke node as per gt3G's instructions and got the same result, albeit it in an array (which is actually more useful for me). What's happenning is this. I hit 'snap' and the current frame is sent to the snap image object. I then click on a point in that image and the pixel coordinates are output (using either property or invoke node). This is great but as soon as I click that point the snap image object updates to the most current frame. It also updates if I resize or minimise then maximise the screen. This is a problem because I will eventually want to pick out four points in an image and get their coordinates. In other words I want the image object to update ONLY when I click on 'snap'. Is it possible to do this without writing/reading to an image file or is that just the nature of the image object?

 

 

Thanks.

 

 

PS. I'm running v8.2 so I couldn't actually open that VI.

0 Kudos
Message 5 of 10
(12,116 Views)

Hello RoBoTzRaWsUm,

 

I am glad to see that the Invoke Node suggestion worked for you.  I believe the next image is displayed on your Front Panel because you are asking the Event Structure to hold the Loop until the Click Event.  When you click, the Loop Iterates, and the next image is acquired, because that is how you programmed it.  You can try and confirm this by wiring and indicator to the Loops interation counter 'i'. 

 

To use the previous frame, I believe you can right click on the Tunnel with your picture reference, and then select 'Add Shift Register'.  This will allow you to work with the previous image several times.  I haven not tried this with your own VI, but I believe it will lead you to the solution you are looking for.  I have attached the previous VI I had made, now for LabVIEW 8.2. 

 

Regards,

George T.
Senior Applications Engineer
National Instruments UK and Ireland
0 Kudos
Message 6 of 10
(11,979 Views)

Hello,

 

I tried to study the structure, and i can't define how to fix the error and warning of the attached examples.

Why is that happen and what to do for fix it?

 

Thanks

 

uk.PNG

0 Kudos
Message 7 of 10
(11,571 Views)

Hello suffyzull,

 

The error codes you are seeing are all related to the Invoke Node inside of the Block Diagram.  It looks like the reference being passed is incorrect.  However, it is important to note that the Invoke Node is not required to get the coordinates.  That was just how I edited the VI and reposted it.  I have attached an update version of the VI that does not include the Invoke note, and still works. 

 

The link below has a further example submitted by another user, returning the coordinates of your mouse.  It is from www.ni.com/community.

 

http://decibel.ni.com/content/docs/DOC-2272

 

Regards,

 

 

George T.
Senior Applications Engineer
National Instruments UK and Ireland
0 Kudos
Message 8 of 10
(11,511 Views)

 


RoBoTzRaWsUm wrote :

 

 

Now what I want to do is to click on a point in the snapped image and have the VI return the coordinates of that pixel in the image coordinate frame.

 

 


Hi, from this line i understand that you just need the coordinates of the pixel you click on, right?

 

Actually, besides using the property/invoke node, there is another method of getting coordinates

 

see in this attached vi

Somil Gautam
Think Weird
0 Kudos
Message 9 of 10
(11,487 Views)

Hello! I have another solution -I think it's more intuitive.

Message 10 of 10
(10,249 Views)