「保護されたメモリを読み書きしようとしました。これは多くの場合、他のメモリが破損していることを示しています。」RetrieveBgrFrame()メソッドを呼び出してフレームを保存しようとすると、このエラーが発生します。実際に私はメディアファイルを開こうとしています.ImageGrabbedイベントがファイルを取得したら、それをさらに処理するために画像変数に保存しようとします.File Type 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();
}
}