Machine Vision

cancel
Showing results for 
Search instead for 
Did you mean: 

absolute difference of subsequent frames

Solved!
Go to solution

Hi all,

 

I'm trying to continuously acquire frames from a webcam, display them, and also display the absolute difference between subsequent frames. The last part isn't working: the display stays white. Does anyone has any suggestions as to what is going wrong? I'm pretty new at this, so I'm probably overlooking something basic. If it's possible, I don't want to use the grab VI twice, because that would lower the frame rate.

I have attached my VI.

 

Koen

0 Kudos
Message 1 of 6
(4,316 Views)

Create three images: Current, Last, and Difference.  Each time through the loop, acquire an image to Current.  Use Abs Difference to calculate the difference of Current and Last using Difference as the destination image.  Finally, use IMAQ Copy to copy Current to Last.

 

This will give you a new Difference image every time through the loop.

 

Bruce

Bruce Ammons
Ammons Engineering
0 Kudos
Message 2 of 6
(4,313 Views)

Thank you very much! That solved my problem

 

One additional question: in terms of performance, if you don't really use the colour data, do you know if it matters much (in general, or in this specific case) whether you first convert the frames to intensity-images or not? 

0 Kudos
Message 3 of 6
(4,302 Views)

I was looking at it more closely, and I noticed that it doesn't seem to work for every frame. Even if there is movement, there are only occasional flashes in "webcam 2". Any ideas why the second display isn't changing continuously when you move the camera around, like the first display does?

 

Attached is an updated VI.

0 Kudos
Message 4 of 6
(4,299 Views)
Solution
Accepted by topic author Oh me

The program is not sequenced properly.  There is nothing to make the difference be calculated before Last is replaced by Current.  If the replacement occurs first, the difference will be zero.  If the subtraction is first, everything works as desired.

 

You could either use a flat sequence structure to make things happen in the desired order, or you connect the error output from the subtraction to the error input on the copy.

 

In answer to your other question, converting to intensity before everything else is just fine.  It uses less memory to store a grayscale image, and the operations will be faster.

 

Bruce

Message Edited by Bruce Ammons on 02-22-2010 08:14 PM
Bruce Ammons
Ammons Engineering
Message 5 of 6
(4,288 Views)
Thanks! It works fine now.
0 Kudos
Message 6 of 6
(4,272 Views)