LoginSignup
9
8

More than 5 years have passed since last update.

オレオレ「Face Detection」ボックスを作る

Posted at

はじめに

こちらの「認識した顔の数を話す」という動作を試してみていて、何となく「Face Detection」ボックスのソースを覗いてみたのですが、何でこれだけのコードでこの機能ができるのだろう、と (そのときは) 不思議に思いました。

仕組みを確認してみるのと、独自ボックスを作成してみるのと合わせて、「Face Detection」同等のボックスを自作してみました。

「Face Detection」ボックスの確認

まず「Face Detection」ボックスの枠があり、その中で「Count Det. Faces」が配置されています。

「Face Detection」ボックス

2014123101.png

「Count Det. Faces」ボックス

ところえ、Mac でスクリーンショットを撮るのに command + shift を押すのですが、画像みたいなヒントが出るみたいですね。

2014123102.png

「Count Det. Faces」のコード

class MyClass(GeneratedClass):
    def __init__(self):
        GeneratedClass.__init__(self, False)

    def onLoad(self):
        self.nFacesDetected = -1

    def onUnload(self):
        #puts code for box cleanup here
        pass

    def onInput_onStart(self, p):
        if(len(p) > 0):
            if(self.nFacesDetected != len(p[1]) -1): # an additional array has been placed at the end for time
                self.nFacesDetected = len(p[1]) -1  # filtered info and has to be substracted when counting faces
                if(self.nFacesDetected != 0):
                    self.onFaceDetected( self.nFacesDetected )
                else:
                    self.onNoFace()
        else:
            if(self.nFacesDetected != 0):
                self.nFacesDetected = 0
                self.onNoFace()

    def onInput_onStop(self):
        pass

オレオレ「Face Detection」ボックスの作成

「oreore Face Detection」ボックスの作成

ボックスを配置するペイン上でコンテキストメニュー

ボックスの新規作成 > ダイヤグラム...

2014123103.png

「名前」「概要」を入力、「出力」の [+] を押して以下の項目を追加します。

Name Type Nature
numberOfFaces 即時
onNoFace "バン" 即時

これで「Face Detection」ボックスと同等の "枠だけ" ができました。

2014123104.png

「oreore Count Det. Faces」ボックスの作成

「oreore Face Detection」ボックス内でコンテキストメニュー

ボックスの新規作成 > Python...

2014123105.png

「名前」「概要」を入力、「出力」の [+] を押して以下の項目を追加します。

Name Type Nature
onFaceDetected onStopped
onNoFace "バン" onStopped

「OK」を押して閉じた後、onStart の入力部分でコンテキストメニューで Edit input を選択し、Type を「ダイナミック」に変更します。

「oreore Count Det. Faces」のコードの編集

「Count Det. Faces」からそのままコピペします。

入出力の接続

ここまで来てようやく「Count Det. Faces」の入力が onStart ではなく、 変なところ につながっていることに気づきました。

2014123106.png

ALMemory という機構を介して、各種 API のイベント、値を取得できるようです。

ということで、ALMemory からのイベントの追加 [+] を押し FaceDetected をチェックして、接続口を作り、入出力を接続します。
(Pepper 実機でないと FaceDetected は出てこないようです)

2014123107.png

「Face Detection」から「oreore Face Detection」に接続し直します。

2014123108.png

オレオレ版で実行

オリジナルと同等の動きをすることを確認しました。

感想

  • 「Face Detected」ボックスでは顔認識結果を ALMemory 経由で受け取って分類するだけ、という処理なことに納得しました。
  • 他にどんなイベントがあるのか確認してみます。楽しみ。
9
8
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
9
8