コード例 #1
0
ファイル: ContactData.cs プロジェクト: zhuangfangwang/ise
		public ContactData(Contact contactData, IntPtr hwnd)
		{
			Id = contactData.Id;
            Position = Utils.ScreenToClient(contactData.Position, hwnd);
			Bounds = Utils.ScreenToClient(contactData.Bounds, hwnd);
			Orientation = contactData.Orientation;
			State = contactData.State;
			Area = contactData.Area;
			MajorAxis = contactData.MajorAxis;
			MinorAxis = contactData.MinorAxis;
			Hwnd = hwnd;
		}
コード例 #2
0
ファイル: InputProvider.cs プロジェクト: francoisvdv/PwTouch
        void VideoSource_NewFrame(object sender, AForge.Video.NewFrameEventArgs eventArgs)
        {
            if(OnCameraFrame != null)
                OnCameraFrame(Image.Clone(eventArgs.Frame));

            if (skipFrames < Global.AppSettings.SkipFrames)
            {
                skipFrames++;
                return;
            }
            else
                skipFrames = 0;

            frame = (Bitmap)eventArgs.Frame.Clone();

            if (detector == null || tracker == null || restartDetector != null)
            {
                if (restartDetector != null)
                    detector = restartDetector;
                else
                    detector = DetectorManager.LoadDetectorWithoutExceptions(DetectorManager.DetectorDirectory + "\\" + Global.AppSettings.DetectorName + ".dll");

                if (detector == null)
                    detector = new Detector1();

                detector.Initialize(Image.Clone(frame));

                tracker = new Tracker1();
                restartDetector = null;
            }

            try
            {
                detector.ProcessFrame(ref frame);
            }
            catch(Exception exc)
            {
                if (detector.GetType() != typeof(Detector1))
                    SetDetector(new Detector1());
                else
                    throw exc;

                return;
            }

            if (OnProcessedFrame != null)
                OnProcessedFrame(Image.Clone(frame));

            List<Blob> trackedBlobs = tracker.ProcessBlobs(detector.GetBlobRectangles());

            if (OnBlobsTracked != null)
                OnBlobsTracked(trackedBlobs);

            Bitmap processedCameraFrame;
            if (OnProcessedFrame != null)
            {
                processedCameraFrame = frame.Clone(new Rectangle(0, 0, frame.Size.Width, frame.Size.Height), System.Drawing.Imaging.PixelFormat.Format32bppArgb);
                Graphics g = Graphics.FromImage(processedCameraFrame);

                Font idFont = new Font("Arial", processedCameraFrame.Width / 20);

                //Draw rectangles to original camera frame
                foreach (Blob blob in trackedBlobs)
                {
                    if (!blob.Active)
                        continue;

                    g.DrawRectangle(Pens.Yellow, blob.Rect);

                    g.FillRectangle(new SolidBrush(Color.FromArgb(150, Color.DarkRed)),
                        new Rectangle(blob.Rect.X, blob.Rect.Y, (int)g.MeasureString(blob.Id.ToString(), idFont).Width, (int)idFont.GetHeight()));
                    g.DrawString(blob.Id.ToString(), idFont, Brushes.White, new PointF(blob.Rect.X, blob.Rect.Y));
                }

                if (OnProcessedCameraFrame != null) //this is a different thread, so it might have changed in the meantime (race condition)
                    OnProcessedCameraFrame(processedCameraFrame);
            }

            if (NewFrame != null)
            {
                List<Contact> contacts = new List<Contact>();
                foreach (Blob blob in trackedBlobs)
                {
                    Point w2s = WebcamToScreen(blob);
                    //Console.WriteLine(w2s.ToString());
                    Contact c = new Contact(blob.Id, blob.ContactState, new System.Windows.Point(w2s.X, w2s.Y), blob.Rect.Width, blob.Rect.Height);
                    contacts.Add(c);
                }

                NewFrame(this, new NewFrameEventArgs(Stopwatch.GetTimestamp(), contacts, null));
                contacts.Clear();
            }

            frame.Dispose();
        }