Пример #1
0
        private void contactTarget_FrameReceived(object sender, FrameReceivedEventArgs e)
        {
            int paddingLeft, paddingRight;

            if (raw == null)
            {
                imageAvailable = e.TryGetRawImage(ImageType.Normalized,
                                                  Microsoft.Surface.Core.InteractiveSurface.PrimarySurfaceDevice.Left,
                                                  Microsoft.Surface.Core.InteractiveSurface.PrimarySurfaceDevice.Top,
                                                  Microsoft.Surface.Core.InteractiveSurface.PrimarySurfaceDevice.Width,
                                                  Microsoft.Surface.Core.InteractiveSurface.PrimarySurfaceDevice.Height,
                                                  out raw, out imageMetrics, out paddingLeft, out paddingRight);
            }
            else
            {
                imageAvailable = e.UpdateRawImage(ImageType.Normalized, raw,
                                                  Microsoft.Surface.Core.InteractiveSurface.PrimarySurfaceDevice.Left,
                                                  Microsoft.Surface.Core.InteractiveSurface.PrimarySurfaceDevice.Top,
                                                  Microsoft.Surface.Core.InteractiveSurface.PrimarySurfaceDevice.Width,
                                                  Microsoft.Surface.Core.InteractiveSurface.PrimarySurfaceDevice.Height);
            }
            if (!imageAvailable)
            {
                return;
            }

            var r = CreateEmguCvImage(raw, imageMetrics);

            ProcessFrame(r);
            DetectInputs();
        }
Пример #2
0
        void target_FrameReceived(object sender, FrameReceivedEventArgs e)
        {
            imageAvailable = false;
            int paddingLeft, paddingRight;

            if (null == normalizedImage)
            {
                imageAvailable = e.TryGetRawImage(ImageType.Normalized,
                                                  Microsoft.Surface.Core.InteractiveSurface.DefaultInteractiveSurface.Left,
                                                  Microsoft.Surface.Core.InteractiveSurface.DefaultInteractiveSurface.Top,
                                                  Microsoft.Surface.Core.InteractiveSurface.DefaultInteractiveSurface.Width,
                                                  Microsoft.Surface.Core.InteractiveSurface.DefaultInteractiveSurface.Height,
                                                  out normalizedImage, out imageMetrics, out paddingLeft, out paddingRight);
            }
            else
            {
                imageAvailable = e.UpdateRawImage(ImageType.Normalized, normalizedImage,
                                                  Microsoft.Surface.Core.InteractiveSurface.DefaultInteractiveSurface.Left,
                                                  Microsoft.Surface.Core.InteractiveSurface.DefaultInteractiveSurface.Top,
                                                  Microsoft.Surface.Core.InteractiveSurface.DefaultInteractiveSurface.Width,
                                                  Microsoft.Surface.Core.InteractiveSurface.DefaultInteractiveSurface.Height);
            }

            if (!imageAvailable)
            {
                return;
            }
            DisableRawImage();

            ShowInWPF();
            CaptureVideo();

            imageAvailable = false;
            EnableRawImage();
        }
Пример #3
0
        private void OnTouchTargetFrameReceived(object sender, FrameReceivedEventArgs e)
        {
            //lock (this)
            //{
            // get image from Surface
            if (_surfaceImage == null)
            {
                e.TryGetRawImage(
                    ImageType.Normalized,
                    0, 0,
                    Microsoft.Surface.Core.InteractiveSurface.PrimarySurfaceDevice.WorkingAreaWidth,
                    Microsoft.Surface.Core.InteractiveSurface.PrimarySurfaceDevice.WorkingAreaHeight,
                    out _surfaceImage,
                    out _surfaceMetrics);
            }
            else
            {
                e.UpdateRawImage(
                    ImageType.Normalized,
                    _surfaceImage,
                    0, 0,
                    Microsoft.Surface.Core.InteractiveSurface.PrimarySurfaceDevice.WorkingAreaWidth,
                    Microsoft.Surface.Core.InteractiveSurface.PrimarySurfaceDevice.WorkingAreaHeight);
            }

            // create EmguCV image and fire event
            _emguCvImage      = CreateEmguCvImage(_surfaceImage, _surfaceMetrics);
            _currentTimeStamp = DateTime.Now.Ticks;
            _imageEvent.Set();
            if (OnNewImage != null)
            {
                OnNewImage(_emguCvImage);
            }
            //}
        }
Пример #4
0
        void target_FrameReceived(object sender, FrameReceivedEventArgs e)
        {
            if (++count < 30)
            {
                return;
            }
            else
            {
                count          = 0;
                imageAvailable = false;
                int paddingLeft, paddingRight;
                if (null == normalizedImage)
                {
                    imageAvailable = e.TryGetRawImage(ImageType.Normalized,
                                                      Microsoft.Surface.Core.InteractiveSurface.DefaultInteractiveSurface.Left,
                                                      Microsoft.Surface.Core.InteractiveSurface.DefaultInteractiveSurface.Top,
                                                      Microsoft.Surface.Core.InteractiveSurface.DefaultInteractiveSurface.Width,
                                                      Microsoft.Surface.Core.InteractiveSurface.DefaultInteractiveSurface.Height,
                                                      out normalizedImage, out imageMetrics, out paddingLeft, out paddingRight);
                }
                else
                {
                    imageAvailable = e.UpdateRawImage(ImageType.Normalized, normalizedImage,
                                                      Microsoft.Surface.Core.InteractiveSurface.DefaultInteractiveSurface.Left,
                                                      Microsoft.Surface.Core.InteractiveSurface.DefaultInteractiveSurface.Top,
                                                      Microsoft.Surface.Core.InteractiveSurface.DefaultInteractiveSurface.Width,
                                                      Microsoft.Surface.Core.InteractiveSurface.DefaultInteractiveSurface.Height);
                }

                if (!imageAvailable)
                {
                    return;
                }

                DisableRawImage();

                //System.IO.MemoryStream stream = new System.IO.MemoryStream(normalizedImage);
                //BmpBitmapDecoder decoder = new BmpBitmapDecoder(stream, BitmapCreateOptions.PreservePixelFormat, BitmapCacheOption.OnLoad);
                //ImageSource source = decoder.Frames[0];
                //source.Freeze();
                //iCapturedFrame.Source = source;

                GCHandle h      = GCHandle.Alloc(normalizedImage, GCHandleType.Pinned);
                IntPtr   ptr    = h.AddrOfPinnedObject();
                Bitmap   bitmap = new Bitmap(imageMetrics.Width,
                                             imageMetrics.Height,
                                             imageMetrics.Stride,
                                             System.Drawing.Imaging.PixelFormat.Format8bppIndexed,
                                             ptr);


                tracker.ProcessImage(bitmap);

                imageAvailable = false;
                //if (!tracker.TrackingDisabled)
                EnableRawImage();
            }
        }
Пример #5
0
        void target_FrameReceived(object sender, FrameReceivedEventArgs e)
        {
            if (++count < 30)
            {
                return;
            }
            else
            {
                count          = 0;
                imageAvailable = false;
                int paddingLeft, paddingRight;
                if (null == normalizedImage)
                {
                    imageAvailable = e.TryGetRawImage(ImageType.Normalized,
                                                      Microsoft.Surface.Core.InteractiveSurface.PrimarySurfaceDevice.Left,
                                                      Microsoft.Surface.Core.InteractiveSurface.PrimarySurfaceDevice.Top,
                                                      Microsoft.Surface.Core.InteractiveSurface.PrimarySurfaceDevice.Width,
                                                      Microsoft.Surface.Core.InteractiveSurface.PrimarySurfaceDevice.Height,
                                                      out normalizedImage, out imageMetrics, out paddingLeft, out paddingRight);
                }
                else
                {
                    imageAvailable = e.UpdateRawImage(ImageType.Normalized, normalizedImage,
                                                      Microsoft.Surface.Core.InteractiveSurface.PrimarySurfaceDevice.Left,
                                                      Microsoft.Surface.Core.InteractiveSurface.PrimarySurfaceDevice.Top,
                                                      Microsoft.Surface.Core.InteractiveSurface.PrimarySurfaceDevice.Width,
                                                      Microsoft.Surface.Core.InteractiveSurface.PrimarySurfaceDevice.Height);
                }

                if (!imageAvailable)
                {
                    return;
                }

                DisableRawImage();

                tracker.ProcessImage(normalizedImage, imageMetrics, captureFrame);
                captureFrame = false;

                imageAvailable = false;
                EnableRawImage();
            }
        }
        void target_FrameReceived(object sender, FrameReceivedEventArgs e)
        {
            imageAvailable = false;
            int paddingLeft, paddingRight;
            if (normalizedImage == null)
            {
                imageAvailable = e.TryGetRawImage(ImageType.Normalized,
                  Microsoft.Surface.Core.InteractiveSurface.DefaultInteractiveSurface.Left,
                  Microsoft.Surface.Core.InteractiveSurface.DefaultInteractiveSurface.Top,
                  Microsoft.Surface.Core.InteractiveSurface.DefaultInteractiveSurface.Width,
                  Microsoft.Surface.Core.InteractiveSurface.DefaultInteractiveSurface.Height,
                  out normalizedImage, out imageMetrics, out paddingLeft, out paddingRight);
            }
            else
            {
                imageAvailable = e.UpdateRawImage(ImageType.Normalized, normalizedImage,
                  Microsoft.Surface.Core.InteractiveSurface.DefaultInteractiveSurface.Left,
                  Microsoft.Surface.Core.InteractiveSurface.DefaultInteractiveSurface.Top,
                  Microsoft.Surface.Core.InteractiveSurface.DefaultInteractiveSurface.Width,
                  Microsoft.Surface.Core.InteractiveSurface.DefaultInteractiveSurface.Height);
            }

            if (!imageAvailable)
                return;

            DisableRawImage();

            GCHandle h = GCHandle.Alloc(normalizedImage, GCHandleType.Pinned);
            IntPtr ptr = h.AddrOfPinnedObject();
            frame = new Bitmap(imageMetrics.Width,
                                  imageMetrics.Height,
                                  imageMetrics.Stride,
                                  System.Drawing.Imaging.PixelFormat.Format8bppIndexed,
                                  ptr);

            Convert8bppBMPToGrayscale(frame);

            //convert the bitmap into an EmguCV image <Gray,byte>
            Image<Gray, byte> imageFrame = new Image<Gray, byte>(frame);
            //process the frame for tracking the blob
            imageFrame = processFrame(imageFrame);

            iCapturedFrame.Source = Bitmap2BitmapImage(imageFrame.ToBitmap());

            /* save the first 40 images captured
             *
             * if (i < 40)
             * {
             * flipper.Save("capture-" + i + ".bmp");
             * i++;
             * }
             *
             */

            imageAvailable = false;
            EnableRawImage();
        }
Пример #7
0
        public void OnContactRecordGesture(object sender, FrameReceivedEventArgs e)
        {
            if (isTouching)
            {
                if (normalizedImage == null)
                {
                    e.TryGetRawImage(
                        ImageType.Normalized,
                        0, 0,
                        InteractiveSurface.DefaultInteractiveSurface.Width,
                        InteractiveSurface.DefaultInteractiveSurface.Height,
                        out normalizedImage,
                        out normalizedMetrics);
                }
                else //updates raw image data
                {
                    e.UpdateRawImage(
                        ImageType.Normalized,
                        normalizedImage,
                        0, 0,
                        InteractiveSurface.DefaultInteractiveSurface.Width,
                        InteractiveSurface.DefaultInteractiveSurface.Height);
                }

                capture.OnContactRecordHelper(normalizedImage, normalizedMetrics);
            }
        }
        private void contactTarget_FrameReceived(object sender, FrameReceivedEventArgs e)
        {
            int padRight, padLeft;

            if (rawImageBytes == null)
            {
                e.TryGetRawImage(ImageType.Normalized,
                    0,
                    InteractiveSurface.DefaultInteractiveSurface.Top,
                    InteractiveSurface.DefaultInteractiveSurface.Width,
                    InteractiveSurface.DefaultInteractiveSurface.Height,
                    out rawImageBytes, out rawImageMetrics, out padLeft, out padRight);
            }
            else
            {
                e.UpdateRawImage(ImageType.Normalized, rawImageBytes,
                    0,
                    InteractiveSurface.DefaultInteractiveSurface.Top,
                    InteractiveSurface.DefaultInteractiveSurface.Width,
                    InteractiveSurface.DefaultInteractiveSurface.Height);
            }
        }
        //  private void getImage(object sender, DoWorkEventArgs args)
        private void getImage(FrameReceivedEventArgs e)
        {
            //    FrameReceivedEventArgs e = args.Argument as FrameReceivedEventArgs;
            bool imageAvailable = false;
            int paddingLeft,
                  paddingRight;
            try
            {
                if (normalizedImage == null)
                {
                    imageAvailable = e.TryGetRawImage(Microsoft.Surface.Core.ImageType.Normalized,
                       0, 0,
                        Microsoft.Surface.Core.InteractiveSurface.PrimarySurfaceDevice.Width,
                        Microsoft.Surface.Core.InteractiveSurface.PrimarySurfaceDevice.Height,
                        out normalizedImage,
                        out normalizedMetrics,
                        out paddingLeft,
                        out paddingRight);
                }
                else
                {

                    imageAvailable = e.UpdateRawImage(Microsoft.Surface.Core.ImageType.Normalized,
                         normalizedImage,
                         0, 0,
                         Microsoft.Surface.Core.InteractiveSurface.PrimarySurfaceDevice.Width,
                         Microsoft.Surface.Core.InteractiveSurface.PrimarySurfaceDevice.Height);
                }

            }

            catch (Exception exc)
            {
                Console.WriteLine(exc.Message);
            }

            if (imageAvailable)
            {
                imageAvailable = false;

                GCHandle h = GCHandle.Alloc(normalizedImage, GCHandleType.Pinned);
                IntPtr ptr = h.AddrOfPinnedObject();
                System.Drawing.Bitmap imageBitmap = new System.Drawing.Bitmap(normalizedMetrics.Width,
                                      normalizedMetrics.Height,
                                      normalizedMetrics.Stride,
                                      System.Drawing.Imaging.PixelFormat.Format8bppIndexed,
                                      ptr);

                ImageHelper.BinarizeImage(imageBitmap);
                System.Drawing.Bitmap imgClone = new System.Drawing.Bitmap(imageBitmap);
                imgClone.Palette = imageBitmap.Palette;
                DateTime now = DateTime.Now;
                snapshots.Add(now, imgClone);

                //  imgClone.Save(".\\aft\\BEFORE" + DateTime.Now.ToString("hh-mm-ss-fff") + ".jpg");

            }
        }
Пример #10
0
        private void OnTouchTargetFrameReceived(object sender, FrameReceivedEventArgs e)
        {
            // Lock the syncObject object so normalizedImage isn't changed while the Update method is using it
            lock (syncObject)
            {
                if (normalizedImage == null)
                {
                    // get rawimage data for a specific area
                    if (e.TryGetRawImage(
                            ImageType.Normalized,
                            0, 0,
                            InteractiveSurface.PrimarySurfaceDevice.WorkingAreaWidth,
                            InteractiveSurface.PrimarySurfaceDevice.WorkingAreaHeight,
                            out normalizedImage,
                            out normalizedMetrics))
                    {

                        scale = (InteractiveSurface.PrimarySurfaceDevice == null)
                                    ? 1.0f
                                    : (float)InteractiveSurface.PrimarySurfaceDevice.WorkingAreaWidth / normalizedMetrics.Width;
                        normalizedImageUpdated = true;
                    }
                }
                else
                {
                    // get the updated rawimage data for the specified area
                    normalizedImageUpdated = e.UpdateRawImage(
                        ImageType.Normalized,
                        normalizedImage,
                        0, 0,
                        InteractiveSurface.PrimarySurfaceDevice.WorkingAreaWidth,
                        InteractiveSurface.PrimarySurfaceDevice.WorkingAreaHeight);
                }

            }
        }
 /// <summary>
 /// Called when the ContactTargetFrameReceived event is raised.
 /// </summary>
 /// <param name="sender">The sender.</param>
 /// <param name="args">The <see cref="Microsoft.Surface.Core.FrameReceivedEventArgs"/> instance containing the event data.</param>
 private static void OnContactTargetFrameReceived(object sender, FrameReceivedEventArgs args)
 {
     imageAvailable = false;
     int paddingLeft, paddingRight;
     if (normalizedImage == null)
     {
         imageAvailable = args.TryGetRawImage(
             ImageType.Normalized,
             InteractiveSurface.DefaultInteractiveSurface.Left,
             InteractiveSurface.DefaultInteractiveSurface.Top,
             InteractiveSurface.DefaultInteractiveSurface.Width,
             InteractiveSurface.DefaultInteractiveSurface.Height,
             out normalizedImage,
             out normalizedMetrics,
             out paddingLeft,
             out paddingRight);
     }
     else
     {
         imageAvailable = args.UpdateRawImage(
              ImageType.Normalized,
              normalizedImage,
              InteractiveSurface.DefaultInteractiveSurface.Left,
              InteractiveSurface.DefaultInteractiveSurface.Top,
              InteractiveSurface.DefaultInteractiveSurface.Width,
              InteractiveSurface.DefaultInteractiveSurface.Height);
     }
 }