|
自分の勉強した内容(プログラミング等)
に関するメモなどを綴る日記
× [PR]上記の広告は3ヶ月以上新規記事投稿のないブログに表示されています。新しい記事を書く事で広告が消えます。
まぁjavaといってもProcessingになるんですが
人間の髪の毛(というか黒い物体)にロックオンカーソル を合わせると反応するプログラム作ってみました まぁ課題のためなんですけどね でもまぁ出来が悪いなぁというのが自分の正直な感想です ちなみに以下のプログラム import processing.video.*; Capture img; PImage result; int label[]; int cnt = 0; int label_num; int L_BASE = 50; int timer=0; float thresh = 30.0; boolean lockflag; void setup(){ colorMode(RGB); size(480, 320); img = new Capture(this, width, height, 30); result = createImage(width, height, RGB); label = new int[width*height]; } void draw(){ if (img.available()) { img.read(); //二値化 binalize(img, label); //ラベリング処理 label_num = labeling(img, label, L_BASE); println(label_num); image(img,0,0); timer++; } rectMode(CENTER); stroke(0,0,255); line(width/4,0,width/4,height); line(width*3/4,0,width*3/4,height); if(label[width*mouseY+mouseX]>50) lockflag=true; else lockflag=false; PFont ft = loadFont("MS-PGothic-48.vlw"); textFont(ft,40); if(lockflag==true){ text("LOCK ON!",20,50); }else if(lockflag==false)text("LOST",20,50); noFill(); if(lockflag==true){ stroke(255,0,0); ellipse(mouseX,mouseY,40,40); }else if(lockflag==false){ stroke(0,0,255); } ellipse(mouseX,mouseY,20,20); ellipse(mouseX,mouseY,30,30); textFont(ft,15); stroke(0,0,255); text(""+mouseX+","+mouseY,mouseX+5,mouseY+5); line(mouseX,0,mouseX,result.width); line(0,mouseY,result.width,mouseY); if(mousePressed){ if(lockflag==true){ textFont(ft,40); fill(255,0,0); text("HIT!",200,200); ellipse(mouseX,mouseY,200,200); }else if(lockflag == false){ textFont(ft,40); fill(0,0,255); text("MISS!",200,200); } stroke(0,0,255); lockflag = false; } } //2値化 void binalize(PImage img_, int[] label_){ for(int j=0;j } else{ label_[img_.width*j+i] = 0; } } } } //ラベリング int labeling(PImage img_, int[] label_, int label_num){ for(int i=0;i if(label_num>=img_.width*img_.height){ println("ERROR!! TOO MANY LABELS."); } label_[i]=label_num; for(;;){ int cnt=0; for(int j=img_.width+1;j if(label_[j+img_.width]==1){ label_[j+img_.width]=label_num; cnt++;} if(label_[j+img_.width-1]==1){ label_[j+img_.width-1]=label_num; cnt++;} if(label_[j-1]==1){ label_[j-1]=label_num; cnt++;} if(label_[j-img_.width-1]==1){ label_[j-img_.width-1]=label_num; cnt++;} if(label_[j-img_.width]==1){ label_[j-img_.width]=label_num; cnt++;} if(label_[j-img_.width+1]==1){ label_[j-img_.width+1]=label_num; cnt++;} if(label_[j+1]==1){ label_[j+1]=label_num; cnt++;} if(label_[j+img_.width+1]==1){ label_[j+img_.width+1]=label_num; cnt++;} } } if(cnt==0) break; } label_num++; } } return label_num; } ちなみにこれ、ラベリングのところなどは先生が作ったソースのこぴぺなんですよね・・・ あぁ情けない・・・ PR |
カレンダー
フリーエリア
最新トラックバック
プロフィール
HN:
矢部竜太
性別:
非公開
ブログ内検索
|
