Download
http://webcamxtra.sourceforge.net/download.shtml


Reference
http://webcamxtra.sourceforge.net/reference.shtml


JMyron 활용
- Motion detection
- Color tracking


다운받은 파일에 포함되어 있는 Example 들입니다.

예제 - Motion detection
frame difference (현재프레임과 다음프레임 이미지의 차이)를 이용하여 움직임을 감지해
녹색원을 그려주는 예제.
frame difference 이미지에서 검출된 여러 glob(덩어리)들의 중심좌표값들을 평균하는 방식


Myron_CameraAsMouse.pde
---------------------------------------------------------------------------------------------------
/*
the green oval is an averaged position of all the detected dark movement in the camera's view.
physical setup:
  - make sure there is a strong value contrast between your hand and a white background.
  - set all camera settings to "manual" for the most stable results.
 last tested to work in Processing 0090

 JTNIMOY
*/

import JMyron.*;

JMyron m;//a camera object

//variables to maintain the floating green circle
float objx = 160;
float objy = 120;
float objdestx = 160;
float objdesty = 120;

void setup(){
  size(640,480);

  m = new JMyron(); // JMyron 개체 생성
  m.start(width,height); // JMyron 시작
  m.trackColor(255,255,255,256*3-100); // white 를 track color 로 지정
  m.update();
  m.adaptivity(10); // frame difference 의 반응속도 설정
  m.adapt(); // 최초 시작시는 바로 adapt
  println("Myron " + m.version());
  rectMode(CENTER);
  noStroke();
}


void draw(){
  background(0);
  m.update();  //update the camera view
  drawCamera();
 
  int[][] centers = m.globCenters(); // glob 의 중심좌표 값들을 centers 라는 2차원 배열에 저장

  float avX=0;
  float avY=0;
 
  // centers 좌표를 모두 더해서 avX 와 avY에 저장
  for(int i=0;i<centers.length;i++){
    avX += centers[i][0];
    avY += centers[i][1];
  }
  // centers.length 로 나누어 평균을 구한다
  if(centers.length-1>0){
    avX/=centers.length-1;
    avY/=centers.length-1;
  }

  // 평균점을 빨간색 사각형으로 표시
  fill(255,0,0);
  rect(avX,avY,5,5);

  // 새로운 평균점을 destination 좌표에 저장
  if(!(avX==0&&avY==0)&&centers.length>0){
    objdestx = avX;
    objdesty = avY;
  }

  // 물체의 좌표를 destination 좌표로 이동 하고 녹색원을 그린다
  // (급작스럽게 튀는 이동을 방지하기위해 easing 방식 으로 더해가면서 이동)
  objx += (objdestx-objx)/5.0f;
  objy += (objdesty-objy)/5.0f;
  fill(30,100,0);
  ellipseMode(CENTER);
  ellipse(objx,objy,30,30); // 원 그리기 : 이를 대체해서 원하는 것을 그릴 수 있습니다.
}

void drawCamera(){
  // 화면에 frame difference 이미지를 그려준다
  int[] img = m.differenceImage(); //get the normal image of the camera
  loadPixels();
  for(int i=0;i<width*height;i++){ //loop through all the pixels
    pixels[i] = img[i]; //draw each pixel to the screen
  }
  updatePixels();
}


public void stop(){
  m.stop();//stop the object
  super.stop();
}



예제 - Color tracking
trackColor 함수로 지정된 컬러를 traking 하여 box들로 그려줍니다.
참고로 reference 에 보시면 trackNotColor 라는 함수도 있어서 검출을 원하지 않는 컬러도
지정이 가능한듯 합니다.


Myron_tracking.pde
---------------------------------------------------------------------------------------------------
/*

This example shows a whole lot of different
tracking methods being rendered at one time.
Don't be surprised if this one runs really slowly.

 last tested to work in Processing 0090
 
 JTNIMOY
 
*/

import JMyron.*;

JMyron m;
 
void setup(){
  int w = 640;
  int h = 480;
 
  size(w,h);
  m = new JMyron();
  m.start(640,480);
  m.findGlobs(1);
  println("Myron " + m.version());
}

void mousePressed(){
  m.settings();
}

void draw(){
  m.trackColor(180,180,120,255); // track하고자 하는 컬러 지정 (r,g,b,tolerance)

  m.update();
  int[] img = m.image();
 
  //first draw the camera view onto the screen
  loadPixels();
  for(int i=0;i<width*height;i++){
      pixels[i] = img[i];
  }
  updatePixels();
 
 
  // 마우스 포인터 영역 근처의 컬러 평균값으로 네모 그리기
  noStroke();
  int c = m.average(mouseX-20,mouseY-20,mouseX+20,mouseY+20);
  fill(red(c),green(c),blue(c));
  rect(mouseX-20,mouseY-20,40,40);

  noFill();
  int[][] a;


  // 검출된 glob 들의 중심점을 노란색으로 찍기
  a = m.globCenters();
  stroke(255,255,0);
  for(int i=0;i<a.length;i++){
    int[] p = a[i];
    point(p[0],p[1]);
    println("p[0]="+p[0]+", p[1]="+p[1]);
  }
 

  // 검출된 glob 을 사각형으로 그리기
  a = m.globBoxes();
  stroke(255,0,0);
  for(int i=0;i<a.length;i++){
    int[] b = a[i];
    rect(b[0], b[1], b[2], b[3]); // 위의 p[0],p[1] 이나 이 b[0], b[1] 등의 값들을 활용해서 작업.
  }


}

public void stop(){
  m.stop();
  super.stop();
}


Posted by 알 수 없는 사용자