LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Acquiring image sequence at 1 fps

Solved!
Go to solution

I have a logitech HD Pro Webcam C920. The frame rate of this camera by default is 30 fps. But I need to record an image sequence at 1 fps for my experiments, by using this camera. I was trying to write the labview code using the NI-IMAQdx utility. The code file is attached (whatever I have tried so far). But I am unable to proceed further like which functionality to use for reducing the rate at which images will be recorded. Can someone please offer any suggestion or help in this ?

 

Thanks, 

 

 

0 Kudos
Message 1 of 7
(1,389 Views)

Have you tried plugging in the camera and using MAX to do a Grab?  When I did this using LabVIEW 2019 SP1 (32-bit), MAX told me (under Acquisition Attributes) that it was using 2560x1472 YUY2 at 2.00fps (which was the highest resolution and the slowest default Frame Rate).  When I did a "Grab", I seemed to get images at 2 Hz (I didn't exactly time it, but it was certainly faster than 1 Hz (though, to be honest, it seemed slower than 2 Hz).  Note that to see the entire image in MAX, I had to right-click the viewer and choose "Zoom to fit" -- it might have slowed down to get all those pixels on the screen).

 

I would imagine I could write a trivial routine in LabVIEW to do the same thing.  I wouldn't, of course, put the "Viewer" inside the same loop as the "Acquirer", but would use a Stream Channel Wire to pass the incoming Images to a "View" loop.

 

Bob Schor

0 Kudos
Message 2 of 7
(1,342 Views)

Thanks Bob_Schor for the reply. I tried to Grab using the MAX. But, I can only see the option of 30 fps, at any resolution. So, can you suggest how to write a routine for this in the labview to capture images at 1 fps ?  

0 Kudos
Message 3 of 7
(1,331 Views)
Solution
Accepted by Simrandeep

I apologize for taking so long to get back to you.  I'm right now sitting in my house, with my Logitech C920 "looking at me", and trying to figure out how to set the Frames/second on this camera.  Turns out this is not an enumerated attribute of the camera!  Which just makes the job a little more difficult, but not impossible (Famous Last Words!).

 

The Good News is you want a very low frame rate, 1 Frame/second.  This is easy -- it is called an IMAQdx Snap (not a Grab), namely "Acquire a single Image".  I'm going to open up LabVIEW and try this out:

  1. New VI.  Front Panel, Error In, Error Out, Image Display.  Block Diagram, IMAQdx Open Camera, Snap, Close Camera.
  2. Wire Error Line, Open Camera, Snap, Close Camera, Error Out.
  3. Wire Session lines from Open Camera, Snap, Close Camera.  Wire Image to Image Out of Snap.
  4. Right-click Session In terminal of Open Camera, "Create Constant".  Click little triangle on Constant, choose your Camera (for me, it is "cam1").
  5. Notice "broken Arrow" -- what did I forget?  Oops, need Image for Snap.  Drop IMAQ Create.  Wire New Image to Snap.  Create Image Name (I used "Test").
  6. Click Run.  Hmm, see something, but not interesting.  Turns out to be picture of the wall behind me.  Right-click Display (on Front Panel), choose "Zoom to Fit", and see I forgot to comb my hair!

So now we are 90% of the way done.  To finish, drop a While Loop around the Snap and Image (leave "Get Image" outside to the left).  Right-click the Stop Icon, "Create Control".    Drop a "Wait until next Multiple" inside the loop, wire 1000 to it (1000 ms = 1 sec).  Create a copy of this "Wait 1 sec" outside the While Loop (on the left), and wire its output to the left edge of the While (this delays the While until the 1 second-clock ticks).  Start the Program, wave your hand, see results, stop the program.

 

Any questions?  [The really hard one is about the Wait -- who uses that one?  I'm not sure if it is still true in 2023, but this function was designed for synchronization, and I believe it may behave "better" as a reliable timer than the Wait (ms).]

 

Bob Schor

Message 4 of 7
(1,310 Views)

Thanks very much Bob Schor for your detailed answer. I have written the labview VI according to the instructions as mentioned and have attached it. It seems to work (Great !), but I have two questions :

 

Why do we need "Wait until next multiple" inside the while loop ? If the "Wait until next multiple outside the while loop delays the loop execution by one second, then what is the need of another one inside the loop ?

 

Secondly, is there any way of storing these images in a sequence in a folder ? Suppose, we run this VI for 60 seconds, so according to the above VI, the camera should acquire 60 images. I need all these 60 images stored in a sequential number in a folder. 

 

Thanks, 

Simrandeep

0 Kudos
Message 5 of 7
(1,302 Views)
Solution
Accepted by Simrandeep

If you read the Help of "Wait on Multiple", you will see it is the the Wait inside the Loop that makes the Loop run at 1 Hz.  Remember the Third Law of Data Flow -- you cannot exit a "Structure" (essentially anything on the "Structure" Palette, including Loops, the Event Structure, Case, etc.) until everything inside the Structure runs.  "The Race Goes to the Slowest" in Data Flow.

 

So what's with the (single) Wait until Multiple outside?  Unlike the ordinary "Wait (ms)", which says "Wait N milliseconds (from when?  that's another problem), Wait until Multiple waits until the 32-bit millisecond timer is a multiple of N.  Suppose we only have the "Wait until Multiple" inside the loop, and we specify 1000 ms (so the Loop waits for 1000, 2000, 3000, ... milliseconds (why would it wait for 2000 ms?  Well, what if whatever else you do inside the loop took 1001 ms?  You'd "miss" the 1000th tick.  There's a "fix" for this, too, but we'll get to that much later).

 

So we enter the While Loop.  What is the value of the Millisecond counter when we enter?  Who knows?  What we do know is if the Millisecond Timer is at 700 when you enter the loop, the "Wait until Multiple" the first time will only be 300 ms, not the 1000 that you wanted.  How to fix this?  Synchronize on the Wait before you enter.

 

Here's an experiment you can do (with a stop-watch or simply counting "1, 2, 3, ").  Change the little program you wrote to Snap at 1 Hz.

  • First delete the Wait Until Multiply inside the While Loop.  What changes?
  • Next, put the Wait Until Multiply back inside the While Loop, but delete the outside Wait.  What happens?
  • This should show you which controls the Loop rate.  Change the Wait to 5000 (or every 5 seconds) and run several more times -- try to see if the first loop is "short".

Conclusion -- the Inside "Wait" basically sets the Rate, and the Outside "Wait" serves to synchronize the Waits with the Millisecond Clock.

 

Bob Schor 

Message 6 of 7
(1,281 Views)

Thanks so much Bob again for the detailed answer. Yeah, I noticed the effect of putting "Wait until next multiple" separately inside and outside the while loop and now better appreciate the solution.

 

Simrandeep

   

0 Kudos
Message 7 of 7
(1,268 Views)