怎样用openFrameworks人脸跟踪器模式控制电机

电子说

1.2w人已加入

描述

在本指南中,我们将记录四个输出的样本:

对于出现在相机前面的面部。

对于出现在相机右侧的脸部。

对于距相机一定距离的脸部。

对于出现在相机前面的物体。

安装openFrameworks人脸跟踪器模式

openFrameworks的安装文件,以及面部追踪功能,可在Wekinator网站上找到。

电机

图像显示Wekinator网站上面部跟踪下载文件的位置ite。

下载面部跟踪文件后,解压缩并运行程序。它应激活计算机网络摄像头以跟踪用户的面部。

使用计算机网络摄像头识别面部的面部跟踪器程序的示例图像。

处理指令

在处理方面,本指南将要求使用草图,该草图将从Wekinator软件接收输出数据并将其转发给Arduino。

import vsync.*; // Importing the library that will help us in sending and receiving the values from the Arduino

import processing.serial.*; // Importing the serial library

// Below libraries will connect and send, receive the values from wekinator

import oscP5.*;

import netP5.*;

// Creating the instances

OscP5 oscP5;

NetAddress dest;

ValueSender sender;

// These variables will be syncronized with the Arduino and they should be same on the Arduino side.

public int output;

void setup()

{

// Starting the serial communication, the baudrate and the com port should be same as on the Arduino side.

Serial serial = new Serial(this, “COM10”, 115200);

sender = new ValueSender(this, serial);

// Synchronizing the variables as on the Arduino side. The order should be same.

sender.observe(“output”);

// Starting the communication with wekinator. listen on port 12000, return messages on port 6448

oscP5 = new OscP5(this, 12000);

dest = new NetAddress(“127.0.0.1”, 6448);

}

// Recieve OSC messages from Wekinator

void oscEvent(OscMessage theOscMessage) {

if (theOscMessage.checkAddrPattern(“/wek/outputs”) == true) {

// Receiving the output from wekinator

float value = theOscMessage.get(0).floatValue();

// Converting the output to int type

output = int(value);

}

}

void draw()

{

// Nothing to be drawn for this example

}

连接直流电机到Arduino

处理草图将从Wekinator发送输出数据到Arduino,它将相应地控制电机。

为了将电机连接到Arduino,请按照下图中的位置。

查看我们的文章详细说明如何通过openFramework发送和接收数据平台使用Arduinoto更好地了解openFrameworks如何与Arduino通信。

电机

连接到Arduino UNO的电机示意图。

Arduino代码

#include //Including the library that will help us in receiving and sending the values from processing

ValueReceiver《1》 receiver; /*Creating the receiver that will receive only one value.

Put the number of values to synchronize in the brackets */

/* The below variable will be synchronized in the processing

and it should be same on both sides. */

int output;

//Motor Pins

int EN_A = 11;

int IN1 = 9;

int IN2 = 8;

int IN3 = 7;

int IN4 = 6;

int EN_B = 10;

void setup()

{

/* Starting the serial communication because we are communicating with the

Processing through serial. The baudrate should be same as on the processing side. */

Serial.begin(115200);

//Initializing the motor pins as output

pinMode(EN_A, OUTPUT);

pinMode(IN1, OUTPUT);

pinMode(IN2, OUTPUT);

pinMode(IN3, OUTPUT);

pinMode(IN4, OUTPUT);

pinMode(EN_B, OUTPUT);

digitalWrite(EN_A, HIGH);

digitalWrite(EN_B, HIGH);

// Synchronizing the variable with the processing. The variable must be int type.

receiver.observe(output);

}

void loop()

{

// Receiving the output from the processing.

receiver.sync();

// Matching the received output to light up led‘s

if (output == 1)

{

//Forward

digitalWrite(IN1, LOW);

digitalWrite(IN2, HIGH);

digitalWrite(IN3, LOW);

digitalWrite(IN4, HIGH);

}

else if (output == 2)

{

//Right

digitalWrite(IN1, HIGH);

digitalWrite(IN2, LOW);

digitalWrite(IN3, LOW);

digitalWrite(IN4, LOW);

}

else if (output == 3)

{

//Left

digitalWrite(IN1, LOW);

digitalWrite(IN2, LOW);

digitalWrite(IN3, HIGH);

digitalWrite(IN4, LOW);

}

else if (output == 4)

{

//Stop

digitalWrite(IN1, LOW);

digitalWrite(IN2, LOW);

digitalWrite(IN3, LOW);

digitalWrite(IN4, LOW);

}

}

在Wekinator中使用人脸检测

第一步是启动Wekinator平台并更改设置以反映下图中的设置。

将输入值设置为3.

将输出值设置为1.

将输出类型指定为“all continuous”

将所有其他设置保留为默认格式。

为了启用Wekinator和openFrameworks平台之间的通信,您需要下载ChucK编程语言,你可以在查克官方网站上这样做。

了解更多信息在安装和使用Wekinator程序时,请查看我们的如何开始使用Wekinator的指南。

Wekinator将从openFrameworks应用程序接收3个输入,然后向ChucK程序发送5个不同的输出,这会提示它产生不同的声音。

电机

Wekinator软件程序中的“创建新项目”窗口。

单击“下一步”,将显示“新建项目”窗口,如下所示。

电机

Wekinator软件程序中的“New Project”窗口。

将脸靠近相机记录一些测试。将分类器输出值指定为“1”。您还需要记录此移动的简短示例。

显示面部追踪器功能如何识别靠近相机的面部的示例图像。

接下来,将您的脸移到屏幕右侧,将分类输出值更改为“2”。再一次,记录运动。

显示脸部追踪器功能如何识别相机右侧脸部的示例图像。

然后将您的脸部从相机中进一步向后移动并将分类器输出更改为“3”。

人脸跟踪器功能如何识别远离相机的脸部的示例图像。

最后一步是完全退出相机视图。将分类器输出分配给’4。‘

脸部追踪器功能的示例图像未在相机视图中识别脸部。

现在,当您点击“列车”然后“运行”按钮时,电机应会在相机上的位置移动。

打开APP阅读更多精彩内容
声明:本文内容及配图由入驻作者撰写或者入驻合作网站授权转载。文章观点仅代表作者本人,不代表电子发烧友网立场。文章及其配图仅供工程师学习之用,如有内容侵权或者其他违规问题,请联系本站处理。 举报投诉

全部0条评论

快来发表一下你的评论吧 !

×
20
完善资料,
赚取积分