I have a small project whereby I capture images from a webcam and decode the qr.
The following code captures an image and stores it to a local file, but only when it is not in the while loop. The system.threading appears to make the captured image just black. If i don't use it(the loop), it captures far too many images a second.
So is there a way of changing the aforge.video framerate so that i can capture an image every x seconds without while loop?
public partial class WebForm1 : System.Web.UI.Page
{
public int FrameRate { get; set; }
private FilterInfoCollection VideoCaptureDevices;
private VideoCaptureDevice FinalVideo;
protected void Page_Load(object sender, EventArgs e)
{
inputDevices.Items.Clear();
VideoCaptureDevices = new FilterInfoCollection(FilterCategory.VideoInputDevice);
foreach (FilterInfo VideoCaptureDevice in VideoCaptureDevices)
{
inputDevices.Items.Add(VideoCaptureDevice.Name);
}
inputDevices.SelectedIndex = 0;
}
public void Start_OnClick(object sender, EventArgs e)
{
FinalVideo = new VideoCaptureDevice(VideoCaptureDevices[inputDevices.SelectedIndex].MonikerString);
FinalVideo.NewFrame += new NewFrameEventHandler(FinalVideo_NewFrame);
FinalVideo.Start();
}
void FinalVideo_NewFrame(object sender, NewFrameEventArgs eventArgs)
{
int i = 0;
while (i < 10)
{
Bitmap video = (Bitmap)eventArgs.Frame.Clone();
video.Save("C:\\Users\\Wayneio\\Desktop\\image\\test" + i + ".jpg");
i++;
System.Threading.Thread.Sleep(5000);
}
}
public void Stop_OnClick(object sender, EventArgs e)
{
this.FinalVideo.Stop();
}
}
Additionally I get this error when trying to stop the capture via the asp button:
Object reference not set to an instance of an object on this.FinalVideo.Stop();
Tried this to no avail: ((VideoCaptureDevice)FinalVideo).DesiredFrameRate = 10;