【问题标题】:Copying pixels from an image to the webcam将像素从图像复制到网络摄像头
【发布时间】:2012-09-27 18:21:55
【问题描述】:

我想要做的是将摄像头中的像素转换为图像 为了更好地解释它,想象一个 3d 模型......像素将是每个多边形,我想做的是将每个多边形转换成图像。

到目前为止,我所拥有的是:

**
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();
} 

希望你能帮我谢谢

注意:每个红色像素应该是gif图像,图像大小为10x10

【问题讨论】:

    标签: java image converter pixel processing


    【解决方案1】:

    我认为您正在做的是循环遍历网络摄像头图像中的每 10 个像素,如果像素为红色,则您将 10x10px gif 的内容放在网络摄像头图像上,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);
                    }
                }
            }
        }
    }
    

    【讨论】:

      猜你喜欢
      • 2020-07-06
      • 2013-02-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-03-24
      相关资源
      最近更新 更多