Grab() public method

Grab a frame
public Grab ( ) : bool
return bool
Exemplo n.º 1
0
        private void run()
        {
            Image<Bgr, Byte> image = new Image<Bgr, byte>("lena.jpg"); //Read the files as an 8-bit Bgr image
            Capture vid = new Capture("kw.avi");
            vid.FlipVertical = true;
            int x = 0;
            TimeSpan time = TimeSpan.Zero;
            MCvFont font = new MCvFont(Emgu.CV.CvEnum.FONT.CV_FONT_HERSHEY_COMPLEX, 1.0, 1.0);
            using (VideoWriter vw = new VideoWriter("out3.avi", 15, 640, 480, true))
            {

                while (vid.Grab())
                {
                    //if (++x % 1 != 0) continue;

                    image = vid.RetrieveBgrFrame();

                    long detectionTime;
                    List<Rectangle> faces = new List<Rectangle>();
                    List<Rectangle> eyes = new List<Rectangle>();
                    DetectFace.Detect(image, "haarcascade_frontalface_default.xml", "supersmile.xml", faces, eyes, out detectionTime);
                    foreach (Rectangle face in faces)
                        image.Draw(face, new Bgr(Color.Red), 2);
                    foreach (Rectangle eye in eyes)
                        image.Draw(eye, new Bgr(Color.Blue), 2);
                    if (eyes.Count > 0) time = time.Add(new TimeSpan(0, 0, 0, 0, 66));
                    //display the image
                    image.Draw(String.Format("{0}:{1}", time.Seconds, time.Milliseconds), ref font, new Point(50, 50), new Bgr(0, 0, 255));
                    setimage(image);
                    vw.WriteFrame<Bgr, Byte>(image);
                }
            }
        }
Exemplo n.º 2
0
        public void ThreadMain()
        {
            //MessageBox.Show("Hi from the thread!");

            VideoWriter writer = new VideoWriter("video.mp4", 60, new Size(1280, 720), true);

            int     frame   = 0;
            Capture cap     = new Emgu.CV.Capture(@"C:\Users\Peter Husman\Downloads\Wildlife.wmv");
            Mat     minions = new Capture(@"C:\Users\Peter Husman\Downloads\maxresdefault.jpg").QueryFrame();

            Mat data   = new Mat();
            Mat chroma = new Mat();

            Mat threshold = new Mat();
            Mat bNot      = new Mat();

            Mat minionsMask = new Mat();
            Mat vidMask     = new Mat();



            var filter = new BackgroundSubtractorMOG();

            while (true)
            {
                try
                {
                    cap.Grab();
                    bool grabbed = cap.Retrieve(data);


                    CvInvoke.InRange(minions, new ScalarArray(new Emgu.CV.Structure.MCvScalar(0, 206, 0)), new ScalarArray(new Emgu.CV.Structure.MCvScalar(129, 255, 164)), threshold);
                    threshold.CopyTo(bNot);
                    CvInvoke.BitwiseNot(bNot, bNot);
                    Mask(minions, bNot, minionsMask);

                    Mask(data, threshold, vidMask);

                    CvInvoke.BitwiseOr(minionsMask, vidMask, chroma);

                    //CvInvoke.CvtColor(data, hsv, ColorConversion.Bgr2Hsv);
                    //BackgroundSubtractorMOG
                    //data.Dispose();
                    //CvInvoke.InRange

                    //filter.Apply(data, hsv);
                    //ChromaKey(data, minions, chroma,min,max);
                    //CvInvoke.Imwrite($"{fileLocation}{frame.ToString()}.jpg", data);
                    //writer.Write(chroma);
                    CvInvoke.Imshow("Window", chroma);
                    CvInvoke.WaitKey(1);
                    frame++;
                }
                catch (Exception ex)
                {
                }
            }
        }
Exemplo n.º 3
0
 private static void Main(string[] args)
 {
     var capture = new Capture(0);
     Native.Create(@"D:\GitHub\videotools\Debug\model\main_clm_general.txt");
     var id = 0;
     while (capture.Grab()) {
         var mat = capture.QueryFrame();
         Native.SessionPoint[] points;
         var result = Native.Process(mat, out points);
         Console.WriteLine(@"{0:D5}:{1}", id, Native.ToString(result));
         ++id;
     }
     Native.Destroy();
 }