Machine Vision

cancel
Showing results for 
Search instead for 
Did you mean: 

Imaq image flickers when subtracting the last frame from the current frame

The problem:
I am having a problem with the output image flickering when I subtract the current frame from the last frame.

The goal:
I want to do a background subtraction from the current frame to detect motion.  The background image should be replaced with the last acquired image.

The setup:
I acquire and image, type cast it to grayscale U8 and use the Canny Edge Detection sub vi to find the edges in the image. The output from the Canny Edge Detection is then wired to the IMAQ Subtract 'image source A' input.  The output on the Canny Edge Detection Vi also gets wired to a shift register.  This shift register is wired to the 'image source B' input for the IMAQ subtract. 

Note:  A new image was created before the while loop begins for the 'Image Dst' input on the IMAQ subtract.  All images are grayscale u8.  There is an image display indicator wired to the output of the Canny Edge detector, a image display indicator wired to the output of the shift register as well as another image display indicator wired to the output of the IMAQ subtract.  To help clarify I am attaching an image to show how things look in the code.

The results:
This should work but when I run the vi I just get a black image in the image display from the subtracted image output.  The only way I could get an image to appear in the IMAQ subtract output was if I made a copy of the Canny Edge detection output using the IMAQ copy sub vi and took the output from the IMAQ copy and wired it to the shift register instead of directly form the Canny Edge detection output.  This seems to work great; I am able to subtract the background from moving objects except the image flickers.   For some reason, the image goes blank (black) on the subtracted image display every now and then and I am not sure why.  I know that it shouldn't go black because  even if  I  focus my camera on a unmoving object  I get a faint snowy out line of the  object from the noise of the camera - this is fine. 

Discussion:
What am I doing wrong?  Do I get this flickering because I am using the IMAQ copy for every iteration of the while loop?  Should I not use shift registers with an IMAQ image?  Should I be using some kind of buffer system? Is there a better method?.....

Thanks in advance!



0 Kudos
Message 1 of 9
(7,769 Views)

Hi Greg

Try this configuration. The light mode is quite more sensible than the border detection. Also, use absolute diference to substract images.

I tested this using a webcam ans it runs fine.

Obviously, this is the first step. Then, you will have to  process results to determine  if there is motion in the image.

Take a look at this link. there are some examples that can help you.
http://www.st-andrews.ac.uk/~gfm2/tracker.htm


Hope it helps
Alipio

---------------------------------------------------------
"Qod natura non dat, Salmantica non praestat"
---------------------------------------------------------
Message 2 of 9
(7,738 Views)

Hi  there,

 

I'm developing a similar algorithm because I need to detect movement in video data. I subtracted the current frame to the previous frame as in your vi, but my application should run in real time and a shift register in the while loop seems to be to slow (a mean of 43 ms). Do you know if there are alternative ways to make the difference between the two frames that are computationally faster than shift register?

 

Thanks so much

Mattia 

0 Kudos
Message 3 of 9
(7,169 Views)

Hi, Greg,

 

You should not use Shift Register with IMAQ Images (at least not for holding previous image as you want), because IMAQ Image is reference to the image, not image data itself. Unitialized shift register with IMAQ Image especially bad, because you will get "Not an Image" error at first iteration.

I will recommend to use solution with buffer. Organize images into array, then framegrabber will write image directly to the ring buffer, so you will have your previous image on every iteration, then you can perform processing / subtract.

 

Andrey.

 

0 Kudos
Message 4 of 9
(7,144 Views)

Hi Andrey,

 

I'm sorry but I'm not so good with labview. Could you be more detailed in your description about using the buffer to subtract the frames?

right now I acquire the frames using the IMAQdxOpen Camera.vi, IMAQdx Configure Grab.vi and IMAQdx Grab.vi. IMAQdx Grab.vi is inside a while loop that stops when the conditional terminal receives a stop input. 

 

 Thank so much for your help

Mattia

 

 

0 Kudos
Message 5 of 9
(7,110 Views)

Hi, Mattia,

 

you wrote: "...shift register in the while loop seems to be to slow (a mean of 43 ms)..."

Attached very simple VI with illustration of the "double buffer" motion detection . I use Shift Register for storing reference to to the previous image. This example able to run up to 800FPS rate on my PC. It means that shift register not very slow. See attachment.

 

Andrey.

 

0 Kudos
Message 6 of 9
(7,101 Views)

Andrey,

 

it was my fault, because I wasn't still working in real time but with an AVI file and counting the time due to the shift register AND the time due to the avi frame decompression.

Now it is working great in real time following your example!thanks for your help.

Mattia 

0 Kudos
Message 7 of 9
(7,084 Views)

Hi there,

 

I'm new in labview and I should solve a problem of frame subtraction. I'm not able to handle the current and previous frames through each iteration. I saw this post and the attached VI but I'm running labview 8.5...Could somebody save the attached VI for labview 8.5 or create a snapshot and post it again? 

thank you so much for your help!

 

gato 

0 Kudos
Message 8 of 9
(6,880 Views)

Hi, 

 

I'd like to help you but I'm not working anymore with Labview 8.6 because I've finished my thesis and I don't have access to the lab.

I'm sorry.

 

Mat 

0 Kudos
Message 9 of 9
(6,855 Views)