Data_read
の編集
https://lab.yoneyone.net/php/pukiwiki/?Data_read
[
トップ
] [
編集
|
差分
|
履歴
|
添付
|
リロード
] [
新規
|
一覧
|
検索
|
最終更新
|
ヘルプ
]
-- 雛形とするページ --
(no template pages)
[[Kinect]]~ 【Data_read.pde】の解説~ ※パーツ毎に記述していきます。~ -プログラムの構成~ ①サーバ経由でKinectからデータを受信する~ ②受信した数字の羅列を分解、再定義~ ③【s】ボタンで受信したデータをpositions.txtに保存~ ================================================================================== * ①サーバ経由でKinectからデータを受信する[#r842de3c] import processing.net.*; //Processingからネットワークを扱いたい時に使うライブラリを宣言~ Client myClient; //クライアント側ですよっ。~ String line; //文字列を入れるためにlineっていう変数を定義する。~ ~ void setup() {~ myClient = new Client(this, "localhost", 12345); //コンピュータの中の12345っていう場所でデータをやりとりしますよ。~ }~ ~ void draw() { if(myClient.available() > 0) { //クライアントが利用できる時。 line = myClient.readString(); //lineに受信したデータを格納します。 } } -参考リンク --[[readString():http://processing.org/reference/libraries/net/Client_readString_.html]]~ --[[string:http://processing.org/reference/String.html]]~ * ②受信した数字の羅列を分解、再定義[#r842de3c] ※ここではクラス化してあります。~ class Bonenow { Bonenow() { String[] pieces = split(line, " "); //データが、"10 30 440 40 40 440..."のようにスペースで区切られたものが1度に45個飛んでくるので、スペースで分解し、1つ1つの数字を扱えるようにする。~ if(pieces.length >= 45) { //鬱陶しいことに、分解したデータが必ずしも45個とは限らないのです。~ //変なスペースなんかが二つ入ってたりすることもあるのです。~ //だから、データが45個以上来てる時、という風にします。~ int headx = int(float(pieces[0])/10); //頭のx座標 int heady = int(float(pieces[1])/10); //頭のy座標 int headz = int(float(pieces[2])/10); //頭のz座標 //45個用意したpiecesって名前の箱(配列)の、~ //最初の3つの文字を頭の(x,y,z)として定義します。~ println("head(x, y, z) = " + "( " + headx + ", " + heady + ", " + headz + ")"); //定義した座標がどうなってるか自分がわかるようにする。 ※この作業を地道に、~ 頭→~ 首→~ 左肩→右肩→~ 左肘→右肘→~ 左手→右手→~ 腰→~ 左尻→右尻→~ 左膝→右膝→~ 左足→右足~ とゆう風に定義していきます。~ //そしたら定義した数字を、line()で繋ぎ合わせます。 stroke(0); strokeWeight(3); line(headx, heady, headz, neckx, necky, neckz); //頭-首 line(leshx, leshy, leshz, rishx, rishy, rishz); //左肩-右肩 line(leshx, leshy, leshz, torsx, torsy, torsz); //左肩-腰 line(rishx, rishy, rishz, torsx, torsy, torsz); //右肩-腰 line(leshx, leshy, leshz, leelx, leely, leelz); //左肩-左肘 line(leelx, leely, leelz, lehax, lehay, leelz); //左肘-左手 line(rishx, rishy, rishz, rielx, riely, rielz); //右肩-右肘 line(rielx, riely, rielz, rihax, rihay, rihaz); //右肘-右手 line(torsx, torsy, torsz, lehix, lehiy, lehiz); //腰-左尻 line(torsx, torsy, torsz, rihix, rihiy, rihiz); //腰-右尻 line(lehix, lehiy, lehiz, rihix, rihiy, rihiz); //左尻-右尻 line(lehix, lehiy, lehiz, leknx, lekny, leknz); //左尻-左膝 line(leknx, lekny, leknz, lefox, lefoy, lefoz); //左膝-左足 line(rihix, rihiy, rihiz, riknx, rikny, riknz); //右尻-右膝 line(riknx, rikny, riknz, rifox, rifoy, rifoz); //右膝-右足 delay(200); //200ミリ秒(=0.2秒)、プログラムの実行を遅らせる } } } -参考リンク~ --[[配列:http://processing.org/reference/Array.html]]~ --[[split():http://processing.org/reference/split_.html]]~ --[[int:http://processing.org/reference/int.html]]~ --[[if:http://processing.org/reference/if.html]]~ --[[length:http://processing.org/reference/String_length_.html]]~ --[[>=(以上):http://processing.org/reference/greaterthanorequalto.html]]~ --[[int():http://processing.org/reference/int_.html]]~ --[[float:http://processing.org/reference/float.html]]~ --[[stroke():http://processing.org/reference/stroke_.html]]~ --[[strokeWeight():http://processing.org/reference/strokeWeight_.html]]~ --[[line():http://processing.org/reference/line_.html]]~ --[[delay():http://processing.org/reference/delay_.html]]~ * ③【s】ボタンで受信したデータをpositions.txtに保存[#r842de3c] PrintWriter output; //PrintWriterを宣言 void setup() { output = createWriter("../Data_play/data/positions.txt"); //positions.txtって名前で保存する。 } void draw() { if(myClient.available() > 0) { //outputに受信したデータを書き込む output.println(headx + " " + heady + " " + headz + " " + neckx + " " + necky + " " + neckz + " " + leshx + " " + leshy + " " + leshz + " " + rishx + " " + rishy + " " + rishz + " " + leelx + " " + leely + " " + leelz + " " + rielx + " " + riely + " " + rielz + " " + lehax + " " + lehay + " " + lehaz + " " + rihax + " " + rihay + " " + rihaz+ " " + torsx + " " + torsy + " " + torsz + " " + lehix + " " + lehiy + " " + lehiz + " " + rihix + " " + rihiy + " " + rihiz + " " + leknx + " " + lekny + " " + leknz + " " + riknx + " " + rikny + " " + riknz + " " + lefox + " " + lefoy + " " + lefoz + " " + rifox + " " + rifoy + " " + rifoz); } } void keyPressed() { if(key == 's') { output.flush(); //ここでぱっと書きこんで output.close(); //書きこみ終了。 exit(); //もうやることもないんでついでにプログラム自体終了。 } } -参照リンク --[[PrintWriter:http://processing.org/reference/PrintWriter.html]] --[[void keyPressed:http://processing.org/reference/keyPressed_.html]] --[[exit():http://processing.org/reference/exit_.html]] [[Data_play]]はコチラ~
タイムスタンプを変更しない
[[Kinect]]~ 【Data_read.pde】の解説~ ※パーツ毎に記述していきます。~ -プログラムの構成~ ①サーバ経由でKinectからデータを受信する~ ②受信した数字の羅列を分解、再定義~ ③【s】ボタンで受信したデータをpositions.txtに保存~ ================================================================================== * ①サーバ経由でKinectからデータを受信する[#r842de3c] import processing.net.*; //Processingからネットワークを扱いたい時に使うライブラリを宣言~ Client myClient; //クライアント側ですよっ。~ String line; //文字列を入れるためにlineっていう変数を定義する。~ ~ void setup() {~ myClient = new Client(this, "localhost", 12345); //コンピュータの中の12345っていう場所でデータをやりとりしますよ。~ }~ ~ void draw() { if(myClient.available() > 0) { //クライアントが利用できる時。 line = myClient.readString(); //lineに受信したデータを格納します。 } } -参考リンク --[[readString():http://processing.org/reference/libraries/net/Client_readString_.html]]~ --[[string:http://processing.org/reference/String.html]]~ * ②受信した数字の羅列を分解、再定義[#r842de3c] ※ここではクラス化してあります。~ class Bonenow { Bonenow() { String[] pieces = split(line, " "); //データが、"10 30 440 40 40 440..."のようにスペースで区切られたものが1度に45個飛んでくるので、スペースで分解し、1つ1つの数字を扱えるようにする。~ if(pieces.length >= 45) { //鬱陶しいことに、分解したデータが必ずしも45個とは限らないのです。~ //変なスペースなんかが二つ入ってたりすることもあるのです。~ //だから、データが45個以上来てる時、という風にします。~ int headx = int(float(pieces[0])/10); //頭のx座標 int heady = int(float(pieces[1])/10); //頭のy座標 int headz = int(float(pieces[2])/10); //頭のz座標 //45個用意したpiecesって名前の箱(配列)の、~ //最初の3つの文字を頭の(x,y,z)として定義します。~ println("head(x, y, z) = " + "( " + headx + ", " + heady + ", " + headz + ")"); //定義した座標がどうなってるか自分がわかるようにする。 ※この作業を地道に、~ 頭→~ 首→~ 左肩→右肩→~ 左肘→右肘→~ 左手→右手→~ 腰→~ 左尻→右尻→~ 左膝→右膝→~ 左足→右足~ とゆう風に定義していきます。~ //そしたら定義した数字を、line()で繋ぎ合わせます。 stroke(0); strokeWeight(3); line(headx, heady, headz, neckx, necky, neckz); //頭-首 line(leshx, leshy, leshz, rishx, rishy, rishz); //左肩-右肩 line(leshx, leshy, leshz, torsx, torsy, torsz); //左肩-腰 line(rishx, rishy, rishz, torsx, torsy, torsz); //右肩-腰 line(leshx, leshy, leshz, leelx, leely, leelz); //左肩-左肘 line(leelx, leely, leelz, lehax, lehay, leelz); //左肘-左手 line(rishx, rishy, rishz, rielx, riely, rielz); //右肩-右肘 line(rielx, riely, rielz, rihax, rihay, rihaz); //右肘-右手 line(torsx, torsy, torsz, lehix, lehiy, lehiz); //腰-左尻 line(torsx, torsy, torsz, rihix, rihiy, rihiz); //腰-右尻 line(lehix, lehiy, lehiz, rihix, rihiy, rihiz); //左尻-右尻 line(lehix, lehiy, lehiz, leknx, lekny, leknz); //左尻-左膝 line(leknx, lekny, leknz, lefox, lefoy, lefoz); //左膝-左足 line(rihix, rihiy, rihiz, riknx, rikny, riknz); //右尻-右膝 line(riknx, rikny, riknz, rifox, rifoy, rifoz); //右膝-右足 delay(200); //200ミリ秒(=0.2秒)、プログラムの実行を遅らせる } } } -参考リンク~ --[[配列:http://processing.org/reference/Array.html]]~ --[[split():http://processing.org/reference/split_.html]]~ --[[int:http://processing.org/reference/int.html]]~ --[[if:http://processing.org/reference/if.html]]~ --[[length:http://processing.org/reference/String_length_.html]]~ --[[>=(以上):http://processing.org/reference/greaterthanorequalto.html]]~ --[[int():http://processing.org/reference/int_.html]]~ --[[float:http://processing.org/reference/float.html]]~ --[[stroke():http://processing.org/reference/stroke_.html]]~ --[[strokeWeight():http://processing.org/reference/strokeWeight_.html]]~ --[[line():http://processing.org/reference/line_.html]]~ --[[delay():http://processing.org/reference/delay_.html]]~ * ③【s】ボタンで受信したデータをpositions.txtに保存[#r842de3c] PrintWriter output; //PrintWriterを宣言 void setup() { output = createWriter("../Data_play/data/positions.txt"); //positions.txtって名前で保存する。 } void draw() { if(myClient.available() > 0) { //outputに受信したデータを書き込む output.println(headx + " " + heady + " " + headz + " " + neckx + " " + necky + " " + neckz + " " + leshx + " " + leshy + " " + leshz + " " + rishx + " " + rishy + " " + rishz + " " + leelx + " " + leely + " " + leelz + " " + rielx + " " + riely + " " + rielz + " " + lehax + " " + lehay + " " + lehaz + " " + rihax + " " + rihay + " " + rihaz+ " " + torsx + " " + torsy + " " + torsz + " " + lehix + " " + lehiy + " " + lehiz + " " + rihix + " " + rihiy + " " + rihiz + " " + leknx + " " + lekny + " " + leknz + " " + riknx + " " + rikny + " " + riknz + " " + lefox + " " + lefoy + " " + lefoz + " " + rifox + " " + rifoy + " " + rifoz); } } void keyPressed() { if(key == 's') { output.flush(); //ここでぱっと書きこんで output.close(); //書きこみ終了。 exit(); //もうやることもないんでついでにプログラム自体終了。 } } -参照リンク --[[PrintWriter:http://processing.org/reference/PrintWriter.html]] --[[void keyPressed:http://processing.org/reference/keyPressed_.html]] --[[exit():http://processing.org/reference/exit_.html]] [[Data_play]]はコチラ~
テキスト整形のルールを表示する