Esempio n. 1
0
        void CaptureListener.OnBuffer(CaptureDevice oCaptureDevice, double i_sample_time, IntPtr i_buffer,
                                      int i_buffer_len)
        {
            Dispatcher.Invoke(new Action(delegate()
            {
                TransformedBitmap b = new TransformedBitmap();
                b.BeginInit();
                b.Source = BitmapSource.Create(oCaptureDevice.video_width, oCaptureDevice.video_height, 96.0, 96.0,
                                               PixelFormats.Bgr32, BitmapPalettes.WebPalette, i_buffer,
                                               i_buffer_len, oCaptureDevice.video_width * (oCaptureDevice.video_bit_count / 8));
                b.SetValue(TransformedBitmap.TransformProperty, new ScaleTransform(-1, -1));
                b.EndInit();
                this.ImgCameraZm.SetValue(Image.SourceProperty, b);

                this.ARMarkerSystem.update(this.ARCameraSensor);
                this.CvMainZm.Children.Clear();

                if (this.ARMarkerSystem.isExistMarker(this.MarkerID_VTT))
                {
                    this.DrawARDetectInfo(this.MarkerID_VTT, "VTT");
                }
                if (this.ARMarkerSystem.isExistMarker(this.MarkerID_ABB))
                {
                    this.DrawARDetectInfo(this.MarkerID_ABB, "ABB");
                }
                if (this.ARMarkerSystem.isExistMarker(this.Marker_Hello))
                {
                    this.DrawARDetectInfo(this.Marker_Hello, "Hello");
                }
            }));
        }
        void CaptureListener.OnBuffer(CaptureDevice i_sender, double i_sample_time, IntPtr i_buffer, int i_buffer_len)
        {
            int w = i_sender.video_width;
            int h = i_sender.video_height;
            int s = w * (i_sender.video_bit_count / 8);

            Dispatcher.Invoke(new Action(delegate()
            {
                TransformedBitmap b = new TransformedBitmap();
                b.BeginInit();
                b.Source = BitmapSource.Create(w, h, 96.0, 96.0, PixelFormats.Bgr32, BitmapPalettes.WebPalette, i_buffer,
                                               i_buffer_len, s);
                b.SetValue(TransformedBitmap.TransformProperty, new ScaleTransform(-1, -1));
                b.EndInit();
                image1.SetValue(Image.SourceProperty, b);

                this._ms.update(this._ss);
                this.CvMainZm.Children.Clear();
                if (this._ms.isExistMarker(this.mid))
                {
                    double d = this._ms.getConfidence(this.mid);
                    NyARIntPoint2d[] oPoints = this._ms.getVertex2D(this.mid);

                    Polygon oPolygon = new Polygon()
                    {
                        SnapsToDevicePixels = true,
                        Fill    = new SolidColorBrush(Colors.Violet),
                        Opacity = 0.8,
                        Stroke  = new SolidColorBrush(Colors.Red)
                    };
                    oPolygon.Points = new PointCollection(new Point[]
                    {
                        new Point(oPoints[0].x, oPoints[0].y),
                        new Point(oPoints[1].x, oPoints[1].y),
                        new Point(oPoints[2].x, oPoints[2].y),
                        new Point(oPoints[3].x, oPoints[3].y)
                    });
                    this.CvMainZm.Children.Add(oPolygon);
                }
                else
                {
                    Console.WriteLine("Checked Nothing");
                }
            }));
        }
Esempio n. 3
0
        void CaptureListener.OnBuffer(CaptureDevice i_sender, double i_sample_time, IntPtr i_buffer, int i_buffer_len)
        {
            int w = i_sender.video_width;
            int h = i_sender.video_height;
            int s = w * (i_sender.video_bit_count / 8);

            try
            {
                Dispatcher.BeginInvoke(new Action(delegate()
                {
                    TransformedBitmap b = new TransformedBitmap();
                    b.BeginInit();
                    b.Source = BitmapSource.Create(w, h, 96.0, 96.0, PixelFormats.Bgr32, BitmapPalettes.WebPalette, i_buffer, i_buffer_len, s);
                    b.SetValue(TransformedBitmap.TransformProperty, new ScaleTransform(-1, -1));
                    b.EndInit();
                    image1.SetValue(Image.SourceProperty, b);
                }), null);
            }
            catch {}
        }
Esempio n. 4
0
        public static ImageSource Get(Expression <Func <Bitmap> > memberAccess, int sizeX, int sizeY)
        {
            BitmapSource image = GetInternal(memberAccess);

            if (image != null)
            {
                if (sizeX != (int)image.Width || sizeY != (int)image.Height)
                {
                    TransformedBitmap transformed = new TransformedBitmap(image, new ScaleTransform
                    {
                        CenterX = image.Width / 2,
                        CenterY = image.Height / 2,
                        ScaleX  = sizeX / image.Width,
                        ScaleY  = sizeY / image.Height
                    });

                    transformed.SetValue(RenderOptions.BitmapScalingModeProperty, BitmapScalingMode.Fant);
                    return(transformed);
                }
            }

            return(image);
        }
Esempio n. 5
0
        void CaptureListener.OnBuffer(CaptureDevice i_sender, double i_sample_time, IntPtr i_buffer, int i_buffer_len)
        {
            int w = i_sender.video_width;
            int h = i_sender.video_height;
            int s = w * (i_sender.video_bit_count / 8);

            AForge.Imaging.Filters.FiltersSequence seq = new AForge.Imaging.Filters.FiltersSequence();
            seq.Add(new AForge.Imaging.Filters.Grayscale(0.2125, 0.7154, 0.0721));
            seq.Add(new AForge.Imaging.Filters.Threshold(127));
            seq.Add(new AForge.Imaging.Filters.GrayscaleToRGB());

            AForge.Imaging.UnmanagedImage srcImg = new AForge.Imaging.UnmanagedImage(i_buffer, w, h, s,
                                                                                     System.Drawing.Imaging.PixelFormat.Format32bppRgb);
            AForge.Imaging.UnmanagedImage outputImg = seq.Apply(srcImg);

            byte[] destArr = new byte[outputImg.Stride * outputImg.Height];
            System.Runtime.InteropServices.Marshal.Copy(outputImg.ImageData, destArr, 0,
                                                        outputImg.Stride * outputImg.Height);
            this.m_raster.wrapBuffer(destArr);

            try
            {
                //this.m_ar.

                int detectedMkrs = this.m_ar.detectMarkerLite(this.m_raster, m_threshold);
                NyARDoublePoint2d[]        points   = null;
                List <NyARDoublePoint2d[]> ltPoints = new List <NyARDoublePoint2d[]>();
                if (detectedMkrs > 0)
                {
                    points = m_ar.getCorners(0);

                    ltPoints.Add(points);
                    for (int i = 1; i < detectedMkrs; i++)
                    {
                        NyARDoublePoint2d[] oMarkerPoints = m_ar.getCorners(i);
                        ltPoints.Add(oMarkerPoints);
                    }
                }

                Dispatcher.BeginInvoke(new Action(delegate()
                {
                    try
                    {
                        TransformedBitmap b = new TransformedBitmap();
                        b.BeginInit();
                        b.Source = BitmapSource.Create(w, h, 96.0, 96.0, PixelFormats.Bgr32, BitmapPalettes.WebPalette,
                                                       i_buffer, i_buffer_len, s);
                        b.SetValue(TransformedBitmap.TransformProperty, new ScaleTransform(-1, -1));
                        b.EndInit();
                        image1.SetValue(Image.SourceProperty, b);

                        if (points != null && points.Length == 4)
                        {
                            recognizedTag.Points = new PointCollection(new Point[]
                            {
                                new Point(cameraResX - points[0].x, cameraResY - points[0].y),
                                new Point(cameraResX - points[1].x, cameraResY - points[1].y),
                                new Point(cameraResX - points[2].x, cameraResY - points[2].y),
                                new Point(cameraResX - points[3].x, cameraResY - points[3].y)
                            });
                            recognizedTag.Visibility = System.Windows.Visibility.Visible;
                        }
                        else
                        {
                            recognizedTag.Visibility = System.Windows.Visibility.Hidden;
                        }

                        this.CvMainZm.Children.Clear();
                        for (int i = 1; i < ltPoints.Count; i++)
                        {
                            NyARDoublePoint2d[] oMarkerPoints = ltPoints[i];
                            Polygon oPolygon = new Polygon()
                            {
                                SnapsToDevicePixels = true,
                                Fill    = new SolidColorBrush(Colors.Violet),
                                Opacity = 0.8,
                                Stroke  = new SolidColorBrush(Colors.Red)
                            };

                            oPolygon.Points = new PointCollection(new Point[]
                            {
                                new Point(cameraResX - oMarkerPoints[0].x, cameraResY - oMarkerPoints[0].y),
                                new Point(cameraResX - oMarkerPoints[1].x, cameraResY - oMarkerPoints[1].y),
                                new Point(cameraResX - oMarkerPoints[2].x, cameraResY - oMarkerPoints[2].y),
                                new Point(cameraResX - oMarkerPoints[3].x, cameraResY - oMarkerPoints[3].y)
                            });
                            this.CvMainZm.Children.Add(oPolygon);
                        }
                    }
                    catch
                    {
                    }
                }), null);
            }
            catch
            {
            }
        }
        void CaptureListener.OnBuffer(CaptureDevice i_sender, double i_sample_time, IntPtr i_buffer, int i_buffer_len)
        {
            // calculate size of the frame bitmap
            int w = i_sender.video_width;
            int h = i_sender.video_height;
            int s = w * (i_sender.video_bit_count / 8); // stride


            AForge.Imaging.Filters.FiltersSequence seq = new AForge.Imaging.Filters.FiltersSequence();
            seq.Add(new AForge.Imaging.Filters.Grayscale(0.2125, 0.7154, 0.0721));
            seq.Add(new AForge.Imaging.Filters.Threshold(127));
            seq.Add(new AForge.Imaging.Filters.GrayscaleToRGB());
            AForge.Imaging.UnmanagedImage srcImg    = new AForge.Imaging.UnmanagedImage(i_buffer, w, h, s, System.Drawing.Imaging.PixelFormat.Format32bppRgb);
            AForge.Imaging.UnmanagedImage outputImg = seq.Apply(srcImg);
            byte[] destArr = new byte[outputImg.Stride * outputImg.Height];
            System.Runtime.InteropServices.Marshal.Copy(outputImg.ImageData, destArr, 0, outputImg.Stride * outputImg.Height);
            this.m_raster.wrapBuffer(destArr);

            try
            {
                int        detectedMkrs = this.m_ar.detectMarkerLite(this.m_raster, m_threshold);
                NyARSquare square       = null;
                if (detectedMkrs > 0)
                {
                    NyARTransMatResult  transMat = new NyARTransMatResult();
                    NyARDoublePoint2d[] points   = m_ar.getCorners(0); // RichF added this method
                    square          = new NyARSquare();
                    square.sqvertex = points;
                }


                Dispatcher.BeginInvoke(new Action(delegate()
                {
                    TransformedBitmap b = new TransformedBitmap();
                    b.BeginInit();
                    b.Source = BitmapSource.Create(w, h, dpiX, dpiY, PixelFormats.Bgr32, BitmapPalettes.WebPalette, i_buffer, i_buffer_len, s);
                    b.SetValue(TransformedBitmap.TransformProperty, new ScaleTransform(-1, -1));
                    b.EndInit();
                    image1.SetValue(Image.SourceProperty, b);

                    if (square != null)
                    {
                        recognizedTag.Points = new PointCollection(new Point[] {
                            new Point(cameraResX - square.sqvertex[0].x, cameraResY - square.sqvertex[0].y),
                            new Point(cameraResX - square.sqvertex[1].x, cameraResY - square.sqvertex[1].y),
                            new Point(cameraResX - square.sqvertex[2].x, cameraResY - square.sqvertex[2].y),
                            new Point(cameraResX - square.sqvertex[3].x, cameraResY - square.sqvertex[3].y)
                        });

                        recognizedTag.Visibility = System.Windows.Visibility.Visible;
                    }
                    else
                    {
                        recognizedTag.Visibility = System.Windows.Visibility.Hidden;
                    }
                }), null);
            }
            catch
            {
            }
        }