从流视频中获取快照(新手)

发布于 2024-12-10 05:44:08 字数 786 浏览 0 评论 0原文

我有一个使用 Emgu(OpenCV 的 .net 包装器)编写的视频播放器,我捕获帧并对某些帧执行一些操作。在功能中,我让用户拍摄流视频的快照,并以不同的形式突出显示快照的部分。

但是,由于视频播放器在下面播放,因此当用户在表单上绘图时,子表单上的图像也会更新。这是不希望的。我很确定这与我的锁定和解锁内容有关,而我是这方面的新手。

有什么想法我哪里出错了吗?我本以为锁定(bmpFrame)会阻止任何更新,但事实并非如此:

 private void btnTag_Click(object sender, EventArgs e)
    {
        if (_video != null && _video.CurrentFrame != null)
        {
            try
            {
                using (Bitmap bmpFrame = (Bitmap)_video.CurrentFrame.Bitmap)
                {
                    lock (bmpFrame)
                    {
                        TagForm f = new TagForm(bmpFrame);
                        f.Show();
                    }
                }
            }
            catch { };
        }
    }

I have a video player written using Emgu (a .net wrapper for OpenCV) and I am capture the frames and performing some operations on certan frames. In on functionality, I let the user take a snapshot of a streaming video and highlight sections of the snapshot in a different form.

However, since the video player is playing underneath the image on the child form is also updated as the user draws on the form. This is undesirable. I am pretty sure this has something to do with my locking and unlocking stuff and I am a newbie to this stuff.

Any ideas where I am going wrong? I would have thought the lock (bmpFrame) would have prevented any updates, but it doesn't:

 private void btnTag_Click(object sender, EventArgs e)
    {
        if (_video != null && _video.CurrentFrame != null)
        {
            try
            {
                using (Bitmap bmpFrame = (Bitmap)_video.CurrentFrame.Bitmap)
                {
                    lock (bmpFrame)
                    {
                        TagForm f = new TagForm(bmpFrame);
                        f.Show();
                    }
                }
            }
            catch { };
        }
    }

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

纵情客 2024-12-17 05:44:08

啊啊!我傻了,这确实是一个疏忽。通过为新位图分配新内存来修复

using (Bitmap bmpFrame = new Bitmap(_video.CurrentFrame.Bitmap)
{

   lock (bmpFrame)
   {
       TagForm f = new TagForm(bmpFrame);
       f.Show();
   }

}

ahhh! silly me, it was indeed a oversight. Fixed by allocating new memory for the new bitmap

using (Bitmap bmpFrame = new Bitmap(_video.CurrentFrame.Bitmap)
{

   lock (bmpFrame)
   {
       TagForm f = new TagForm(bmpFrame);
       f.Show();
   }

}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文