“试图读取或写入受保护的内存。这通常表明其他内存已损坏。” 当我尝试通过调用RetrieveBgrFrame()方法来存储帧时出现此错误。实际上我正在尝试打开一个中间文件,当 ImageGrabbed 事件获取文件时尝试将其存储在图像变量中以进一步处理文件类型 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();
}
}