简体   繁体   English

将像素从图像复制到网络摄像头

[英]Copying pixels from an image to the webcam

What I am trying to do is to convert a pixel from a video cam, into an image to expalin it better imagine a 3d model so.. the pixels would be each polying, and i want to do is to conver each polyigon into an image. 我想要做的是将视频摄像机中的像素转换为图像,以更好地想象3D模型,这样..像素将是每个多边形,而我想做的是将每个多边形都转换为图像。

What i have so far is this: 我到目前为止所拥有的是:

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

The problem is that each pixel is creating me a matrix, so.. is not recreating what id that to do. 问题在于每个像素都在创建一个矩阵,因此..没有重新创建该ID。

I had the method filtroUno but it wasn't showing ok.. and was the result 我有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();
} 

在此处输入图片说明

i hope you can help me thanks 我希望你能帮助我,谢谢

note: each red pixel should be the gif image the imge size is 10x10 注意:每个红色像素应为gif图像,图像大小为10x10

I think what you are doing is looping through every 10th pixel in a webcam image and if the pixel is red you are placing the contents of a 10x10px gif over the webcam image with the top left corner of the gif positioned at the pixel that was red. 我认为您正在执行的操作是遍历网络摄像头图像中的第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);
                }
            }
        }
    }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM