LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Drawing a selection rectangle over an image

Solved!
Go to solution

Hello, this is my first time on labview and i have to make a program where i can draw a rectangle over an image which i choose from my files with a file dialog and save the x1,y1,x2 and y2 coordinates.

I did this code but it has two drawback first the screen flash when you move the mouse because the image get reprinted everytime, and also for some reason the picture control is 1600x900 but when i draw on it, it is 1672x936 and so my rectangle is drawn for the 1600x900 size so it's smaller then how it should compared to the image which get printed at 1672x936.

Also the rectangle is made to be drawn with dash but when i run it, it draw a solid line.

 

Capture d'écran 2026-10-22 154346.png

Thanks very much for any response and sorry for my terrible english

0 Kudos
Message 1 of 26
(2,238 Views)

Hello,

 

To avoid the flash, you can uncheck the "Erase first" property of the "image carte" indicator on the Front Panel :

 

PinguX_0-1792677455399.png


For the position and size problem, be careful not to mix : position on monitor, position on front panel, position on indicator.

These are three different things that can lead to headaches if you try to fight them blindly.

Message 2 of 26
(2,215 Views)
Solution
Accepted by topic author Timfromcofidur

The code you are showing is highly flawed. Why is there a sequence? Where is the top-level loop? (I hope you are not using "continuous run" mode! 😮 )

 

To draw on a picture indicator with the mouse, you can use an event structure and get the image coordinates.

 

To get you started, look at my 20+(!!) year old example here. It would be easy to modify for your requirements.

 

altenbach_0-1792683629468.png

 

 

Feel free to attach your code so we give more specific advice. Also make sure to enable "smooth updates" in the picture display. If the picture is too big for the display, you can modify the zoom factor and adjust accordingly.

 

On a related note, please vote for my idea here!

Message 3 of 26
(2,178 Views)

@altenbach wrote:

The code you are showing is highly flawed. Why is there a sequence? Where is the top-level loop? (I hope you are not using "continuous run" mode! 😮 )

 

To draw on a picture indicator with the mouse, you can use an event structure and get the image coordinates.

 

To get you started, look at my 20+(!!) year old example here. It would be easy to modify for your requirements.

 

altenbach_0-1792683629468.png

 

 

Feel free to attach your code so we give more specific advice. Also make sure to enable "smooth updates" in the picture display. If the picture is too big for the display, you can modify the zoom factor and adjust accordingly.

 

On a related note, please vote for my idea here!


Nice.

Here's a sub VI based on that.

Download All
Message 4 of 26
(2,124 Views)

Thanks for everyone answer, i didn't tought anyone would answer

i'll link my .vi so you can understand more how it works but it's very unfinished and bad, i fixed the blinking, tho the coordinates are still not perfect

I will have to divide it into multiple sub-vi i think for my main program, maybe i will try the ImageSubset.vi example but mine kinda work for what i need and imagesubset is confusing me so much.

0 Kudos
Message 5 of 26
(2,093 Views)

@Timfromcofidur wrote:

Thanks for everyone answer, i didn't tought anyone would answer

i'll link my .vi so you can understand more how it works but it's very unfinished and bad, i fixed the blinking, tho the coordinates are still not perfect

I will have to divide it into multiple sub-vi i think for my main program, maybe i will try the ImageSubset.vi example but mine kinda work for what i need and imagesubset is confusing me so much.


Yikes!  That's not serviceable.  I suggest that you learn good coding practices, then start over.

0 Kudos
Message 6 of 26
(2,033 Views)

where can i find good coding practices tho ?

0 Kudos
Message 7 of 26
(1,885 Views)

Hi Tim,

 


@Timfromcofidur wrote:

where can i find good coding practices tho ?


  • There is a LabVIEW help, with lots of "Concepts" and "How Tos". And it includes a "Style Guidlines" section!
  • You might learn from all those example VIs and projects found in the LabVIEW ExampleFinder…
Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 8 of 26
(1,879 Views)

thx for the ressources.

 

Last question, I used the vi from altenbach, it work well, but i can't manage to do it twice, on the same image.

I need the vi to first make the rectangle and trim the image around it, and then make again a rectangle and save the x,y coordinates

0 Kudos
Message 9 of 26
(1,865 Views)

@Timfromcofidur wrote:

thx for the ressources.

 

Last question, I used the vi from altenbach, it work well, but i can't manage to do it twice, on the same image.

I need the vi to first make the rectangle and trim the image around it, and then make again a rectangle and save the x,y coordinates


Once you do a "save for previous" (LabVIEW 2020 or below) and attach it again, i will be able to look at your program and help.

0 Kudos
Message 10 of 26
(1,815 Views)