我一直在写这个运动检测程序,遇到了“if语句”的问题,代码如下:
for (int i = 0; i < frameSize; i++, backFrame++, currFrame++)
{
// difference
diff = ((int)*currFrame) - ((int)*backFrame);
// threshold
if ((diff >= differenceThreshold) || (diff <= differenceThresholdNeg))
{
*currFrame = (byte)255;
if (i < 640)
{
x[i] = i;
y[i] = 0;
}
else
{
x[i] = i % 640;
y[i] = i / 640;
}
if (xMax < x[i]) xMax = x[i];
if (xMin > x[i]) xMin = x[i];
if (yMax < y[i]) yMax = y[i];
if (yMin > y[i]) yMin = y[i];
xC = ((xMax - xMin) / 2) + xMin;
yC = ((yMax - yMin) / 2) + yMin;
}
else
{
*currFrame = (byte)0;
}
}
问题是它在“if”之后跳过代码并执行“else”,即使条件
(((diff >= differenceThreshold) || (diff <= differenceThresholdNeg))) is true.
我是 C# 的新手,所以有人可以帮助我吗?