Why not login to Qiita and try out its useful features?

We'll deliver articles that match you.

You can read useful information later.

14
12

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

UnityとRealSenseで表情の認識

Last updated at Posted at 2017-06-11

笑うと回る箱(動画では何も伝わらない)

Version
Unity:5.6.1f1 Personal
RealSenseSDK:2016 R3
Device:SR300

動かし方
空のシーンを作ってカメラに下のコードをコピペして作ったスクリプトをアタッチするだけです。
※箱の座標は0,0,0

using System.Collections.Generic;
using UnityEngine;
using Intel.RealSense;
using Intel.RealSense.Face;

public class FaceExpressions : MonoBehaviour
{
    SenseManager SenseM;
    FaceModule FaceM;
    FaceConfiguration FaceC;
    FaceData FaceD;

    Dictionary<FaceExpression, FaceExpressionResult> Expression;

    GameObject Obj;

    void Start()
    {
        SenseM = SenseManager.CreateInstance();

        FaceM = FaceModule.Activate(SenseM);
        FaceM.FrameProcessed += FaceM_FrameProcessed;

        FaceC = FaceM.CreateActiveConfiguration();
        FaceC.Expressions.EnableAllExpressions();
        FaceC.Expressions.Properties.Enabled = true;
        FaceC.ApplyChanges();

        FaceD = FaceM.CreateOutput();

        SenseM.Init();
        SenseM.StreamFrames(false);

        Obj = GameObject.CreatePrimitive(PrimitiveType.Cube);
        Obj.transform.localScale = new Vector3(1, 1, 1);
    }

    void FaceM_FrameProcessed(object sender, FrameProcessedEventArgs args)
    {
        FaceD.Update();
        var face = FaceD.QueryFaceByIndex(0);
        if (face != null)
        {
            if (face.Expressions != null)
            {
                Expression = face.Expressions.ExpressionResults;
            }
        }
    }

    void Update()
    {
        float z = 0;

        if (Expression != null)
        {
            z = Expression[FaceExpression.EXPRESSION_SMILE].intensity;
        }

        Obj.transform.Rotate(new Vector3(0, 0, z));
    }
}

参考
拾える情報

namespace Intel.RealSense.Face
{
    public enum FaceExpression
    {
        EXPRESSION_BROW_RAISER_LEFT = 0,
        EXPRESSION_BROW_RAISER_RIGHT = 1,
        EXPRESSION_BROW_LOWERER_LEFT = 2,
        EXPRESSION_BROW_LOWERER_RIGHT = 3,
        EXPRESSION_SMILE = 4,
        EXPRESSION_KISS = 5,
        EXPRESSION_MOUTH_OPEN = 6,
        EXPRESSION_EYES_CLOSED_LEFT = 7,
        EXPRESSION_EYES_CLOSED_RIGHT = 8,
        EXPRESSION_HEAD_TURN_LEFT = 9,
        EXPRESSION_HEAD_TURN_RIGHT = 10,
        EXPRESSION_HEAD_UP = 11,
        EXPRESSION_HEAD_DOWN = 12,
        EXPRESSION_HEAD_TILT_LEFT = 13,
        EXPRESSION_HEAD_TILT_RIGHT = 14,
        EXPRESSION_EYES_TURN_LEFT = 15,
        EXPRESSION_EYES_TURN_RIGHT = 16,
        EXPRESSION_EYES_UP = 17,
        EXPRESSION_EYES_DOWN = 18,
        EXPRESSION_TONGUE_OUT = 19,
        EXPRESSION_PUFF_RIGHT = 20,
        EXPRESSION_PUFF_LEFT = 21
    }
}

14
12
0

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

Qiita Conference 2025 will be held!: 4/23(wed) - 4/25(Fri)

Qiita Conference is the largest tech conference in Qiita!

Keynote Speaker

ymrl、Masanobu Naruse, Takeshi Kano, Junichi Ito, uhyo, Hiroshi Tokumaru, MinoDriven, Minorun, Hiroyuki Sakuraba, tenntenn, drken, konifar

View event details
14
12

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?