proce55ingでスライダーを実装する。
proce55ingでcontrolP5というライブラリを使うと
スライダーやトグルといったUIを追加することができます。
controlP5を使うには上記のサイトからダウンロードしてきて
processingのライブラリフォルダーに追加する必要があります。
ライブラリをダウンロードしてきたらデスクトップにcontrolP5を解凍
cd /Applications/Processing/libraries
mkdir controlP5
mv ~/Desktop/controlP5/library /Applications/Processing/libraries/controlP5/
ということで
前々回実装した2値化処理にスライダーを実装し少し改良してみました。
import processing.video.*; import controlP5.*; Capture cam; ControlP5 controlP5; //フレームレート int fps = 30; //フレーム boolean newFrame = false; //しきい値 float threshold = 0.3; //controlP5 initialze float bMin = 0;//最小値 float bMax = 1;//最大値 float bDefault = 0.3; int bX = 0; int bY = 0; int bWidth = 100; int bHeight = 10; void setup(){ size(320, 240);//ウィンドサイズ //カメラ cam = new Capture(this, width, height, fps); //controlP5(Slider) controlP5 = new ControlP5(this); controlP5.addSlider("threshold",bMin,bMax,bDefault,bX,bY,bWidth,bHeight); } void draw(){ if (newFrame) { newFrame=false; image(cam,0,0,width,height); } } void captureEvent(Capture cam) { cam.read(); //2値化 cam.filter(THRESHOLD,threshold); newFrame = true; } //キー入力イベント void keyPressed(){ // 2値化閾値の調整 if('A' <= key && key <= 'z'){ switch(key){ case 'a': if(threshold > bMin) threshold -= 0.01; controlP5.controller("threshold").setValue(threshold); break; case 's': if(threshold < bMax) threshold += 0.01; controlP5.controller("threshold").setValue(threshold); break; } } }
スクリーンショット:
ちなみにosxはshift+コマンド(林檎マーク)+4のあと
スペースでウィンドウキャプチャーができる。