aforge 相机标定_c# – Aforge.net相机捕获并将图像保存到目录

本文档描述了在使用AForge.net进行相机标定过程中遇到的图像保存错误。作者在尝试捕获和保存摄像头图像时遇到GDI+错误,并且调试器行为异常。代码示例展示了如何初始化摄像头、捕获帧并尝试保存图像,但存在资源管理问题导致程序崩溃。问题可能源于未正确处理和释放图像对象。
摘要由CSDN通过智能技术生成

大家.我已经被困在这里处理这些错误了好几天,但我仍然无法弄明白.

我的猜测:我认为我的代码存在一些问题,因为我在使用它之后没有正确处理对象,(我不太熟悉释放资源,线程的这些概念).

我通过参考人们在youtube上做了什么来获得这些代码,但是尽管我做了完全相同的事情,但我的代码并没有很好地解决.

情况:

我有两个图片框,左边一个可以拍摄我的视频,右边一个拍快照,如果你按下button1,你将启动视频,clone_button将复制一个图像即拍摄快照,save_image应该保存到路径参考但是,当我试图保存时,我一次又一次地在GDI中发生一般错误.此外,我的调试器似乎变得疯狂(即无法终止vshost.exe)一旦我运行此程序,我必须重新启动计算机以使我的代码再次运行,这是令人沮丧和令人沮丧的.

using System;

using System.Collections.Generic;

using System.ComponentModel;

using System.Data;

using System.Drawing;

using System.Linq;

using System.Text;

using System.Windows.Forms;

using System.IO;

using System.Drawing.Imaging;

//AForge.Video dll

using AForge.Video;

using AForge.Video.DirectShow;

using AForge.Imaging;

using AForge.Imaging.Filters;

using AForge;

namespace WebCameraCapture

{

public partial class Form1 : Form

{

public Form1()

{

InitializeComponent();

}

private FilterInfoCollection CaptureDevice; // list of webcam

private VideoCaptureDevice FinalFrame;

private void Form1_Load(object sender, EventArgs e)

{

CaptureDevice = new FilterInfoCollection(FilterCategory.VideoInputDevice);//constructor

foreach (FilterInfo Device in CaptureDevice)

{

comboBox1.Items.Add(Device.Name);

}

comboBox1.SelectedIndex = 0; // default

FinalFrame = new VideoCaptureDevice();

}

private void button1_Click(object sender, EventArgs e)

{

FinalFrame = new VideoCaptureDevice(CaptureDevice[comboBox1.SelectedIndex].MonikerString);// specified web cam and its filter moniker string

FinalFrame.NewFrame += new NewFrameEventHandler(FinalFrame_NewFrame);// click button event is fired,

FinalFrame.Start();

}

void FinalFrame_NewFrame(object sender, NewFrameEventArgs eventArgs) // must be void so that it can be accessed everywhere.

// New Frame Event Args is an constructor of a class

{

pictureBox1.Image = (Bitmap)eventArgs.Frame.Clone();// clone the bitmap

}

private void From1_CLosing(object sender, EventArgs e)

{

if (FinalFrame.IsRunning==true) FinalFrame.Stop();

}

private void save_Click(object sender, EventArgs e)

{

if (pictureBox2.Image != null)

{

Bitmap varBmp = new Bitmap(pictureBox2.Image);

Bitmap newBitmap = new Bitmap(varBmp);

varBmp.Dispose();

varBmp = null;

varBmp.Save(@"C:\a.png", ImageFormat.Png);

}

else

{ MessageBox.Show("null exception"); }

}

private void clone_Click(object sender, EventArgs e)

{

pictureBox2.Image = (Bitmap)pictureBox1.Image.Clone();

}

}

}

任何AForge.net用户都可以按下面的LINK并尝试一下.谢谢!

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值