Get() public method

Retrieves the specified property of camera or video file.
public Get ( CaptureProperty propertyId ) : double
propertyId CaptureProperty property identifier.
return double
Ejemplo n.º 1
0
        private void timer1_Tick(object sender, EventArgs e)
        {
            if (cap == null || pause)
            {
                return;
            }
            if (forwTo)
            {
                var ofps = cap.Get(5);//5 fps

                forwTo = false;
                var frm  = cap.Get(7);//7 frame count
                var secs = (frm / ofps) * 1000;

                cap.Set(0, forwPosPercetange * secs);//posmsec 0
            }

            if (oneFrameStep && oneFrameStepDir == -1)
            {
                var pf = cap.Get(1);//1 posframes
                cap.Set(1, Math.Max(0, pf - 2));
            }
            if (oneFrameStep)
            {
                pause = true; oneFrameStep = false;
            }


            Mat mat = new Mat();

            cap.Read(mat);
            pictureBox1.Image = BitmapConverter.ToBitmap(mat);
        }
Ejemplo n.º 2
0
        private void button1_Click(object sender, EventArgs e)
        {
            if (th != null)
            {
                button1.Text = "start";
                stop         = true;
                th           = null;
                return;
            }
            button1.Text = "stop";
            th           = new Thread(() =>
            {
                cap          = new OpenCvSharp.VideoCapture(path);
                Stopwatch sw = Stopwatch.StartNew();
                var session1 = new InferenceSession(netPath);

                var inputMeta = session1.InputMetadata;


                Mat mat     = new Mat();
                var nFrames = cap.Get(VideoCaptureProperties.FrameCount);
                cap.Read(mat);
                var sz = mat.Size();
                if (inputDims[2] == -1)
                {
                    sz.Height = mat.Height;
                    sz.Width  = mat.Width;
                }
                string key = $"{sz.Width}x{sz.Height}";
                if (!Processing.allPriorBoxes.ContainsKey(key))
                {
                    var pd = Decoders.PriorBoxes2(sz.Width, sz.Height);;
                    Processing.allPriorBoxes.Add(key, pd);
                }
                var prior_data  = Processing.allPriorBoxes[key];
                var ofps        = cap.Get(VideoCaptureProperties.Fps);
                VideoWriter vid = null;
                if (checkBox1.Checked)
                {
                    vid = new VideoWriter("output.mp4", FourCC.XVID, ofps, mat.Size());
                }
                while (true)
                {
                    if (stop)
                    {
                        break;
                    }
                    var pf   = cap.Get(VideoCaptureProperties.PosFrames);
                    int perc = (int)Math.Round((pf / (float)nFrames) * 100);
                    progressBar1.Invoke(((Action)(() =>
                    {
                        label1.Text = $"{pf} / {nFrames}  {perc}%";
                        progressBar1.Value = perc;
                    })));
                    if (!cap.Read(mat))
                    {
                        break;
                    }
                    Mat orig = mat.Clone();
                    if (inputDims[2] == -1)
                    {
                        inputDims[2] = mat.Height;
                        inputDims[3] = mat.Width;
                    }

                    mat.ConvertTo(mat, MatType.CV_32F);
                    object param = mat;
                    foreach (var pitem in preps)
                    {
                        param = pitem.Process(param);
                    }

                    var inputData = param as float[];
                    var tensor    = new DenseTensor <float>(param as float[], inputDims);
                    var container = new List <NamedOnnxValue>();

                    container.Add(NamedOnnxValue.CreateFromTensor <float>(inputName, tensor));

                    float[] confd;
                    float[] locd;
                    using (var results = session1.Run(container))
                    {
                        var data = results.First().AsTensor <float>();
                        locd     = data.ToArray();
                        confd    = results.Skip(1).First().AsTensor <float>().ToArray();
                    }


                    Stopwatch sw2 = Stopwatch.StartNew();
                    var ret       = Processing.boxesDecode(orig.Size(), confd, locd, new System.Drawing.Size(sz.Width, sz.Height), prior_data, visTresh);
                    if (checkBox1.Checked)
                    {
                        var out1 = Processing.drawBoxes(orig, ret.Item1, ret.Item2, visTresh, ret.Item3);
                        vid.Write(out1);
                    }
                    sw2.Stop();
                }
                vid.Release();



                sw.Stop();
            });
            th.IsBackground = true;
            th.Start();
        }