<commit_before>﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel;

using Emgu.CV;
using Emgu.CV.Structure;
using System.Threading;

namespace Parsley.Core {

  /// <summary>
  /// Grabs continously frames from camera asynchronously.
  /// </summary>
  public class FrameGrabber : FrameProducer {
    private BackgroundWorker _bw;
    private Camera _camera;

    public FrameGrabber(Camera camera) {
      _camera = camera;
      _bw = new BackgroundWorker();
      _bw.WorkerSupportsCancellation = true;
      _bw.DoWork += new DoWorkEventHandler(_bw_DoWork);
    }

    public void Start()
    {
      if (!_bw.IsBusy) {
        _bw.RunWorkerAsync();
      }
    }

    public void RequestStop() {
      _bw.CancelAsync();
    }

    public Camera Camera
    {
      get { return _camera; }
    }

    protected override void DisposeManaged() {
      this.RequestStop();
    }

    void _bw_DoWork(object sender, DoWorkEventArgs e) {
      BackgroundWorker bw = sender as BackgroundWorker;
      using (Resource.SharedResource.Breath b = _camera.KeepAlive()) {
        while (!bw.CancellationPending) {
          // Note: the image is disposed once the camera gets disposed.
          // Therefore you should copy the image if needed in another
          // thread or make sure the camera is not disposed.
          DateTime dt = DateTime.Now;
          Image<Bgr, byte> img = _camera.Frame();
          this.FireOnFrame(img);
          img.Dispose();
          Console.WriteLine("Framegrabber {0}", (DateTime.Now - dt).TotalSeconds);
        }
      }
      e.Cancel = true;
    }
  }
}<commit_msg>removed timing code<commit_after>﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel;

using Emgu.CV;
using Emgu.CV.Structure;
using System.Threading;

namespace Parsley.Core {

  /// <summary>
  /// Grabs continously frames from camera asynchronously.
  /// </summary>
  public class FrameGrabber : FrameProducer {
    private BackgroundWorker _bw;
    private Camera _camera;

    public FrameGrabber(Camera camera) {
      _camera = camera;
      _bw = new BackgroundWorker();
      _bw.WorkerSupportsCancellation = true;
      _bw.DoWork += new DoWorkEventHandler(_bw_DoWork);
    }

    public void Start()
    {
      if (!_bw.IsBusy) {
        _bw.RunWorkerAsync();
      }
    }

    public void RequestStop() {
      _bw.CancelAsync();
    }

    public Camera Camera
    {
      get { return _camera; }
    }

    protected override void DisposeManaged() {
      this.RequestStop();
    }

    void _bw_DoWork(object sender, DoWorkEventArgs e) {
      BackgroundWorker bw = sender as BackgroundWorker;
      using (Resource.SharedResource.Breath b = _camera.KeepAlive()) {
        while (!bw.CancellationPending) {
          // Note: the image is disposed once the camera gets disposed.
          // Therefore you should copy the image if needed in another
          // thread or make sure the camera is not disposed.
          Image<Bgr, byte> img = _camera.Frame();
          this.FireOnFrame(img);
          img.Dispose();
        }
      }
      e.Cancel = true;
    }
  }
}
{'fraction_non_alphanumeric': 0.09791731426795151, 'fraction_numerical': 0.00031084861672365556, 'mean_word_length': 2.4417112299465242, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3192822', 'n_tokens_mistral': 937, 'n_tokens_neox': 922, 'n_words': 255}