convert pixels into image

Posted by Zeta Op on Stack Overflow See other posts from Stack Overflow or by Zeta Op
Published on 2012-10-07T03:11:23Z Indexed on 2012/10/07 3:37 UTC
Read the original article Hit count: 238

Filed under:
|
|
|
|

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. 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 broblem is that each pixel is creating me a matrix, so.. is not recreating what id that to do.

i had the method filtroUno but it wasn't showing ok.. and was the result

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

i hope you can help me thanks

note: each red pixel should be the gif image the imge size is 10x10

© Stack Overflow or respective owner

Related posts about java

Related posts about image