Exemplo n.º 1
0
 public Form1()
 {
     InitializeComponent();
     webcam = new WebCam();
     webcam.InitializeWebCam(ref pictureBox1);
     this.pictureBox1.SizeMode = PictureBoxSizeMode.StretchImage;
     //webcam.Stop();
 }
Exemplo n.º 2
0
        unsafe void webcam_ImageCaptured(object source, WebcamEventArgs e)
        {
            //_FrameImage.Image = e.WebCamImage;
            Bitmap     bm      = (Bitmap)e.WebCamImage;
            Bitmap     bm_copy = (Bitmap)bm.Clone();
            BitmapData data    = bm.LockBits(new Rectangle(0, 0, bm.Width, bm.Height), ImageLockMode.ReadWrite, PixelFormat.Format24bppRgb); //.Format32bppArgb); //.Format24bppRgb);
            //IntPtr ptr = data.Scan0;
            Byte *bptr = (Byte *)data.Scan0.ToPointer();

            if (this.inversion)
            {
                WebCam.InvertImage((char *)bptr, (int)(bm.Width * bm.Height * 3));
            }
            if (this.detection)
            {
                if (bm_prev != null)
                {
                    BitmapData data2 = bm_prev.LockBits(new Rectangle(0, 0, bm.Width, bm.Height), ImageLockMode.ReadWrite, PixelFormat.Format24bppRgb); //.Format32bppArgb); //.Format24bppRgb);
                    Byte *     bptr2 = (Byte *)data2.Scan0.ToPointer();
                    WebCam.SubtractImage((char *)bptr, (char *)bptr2, (int)(bm.Width * bm.Height * 3), 30);
                }
            }

            /*if (this.detection)
             * {
             *  if (bInitialized == false)
             *  {
             *      int ret = WebCam.foo(null, 0, 0);
             *      if (ret < 0)
             *      {
             *          MessageBox.Show("foo returned " + ret);
             *          detection = false;
             *      }
             *      else
             *      {
             *          bInitialized = true;
             *      }
             *  }
             *  int ret2 = WebCam.detectFace((char*)bptr, (int)bm.Width, (int)bm.Height);
             *  //int ret = WebCam.foo((char*)bptr, (int)bm.Width, (int)bm.Height);
             *  if (ret2 < 0)
             *  {
             *      MessageBox.Show("detectFace returned " + ret2);
             *      detection = false;
             *  }
             * }*/
            bm.UnlockBits(data);
            _FrameImage.Image = bm;
            bm_prev           = bm_copy;
        }