Hi
(I'm the same person who gave you this answer on Stackoverflow in case you think I'm copying :), this is just in case others stumble across this question)
Well the problem you have is that your not disposing of your old capture so when you send of for another it will always return the old one and then get another. The following code adjusted from the Web camera example should do the trick.
_capture = new Capture();
Image<Bgr, Byte> frame = _capture.QueryFrame();
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(new Gray(100), new Gray(60));
captureImageBox.Image = frame;
grayscaleImageBox.Image = grayFrame;
smoothedGrayscaleImageBox.Image = smoothedGrayFrame;
cannyImageBox.Image = cannyFrame;
_capture.Dispose();
It is the _capture.Dispose(); that is the important bit.
As for your 1600x1200 yes your right it is because you have a large amount of data in memory. First of start by efficiently 'using' the memory stream and disposing of it when where done with it. This is done with the 'using' statement which automatically creates the object at the start and calls its .Dispose function at the end, just so you don't have to. Note the copy procedure else a pointer is passed and when you exit the using code you will dispose of frame as well. You should also practice the 'using' statement when using images. But the above code will now look like this:
Image<Bgr, Byte> frame;
using (Capture capture = new Capture())
{
frame = capture1.QueryFrame().Copy();
}
Image<Gray, Byte> grayFrame = frame.Convert<Gray, Byte>();
Image<Gray, Byte> smallGrayFrame = grayFrame.PyrDown();
Image<Gray, Byte> smoothedGrayFrame = smallGrayFrame.PyrUp();
Image<<gray,> cannyFrame = smoothedGrayFrame.Canny(new Gray(100), new Gray(60));
grayscaleImageBox.Image = grayFrame;
smoothedGrayscaleImageBox.Image = smoothedGrayFrame;
cannyImageBox.Image = cannyFrame;
Second of all you can resize the captured image using .Resize(scale, Interpolation Method). Large images are usually passed from a camera using a dedicated frame grabber so system dependency is avoided obviously this is no longer the case with HD USB web cams.
You can resize your input image like so and with your 'using' statements efficiently your final code will look like this:
Image<Bgr, Byte> frame;
using (Capture capture1 = new Capture())
{
frame = capture1.QueryFrame().Resize(0.5, Emgu.CV.CvEnum.INTER.CV_INTER_AREA).Copy();
captureImageBox.Image = frame;
}
using (Image<Gray, Byte> grayFrame = frame.Convert<Gray, Byte>())
{
grayscaleImageBox.Image = grayFrame;
using (Image<Gray, Byte> smallGrayFrame = grayFrame.PyrDown())
{
using (Image<Gray, Byte> smoothedGrayFrame = smallGrayFrame.PyrUp())
{
smoothedGrayscaleImageBox.Image = smoothedGrayFrame;
using (Image<Gray, Byte> cannyFrame = smoothedGrayFrame.Canny(new Gray(100), new Gray(60)))
{
cannyImageBox.Image = cannyFrame;
}
}
}
}
Cheers
Chris