Why specifically do we need to cast frames to double to detect movement?

1 回表示 (過去 30 日間)
Andrew Killian 2021 年 9 月 6 日

In order to detect movement from subsequent frames... My understanding is that we subtract all the pixel values from the previous or next frame and if the differences are anything other than zero then movement has taken place. But our slide says :
– diff1 = abs(frame61 – frame62).
– diff2 = abs(frame63 – frame62).
• Note: frames must first be cast to double, Otherwise, the above lines will not work.
• E.g.: frame61 = double(frame61);
I was just wondering why specifically we need to do this. It offered no explanation.

サインインしてコメントする。

回答 (1 件)

Walter Roberson 2021 年 9 月 6 日
img2 = 2*fliplr(img);
imshowpair(img, img2)
Lots of differences, so you would expect that "movement" would be deteted on both the right and the left, right?
diff1 = img - img2;
imshow(diff1, [])
That's odd, almost no "movement" detected to the left ??
diff2 = double(img) - double(img2);
imshow(diff2, [])
But there it is if we used double() ... why didn't the first one work?
Well, look at this:
A = uint8(10)
A = uint8 10
B = uint8(20)
B = uint8 20
A - B
ans = uint8 0
double(A) - double(A)
ans = 0
Subtracting a uint8 from a uint8 always has to give a uint8 result. But uint8 cannot represent negative numbers.

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeProgramming についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by