LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Save Sequence Images with a given timing

Solved!
Go to solution

Dear all,

 

I have to build a VI that acquires images from a digital Camera and saves them with a given timing, say one image every 200ms. The program also has to convert the image from raw image to coloured image, by means of the Bayer decoding, so also a certain processing time is needed. To allow that, I have kept a buffer, as I have also have found in the Labview example Ring with Bayer Decoding.vi. I also would like to show the images I am capturing.

 

I have modified conveniently the example, obtaining the program that I attach below in a snapshot. The program works fine, but for the moment I haven't been able to save the images at a given required timing. I actually have not understood either what is the frame rate at which the images are saved with the code I've written.

 

Do you think that I'm on the right track? How can I implement the timing in the program ? and how do i regulate the buffer?

 

Please let me know.

As i told you,  snapshot of the VI block panel is attached.

 

Thank you very much for your help.

Best regards,

 

Emanuele

0 Kudos
Message 1 of 69
(4,867 Views)

Hi there,

 

I see a few things that could be improved.

 

First of all, right now you don't have any kind of timing in your while loop at all, so you'll need to add some.  In the "programming" palette is a "Timing" palette.  You'll find timing VIs in there that you can put in your loop.  That will help control your timing.  However, I must point out that the timing VIs such as "Wait(ms)" and "Wait Until ms Multiple" will run in parallel with the rest of your code.  Therefore, if it takes longer to capture your image than it does for the timing VI to execute, your loop won't run at the speed you might expect.

 

(For instance:  if you put a "Wait(ms)" function in your loop and set the delay to 200msec, but it takes 500msec to capture your image, your loop won't iterate at 200msec.  It will wait until everything inside it is finished executing, then iterate.  Does that make sense?)

 

The second thing I see is your architecture.  I'd direct you towards a Producer-Consumer, where you capture images in one loop and write them to file in another, separate loop.  Transfer the image data from your capture loop to your file loop with a queue.  To look at an example of a Producer-Consumer architecture, in LabVIEW click "File...New..."  then under "VI" choose "From Template...Design Patterns...Producer/Consumer Design Pattern (data)".  Changing your architecture will allow you to capture images at one rate, then write them to file at a different rate...so that writing the images to file doesn't slow down your acquisition the way it does now.

 

Does that give you something to get started with?

 

producerconsumer.png

Message 2 of 69
(4,845 Views)

Dear Diane,

 

thank you, I'll to make the changes you suggested,  I believe that the producer-consumer structure is actually what I need to use. I'll let you know whether I have some problems in implementing it.

Thank you again.

 

Emanuele

0 Kudos
Message 3 of 69
(4,834 Views)

Hi again,

 

I've worked a little bit on the producer consumer-structure, and I've build the VI that I attach.

I hope that I'm on the right track, but I'm not sure. I've set the timing with 100 ms delay, because I'd like to acquire images at 10Hz.

 

Now I' unfortunately stuck because I don't know how to transfer data from the producer to the consumer and what is the input block from which I have to start the processing code.

Could you please give me some hints? I've tried to understand how to do it form the examples, but I haven't understood how the structure properly works...

 

Thank you again

 

Emanuele

0 Kudos
Message 4 of 69
(4,824 Views)

Hi Emanuele,

 

You use the queue to transfer the data.  That's the whole idea.  Smiley Happy  Look at the help files for Enqueue, Dequeue, etc.

 

I've modified your VI slightly, added some comments for you, and set up your queue.  I have a question and a comment or two.

 

The question:  why do you have a "False" constant wired to your case structure?  That will ensure that the "False" case executes with every loop iteration -- and the "False" case doesn't contain any code.  Either that constant needs to be replaced by a button, or you need to eliminate the case structure.  With the way it's written now, you'll never capture any images at all, because your image capture code is inside the "True" case, and that case will never execute.

 

The comments:

 

Please straighten out your wires.  It really does make your block diagram much more readable, and that's very important.  I've straightened all of your wires for you.  It may feel like an unimportant detail, but it's actually quite important.

 

I don't know if you'll be able to capture images at 10Hz with the way you have things written now.  All of that code might very well take more than 100msec to execute.  You may have to streamline things somewhat.  I believe you only need to configure your buffer list once, so you can do that outside the loop.  (Forgive me if I am wrong about that -- you'll have to play with it a bit.)  Then configure each buffer before you acquire the image.

 

Ok, take a look at this, and have a look at those help files for the queue functions.

 

Edit:  I forgot to attach the error wire from your property node to your "IMAQ Create" function!

Message 5 of 69
(4,815 Views)

Dear Diane,

 

thank you.

I have modified the program and added the processing and saving part in the consumer loop.

However I recieve an error during the highlight execution, which iI report below. Probably I have not set up the buffer acquistion correctly. I have been trying to correct the error, but I have't made it. I hope you can help me sort it out. The new code is attached.

Thank you for your time again.

 

Emanuele

 

-1074397155   IMG_ERR_BBLB  

One or more of the buffers in the buffer list is not configured

0 Kudos
Message 6 of 69
(4,804 Views)

Hi Emanuele,

 

You have no buffer number wired to your "Configure buffer" function.  You can use the loop's iteration terminal to increment the buffer number.  You need to wire a buffer number to that function so that it knows which buffer to configure.

 

 

Diane 

0 Kudos
Message 7 of 69
(4,800 Views)

Dear Diane,

 

thank you. I have modified the program following some Labview examples and now it works. I attach it, to show you how it looks like.

I used a timed loop instead of a while loop as the producer loop, as I think that it is the best way to obtain images at a given sample rate: do you agree?

In addition I would like to ask you whether it is possible to acquire/show images at a given frame rate (higher) and save only a part of them, say I acquire at 20 frames per second, but I save only at 5 frame per second, so as to save space in the hard disk. I think it may only be possible to choose a saving -frame-rate which is a sub-multiple of the acquiring-frame-rate rate.

Please let me know how you would suggest doing it.

 

Thank you again

 

Emanuele

0 Kudos
Message 8 of 69
(4,784 Views)

Hi Emanuele,

 

You're welcome.  I'm glad it works now.  I'm not convinced that the timed loop is going to ensure that you capture images at the rate you want -- you'll have to try it and see.  I don't use timed loops, so I don't know how reliable they are.  You're still dependent upon the Windows processor for your timing.  As I understand it, timed loops are mainly for use with RIO systems, where they're using a hardware clock (and therefore have a reliable timing source).  But if it works for you, great!

 

Of course you can save images at a different rate from which you acquire them, and doing so at a sub-multiple of your capture rate is a very good idea.  I'd use a simple counter.  See attached to give you an idea.  This is something I'm pretty sure you could have figured out yourself -- it's not a hard question and you are clearly smart -- so next time I'm going to ask you to try to solve the problem yourself first and then show me what you've done.  Fair?  Smiley Happy  You're doing a good job of putting the pieces together from different sources, but I do feel like you're sometimes asking for help earlier than you need to!

 

Finally -- remember what I said about straight wires?  It's important!  Straighten out your wires!  Smiley Happy 

 

Keep up the good work!

Message 9 of 69
(4,780 Views)

Dear Diane,

 

as I told you I am still a new user of Labview and I don't know all the available features: I'm just trying to do my best by looking at the examples and using your advice. I don't have any manual, so it's very hard for me to start doing something from scratch, I spend hours in front on my PC doing also simple things (simple maybe for an advanced user like you) and I progress very slowly, step by step... please don't blame me for asking these questions. I didn't even know how to use a counter before you told me.

 

I modified the program: I attached it. The problem is that now it's not working anymore, every time I run it I receive the error message Error -1074396120 occurred at IMAQ Bayer Color Decode.vi...

Can you see where the problem is? I have already spent two hours trying to find it, but with no result... I also tried to do my best to straighten the wires but I can't really know how to improve the code also under this aspect, it takes so much time also to do that...

 

Please let me know as soon as you can.

Thank you again a lot

 

Emanuele

0 Kudos
Message 10 of 69
(4,762 Views)