Search code examples
c#opencvunity-game-engineface-detection

Draw contours for determined landmark points ( OpenCvForUnity )


I have worked OpenCV with python before. But I am getting hard to using OpenCV with unity.

I training data for the specific points on the face. I can find landmark point and I can show that points on the unity webcamTexture but I want to draw contours on landmarks point that is determined by me. Firstly I need to convert landmark points to convex hull points for draw contour among existing points. How can I convert?

I tried

List<List<Vector2>> landmarkPoints = new List<List<Vector2>>();
OpenCVForUnityUtils.ConvertVector2ListToArray(landmarkPoints) ;

But landmark points doesn't convert. I need to convert landmark points to Hull Points.

Imgproc.drawContours (rgbaMat, hullPoints, -1, new Scalar (0, 255, 0), 2);

Could you help me, please?


Solution

  • I found this solution, finally . If you have match same problem that answer could help you.

    // detect face landmark points.
    OpenCVForUnityUtils.SetImage(faceLandmarkDetector, rgbaMat);
    for (int i = 0; i < trackedRects.Count; i++)
    {
      List<Vector2> points = faceLandmarkDetector.DetectLandmark(rect);
      List<Vector2> pointss = new List<Vector2>();
      //Draw Contours
      List<Point> pointsss = OpenCVForUnityUtils.ConvertVector2ListToPointList(pointss);
      MatOfPoint hullPointMat = new MatOfPoint();
      hullPointMat.fromList(pointsss);
      List<MatOfPoint> hullPoints = new List<MatOfPoint>();
      hullPoints.Add(hullPointMat);
      Imgproc.drawContours(rgbaMat, hullPoints, -1, new Scalar(150, 100, 5,255), -1);
    }