import processing.video.*;
Capture video;
PFont font;//フォントを用意
//画面サイズの変数と値
int w=800;
int h=600;
int th=240;
int num=0;
boolean showVideo=true;
void setup() {
size(w, h);
video = new Capture(this, w, h, 30);
font=createFont("Monaco",10);
textFont(font);//フォントの設定
background(0);
noStroke();
frameRate(30);
}
void draw() {
stroke(255,0,0);
for(int j=0;j<h;j++){
for(int i=0;i<w;i++){
if(brightness(video.pixels[i+j*w])>=th){
point(w-i,j);
if(w-i<50 && j>height-12){
background(0);
}
}
}
}
noStroke();
//しきい値と撮影画像番号の表示
fill(50);
rect(0,height-12,50,12);
fill(100);
text(th+": "+num,8,height-2);
if(showVideo){
tint(255,8);//透明度128(50%)
scale(-1.0, 1.0);//左右反転(鏡像)
image(video, -w, 0);//映像出力
}
}
void captureEvent(Capture video) {
video.read();
}
void mousePressed(){
background(0);
}
void keyPressed(){
if(key==CODED){
if(keyCode==LEFT){//左キーを押した場合
th-=1; //許容値を-1する
if(th<0){th=0;}
}
if(keyCode==RIGHT){//右キーを押した場合
th+=1; //許容値を+1する
if(th>255){th=255;}
}
if(keyCode==DOWN){
showVideo=!showVideo;
}
}
if(key==' '){
String s="image_"+num+".jpg";//記録画像インデックス名(jpgで保存)
save(s);//画像を保存
num++;//インデックス番号を更新
}else if(key=='c'){
video.settings();//カメラセッティング
}
}
0 件のコメント:
コメントを投稿