trying to create a video out of a color-array
in
Programming Questions
•
3 years ago
hi all,
I am pretty new to processing, trying to start a sketch that is using a video and display it onto the screen until the user presses a mouse-button and then the video should be transformed in the following way: comparing the values of red, green and blue of each pixel and setting the pixel's color to the color (r,g,b) that has the highest value
I do have a working version for a image already and I am trying to do a similar thing for a video write now. I thought I could just create a new image, creating an array for the new color and with the pixels-function I can set the new color to the color stored in the array and then display the image... but somehow it doesn't work as expected.... I get the following error ArrayIndexOutOfBorder in the last line...
here is the code, maybe someone could help?? thanks in advance!
SuseJule
import processing.video.*;
Capture video;
PImage transformed_picture;
void setup()
{
size (640,480);
video = new Capture(this, width, height, 1);
transformed_picture = createImage(width, height, ARGB);
}
void draw()
{
originalpicture(); // function to display original picture as long as mouse has not been pressed
}
void mousePressed() //on mousepress show the transformed video
{
transformedpicture();
}
void originalpicture()
{
video.read();
loadPixels();
// loading video pixels
video.loadPixels();
for (int y = 0; y < height; y++) {
for (int x = 0; x < width; x++) {
int mycolor = x + y*width;
// getting values of red, green, blue of the pixel
float r = red(video.pixels[mycolor]);
float g = green(video.pixels[mycolor]);
float b = blue(video.pixels[mycolor]);
pixels[mycolor] = color(r,g,b);
}
}
updatePixels();
}
color [] transformedcolor= new color [height*width]; //array for new colors
void transformedpicture()
{
video.read();
loadPixels();
//loading pixels of video
video.loadPixels();
for (int y = 0; y < video.height; y++) {
for (int x = 0; x < video.width; x++) {
int mycolor = x + y*video.width;
// getting values of red, green, blue of the pixel
float r = red(video.pixels[mycolor]);
float g = green(video.pixels[mycolor]);
float b = blue(video.pixels[mycolor]);
//compare red, green and blue values and set the pixels to the color that is most in
if (r<=g)
{
transformedcolor[mycolor]= color(0,255,0);
} //green
if (g<=b)
{
transformedcolor[mycolor]= color(0,0,255);
} //blue
if (b<r)
{
transformedcolor[mycolor]= color(255,0,0);
} //red
transformed_picture.pixels[mycolor]=transformedcolor[mycolor];
}
image(transformed_picture,0,0);
}
}
1