Beispiel #1
0
        private static void withoutKeyframes(bool isFast, string videoSource = null)
        {
            ImageViewer viewer = new ImageViewer();

            try
            {
                Capture           capture = videoSource != null ? new Capture(videoSource) : new Capture(0);
                Image <Bgr, Byte> lastFrame = null, result = null;
                Application.Idle += new EventHandler(delegate(object sender, EventArgs e)
                {
                    IDrawer drawer;
                    if (isFast)
                    {
                        drawer = new FastDrawer();
                    }
                    else
                    {
                        drawer = new SURFDrawer();
                    }
                    try
                    {
                        Mat frame = capture.QueryFrame();
                        if (frame.Width > 720 || frame.Height > 480)
                        {
                            double width  = 720.0 / frame.Width;
                            double height = 480.0 / frame.Height;

                            CvInvoke.Resize(frame, frame, new Size(), width, height, Inter.Linear);
                        }
                        result = frame.ToImage <Bgr, Byte>();
                        if (lastFrame != null)
                        {
                            result = drawer.FindMatch(frame.ToImage <Bgr, Byte>(), lastFrame).Draw(frame.ToImage <Bgr, Byte>(), lastFrame);
                        }

                        lastFrame    = frame.ToImage <Bgr, Byte>();
                        viewer.Width = frame.Width * 2 + 50;
                        viewer.Image = result;
                        //result.Dispose();
                    }
                    catch (Exception ex1)
                    {
                    }
                    finally
                    {
                        result.Dispose();
                        drawer.Dispose();
                    }
                });
            }
            catch (Exception ex)
            {
            }
            viewer.ShowDialog();
        }
Beispiel #2
0
        private static void withKeyframes(bool isFast, string videoSource = null)
        {
            ImageViewer viewer = new ImageViewer();

            try
            {
                Capture           capture  = videoSource != null ? new Capture(videoSource) : new Capture(0);
                Image <Bgr, Byte> result   = null;
                KeyFrame          keyFrame = null;

                Application.Idle += new EventHandler(delegate(object sender, EventArgs e)
                {
                    counter++;
                    if (keyFrames.Count < 15)
                    {
                        IDrawer drawer;
                        if (isFast)
                        {
                            drawer = new FastDrawer();
                        }
                        else
                        {
                            drawer = new SURFDrawer();
                        }
                        try
                        {
                            Mat frame = capture.QueryFrame();
                            if (frame.Width > 720 || frame.Height > 480)
                            {
                                double width  = 720.0 / frame.Width;
                                double height = 480.0 / frame.Height;

                                CvInvoke.Resize(frame, frame, new Size(), width, height, Inter.Linear);
                            }
                            Image <Bgr, Byte> framebuffer = frame.ToImage <Bgr, Byte>();
                            if (keyFrames.Count == 0)
                            {
                                keyFrames.Add(new KeyFrame()
                                {
                                    Frame = framebuffer
                                });
                            }
                            for (int i = keyFrames.Count - 1; i >= 0; i--)
                            {
                                KeyFrame kf = keyFrames[i];
                                drawer.FindMatch(kf, framebuffer, keyFrames);
                                if (counter == 65)
                                {
                                    //homography ile camera pozu ayarla, nesneyi koy
                                }
                                if (drawer.homography != null)
                                {
                                    KeyFrame buffer_kf = keyFrames[keyFrames.Count - 1];
                                    if (kf != buffer_kf)
                                    {
                                        keyFrames[i] = buffer_kf;
                                        keyFrames[keyFrames.Count - 1] = kf;
                                    }
                                    keyFrame = kf;
                                    break;
                                }
                                if (i == 0)
                                {
                                    if (drawer.homography == null)
                                    {
                                        keyFrames.Add(new KeyFrame()
                                        {
                                            Frame = framebuffer, KeyPoints = drawer.observedKeyPoints, Descriptors = drawer.observedDescriptors
                                        });
                                    }
                                }
                                drawer.Clear();
                            }
                            result = frame.ToImage <Bgr, Byte>();
                            if (keyFrame != null)
                            {
                                result = drawer.Draw(keyFrame, framebuffer);
                            }

                            viewer.Width = frame.Width * 2 + 50;
                            viewer.Image = result;
                            //result.Dispose();
                        }
                        catch (Exception ex1)
                        {
                        }
                        finally
                        {
                            result.Dispose();
                            drawer.Dispose();
                        }
                    }
                    else
                    {
                        keyFrames.RemoveRange(0, keyFrames.Count / 2);
                    }
                });
            }
            catch
            {
            }
            viewer.ShowDialog();
        }