CURELab.SignLanguage.HandDetector.VideoProcessor.ProcessFrame C# (CSharp) Метод

ProcessFrame() публичный Метод

public ProcessFrame ( ) : bool
Результат bool
        public bool ProcessFrame()
        {
            if (CurrentFrame >= TotalFrames -1)
            {
                return false;
            }
            if (_CCapture != null)
            {
                var r = _CCapture.Grab();
                var imgc = _CCapture.RetrieveBgrFrame();
                ImageConverter.UpdateWriteBMP(colorWriteBitmap, imgc.ToBitmap());

            }
            if (_DCapture != null)
            {
                var r = _DCapture.Grab();
                var img = _DCapture.RetrieveBgrFrame();

                int framenumber = (int)_DCapture.GetCaptureProperty(Emgu.CV.CvEnum.CAP_PROP.CV_CAP_PROP_POS_FRAMES);
                //Console.WriteLine("frame:"+framenumber.ToString());
                CurrentFrame = framenumber - 1;
                if (img == null)
                {
                    return false;
                }
                //Show time stamp
                double time_index = _DCapture.GetCaptureProperty(Emgu.CV.CvEnum.CAP_PROP.CV_CAP_PROP_POS_MSEC);

                PointF rightVector = new PointF(-10, -10);
                PointF leftVector = new PointF(10, -10);
                bool isSkip = false;
                bool leftHandRaise = false;
                if (CurrentFrame >= sktList.Count || !sktList[CurrentFrame].Tracked)
                {
                    // no skeleton detected
                    headDepth = 0;
                }
                else
                {
                    headPosition = sktList[CurrentFrame][MyJointType.Head].PosDepth;
                    headDepth = Math.Min((int)img[headPosition.Y, headPosition.X].Green,(int)img[headPosition.Y, headPosition.X].Red);
                    headDepth = Math.Min(headDepth, (int) img[headPosition.Y, headPosition.X].Blue);
                    PointF hr = sktList[CurrentFrame][MyJointType.HandR].PosDepth;
                    PointF hl = sktList[CurrentFrame][MyJointType.HandL].PosDepth;
                    PointF er = sktList[CurrentFrame][MyJointType.ElbowR].PosDepth;
                    PointF el = sktList[CurrentFrame][MyJointType.ElbowL].PosDepth;
                    PointF hip = sktList[CurrentFrame][MyJointType.HipCenter].PosDepth;
                    // hand is lower than hip
                    //Console.WriteLine(sktList[CurrentFrame][MyJointType.HandR].Pos3D.Y);
                    //Console.WriteLine(sktList[CurrentFrame][MyJointType.ElbowR].Pos3D.Y);
                    //Console.WriteLine(sktList[CurrentFrame][MyJointType.HipCenter].Pos3D.Y);
                    //Console.WriteLine("-------------");
                    if (sktList[CurrentFrame][MyJointType.HandR].Pos3D.Y <
                        sktList[CurrentFrame][MyJointType.HipCenter].Pos3D.Y + 0.05)
                    {
                        isSkip = true;
                    }
                    if (sktList[CurrentFrame][MyJointType.HandL].Pos3D.Y >
                        -0.02f)
                    {
                        leftHandRaise = true;
                    }

                    rightVector.X = (hr.X - er.X);
                    rightVector.Y = (hr.Y - er.Y);
                    leftVector.X = (hl.X - el.X);
                    leftVector.Y = (hl.Y - el.Y);
                }

                #region temp

                //isSkip = false;
                //leftHandRaise = false;
                //rightVector = new PointF(-10, -10);
                //leftVector = new PointF(10, -10);
                //headDepth = (int)img[85, 315].Blue;
                #endregion
               // Console.WriteLine("headdepth:"+headDepth.ToString());

                //***********cull image*****************
                double cull = headDepth - CullingThresh;
                var depthImg = img.ThresholdToZeroInv(new Bgr(cull, cull, cull));
                //Image<Gray, Byte> depthImg = img.Convert<Gray, byte>().ThresholdBinary(new Gray(160), new Gray(255));
                var sw = Stopwatch.StartNew();
                int handDepth = (int)(2600.0 / 255 * cull + 400);
                HandShapeModel handModel = null;
                Image<Gray, Byte> rightFront = null;
                Image<Gray, Byte> leftFront = null;
                // isskip is invalid coz no hip data
                isSkip = false;
                if (cull> 0)
                {
                    handModel = m_opencv.FindHandPart(ref depthImg, out rightFront, out leftFront, handDepth, rightVector, leftVector, leftHandRaise);
                }
                viewer.Image = depthImg;

                // no hands detected
                if (handModel == null)
                {
                    handModel = new HandShapeModel(0, HandEnum.None);
                }
                var row = new CsvRow();
                row.Add(CurrentFrame.ToString());
                row.Add(handModel.type.ToString());
                switch (handModel.type)
                {
                    case HandEnum.Intersect:
                    case HandEnum.Right:
                        row.Add(handModel.handPosRight.center.X.ToString());
                        row.Add(handModel.handPosRight.center.Y.ToString());
                        row.Add(handModel.handPosRight.size.Width.ToString());
                        row.Add(handModel.handPosRight.size.Height.ToString());
                        row.Add(handModel.handPosRight.angle.ToString());
                        break;
                    case HandEnum.Both:
                        row.Add(handModel.handPosRight.center.X.ToString());
                        row.Add(handModel.handPosRight.center.Y.ToString());
                        row.Add(handModel.handPosRight.size.Width.ToString());
                        row.Add(handModel.handPosRight.size.Height.ToString());
                        row.Add(handModel.handPosRight.angle.ToString());
                        row.Add(handModel.handPosLeft.center.X.ToString());
                        row.Add(handModel.handPosLeft.center.Y.ToString());
                        row.Add(handModel.handPosLeft.size.Width.ToString());
                        row.Add(handModel.handPosLeft.size.Height.ToString());
                        row.Add(handModel.handPosLeft.angle.ToString());
                        break;
                }
                row.Add(cull.ToString());
                labelWriter.WriteRow(row);
                if (rightFront != null)
                {
                    ImageConverter.UpdateWriteBMP(WrtBMP_RightHandFront, rightFront.ToBitmap());
                }

                ImageConverter.UpdateWriteBMP(depthWriteBitmap, img.ToBitmap());

                if (CurrentFrame < TotalFrames -1)
                {
                    return true;
                }
            }
            return false;
        }

Usage Example

Пример #1
0
        private void Window_KeyDown_1(object sender, System.Windows.Input.KeyEventArgs e)
        {
            switch (e.Key)
            {
            case Key.Space:
                m_VideoProcessor.ProcessFrame();
                break;

            case Key.R:
                m_VideoProcessor.ProcessSample();
                break;

            default:
                break;
            }
        }