I have a sequence of frames of a moving camera. The frames have been stabilized. I want to calculate the frame difference between each two subsequent frames. I do it using
diff = abs(frame1 - frame2);
Frames are Mat objects. However, the two frames will have areas that are not overlapped (i.e. one of the two pixel values of the two frames will be equal to 0), which I don't want to include.
If two pixel values are a (= 0)
and b (!= 0)
, then the abs()
will be |b|, but I would like to instead have the value 0 if one of the two pixels is 0.
EDIT: I would like to do it without looping over the pixels
Okay so I figured it out. Basically, we threshold the two frames,
A
andB
, to convert them to a binary image (threshold
value = 0,THRESH_BINARY
mode), then the two binary images are ANDed, and that result is ANDed with the differenced frame to get the final result.