Machine Vision

cancel
Showing results for 
Search instead for 
Did you mean: 

How to save one imaq image from a continuous stream, like a snapshot

Solved!
Go to solution

Hi,

 

I spent hours trying to find a solution for this on the internet for what I think must be really straight forward:

 

I have a camera which gives me a stream of images, which I show in an image graph.

Now when the user presses a "save" button, I want that the image which was shown at the moment when the user was hitting "save" is saved. However, the user is prompted for a file location and name, so some time passes between hitting "save" and writing the image to the disk. 

In that time, new images will be at the pointer position of the image I wanted to save.

 

It is clear to  me why this happens, but how do I get around it?

 

I tried to make a copy with Imaq copy, but this will just give me a new pointer which is still linked to the old one.

I tried converting to an array, same effect.

I also tried writing a queue with one element which has one image buffer. The queue was not in a loop (which would of course replace the image there) but still, the queue also just seemed to save the pointer position, although I was creating in advance a new empty image, and copied the image I want with Imaq Copy in this image buffer.

 

So how do I store the actual image (not pointer) in the memory to save it a few seconds later?

I basically want something similar to what the "snapshot" function of the image graph does.

 

Any ideas? 

 

Many thanks!
Philipp

 

0 Kudos
Message 1 of 6
(3,958 Views)

Please post the VI so that it is easier to debug.

Few pointers:

-Try to use Producer/Consumer design pattern

-So you want the pop-up to be shown or not? If not try creating the path constant and build path for each image so that program automatically saves without user interaction to save image.

Thanks
uday
Message 2 of 6
(3,945 Views)

Sorry, thought it is very clear from the description, I can't upload an image right now, but will do it later tonight.

 

Thanks for your tips!

 

Yes, I do want the pop-up to be shown so that the user can decide for the filename each time.

I tried using a producer, consumer pattern, however, it was still overwriting the image. Of course, I could make a buffer with 1000 images an then the camera wouldn't be fast enough to fill it during the process, but this sounds very inefficient to me. 

Because I really only need one image at a time.

 

 

 

0 Kudos
Message 3 of 6
(3,939 Views)

How fast are you acquiring images?

-You need to have enough buffers until the user finishes writing the file name without overwriting.And it can be sometimes slow sometimes fast which is uncertain.

-I think it is easier to give predefined path for images programatically to avoid these kind of overwriting.

-When you enqueue the image in only reference to the image is passed and still Producer loop has capability to overwrite the image.

-Instead make copy of the image at that instant with new buffer(Inside Producer create case to  and then pass to consumer loop via queue.

-So untill you press the snapshot button, the image will not be overwritten and gives sufficient time to save the image and give name in consumer loop.

-Attached quick draft what i am explaining

Image Aquairing 2_BD.png

Thanks
uday
Message 4 of 6
(3,931 Views)
Solution
Accepted by topic author pliehm2

Hi, 

 

many many thanks. 

I did consider your solution already, however, I thought this is a bit of an overkill.

 

For some reason I do not know, it now works as I wanted. See the example below (I really just wanted always one image).

The only difference to what I was trying earlier, is that now I did not specify the data type and size of the new image...not sure if this was the reason it did not work.

 

Thank you uday for your help!

Philipp

 

PS: How did you make the image you posted visible in your post? Mine is just a link.

0 Kudos
Message 5 of 6
(3,925 Views)

-Definitely your code will fail at some because of "race condition" with local variables (Please search in forum you will get lot of resources)

-Hence the same reason it can work sometimes and cannot sometimes.

 


I did consider your solution already, however, I thought this is a bit of an overkill.

 

-Care to explain why it is overkill?


For some reason I do not know, it now works as I wanted. See the example below (I really just wanted always one image).

 

-As said earlier if you want to separate the acquisition process and saving independently(Paralelly) you need atleast two buffers to avoid overwriting.


The only difference to what I was trying earlier, is that now I did not specify the data type and size of the new image...not sure if this was the reason it did not work.

 

 


Without seeing the original post cannot comment.

 


 

PS: How did you make the image you posted visible in your post? Mine is just a link.


When you click on Insert/edit image Click on Insert image it will be added.

 

P.S.The only way to thank is by giving kudos and marking correct post as solution.

 

 

 

Thanks
uday
0 Kudos
Message 6 of 6
(3,917 Views)