I want to Capture Image Using Webcam. I am using WebCam_Capture.dll
library.
sometimes following code work Perfect. (Mostly after restarting system
or turn on and off Vcamp.exe
)
sometimes Camera won't turn on and It seems an Image captured of Green color
sometimes camera won't turn on and a message-box Shows with description "Object reference not set to an instance of an object
" message always on webcam.Start(0);
in capture()
I want to know the cause of error. How to solve this problem
global Variables
private WebCamCapture webcam;
private System.Windows.Forms.PictureBox _FrameImage;
private int FrameNumber = 50;
bool FCapture=true;
Webcam Inetilization
public void InitializeWebCam(ref System.Windows.Forms.PictureBox ImageControl)
{
try
{
webcam.Dispose();
}
catch (Exception)
{
}
webcam = new WebCamCapture();
webcam.FrameNumber = ((ulong)(0ul));
webcam.TimeToCapture_milliseconds = FrameNumber;
webcam.ImageCaptured += new WebCamCapture.WebCamEventHandler(webcam_ImageCaptured);
_FrameImage = ImageControl;
}
Webcam Capturing Function
void webcam_ImageCaptured(object source, WebcamEventArgs e)
{
if (FCapture == true)
{
imgbox1.Image = e.WebCamImage;
FCapture = false;
}
else
{
webcam.Stop();
}
}
Call function.
public void capture()
{
InitializeWebCam(ref _FrameImage);
webcam.TimeToCapture_milliseconds = FrameNumber;
webcam.Start(0);
}