Ejemplo n.º 1
0
        private void CameraZm_NewVideoSample(object sender, WPFMediaKit.DirectShow.MediaPlayers.VideoSampleArgs e)
        {
            Dispatcher.Invoke(new Action(delegate()
            {
                System.Drawing.Bitmap oNewFrame = e.VideoFrame;
                var bitmapData = oNewFrame.LockBits(
                    new System.Drawing.Rectangle(0, 0, oNewFrame.Width, oNewFrame.Height),
                    System.Drawing.Imaging.ImageLockMode.ReadOnly, oNewFrame.PixelFormat);

                byte[] oFrameBytes = new byte[bitmapData.Stride * bitmapData.Height];
                System.Runtime.InteropServices.Marshal.Copy(bitmapData.Scan0, oFrameBytes, 0,
                                                            bitmapData.Stride * bitmapData.Height);
                oNewFrame.UnlockBits(bitmapData);

                this.ARRgbRaster.wrapBuffer(oFrameBytes);
                int detectedMkrs = this.ARDetectMarker.detectMarkerLite(this.ARRgbRaster, 100);

                double d = this.ARDetectMarker.getConfidence(3);
                int n    = this.ARDetectMarker.getARCodeIndex(3);

                this.TbkInfoZm.Text = detectedMkrs.ToString();
                //NyARDoublePoint2d[] points = null;
                //List<NyARDoublePoint2d[]> ltPoints = new List<NyARDoublePoint2d[]>();
                //if (detectedMkrs > 0)
                //{
                //    //points = ARDetectMarker.getCorners(0);

                //    //ltPoints.Add(points);
                //    for (int i = 0; i < detectedMkrs; i++)
                //    {
                //        NyARDoublePoint2d[] oMarkerPoints = ARDetectMarker.getCorners(i);
                //        ltPoints.Add(oMarkerPoints);
                //    }
                //}
                //Dispatcher.BeginInvoke(new Action(delegate ()
                //{
                //    try
                //    {
                //        this.CvMainZm.Children.Clear();
                //        for (int i = 0; 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(oMarkerPoints[0].x, 600 - oMarkerPoints[0].y),
                //                      new Point(oMarkerPoints[1].x, 600 - oMarkerPoints[1].y),
                //                      new Point(oMarkerPoints[2].x, 600 - oMarkerPoints[2].y),
                //                      new Point(oMarkerPoints[3].x, 600 - oMarkerPoints[3].y)
                //            });
                //            this.CvMainZm.Children.Add(oPolygon);
                //        }
                //    }
                //    catch
                //    { }
                //}), null);
            }));
        }
Ejemplo n.º 2
0
        private void CameraZm_NewVideoSample(object sender, WPFMediaKit.DirectShow.MediaPlayers.VideoSampleArgs e)
        {
            Dispatcher.Invoke(new Action(delegate()
            {
                System.Drawing.Bitmap oNewFrame = e.VideoFrame;
                var bitmapData = oNewFrame.LockBits(
                    new System.Drawing.Rectangle(0, 0, oNewFrame.Width, oNewFrame.Height),
                    System.Drawing.Imaging.ImageLockMode.ReadOnly, oNewFrame.PixelFormat);

                byte[] destArr = new byte[bitmapData.Stride * bitmapData.Height];
                System.Runtime.InteropServices.Marshal.Copy(bitmapData.Scan0, destArr, 0,
                                                            bitmapData.Stride * bitmapData.Height);
                oNewFrame.UnlockBits(bitmapData);
                this.m_raster.wrapBuffer(destArr);

                try
                {
                    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 = 0; i < detectedMkrs; i++)
                        {
                            NyARDoublePoint2d[] oMarkerPoints = m_ar.getCorners(i);
                            ltPoints.Add(oMarkerPoints);
                        }
                    }
                    Dispatcher.BeginInvoke(new Action(delegate()
                    {
                        try
                        {
                            this.CvMainZm.Children.Clear();
                            for (int i = 0; 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(oMarkerPoints[0].x, cameraResY - oMarkerPoints[0].y),
                                    new Point(oMarkerPoints[1].x, cameraResY - oMarkerPoints[1].y),
                                    new Point(oMarkerPoints[2].x, cameraResY - oMarkerPoints[2].y),
                                    new Point(oMarkerPoints[3].x, cameraResY - oMarkerPoints[3].y)
                                });
                                this.CvMainZm.Children.Add(oPolygon);
                            }
                        }
                        catch
                        {}
                    }), null);
                }
                catch
                {}
            }));
        }