基本上,我要做的是创建一个包含图像列表和大图像视图框的窗口。如果用户指向列表中的一个图像,则图像框应显示该图像,否则应显示网络摄像头的实时馈送。
我正在尝试通过使用EmguCV.Capture的ImageGrabbed事件和存储当前查看图像的索引的字段来实现这一点。相机输入正常工作,但是,当我将鼠标移到列表框上时,图像视图仅停止更新。它一直停留在它看到的最后一帧,并且不显示我指向的图像。我已检查列表中是否有图像,该索引是否正确,以及来自摄像机的图像与列表中保存的图像不同。此外,当我使用vanila PictureBox时会发生相同的行为。
请参阅下面的代码(删除额外部分)。
初始化:
not()
帧捕获:
int ViewedFrame = -1;
var Frames = new List<Image<Rgb, byte>>();
// This list will have some images added to it along the way.
// They will be displayed in a custom drawn ListBox bound to the list.
Camera = new Emgu.CV.Capture(cameraid);
Camera.SetCaptureProperty(Emgu.CV.CvEnum.CAP_PROP.CV_CAP_PROP_FRAME_WIDTH, width);
Camera.SetCaptureProperty(Emgu.CV.CvEnum.CAP_PROP.CV_CAP_PROP_FRAME_HEIGHT, height);
Camera.ImageGrabbed += UpdateCamera;
Camera.Start();
鼠标处理:
private void UpdateCamera(object sender, System.EventArgs ev)
{
if (ViewedFrame == -1)
Preview.Image = Camera.RetrieveBgrFrame();
else
// !!! this line has no apparent effect, image in the ImageBox is still the same
Preview.Image = Frames[ViewedFrame];
}
UPD:我尝试将private void FrameList_MouseMove(object sender, MouseEventArgs e)
{
int index = FrameList.IndexFromPoint(e.Location);
if (index == ListBox.NoMatches)
ViewedFrame = -1;
else if (index != ViewedFrame)
{
ViewedFrame = index;
}
}
private void FrameList_MouseLeave(object sender, EventArgs e)
{
ViewedFrame = -1;
}
和Preview.Update()
添加到与Frames [ViewedFrame]相同的分支中,并在条件运算符之后。在第一种情况下,它没有任何影响。在第二种情况下,根本没有显示。如果ImageBox无法跟上自己的更新,我启用了双缓冲,但这也无济于事。此外,将鼠标悬停在列表中的图像上后,相机流也会中断。上面的代码是唯一有效的代码。