“尝试读取或写入受保护的内存。这通常表示其他内存已损坏。”当我试图通过调用 RetrieveBgrFrame()方法来存储框架时出现此错误。 实际上我正在尝试打开一个medial文件,当ImageGrabbed事件获取文件时,尝试将其存储在image变量中以便进一步处理 文件类型Dummy.avi 这是我的代码:
public partial class CameraCapture : Form
{
private Capture _capture = null;
private bool _captureInProgress;
public CameraCapture()
{
InitializeComponent();
try
{
_capture = new Capture(@"D:\imageprocessing\CapturedImages\CameraSample-1.avi");
_capture.ImageGrabbed += ProcessFrame;
}
catch (NullReferenceException excpt)
{
MessageBox.Show(excpt.Message);
}
}
private void ProcessFrame(object sender, EventArgs arg)
{
**Image<Bgr, Byte> frame = _capture.RetrieveBgrFrame();**
*//Here is the Error*
Image<Gray, Byte> grayFrame = frame.Convert<Gray, Byte>();
Image<Gray, Byte> smallGrayFrame = grayFrame.PyrDown();
Image<Gray, Byte> smoothedGrayFrame = smallGrayFrame.PyrUp();
Image<Gray, Byte> cannyFrame = smoothedGrayFrame.Canny(100, 60);
captureImageBox.Image = frame;
grayscaleImageBox.Image = grayFrame;
smoothedGrayscaleImageBox.Image = smoothedGrayFrame;
cannyImageBox.Image = cannyFrame;
}
private void captureButtonClick(object sender, EventArgs e)
{
if (_capture != null)
{
if (_captureInProgress)
{ //stop the capture
captureButton.Text = "Start Capture";
_capture.Pause();
}
else
{
//start the capture
captureButton.Text = "Stop";
_capture.Start();
}
_captureInProgress = !_captureInProgress;
}
}
private void ReleaseData()
{
if (_capture != null)
_capture.Dispose();
}
}
答案 0 :(得分:0)
我认为您需要在使用Grab()
之前执行RetrieveBgrFrame
(请参阅该功能的IntelliSense文档)。通过使用QueryFrame()
函数,有一种更简单的方法。
以下是在EmguCV中捕获视频的最小代码:
using Emgu.CV;
using Emgu.CV.UI;
using Emgu.CV.Structure;
using System.Drawing;
using System.Windows.Forms;
...
ImageViewer viewer = new ImageViewer(); //create an image viewer
Capture capture = new Capture(); //create a camera captue
Application.Idle += new EventHandler(delegate(object sender, EventArgs e)
{ //run this until application closed (close button click on image viewer)
viewer.Image = capture.QueryFrame(); //draw the image obtained from camera
});
viewer.ShowDialog(); //show the image viewer
您可以在官方EmguCV website上找到此示例。