I am developing a project in c#. I have a stop button which calls grabber.dispose but when I click it the application crashes and I get the following error:
object reference is not set to an instance of object.
FrameGrabber function should stop the program and move it to currentframe.
Capture grabber:
private void FDButton_Click(object sender, EventArgs e)
{
CameraCapture();
Application.Idle += new EventHandler(FrameGrabber);
//initalize Frame grabber event
FDButton.Enabled = false;
}
private void FrameGrabber(object sender, EventArgs e)
{
currentFrame = grabber.QueryFrame().Resize(320, 240, Emgu.CV.CvEnum.INTER.CV_INTER_CUBIC);
//convert frame to gray scale
gray = currentFrame.Convert<Gray, Byte>();
//now detect face by using classifier
MCvAvgComp[][] facesDetected = gray.DetectHaarCascade(
face,//name of cascade
1.2,
10,
Emgu.CV.CvEnum.HAAR_DETECTION_TYPE.DO_CANNY_PRUNING,
new Size(20, 20));
//now check each frame of imagebox containing video and detect face
foreach (MCvAvgComp f in facesDetected[0])
{
//if face found increment t
t = t + 1;
//now see result by copying detected face in a frame name as result
result = currentFrame.Copy(f.rect).Convert<Gray, byte>().Resize(100, 100, Emgu.CV.CvEnum.INTER.CV_INTER_CUBIC);
//we convert current frame to gray scale and resize to 200x100
//now draw rectangle on detected image
currentFrame.Draw(f.rect, new Bgr(Color.Red), 2);
}
//view currentframe in imported imagebox
DetectionImageBox.Image = currentFrame;
}
Camera Capture Function:
public void CameraCapture()
{
grabber = new Capture();
grabber.QueryFrame();
}
Cancel Button:
private void FDStopButton_Click(object sender, EventArgs e)
{
grabber.Dispose();
}