04-14-2009 08:30 AM - edited 04-14-2009 08:34 AM
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.
Solved! Go to Solution.
04-14-2009 09:05 AM
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
04-14-2009 09:14 AM
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.
04-16-2009 09:08 AM
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
04-16-2009 11:54 AM
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.
05-05-2009 03:40 AM
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,
10-19-2009 10:26 PM
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
10-23-2009 08:49 AM
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,
10-26-2009 05:27 AM
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.
Actually, besides using the property/invoke node, there is another method of getting coordinates
see in this attached vi
11-04-2011 10:00 AM
Hello! I have another solution -I think it's more intuitive.