gpt4 book ai didi

c# - 网络摄像头代码中的内存泄漏

转载 作者:太空狗 更新时间:2023-10-29 17:56:20 24 4
gpt4 key购买 nike

<分区>

好的,我一直在尝试对来自网络摄像头的视频进行一些特定的处理。我有一个 Lumenera Infinity 2 显微镜,我正试图从中提取提要,并希望能够在提要进来时对其进行修改。由于我找不到使用视频源播放器来做到这一点的方法,我决定改用将每一帧(相机最大 15fps)拉为位图,以便我可以在那里进行修改。

问题是:我有一个巨大的内存泄漏。当我仅使用 videoSourcePlayer 运行视频时,它徘徊在使用 30 兆左右。当我将帧作为位图运行时,它会在几秒钟内破坏 1 gig 的内存。

我在这里错过了什么?我认为自动垃圾收集会在旧框架变得无法访问时将其收集起来。我应该尝试强制对位图进行垃圾回收吗?或者它完全是别的东西,我很想念它。

FilterInfoCollection captureDevices;
VideoCaptureDevice cam;
Bitmap bitmap;

public Form1()
{
InitializeComponent();
}

private void Form1_Load(object sender, EventArgs e)
{
try
{
captureDevices = new FilterInfoCollection(FilterCategory.VideoInputDevice);

if (captureDevices.Count == 0)
throw new ApplicationException();

CameraSelectComboBox.Items.Clear();

foreach (FilterInfo device in captureDevices)
{
CameraSelectComboBox.Items.Add(device.Name);
}

CameraSelectComboBox.SelectedIndex = 0;
CameraSelectComboBox.Enabled = true;
}
catch (ApplicationException)
{
CameraSelectComboBox.Enabled = false;
}
}

private void connectButton_Click(object sender, EventArgs e)
{
cam = new VideoCaptureDevice(captureDevices[CameraSelectComboBox.SelectedIndex].MonikerString);
cam.NewFrame -= Handle_New_Frame; //Just to avoid the possibility of a second event handler being put on
cam.NewFrame += new AForge.Video.NewFrameEventHandler(Handle_New_Frame);
videoSourcePlayer1.Visible = false;
cam.Start();

//videoPictureBox1.Visible = false;
//videoSourcePlayer1.VideoSource = new VideoCaptureDevice(captureDevices[CameraSelectComboBox.SelectedIndex].MonikerString);
//videoSourcePlayer1.Start();
}

private void Handle_New_Frame(object sender, NewFrameEventArgs eventArgs)
{
bitmap = (Bitmap)eventArgs.Frame.Clone();

videoPictureBox1.Image = bitmap;
}

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com