Search Unity

Draw contours for determined landmark points ( OpenCvForUnity )

Discussion in 'Scripting' started by erncncbk, Nov 15, 2019.

  1. erncncbk

    erncncbk

    Joined:
    Oct 23, 2019
    Posts:
    4
    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 landmarkPoints to hull Points.

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

    Could you help me, please?
     
  2. erncncbk

    erncncbk

    Joined:
    Oct 23, 2019
    Posts:
    4
    I found this solution, finally. If you have match same problem that answer could help you.


    Code (CSharp):
    1. // detect face landmark points.
    2. OpenCVForUnityUtils.SetImage(faceLandmarkDetector, rgbaMat);
    3. for (int i = 0; i < trackedRects.Count; i++)
    4. {
    5.   List<Vector2> points = faceLandmarkDetector.DetectLandmark(rect);
    6.   List<Vector2> pointss = new List<Vector2>();
    7.   //Draw Contours
    8.   List<Point> pointsss = OpenCVForUnityUtils.ConvertVector2ListToPointList(pointss);
    9.   MatOfPoint hullPointMat = new MatOfPoint();
    10.   hullPointMat.fromList(pointsss);
    11.   List<MatOfPoint> hullPoints = new List<MatOfPoint>();
    12.   hullPoints.Add(hullPointMat);
    13.   Imgproc.drawContours(rgbaMat, hullPoints, -1, new Scalar(150, 100, 5,255), -1);
    14. }