HandInput.Util.PlayerDetector.FindPlayerContour C# (CSharp) Method

FindPlayerContour() private method

private FindPlayerContour ( Byte>.Image mask ) : Seq
mask Byte>.Image
return Seq
        Seq<Point> FindPlayerContour(Image<Gray, Byte> mask)
        {
            var contourPtr = new IntPtr();
              if (tempPlayerMask == null)
            tempPlayerMask = new Image<Gray, Byte>(width, height);

              CvInvoke.cvCopy(mask.Ptr, tempPlayerMask.Ptr, IntPtr.Zero);
              CvInvoke.cvFindContours(tempPlayerMask.Ptr, mem.Ptr, ref contourPtr, StructSize.MCvContour,
              RETR_TYPE.CV_RETR_EXTERNAL, CHAIN_APPROX_METHOD.CV_CHAIN_APPROX_SIMPLE, new Point(0, 0));
              var contour = new Seq<Point>(contourPtr, null);

              double maxPerim = 0;
              Seq<Point> largestContour = null;

              for (; contour != null && contour.Ptr.ToInt32() != 0; contour = contour.HNext) {
            var perim = CvInvoke.cvContourPerimeter(contour.Ptr);
            if (perim > maxPerim) {
              maxPerim = perim;
              largestContour = contour;
            }
              }
              var polyPtr = largestContour.ApproxPoly(ContourApproxLevel, mem);
              return polyPtr;
        }