Пример #1
0
        System.Drawing.Font font = new System.Drawing.Font("Arial", 12); //int a = 0;
        void videoCapture_ProcessFrame(object sender, EventArgs e)
        {
            frame = videoCapture.ReadAs <Bgr, byte>();
            if (frame == null)
            {
                return;
            }

            frame.StretchContrast(inPlace: true);

            long start = DateTime.Now.Ticks;

            long matchTimeMs;

            processFrame(frame, out matchTimeMs);

            long end       = DateTime.Now.Ticks;
            long elapsedMs = (end - start) / TimeSpan.TicksPerMillisecond;

            frame.Draw("Processed: " + /*matchTimeMs*/ elapsedMs + " ms", font, new PointF(15, 10), new Bgr(0, 255, 0));
            this.pictureBox.Image = frame.ToBitmap();
            //frame.Save("C:/imageAnn_" + a + ".jpg");
            //a++;
            GC.Collect();
            //Application.RaiseIdle(new EventArgs());
        }
        void videoCapture_NewFrame(object sender, EventArgs e)
        {
            frame = videoCapture.ReadAs <Bgr, byte>();
            if (frame == null)
            {
                return;
            }

            var im = frame.Convert <FlowColor, float>();//.SmoothGaussian(5); //smoothing <<parallel operation>>;

            long start = DateTime.Now.Ticks;

            List <PointF> newPositions;

            processImage(prevIm, im, this.oldPositions, out newPositions);

            prevIm       = im;
            oldPositions = newPositions;

            long end       = DateTime.Now.Ticks;
            long elapsedMs = (end - start) / TimeSpan.TicksPerMillisecond;

            frame.Draw("Processed: " + elapsedMs + " ms", font, new PointF(15, 10), new Bgr(0, 255, 0));
            drawPoints(frame, newPositions);
            this.pictureBox.Image = frame.ToBitmap(); //it will be just casted (data is shared) 24bpp color

            GC.Collect();
        }
        private void loadCurrentImageAnnotations()
        {
            if (capture.Position == capture.Length)
            {
                return;
            }

            drawingManager.Clear();

            frame = capture.ReadAs <Bgr, byte>(); //the order is relevant (position is automatically increased)
            var imageKey = getCurrentImageKey();

            if (Database.ContainsKey(imageKey))
            {
                drawingManager.AddRange(Database[imageKey]);
            }

            this.pictureBox.Image = frame.ToBitmap();
            pictureBox.Update();

            this.Text                 = getCurrentImageKey() + " -> " + new FileInfo(databaseFileName).Name;
            this.slider.Value         = (int)Math.Max(0, this.capture.Position - 1);
            this.slider.Maximum       = (int)(capture.Length - 1);
            this.lblCurrentFrame.Text = this.slider.Value.ToString();
            this.lblTotalFrames.Text  = this.slider.Maximum.ToString();
        }
Пример #4
0
        void videoCapture_NewFrame(object sender, EventArgs e)
        {
            frame = videoCapture.ReadAs <Bgr, byte>();
            if (frame == null)
            {
                return;
            }

            long preprocessTime, matchTime;
            var  bestRepresentatives = findObjects(frame, out preprocessTime, out matchTime);

            /************************************ drawing ****************************************/
            foreach (var m in bestRepresentatives)
            {
                frame.Draw(m.BoundingRect, new Bgr(0, 0, 255), 1);

                if (m.Template is ImageTemplateWithMask)
                {
                    var mask = ((ImageTemplateWithMask)m.Template).BinaryMask;
                    if (mask == null)
                    {
                        continue;               //just draw bounding boxes
                    }
                    var area = new Rectangle(m.X, m.Y, mask.Width, mask.Height);
                    if (area.X < 0 || area.Y < 0 || area.Right >= frame.Width || area.Bottom >= frame.Height)
                    {
                        continue;                                                                                       //must be fully inside
                    }
                    using (var someImage = new Image <Bgr, byte>(mask.Width, mask.Height, Bgr8.Red))
                    {
                        someImage.CopyTo(frame.GetSubRect(area), mask);
                    }
                }
                else
                {
                    frame.Draw(m, Bgr8.Blue, 3, true, Bgr8.Red);
                }

                Console.WriteLine("Best template: " + m.Template.ClassLabel + " score: " + m.Score);
            }

            frame.Draw(String.Format("Matching {0} templates in: {1} ms", templPyrs.Count, matchTime),
                       font, new PointF(5, 10), new Bgr(0, 255, 0));
            /************************************ drawing ****************************************/

            this.pictureBox.Image = frame.ToBitmap(); //it will be just casted (data is shared) 24bpp color

            //frame.Save(String.Format("C:/probaImages/imgMarked_{0}.jpg", i)); b.Save(String.Format("C:/probaImages/img_{0}.jpg", i)); i++;
            GC.Collect();
        }
Пример #5
0
        void videoCapture_InitFrame(object sender, EventArgs e)
        {
            frame = videoCapture.ReadAs <Bgr, byte>();
            if (frame == null)
            {
                return;
            }

            if (isROISelected)
            {
                initTracking(frame);
                Application.Idle -= videoCapture_InitFrame;
                Application.Idle += videoCapture_NewFrame;
                return;
            }
            else
            {
                frame.Draw(roi, new Bgr(0, 0, 255), 3);
            }
            this.pictureBox.Image = frame.ToBitmap(); //it will be just casted (data is shared)

            GC.Collect();
        }
Пример #6
0
        void capture_NewFrame(object sender, EventArgs e)
        {
            //frame = await capture.ReadAsync(); //faster (does not apply for live streams)
            frame = reader.ReadAs <Bgr, byte>();

            if (frame == null)
            {
                Application.Idle -= capture_NewFrame;
                return;
            }

            this.pictureBox.Image = frame.ToBitmap();
            GC.Collect();
        }
Пример #7
0
        void Application_Idle(object sender, EventArgs e)
        {
            _frame = _reader.ReadAs <Bgr, byte>();

            if (_frame == null)
            {
                Application.Idle -= Application_Idle;
                return;
            }

            var imgCaputre = _frame.ToBitmap();

            this.picCamera.Image = imgCaputre;
            GC.Collect();
        }
        void videoCapture_ProcessFrame(object sender, EventArgs e)
        {
            frame = videoCapture.ReadAs <Bgr, byte>();
            if (frame == null)
            {
                return;
            }

            long start = DateTime.Now.Ticks;

            predict();
            update();

            long end       = DateTime.Now.Ticks;
            long elapsedMs = (end - start) / TimeSpan.TicksPerMillisecond;

            drawParticles(particleFilter.Draw(sampleCount: particleFilter.Count / 2), frame); //draw only better particles
            frame.Draw("Processed: " + elapsedMs + " ms", font, new PointF(15, 10), new Bgr(0, 255, 0));
            this.pictureBox.Image = frame.ToBitmap();                                         //it will be just casted (data is shared)

            GC.Collect();
        }
        public KLDemo()
        {
            InitializeComponent();

            lkStorage = new PyrLKStorage <FlowColor>(pyrLevels: 1);

            try
            {
#if FILE_CAPTURE
                string resourceDir = Path.Combine(Directory.GetParent(Directory.GetCurrentDirectory()).FullName, "Resources");
                videoCapture = new ImageDirectoryReader(Path.Combine(resourceDir, "ImageSequence"), "*.jpg");

                prevIm       = videoCapture.ReadAs <FlowColor, float>();
                oldPositions = prevIm.
                               Convert <Gray, float>().
                               GoodFeaturesToTrack(winSize, 0.05f)
                               .Select(x => new PointF(x.X, x.Y)).Take(100).ToList();
#else
                videoCapture = new CameraCapture(0);
                oldPositions = new List <PointF>();
                prevIm       = new Image <FlowColor, float>(imgSize);
#endif
            }
            catch (Exception)
            {
                MessageBox.Show("Cannot find any camera!");
                return;
            }

            if (videoCapture is CameraCapture)
            {
                (videoCapture as CameraCapture).FrameSize = imgSize;
            }

            this.FormClosing += CamshiftDemo_FormClosing;
            Application.Idle += videoCapture_NewFrame;
            videoCapture.Open();
        }
Пример #10
0
 /// <summary>
 /// Reads an element form the input stream and fills the specified buffer.
 /// <para>If the read element does not match the specified type a null value will be written.</para>
 /// </summary>
 /// <typeparam name="TColor">Color type.</typeparam>
 /// <param name="imageStream">Image source stream.</param>
 /// <param name="buffer">
 /// Buffer to write to.
 /// <para>The specified buffer can be null, as it is managed by the function itself.</para>
 /// </param>
 public static void ReadTo <TColor>(this ImageStreamReader <IImage> imageStream, ref TColor[,] buffer)
     where TColor : struct
 {
     imageStream.ReadAs <TColor>().CopyToOrCreate(ref buffer);
 }
Пример #11
0
        public KLDemo()
        {
            InitializeComponent();

            lkStorage = new PyrLKStorage<FlowColor>(pyrLevels: 1);
            
            try
            {
#if FILE_CAPTURE
                string resourceDir = Path.Combine(Directory.GetParent(Directory.GetCurrentDirectory()).FullName, "Resources");
                videoCapture = new ImageDirectoryReader(Path.Combine(resourceDir, "ImageSequence"), "*.jpg");

                prevIm = videoCapture.ReadAs<FlowColor, float>();
                oldPositions = prevIm.
                              Convert<Gray, float>().
                              GoodFeaturesToTrack(winSize, 0.05f)
                              .Select(x => new PointF(x.X, x.Y)).Take(100).ToList();
#else
                videoCapture = new CameraCapture(0);
                oldPositions = new List<PointF>();
                prevIm = new Image<FlowColor, float>(imgSize);
#endif
            }
            catch (Exception)
            {
                MessageBox.Show("Cannot find any camera!");
                return;
            }

            if(videoCapture is CameraCapture)
                (videoCapture as CameraCapture).FrameSize = imgSize; 

            this.FormClosing += CamshiftDemo_FormClosing;
            Application.Idle += videoCapture_NewFrame;
            videoCapture.Open();
        }