もうすぐクリスマスだ~.
ということで, HVC-Cを使ってクリスマスツリーのLEDイルミネーションの制御にチャレンジしてみた.
1. システム構成
システム構成は以下のようになっている.
注) LEDイルミネーションは以下のものをばらして使用した.
2. コード[1]
考え方は, 「OKAO Visionがやってきた!!(3)」と同じである.
2.1 Android側
SimpleDemoをベースとしていて, 認識結果の関連部分は以下の通り.
@Override
public void onPostExecute(int nRet, byte outStatus) {
byte[] cmd = new byte[2];
: (省略)
if ( (hvcRes.executedFunc & HVC.HVC_ACTIV_EXPRESSION_ESTIMATION) != 0 ) {
str += String.format(" [Expression Estimation] : expression = %s, score = %d, degree = %d\n",
faceResult.exp.expression == HVC.HVC_EX_NEUTRAL ? "Neutral" :
faceResult.exp.expression == HVC.HVC_EX_HAPPINESS ? "Happiness" :
faceResult.exp.expression == HVC.HVC_EX_SURPRISE ? "Supprise" :
faceResult.exp.expression == HVC.HVC_EX_ANGER ? "Anger" :
faceResult.exp.expression == HVC.HVC_EX_SADNESS ? "Sadness" : "" ,
faceResult.exp.score, faceResult.exp.degree);
if (faceResult.exp.expression == HVC.HVC_EX_HAPPINESS) {
cmd[0] = '4';
}
else if (faceResult.exp.expression == HVC.HVC_EX_SURPRISE) {
cmd[0] = '3';
}
else if (faceResult.exp.expression == HVC.HVC_EX_NEUTRAL) {
cmd[0] = '2';
}
else if (faceResult.exp.expression == HVC.HVC_EX_ANGER) {
cmd[0] = '1';
}
else { // HVC.HVC_EX_SADNESS
cmd[0] = '0';
}
mUsb.write(cmd, 1);
}
2.2 Arudino側
Androidからのコマンドにより, LEDの点滅時間を変えている.
char mCtrlPin = 13;
void setup() {
// put your setup code here, to run once:
pinMode(mCtrlPin, OUTPUT);
Serial.begin(9600);
}
void loop() {
// put your main code here, to run repeatedly:
int high[] = { 100, 300, 1000, 300, 50};
int low[] = { 2000, 1000, 1000,300, 50};
int level = 2; // default
while (true) {
if (Serial.available() > 0) {
level = Serial.parseInt();
if (level < 0) level = 0;
else if (level > 4) level = 4;
}
if (high[level] > 0) {
digitalWrite(mCtrlPin, HIGH);
delay(high[level]);
}
if (low[level] > 0) {
digitalWrite(mCtrlPin, LOW);
delay(low[level]);
}
}
delay(10);
}
3. 動作例
とりあえず第一弾のプロトタイプということで, Sensing Egg Project 事務局に連絡だ~.
----
参照URL:
[1] OKAO Visionがやってきた!!(3)