LoginSignup
0
0

More than 5 years have passed since last update.

Unity + OpenCV FaceTrackerで点の位置をスケールさせる; How to scale face parts in Unity + OpenCV

Last updated at Posted at 2018-11-13
  • FaceTracker.csに書き足す
        private void ScalePoints(int startIndex, int endIndex, float scale)
        {
            int pointNum = endIndex - startIndex + 1;
            double xSum = 0;
            double ySum = 0;
            for (int i = startIndex; i <= endIndex; i++)
            {
                xSum += points[0][i].x;
                ySum += points[0][i].y;
            }
            double xMean = xSum / pointNum;
            double yMean = ySum / pointNum;

            // scale from mean
            for (int i = startIndex; i <= endIndex; i++)
            {
                double relativeX = points[0][i].x - xMean;
                double relativeY = points[0][i].y - yMean;
                relativeX *= scale;
                relativeY *= scale;
                points[0][i].x = relativeX + xMean;
                points[0][i].y = relativeY + yMean;
            }
        }
  • 平均をとってそこを中心にスケールさせる
  • 片方の眉毛の領域を拡大したい時は、
    • ScalePoints(15, 20, 2.2f);
  • 顔は1つを想定
  • ハマりポイント
    • points[0][i].xと書く必要がある
    • points[i]で二次元ベクトルが取れると思ったが違った
  • 想定通り動くことを確認した
0
0
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0