我用emguCV开始冒险。我想写一个简单的算法来检测移动的物体。我尝试减去背景但图像全黑。
public Form1()
{
previous = grabber.QueryFrame();
Application.Idle += new EventHandler(FrameGrabber27);
}
void FrameGrabber27(object sender, EventArgs e)
{
Image<Bgr, Byte> output = new Image<Bgr,Byte>(300,300);
Image<Bgr, Byte> actual = grabber.QueryFrame();
int width = output.Width;
int height = output.Height;
image27.Image = grabber.QueryFrame();
ibProcessed.Image = actual;
for (int i = 0; i < width; i++)
{
for (int j = 0; j < height; j++)
{
if ((actual[j, i].Blue == previous[j, i].Blue) && ( actual[j, i].Red == previous[j, i].Red)&&(actual[j, i].Green == previous[j, i].Green))
{
output[j, i] =newBgr(0,0,0);
}
else
{
output[j, i] = new Bgr(255, 255, 255);
}
}
}
im.Image = output;
答案 0 :(得分:0)
output[j, i] =newBgr(0,0,0);
我希望你的项目中没有忘记空间吗?((actual[j, i].Blue == previous[j, i].Blue) && ( actual[j, i].Red == previous[j, i].Red)&&(actual[j, i].Green == previous[j, i].Green))
这几乎总是如此,即使网络摄像头和场景是静态的,两帧之间的每个像素上的颜色总会有微小的变化。