2012-10-07 95 views
1

我想要做的是将像素从视频摄像头转换为图像 以更好地展现它想象一个3D模型,所以..像素将是每个polying,并且我想要做的是将每个polyigon转换成图像。将像素从图像复制到网络摄像头

什么我到目前为止是这样的:

** 
import processing.video.*; 
PImage hoja; 
Capture cam; 
boolean uno, dos, tres, cuatro; 


import ddf.minim.*; 

Minim minim; 
AudioPlayer audio; 
float set; 



void setup() { 

    //audio 
    minim = new Minim(this); 
// audio = minim.loadFile("audio"); 
// audio.loop(); 

// 
    uno=false; 
    dos=false; 
    tres=false; 
    cuatro=true; 
    size(640, 480); 
    hoja=loadImage("hoja.gif"); 


    cam = new Capture(this, width, height); 
    cam.start(); 

} 

void draw() { 
    if (cam.available() == true) { 
    cam.read(); 

    if (uno==true) { 
     filtroUno(); 
     image(cam, 0, 0, 640, 480); 
     } 
      if (dos==true) { 
     filtroDos(); 
     } 

     if(tres==true){ 
     filtroTres(); 
     } 

     if(cuatro==true){ 
     filtroCuatro(); 
     image(cam, set, 0,640,480); 
     } 
    } 


    // The following does the same, and is faster when just drawing the image 
    // without any additional resizing, transformations, or tint. 
    //set(0, 0, cam); 
} 

void filtroUno() { 
    cam.loadPixels(); 
    hoja.loadPixels(); 
    for (int i=0;i<cam.pixels.length;i++) { 
    if (brightness(cam.pixels[i])>110) { 
     cam.pixels[i]=color(0, 255, 255); 
    } 
    else { 
     cam.pixels[i]=color(255, 0, 0); 
    } 
    } 

    for (int i=0;i<cam.width;i+=10) { 

    for (int j=0;j<cam.height;j+=10) { 
     int loc=i+(j*cam.width); 
     if (cam.pixels[loc]==color(255, 0, 0)) { 
     for (int x=i;x<i+10;x++) { 
      for (int y=j;y<j+10;y++) { 
      // println("bla"); 
      int locDos=i+(j*cam.width); 
      cam.pixels[locDos]=hoja.get(x, y); 
      } 
     } 
     } 
    } 
    } 

    cam.updatePixels(); 
} 
** 

的问题是,每个像素都创造了我一个矩阵,所以..没有什么重建ID,这样做。

我有方法filtroUno但它没有表现出好的.. ,是结果

void filtroUno() { 
    cam.loadPixels(); 
    hoja.loadPixels(); 
    for (int i=0;i<cam.pixels.length;i++) { 
    if (brightness(cam.pixels[i])>110) { 
     cam.pixels[i]=color(0, 255, 255); 
    } 
    else { 
     cam.pixels[i]=color(255, 0, 0); 
    } 
    } 

    for (int i=0;i<cam.width;i+=10) { 

    for (int j=0;j<cam.height;j+=10) { 
     int loc=i+j*hoja.width*10; 
     if (cam.pixels[loc]==color(255, 0, 0)) { 
     for (int x=i;x<i+10;x++) { 
      for (int y=j;y<j+10;y++) { 
      // println("bla"); 
      int locDos=x+y*hoja.height*10; 
      cam.pixels[locDos]=hoja.get(x, y); 
      } 
     } 
     } 
    } 
    } 

    cam.updatePixels(); 
} 

enter image description here

我希望你能帮助我感谢

注:每个红像素应该是gif图片的大小IMGE是10×10

回答

1

我认为你正在做的事情是通过每10个像素网络循环凸轮的图像,如果像素是红色的,你用位于那是红色像素的GIF的左上角放置一个10x10px GIF的内容在网络摄像头图像。

// loop through each 10th column in the camera 
for (int i=0;i<cam.width;i+=10) { 

    // loop through each 10th row in the camera 
    for (int j=0;j<cam.height;j+=10) {    

     // calculate the pixel location at (i, j) 
     int loc=i+(j*cam.width); 

     // check the pixel is red 
     if (cam.pixels[loc]==color(255, 0, 0)) { 

      // loop through each column in the gif image 
      for (int x=0;x<10;x++) { 

       // loop through each row in the gif image 
       for (int y=0;y<10;y++) { 

        int locDos = (i + x) + ((j + y) * cam.width); 
        cam.pixels[locDos]=hoja.get(x, y); 
       } 
      } 
     } 
    } 
} 
+0

感谢的人!!!!我爱你...但显示图像,只是黑色的正方形 –

+0

再试一次,我更新的代码。 –

+0

谢谢你,它的工作 –