Example #1
0
        private void timer1_Tick(object sender, EventArgs e)
        {
            var frame = _source.NextFrame();

            if (frame == null)
            {
                timer.Stop();
            }
            else
            {
                controlScene.Show(frame);
            }
        }
Example #2
0
        public void SuperResolutionTest()
        {
            Mat frame  = new Mat(); // input video frame
            Mat result = new Mat(); // output superresolution image

            //FrameSource _frameSource = new FrameSource(0); // input frames are obtained from WebCam or USB Camera
            FrameSource _frameSource = new FrameSource(@"C:\Users\Samantha\Documents\University\Fourth Year\METR4810\Data\Backlight\vi_0004_20180430_015632.mp4", false); // input frames are read from a file

            _frameSource.NextFrame(frame);                                                                                                                                // input frames are obtained from WebCam or USB Camera

            try
            {
                for (int i = 0; i < 5; i++)
                {
                    frame.Save(@"C:\Users\Samantha\Documents\University\Fourth Year\METR4810\Data\SuperresTest\In" + i.ToString("00i") + ".png");

                    SuperResolution _superResolution = new SuperResolution(Emgu.CV.Superres.SuperResolution.OpticalFlowType.Btvl, _frameSource);
                    _superResolution.NextFrame(result); // output super resolution image

                    result.Save(@"C:\Users\Samantha\Documents\University\Fourth Year\METR4810\Data\SuperresTest\Out" + i.ToString("00i") + ".png");
                }
            }
            catch (Exception ex)
            {
                Console.Write(ex);
            }
        }
Example #3
0
        public void ShowGame(FrameSource source)
        {
            _source          = source;
            this.DataContext = _source;

            var frame = _source.NextFrame();

            controlScene.Show(frame);
        }
Example #4
0
        public static void Run()
        {
            Mat image = new Mat();

            frameSource = Cv2.CreateFrameSource_Camera(0);
            while (true)
            {
                //Grab the current frame
                frameSource.NextFrame(image);

                Mat gray = new Mat();
                Cv2.CvtColor(image, gray, ColorConversionCodes.BGR2GRAY);

                Mat blur = new Mat();
                Cv2.GaussianBlur(gray, blur, new Size(19, 19), 0);

                Mat    threshImg = new Mat();
                double thresh    = Cv2.Threshold(gray, threshImg, 150, 255, ThresholdTypes.Otsu);

                Mat[] contours;

                Mat hierarchy = new Mat();
                Cv2.FindContours(threshImg, out contours, hierarchy, RetrievalModes.Tree, ContourApproximationModes.ApproxSimple);
                double maxArea     = 100;
                Mat    handContour = new Mat();
                handContour = contours.OrderByDescending(x => (x.ContourArea())).ToList()[0];
                //foreach (var item in contours)
                //{
                //    if(item.ContourArea() > maxArea)
                //    {
                //        handContour = item;
                //        break;
                //    }
                //}

                Mat hull = new Mat();
                Cv2.ConvexHull(handContour, hull);

                Mat defects = new Mat();
                Cv2.ConvexityDefects(handContour, hull, defects);

                Cv2.ImShow("frame", hull);
                //Cv2.WaitKey(0);
                if (Cv2.WaitKey(1) == (int)ConsoleKey.Enter)
                {
                    break;
                }
            }
        }
 public Mat CaptureImage()
 {
     try
     {
         _source.NextFrame(_image);  //Grab screenshot from webcam
         _image.SaveImage(FilePath); //Save screenshot to file destination
         //image.Dispose();                      //Release the Matrix resources
         return(_image);
     }
     catch (Exception e)
     {
         Console.WriteLine(e);
         throw;
     }
 }
Example #6
0
        public void CaptureImage()
        {
            using var image = new Mat();            //Create a Mat object

            try
            {
                Console.WriteLine("Capturing image ...");
                _source.NextFrame(image);      //Grab screenshot from webcam
                image.SaveImage(FilePath);     //Save screenshot to file destination
                image.Dispose();               //Release the Matrix resources
                Console.WriteLine("Image captured!");
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                throw;
            }
        }
Example #7
0
        public Mat Capture(bool save)
        {
            //Initialise the image matrix
            Mat img = new Mat();

            //Grab the frame to the img variable
            frameSource.NextFrame(img);

            //Check save variable is true
            if (save)
            {
                string imagePath = string.Format("{0}\\cam.jpg", AppDomain.CurrentDomain.BaseDirectory);

                //Save the captured image
                img.SaveImage(imagePath);
                //Cv2.ImShow("Org Img", img);
            }

            return(img);
        }
Example #8
0
        private void FirstButton_OnClick(object sender, RoutedEventArgs e)
        {
            //Mat src = new Mat("lenna.png", ImreadModes.Grayscale);
            //Mat dst = new Mat();
            //Cv2.Canny(src, dst, 10, 300, 3);


            //SrcImage.Source = bitmapToBitmapImage(OpenCvSharp.Extensions.BitmapConverter.ToBitmap(src));
            //if (src.ImWrite("srcLenna.jpg"))
            //{

            //    Uri srcUri = new Uri(Path.Combine(Environment.CurrentDirectory, "srcLenna.jpg"));
            //    SrcImage.Source = new BitmapImage(srcUri);
            //}

            //if (dst.ImWrite("dstLenna.jpg"))
            //{
            //    Uri dstUri = new Uri(Path.Combine(Environment.CurrentDirectory, "dstLenna.jpg"));
            //    DstImage.Source = new BitmapImage(dstUri);
            //}

            //VideoCapture capture = new VideoCapture(0);
            FrameSource frame = Cv2.CreateFrameSource_Camera(0);

            //using var window = new OpenCvSharp.Window("Camera");

            Task.Run(() =>
            {
                isOpen          = true;
                using var image = new Mat();
                using var dst   = new Mat();

                while (isOpen)
                {
                    //capture.Read(image);
                    //if (image.Empty()) break;

                    //window.ShowImage(image);
                    //image.ImWrite("camera.jpg");
                    //Uri dstUri = new Uri(Path.Combine(Environment.CurrentDirectory, "camera.jpg"));
                    //DstImage.Source = new BitmapImage(dstUri);

                    //DstImage.Source = bitmapToBitmapImage//(OpenCvSharp.Extensions.BitmapConverter.ToBitmap(image));

                    //Cv2.WaitKey();

                    frame.NextFrame(image);
                    if (image.Empty())
                    {
                        break;
                    }

                    Dispatcher.Invoke(new Action(() =>
                    {
                        var src_gray = new Mat();
                        Cv2.CvtColor(image, src_gray, ColorConversionCodes.RGB2GRAY);
                        Cv2.Blur(src_gray, src_gray, new OpenCvSharp.Size(2, 2));
                        Cv2.Canny(src_gray, dst, Threshold1.Value, Threshold2.Value);
                        SrcImage.Source = bitmapToBitmapImage(BitmapConverter.ToBitmap(src_gray));
                        DstImage.Source = bitmapToBitmapImage(BitmapConverter.ToBitmap(dst));
                    }));
                }
            });
        }