LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Camera image updates with difficulty

Hi,

 

I want to make an acquisition of image with a camera C920e from logitech in real time to display it as video. It seems to be updating the image with difficulty, very slow, lagging (I guess you know what I mean). I read that it was possible to solve it with low-level functions but I can't find the way to display it as IMAQdx Start Acquisition has session out as strict but displays must be non-strict. Before trying this I tried to use Active Attribute which I also read here (https://knowledge.ni.com/KnowledgeArticleDetails?id=kA00Z000000PAQ5SAO&l=es-ES) in case it is a frame rate issue but I got an error of 

-1074360305 IMAQdxErrorAttributeNotSupported

 

Can you help me with this please?

 

Thanks!

 

0 Kudos
Message 1 of 11
(382 Views)

Sigh.  I've not done this recently, but if all you want to do is to stream Video from your WebCam to an Image Display on the Front Panel of your VI, you just run the wire from the Camera to the Display and start acquiring.

 

If you want to broadcast your Video, I believe that might be (significantly) more difficult.  I never tried, as the program I was writing was to "Take images and show them to me right now".

 

I'm running LabVIEW 2019 and 2021, so I couldn't open your VI (saved in LabVIEW 2022).  Can you "Save for Previous Version" (unless someone else solves your problem for you)?

 

Bob Schor 

0 Kudos
Message 2 of 11
(350 Views)

Mmmm I believe the word is "stream". The issue is that in the IV it doesn't display the video smoothly so my idea was to change frame rate but they way I found in documentation gave the error I copied in the previous message. 

 

Find attached the 21 version.

0 Kudos
Message 3 of 11
(345 Views)

Thank you for attaching your code saved for LabVIEW 2019.  I don't usually do this, but I "fixed" your code, and am going to use it as a "lesson" about LabVIEW coding, and why you should not "byte off more than you can chew", or "Don't try to do things with LabVIEW Vision before you (a) have a good grasp of LabVIEW, (b) can write "reasonably readable" LabVIEW code, and (c) have some experience (via DAQmx) with the "simple" version of LabVIEW I/O with external hardware.  LabVIEW Vision is much more difficult, complex, and arcane than DAQmx (my first LabVIEW project was to maintain a large LabVIEW 7 program that used "Traditional DAQ" -- DAQmx is so much simpler!).

 

Here is a "cleaned up" version of your original code:

cam_fps_2019.png

The While loop repeatedly starts the Camera, but there is no "Image Acquisition", and the Image is disconnected from everything.  [I straightened the wires, made the Diagram more compact, and fit the Front Panel into a reasonable space so you could see all the Controls without needing a second monitor to find the "Stop" button].

 

Needless to say, this didn't do anything.  The control "Session In" is a pointer to an IMAQdx camera, but there is no provision (and I didn't change this!) to look for a Camera, if it finds one, choose it, if it finds none, exit with a "No Camera!" error message, and if it finds more than one, ask "Which camera do you want".  In addition, it makes no attempt to query the Camera settings and to set it to something appropriate (more on this later).

If you had experience with DAQmx (and had read "Learn 10 Functions in NI DAQmx and Handle 80 Percent of your Data Acquisition Applications" (do a Web search and you'll find this!), you'd know that for continuous acquisition and display, you need a "Start Something", a While Loop with "Read Something" and either "Show Something" or "Export Something to a parallel loop for Showing or Saving", and a "Stop Something" when the While Loop exits.   So let's put the Start IMAQdx outside the While Loop.

 

If you had experience with DAQmx, you'd know you should not (I was going to say "never", but you should "rarely say never") put a "Wait" function inside an acquisition loop.  You want the hardware to control the Loop Speed.  One hopes that putting, say, a IMAQdx Grab function inside the loop will (a) acquire an Image, and (b) serve as a "clock" to make the loop run at the frame rate (30 fps) of the Camera.  In addition, the "Grab" should give you an "Image Out" which you can wire to your Image.cam_fps_BS_2019.png

 So here is my VI.  I knew it wouldn't work when I tried it, because "Session In" was blank.  But I could right-click it, let MAX find my PC's WebCam (called "cam0"), and give it a whirl.  Yuck, very, very slow.  It was running at some ridiculous number of pixels (1280 x 720?) and at a huge magnification, so I went into MAX, changed the frame rate to 640 x 480, went to the Front Panel and set the Image to "Zoom to fit", and tried again -- unfortunately, I can't do anything about the ugly image that stared back at me and waved back at me when I waved at it, but it worked (now) just fine.

 

So:

  1. Learn basic LabVIEW, including File I/O, DAQmx (to learn "simple" hardware), the advantages of Data Flow, and concurrent processing (you'll want to understand the Producer/Consumer Design Pattern, which I didn't use here because for smaller Images, LabVIEW was fast enough).
  2. Practice writing legible LabVIEW code -- it takes 20% more time to run wires straight and keep things neat and compact, but pays off in the long run!
  3. Tackle IMAQdx and LabVIEW Vision when you finish #1 and #2.

Bob Schor

 

P.S. -- the above "pictures" are LabVIEW Snippets, a special form of PNG file that can be dropped onto a LabVIEW Block Diagram and magically become LabVIEW code.

 

0 Kudos
Message 4 of 11
(322 Views)

First of all, thank you for your explanation.

 

Second, I am doing a project for university which is much more complex than just this. Don't feel as if you were doing my homework, please 😅 It's just a small thing that I tried to do to make it perfect.

 

I learnt some basics of Labview at a subject but they didn't teach me DAQmx. I wanted to go straightforward to the problem. My original camera loop was this but I tried to change the functions by low-level functions and disconnected the display because it was impossible to attach strict with non-strict. Then, I posted the one you saw which of course doesn't work.

 

I don't have right now the camera I was using and my webcam seems odd for no reason (reddish color and light blue the background) but the problem I wanted to solve was the speed. If I opened the camera in Windows it worked fine but the image acquisition was lagged. How did you change the frame rate in the code? I couldn't find it and I still don't know from your reply how to do it. Let me show the original snippet I was working in before I posted the code you saw in this query. As you can see, I already changed the resolution (not the frame rate) to make smaller the image of the camera.  

bitsandscience_0-1716033306951.png

Once again, thank you so much and sorry for bothering.

 

0 Kudos
Message 5 of 11
(304 Views)

Hello, Bits and Science.

 

     First, you never need to apologize for giving an academician an opportunity to teach.

 

     Just below my Snippet, I mention that I used MAX to set the Image Size and Frame Rate.

  1. Open MAX.  Expand Devices and Interfaces and find your Camera (mine is called "cam0".  Select it.
  2. On the right pane, open the Acquisition Tab.  Set "Video Mode" to 640 x 480 (desired Image size, fewer pixels to save per image) and 30 FPS.
  3. It is possible to write LabVIEW code that will interrogate your PC and identify all the cameras it (MAX) can see, and allow you to interrogate its properties and set them programmatically, but this comes under the heading of "really advance IMAQdx stuff", so just do it "manually" and get all those settings by using "cam0" with the IMAQdx Open Camera function.

When you say you changed the resolution of the Image, in fact, you only changed the number of pixels you extracted from the Image.  I'm guessing the default Image in MAX was way higher (maybe a factor of 8 or 16), and you were only visualizing 10% of the Image (probably the upper left corner) -- the camera was sending you a BIG picture (with lots and lots of pixels), which was all being stored in PC memory (in a Camera "Buffer"), which is where the time went.  Try my steps to get MAX to change the Buffer size, and you should be happier.

 

(Professor) Bob Schor

0 Kudos
Message 6 of 11
(283 Views)

Hi Bob,

 

I didn't understand what you meant. Now I have changed the settings in MAX as you said but I see no difference in frame rate. The image still wobbles when I move my fingers in front of the camera. I fixed the image size but it does what I say. Probably it's my computer or the camera. 

 

Anyway, thank you so much 😉

 

Carlos

0 Kudos
Message 7 of 11
(245 Views)

Does your computer have a Camera (for Teams, WebEx, Zoom, etc.)?  That should be using the GenICam standards that work with IMAQdx.  Note you do need the IMAQdx driver, not IMAQ ...

 

Bob Schor

0 Kudos
Message 8 of 11
(238 Views)

Yes, it has a camera. But for the application I was implementing I needed a better one to point to an experiment, so that's why I picked an external one. It's a C920e from logitech.

 

Carlos

0 Kudos
Message 9 of 11
(233 Views)

Try with the Webcam.  Did you open your C920 camera in MAX and adjust the image size to 640 x 480, 30 FPS?

 

Bob Schor

0 Kudos
Message 10 of 11
(226 Views)