【CurieNano试用】processing+图形检测+机器学习
之前看见CurieNano的试用,一直想学点机器学习方面的知识,所以一直很关注,但是看了一圈试用项目,很多都拿这块板子做了普通arduino板子就能做的东西,没有用到居里的128个神经单元,感觉很可惜,我都斗胆向Luna大大申请了一块CurieNano,做点机器学习的研究,希望抛砖引玉,大神上点更多的创意想法。1、下载arduino IDE 1.8.2 可以去www.arduino.cc 下载.
版本不够,编译不过,别怪我通过IDE自带的板卡管理器下载,速度太慢了,且有时候还会被墙,导致我这更新过慢,实在不好意思
2、打开IDE,下载支持文件
当然也可以通过其他方式,这里要感谢奈何大大制作的安装包
所以这里我把都传到了百度运,如果你等不急的话,直接从百度云下载吧(里面有版本编号,推荐下载版本号高的)
http://pan.baidu.com/s/1bogLHF5
3、驱动安装
驱动下载:
http://pan.baidu.com/s/1nuz3Wjn
如果你已经安装了 101/CurieNano扩展包,那么可以通过如下地址找到驱动,并安装。
C:\Users\Administrator\AppData\Local\Arduino15\packages\Intel\hardware\arc32\2.0.2\drivers
32位系统运行dpinst-x86.exe,64位系统运行dpinst-amd64.exe
安装完成后,查看设备管理器,如果有名为Genuino 101/CurieNano的串口出现,则说明安装成功,如图:
项目原理1.电脑上运行Processing客户端,负责收集实时视频,发送给Intel Curie Genduino 101/CurieNano,
2.电脑USB外接Intel Curie Genduino101/CurieNano,负责对视频进行训练和识别,可直接在arduino sketch中编译传送给CurieNano:
当然有人会说CurieNano处理不了视频,实际处理的是光流向量。
接下来部署Processing开发环境
首先在电脑安装Processing开发平台。在https://www.processing.org下载安装最新版本Processing软件。
然后打开Processing软件,给Processing平台添加OpenCV库。
选择菜单栏 工具-添加工具。点击鼠标。打开工具管理器。
选择第一页, Libraries,在下拉菜单中选择OpenV,点击Install安装。(注意,这一步需翻墙)
安装成功后,就可以使用本文后附的Processing程序代码了。程序代码启动电脑摄像头,分析拍摄的实时录像光流方向,并传递给Intel Curie nano / Genduino 101进行处理。
再回到arduinoIDE
确保sketch的开发板管理器已经安装和正确识别Curie以后,再添加CuireNeuron库。
下载CuireNeuron库
现在这个库官网收费了,我这里提供个免费版本
链接:http://pan.baidu.com/s/1eRNrRLg 密码:j7w5
然后添加刚才我们下载好的CuireNeuron.zip库文件。
再然后arduino代码
/**
*processing control a 2-4 servos platform
*/
#include <CurieNeurons.h>
CurieNeurons hNN;
int catL = 0;
int prevcat = 0;
int dist, cat, nid, nsr, ncount;
const short sampleNbr = 20;
const short signalNbr = 2;
byte vector;
byte flowX;
byte flowY;
boolean a = false;
void setup()
{
pinMode(13, OUTPUT);
Serial.begin(115200);
while (!Serial);
if(hNN.begin()==0){
Serial.print("neurons initialized");
hNN.forget(500);
}
else{
Serial.print("error.");
}
}
void loop()
{
while(Serial.available()==0);
char data=Serial.read();
for(int i = 0; i < sampleNbr; i++)
{
while(Serial.available()==0);
vector=Serial.read();
}
for(int i = 0; i < sampleNbr; i++)
{
while(Serial.available()==0);
vector=Serial.read();
}
a = !a;
digitalWrite(13, a); // turn the LED on (HIGH is the voltage level)
switch(data)
{
case '%':
//learn 1
catL = 1;
/*for(int i = 0; i <sampleNbr; i++){
Serial.write(vector);
Serial.write(vector);
}*/
ncount = hNN.learn(vector, sampleNbr*signalNbr, catL);
Serial.write(ncount);
Serial.write("#");
Serial.flush();
break;
case '^':
//learn 1
catL = 2;
/*for(int i = 0; i <sampleNbr; i++){
Serial.write(vector);
Serial.write(vector);
}*/
ncount = hNN.learn(vector, sampleNbr*signalNbr, catL);
Serial.write(ncount);
Serial.write("#");
Serial.flush();
break;
case '这个时候你还需要下载个video库
收工
:
// Recognize
hNN.classify(vector, sampleNbr*signalNbr,&dist, &cat, &nid);
Serial.write(cat);
Serial.write("#");
Serial.flush();
break;
}
}
Processing程序
import gab.opencv.*;
import processing.video.*;
import processing.serial.*;
Serial port;
OpenCV opencv;
Capture video;
byte lastx, lasty;
byte currentx, currenty;
byte[] rawVecX;
byte[] rawVecY;
int index;
int count;
boolean action;
final int sampleNbr = 20;
byte state;
byte[] result;
int P_result;
void setup() {
size(640, 240);
result = new byte;
P_result = 0;
rawVecX = new byte;
rawVecY = new byte;
lastx = 0;
lasty = 0;
count = 0;
port = new Serial(this, Serial.list(), 115200);
video = new Capture(this, 320, 240);
opencv = new OpenCV(this, 320, 240);
video.start();
}
void draw() {
if(keyPressed){
if (key == 'a' || key == 'A') {
state = 1;
println("change state to learning 1");
}
else if (key == 's' || key == 'S') {
state = 2;
println("change state to learning 2");;
}
else{
state = 3;
println("change state to classifying");
}
}
background(0);
opencv.loadImage(video);
opencv.calculateOpticalFlow();
image(video, 0, 0);
translate(video.width,0);
stroke(255,0,0);
opencv.drawOpticalFlow();
PVector aveFlow = opencv.getAverageFlow();
int flowScale = 50;
stroke(255);
strokeWeight(2);
textSize(50);
if(result == 1){
text("Yes", 10, 230);
}
else if(result == 2){
text("No", 10, 230);
}
else{
text("?", 10, 230);
}
textSize(40);
if(result == 1){
text("Yes", 10, 175);
}
else if(result == 2){
text("No", 10, 175);
}
else{
text("?", 10, 175);
}
textSize(30);
if(result == 1){
text("Yes", 10, 130);
}
else if(result == 2){
text("No", 10, 130);
}
else{
text("?", 10, 130);
}
line(video.width/2, video.height/2, video.width/2 + aveFlow.x*flowScale, video.height/2 + aveFlow.y*flowScale);
currentx=byte(map(aveFlow.x, -1, 1, 0, 255));
currenty=byte(map(aveFlow.y, -1, 1, 0, 255));
if (action == true){
if(index < sampleNbr){
rawVecX = currentx;
rawVecY = currenty;
index++;
}
else
{
action = false;
print("count=");
println(count);
for(int i = 0; i < sampleNbr; i++){
print(int(rawVecX));
print(",");
}
println();
for(int i = 0; i < sampleNbr; i++){
print(int(rawVecY));
print(",");
}
print("|");
println(state);
sendToCurie(state, rawVecX, rawVecY);
println("accepted");
}
}
else
{
if(abs(int(currentx)-int(lastx)) > 30 || abs(int(currenty)-int(lasty)) > 30){
action = true;
index = 0;
count = count + 1;
println("started");
}
}
lastx = currentx;
lasty = currenty;
}
void captureEvent(Capture c) {
c.read();
}
void sendToCurie(byte LorC, byte[] vecX, byte[] vecY) //send yaw and roll angel to MegaPi to control servos
{
if(LorC == 1){
port.write('%');
}
else if(LorC == 2){
port.write('^');
}
else{
port.write('这个时候你还需要下载个video库
收工
);
}
port.write(vecX);
port.write(vecY);
byte inByte;
int ct = 0;
while (port.available() > 0){
inByte = byte(port.read());
print(int(inByte));
if(ct == 0){
result = result;
result = result;
result = inByte;
}
print(">");
if(inByte == '#'){
break;
}
ct = ct + 1;
}
}这个时候你还需要下载个video库
收工
qidai 占楼~围观大项目 期待中。。。。。。。。。。。。。。。 luna 发表于 2017-5-23 10:33
占楼~围观大项目
稍等哦
页:
[1]