LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

improving Image processing time and efficiency

Hello all

I have started a project for image processing and would like to have some inputs to improve the processing time,speed and overall efficiency. I am using a Basler ace 1300-30um camera and a DAQ USB module ( not NI DAQ). A display card has to be tested for each display and depending on the image processing result, a button is pressed on the display.
The current situation is like this:
STEP1:I start camera and grab an image. close camera. Do the Vision processing for parameter 1 with acquired image and if the result is TRUE, then go to STEP2.
STEP2:I start camera and grab an image. close camera. Do the Vision processing for parameter 2 with acquired image and if the result is TRUE, then go to STEP3
STEP3:I start camera and grab an image. close camera. Do the Vision processing for parameter 3 with acquired image and if the result is TRUE, then go to STEP4
.
.
Like this i have around 10 - 15 test steps. For some teststeps, the camera have to wait a few seconds to grab image as the display have different timings. Some steps also include text recognition.

 

I have a MAIN VI using queue sturcture( producer- consumer) and all test steps are subVIs. For each subVI, camera is started, image is grabbed, camera is closed and image is processed.

Is there any better option to decrease the processing time? at the moment the camera is triggered manually based on the Image processing result( TRUE or FALSE).i.e each time starting , grabbing and closing camera.

Is it possible to initialize and open the camera in the beginning and then just trigger it dependng  on the Image processing result( TRUE or FALSE)? Will that be beneficial or will it just lag the whole process.?

Thanks

Nghtcwrlr

---------------------------------------------------------------------------------------------
*************************************
---------------------------------------------------------------------------------------------
0 Kudos
Message 1 of 15
(3,468 Views)
0 Kudos
Message 2 of 15
(3,458 Views)

A few questions and comments.

  • You use the phrase "grab an image".  In MAX, "Grab" means start a Video stream of images, while "Snap" means take a single image.  What do you mean by "grab an image", the IMAQ function "Grab" or "Snap"?
  • I could be very wrong about this, but I would venture to guess that a very small fraction of your processing time is spend opening, configuring, and closing the Camera.  On the other hand, if you are basically doing exactly the same thing before and after each test, it makes much more sense to do it once.
  • Your description of the over-all process sounds to me like a State Machine, with the first State being setting up the Camera, Get Image 1, Process Image 1, Get Image 2, Process Image 2, etc.  Possibly Get/Process could be a single State, but the key is that you use the results of the Process to decide on the next State to do.  One virtue of the State Machine architecture is that you can keep State Variables (such as the Camera I/O Ref) available throughout the lifetime of the State Machine.  Don't forget the final (exit) State that closes the Camera.

Bob Schor

Message 3 of 15
(3,408 Views)

Hi Bob

  • I use a IMAQ Snap.
  • Yes. a small portion of my processing time is spend in opening, configuring and closing camera each time. So, do you mean i open the camera and configure it initially just once ( in initialize state) and then do the IMAQ snap each time the processing is finished?
  • I programmed my test steps as State Machines. Each State Machine is running like this: Initialize controls , Get & process Image 1 , Check result, End. Depending on the result of one Test step, it goes to the next.

 

Nghtcwrlr

---------------------------------------------------------------------------------------------
*************************************
---------------------------------------------------------------------------------------------
0 Kudos
Message 4 of 15
(3,388 Views)

@Nghtcrwlr wrote:

Hi Bob

  • Yes. a small portion of my processing time is spend in opening, configuring and closing camera each time. So, do you mean i open the camera and configure it initially just once ( in initialize state) and then do the IMAQ snap each time the processing is finished?  Exactly.  With my camera, I turn it on, take a picture, look at the picture, take another picture, look, take, look, take, then turn it off.  I could turn on and off around each single picture, but that just wastes time ...
  • I programmed my test steps as State Machines. Each State Machine is running like this: Initialize controls , Get & process Image 1 , Check result, End. Depending on the result of one Test step, it goes to the next.  Modify slightly.  First State is "Turn on", middle states are "Snap", "Process", "Crackle", "Pop", after which you go back to "Snap" or, if you are all done, to the last state, "Turn off and Exit".

Bob Schor

0 Kudos
Message 5 of 15
(3,374 Views)

Hi!

 

have I overlooked that, or can you post (the interesting section of) your code?
As Bob wrote I would strongly recommend to open and close the IMAQdx sesssion only once. Depending on your priority (latency, throughput) it could be helpful to transfer your image processing to another loop (if the processing takes a considerable amount of time), so you do not have [once: open camera] [loop: -> wait for trigger -> snap -> process ->] [once: close camera]

 

Best regards,

Christoph

Staff Applications Engineer
National Instruments
Certified LabVIEW Developer (CLD), Certified LabVIEW Embedded Systems Developer (CLED)


Don't forget Kudos for Good Answers, and Mark a solution if your problem is solved
0 Kudos
Message 6 of 15
(3,366 Views)

A note about the open/close each loop, it tends to leave a ref in memory so the memory grows, which can cause out of memory if running for too long. That won't happen if opening once, ofc. 🙂

 

If the processing take too long, you can send the image off to a queue and have one or several consumers that'll process in parallell.

 

/Y

G# - Award winning reference based OOP for LV, for free! - Qestit VIPM GitHub

Qestit Systems
Certified-LabVIEW-Developer
Message 7 of 15
(3,363 Views)

The code is a bit large. But here is what i do. The below snippet is a state machine with 3 states. After one time the  state TEST is executed, it remains again in the TEST state until all teststeps ( test1,test2,test3)are completed.

 

I tried taking the open camera and close camera sessions in Initialise and End states respectively. ( oipening and closing just once). But then I have always an error( Camera already in Use)

Test VI_2.png

Nghtcwrlr

---------------------------------------------------------------------------------------------
*************************************
---------------------------------------------------------------------------------------------
0 Kudos
Message 8 of 15
(3,346 Views)

Before getting why it's giving error

-Where is the stop button to stop the loop?

-Are you using Abort button?

 

-Post your code as you mentioned with following setup:


@Nghtcrwlr wrote:

I tried taking the open camera and close camera sessions in Initialise and End states respectively. ( oipening and closing just once). But then I have always an error( Camera already in Use)

 


-You get the Camera already in Use either because you didn't close camera properly or aborted in between.

-As suggested by  others it is always nice to have Camera Open in Init case, and snap in test case and Close the camera in End case.

Thanks
uday
0 Kudos
Message 9 of 15
(3,336 Views)
Edit: Look into the manual for more details into the acquisition types and usage: C:\Program Files (x86)\National Instruments\NI-IMAQdx\Help\niimaqdx_concepts.chm
Thanks
uday
0 Kudos
Message 10 of 15
(3,332 Views)