what am I doing wrong?
I’m trying to get rgb values from camera an draw circles with those values
it works fine with the get function but with the pixel array it doesn’t look right
import processing.video.*;
Capture video;
float r,g,b;
void setup() {
size(320, 240);
video = new Capture(this, 320, 240);
video.start();
}
void captureEvent(Capture video) {
video.read();
}
void draw() {
loadPixels();
video.loadPixels();
for (int x = 0; x < video.width; x++) {
for (int y = 0; y < video.height; y++) {
int loc = x + y * video.width;
r = red (video.pixels[loc]);
g = green(video.pixels[loc]);
b = blue (video.pixels[loc]);
color c = color(r, g, b);
}
}
updatePixels();
noStroke();
fill(r,g,b);
ellipse(random(width), random(height), 10, 22);
}
if I use the get function it works tho
for example
import processing.video.*; //import the video library
Capture cam; //Capture Class, ctreat an object of type Capture and call it cam
void setup() {
background(0); //black background
frameRate(120);
size(displayWidth,displayHeight);
cam = new Capture(this); //initialize the cam object
cam.start(); //start reading from the webcam
}
void draw() {
//we aren't using the image function because we're not actually displaying the video from webcam
//image(cam,0,0);
//every frame draw 200 circles that pull their color from the camera
for(int i = 0; i < 500; i++) {
//pick a random location for each circle
float xPos = random(0,width);
float yPos = random(0,height);
color c = (cam.get(int(xPos),int(yPos)));
fill(c,50);
noStroke();
ellipse(xPos, yPos, 20, 20);
}
}
//callback function, whenever there is a new frame of video available this function is called
void captureEvent(Capture camera) {
camera.read();
}