lundi 19 mai 2014

Java - copie les pixels d'une image pour la webcam - Stack Overflow


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 problem 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




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.


// 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);
}
}
}
}
}


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 problem 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



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.


// 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 commentaires:

Enregistrer un commentaire