LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How to Save and Load ROIs?

Solved!
Go to solution

Hi, 

 

I'm not experienced with Labview, and need help to figure out the following:

 

1. How to save single/multiple ROIs (of any shape) drawn on an image?

2. Once saved, how to load ROIs back on the image to the same location?

 

I searched on nimax forum and found the following reference, but I do not know how to use open, write file functionality as described on this link below: https://forums.ni.com/t5/Machine-Vision/Saving-ROI-of-an-image-in-a-file/m-p/26868

 

Thank you for your help!

 

Best,

Swati

0 Kudos
Message 1 of 9
(1,816 Views)
Solution
Accepted by topic author Swati.Bh

Hi Swati,

 

You can write the ROI data (from a property node) to a binary file, then read it from the binary file when you want it. 

The "clear ROI" and wait of 1sec is just so you can see the ROI disappearing and being restored.

 

Capture.PNG

Message 2 of 9
(1,781 Views)

Hi Gregory, This is awesome!! Thank you so much for a quick and detailed reply with the block diagram and explanation!! That's super helpful, I'm going to try it out right away! I really appreciate your time and help!! 

Best Wishes

Swati

0 Kudos
Message 3 of 9
(1,750 Views)

Hi Gregory,

 

I have been trying to recreate this block diagram to understand the steps and I have the following follow-up questions:

 

1. How to get 'Clear ROI' module? I tried using property node to get that, but haven't been successful. 

 

2. What is the purpose of "ROI.bin" input given to the Build Path VI? What does "ROI.bin" signify? Is this the binary file which will have the saved ROI's? And why is the output of 'Build Path VI' connected to both 'Write' and 'Read' VI's ( if the aim is to read ROI from the written binary file)?

 

What is the motive of adding 'Get System directory' ? Is it because this will allow user to specify the path to which user wants to save the ROI binary file? Could you please explain the sequence in words?

 

3. How to get a grey square around timer?

 

I'm sorry for these naïve questions as I'm still learning. Thank you for your great help!

 

Thanks

Best,

Swati

  

0 Kudos
Message 4 of 9
(1,739 Views)

@Swati.Bh wrote:

Hi Gregory,

 

I have been trying to recreate this block diagram to understand the steps and I have the following follow-up questions:

 

1. How to get 'Clear ROI' module? I tried using property node to get that, but haven't been successful. 

 

2. What is the purpose of "ROI.bin" input given to the Build Path VI? What does "ROI.bin" signify? Is this the binary file which will have the saved ROI's? And why is the output of 'Build Path VI' connected to both 'Write' and 'Read' VI's ( if the aim is to read ROI from the written binary file)?

 

What is the motive of adding 'Get System directory' ? Is it because this will allow user to specify the path to which user wants to save the ROI binary file? Could you please explain the sequence in words?

 

3. How to get a grey square around timer?

 

I'm sorry for these naïve questions as I'm still learning. Thank you for your great help!

 

Thanks

Best,

Swati

  


Hi Swati, no problem at all, I am glad you are trying to create it yourself.

1. That is an invoke node. A lot of times if you think you want to "set" something, it's a property, and if you want to "do" something, it's a method done through an invoke node. This isn't always the case, sometimes you just have to explore.

 

2. Yes, ROI.bin is just the filename, and I used that desktop folder so it will go on your desktop. But you should put it wherever you need it. "Application directory" is useful for getting a path relative to your project or executable. The path that is built is the file where the data is first saved, and then read from. If you want to save different ROIs, you can use a different filename for each one.

 

3. That is a flat sequence structure. This is a rare case of where this structure is needed and useful to ensure the wait time occurs right after clearing the ROI. Again, the wait time is just for demonstration purposes, and usually you would not want it.

0 Kudos
Message 5 of 9
(1,735 Views)

Hi Gregory,

 

That's super helpful! I learnt so many things today. Thanks to you for your great explanation and patience!!!

 

Kudos to you!

 

Thank you so much!!!

Best Wishes

Swati

0 Kudos
Message 6 of 9
(1,727 Views)

Hi Gregory,

 

I followed the steps you mentioned and that's very helpful!! Although I'm close to what I wanted to achieve, but I'm facing one problem. I'm using the live video (using webcam) and making several ROI's on that live video images. And those are the ROI's I wanted to save and re-load later when needed.

 

The problem is that the ROI's I make on the live image, do not get recognized until I "re-run" the program: So initially the saved/written ROI file is empty! The work around is that once I run the program, then I draw ROI's, and then I re-run the VI. This time, since ROI's are already present on the live image, it saves those ROI's. I tried adding some time delay, but that didn't work. Any leads on how to solve this problem? 

 

Below are the snapshots of my current file. First half shows how I'm capturing the live video. Then below there is a case structure. Depending on user input, it will either Write the binary ROI file or Read the selected ROI file.

Video capture on top, and WriteROI Case structure belowVideo capture on top, and WriteROI Case structure below

 

 

 

Video capture on top, and ReadROI Case structure belowVideo capture on top, and ReadROI Case structure below

 

 

Also, attached is the VI file.

 

As a solution to my problem: I was thinking to separate the code into separate VI's (say videocapture VI, WriteROI VI, and ReadROI VI)  and, then possibly add a button to the videocapture VI, which when pressed will call WriteROI VI, so write is done only when it is called. But, I still want the videocapture VI to be continuously running. I'm not sure what will happen after the WriteROI VI is called... 

 

I wanted to know if there is another better way to make it work? or am I thinking in the right direction? For now, I've started checking online resources about event handling in labview, and will move forward from there.

 

Thanks so much, any leads will be greatly helpful.

 

Best regards

Swati

 

 

0 Kudos
Message 7 of 9
(1,673 Views)
Hi Swati,
Your Read/Write ROI code is only going to run one time, at the beginning of the program.
If you want it to behave more like a "normal" program, where you can push buttons and do different actions while the program is running, you need to modify the architecture.

When I want to be able to push some buttons, but also have something run repetitively (like streaming the camera), I usually use an event structure inside a while loop. You can have your camera read occur in the timeout case (wire up a small value like 10ms), then create a button, with corresponding event, for "save image", "save ROI", and "load ROI".
Do read up on the event structure here:
https://zone.ni.com/reference/en-XX/help/371361R-01/glang/event_structure/
Message 8 of 9
(1,652 Views)

Hi Gregory,

Thanks a lot for sharing your insight on how this should be done and the link. That's indeed very helpful information for me to move forward in the right direction, super thanks!!

Kind Regards

Swati

0 Kudos
Message 9 of 9
(1,650 Views)