Projeto

Geral

Perfil

Estatísticas
| Revisão:

root / first_draft / Detector.pde @ 4

Histórico | Ver | Anotar | Download (1,47 KB)

1
class Detector
2
  {
3
  JMyron cam;
4
  
5
  float camwidth  = 640;
6
  float camheight = 480;
7
  float width_factor;
8
  float height_factor;
9
  float r, g, b, av;
10
  
11
  Detector ()
12
    {
13
    cam = new JMyron();           //make a new instance of the object
14
    cam.start((int)camwidth, (int)camheight);          //start a capture at 320x240
15
    cam.findGlobs(0);             //disable the intelligence to speed up frame rate
16

    
17
    
18
    
19
    this.width_factor  = _width_/this.camwidth;
20
    this.height_factor = _height_/this.camheight;
21
    
22
    println (_width_);
23
    println (_height_);
24
    println (this.camwidth);
25
    println (this.camheight);
26
    println (this.width_factor);
27
    println (this.height_factor);
28
    }
29
    
30
  void draw ()
31
    {
32
    fill (255, 125);
33
    noStroke ();  
34
      
35
    cam.update();              
36
    int[] img = cam.image();  //get the normal image of the camera
37

    
38
    for(int y = 0; y < camheight; y += 5)
39
      {
40
      for(int x = 0;x < camwidth; x += 5)
41
        {
42
        r = red   (img [y * (int) camwidth + x]);
43
        g = green (img [y * (int) camwidth + x]);
44
        b = blue  (img [y * (int) camwidth + x]);
45

    
46
        av = (r + g + b)/3.0;
47

    
48
        if (av < 230)
49
          continue;
50
 
51
        Point p = new Point ();
52
        p.x = x * width_factor;
53
        p.y = y * height_factor;
54
       
55
//        lighted = (Point[])append (lighted, p);
56

    
57
   
58
        fill(r, g, b);
59
        rect (x * width_factor , y * height_factor, 5* width_factor, 5*height_factor);
60
        }
61
      }
62
    }
63
  }