We are about to switch to a new forum software. Until then we have removed the registration on this forum.
import processing.video.*;
Capture video;
void setup() {
size(640, 480);
// Uses the default video input, see the reference if this causes an error
video = new Capture(this, width, height);
video.start();
noStroke();
smooth();
}
void draw() {
if (video.available()) {
video.read();
image(video, 0, 0, width, height); // Draw the webcam video onto the screen
int brightestX = 0; // X-coordinate of the brightest video pixel
int brightestY = 0; // Y-coordinate of the brightest video pixel
float brightestValue = 0; // Brightness of the brightest video pixel
// Search for the brightest pixel: For each row of pixels in the video image and
// for each pixel in the yth row, compute each pixel's index in the video
video.loadPixels();
int index = 0;
for (int y =0 ; y < video.height; y++) {
for (int x = 0; x < video.width; x++) {
// Get the color stored in the pixel
int pixelValue = video.pixels[index];
// Determine the brightness of the pixel
float pixelBrightness = brightness(pixelValue);
// If that value is brighter than any previous, then store the
// brightness of that pixel, as well as its (x,y) location
if (pixelBrightness > brightestValue) {
brightestValue = pixelBrightness;
brightestY = y;
brightestX = x;
pixelBrightness = color(256);
}
index++;
}
}
// Draw a large, yellow circle at the brightest pixel
fill(255, 204, 0, 128);
ellipse(brightestX, brightestY, 50, 50);
text("brightestX: " + brightestX, 20,20);
text("brightestY: " + brightestY, 20,40);
text("brightnesslevel: " + brightestValue, 20, 60);
}
}
Answers
Edit post, highlight code, press Ctrl-o.
If we can't read it, we can't fix it.
i want to scan from 100 to 380 of my video.height
Which part of
Did you not understand?
Lord_of_the_Galaxy i dont understand
Can you see that gear icon at the top right corner of your post? Press it to edit your post.
Then select your code as you would select any text on a computer. Press CTRL + O to indent your code. Then leave a line above and below the code and press save.
well, line 25 currently does ALL of the video height
can you see how you would restrict it to just lines 100 to 380?
More clearly, it scans from 0 to video.height. You need from 100 to 380. See some sort of relation?
You're declaring
y = 0
and limiting it withy < video.height
. You need it to start at 100 and limit at 380. So you must replace two things here.what i mean is have screen size 640X480 but only scan the middle screen to increase FPS speed.
And what did we tell you to do? Did you try it?
i have tried for (int y =100 ; y < video.height; y++) although my screen size 640X480 and the apps only scan 100 to 640. i also tried this but nothing for (int y =100 ; y < video.height > 380; y++).
@doni
You need to use a different index definition after you implement previous post's feedback. See the code below. Notice I have only pasted the relevant code, the for loops..
One a side note, this line is not proper:
y < video.height > 380
. To make things clear, I will write it this other way:(y < video.height) && (video.height > 380)
. As you see, the comparison on the right is constant and not really useful.Lastly,
pixelBrightness = color(256);
might not do what you want. Please check colorMode() in the reference. As default, a color definition will range from 0 to 255, inclusive. In you case, if you use 256, then you are probably looping around the full range. If you intend 256 to be white, you are going to get black. In other words, 255=white but 256=255+1 will be interpret as color(1) which is black.Kf
Huh? Scan from 100 to 640? Are you using x for y and vice versa???
thanks all you guys, especially @kfrajer. i got inspired by your idea and i tried some modification and ended at this code
for (int y = 100; (y < video.height && y < 380) ; y++)
No, no, no. Just use
for (int y = 100; y < 380 ; y++)
i thought that too, but if the video is less than 380 high (is it?) you'll get errors.
The video is 640x480 as mentioned by the OP.
Where exactly does he say that?
In that case, I'd like to know what you thought he means by
(The OP's posts are indeed very confusing)
That's talking about screen size, obviously.
Don't assume the video is the same size.
@koogs int that case would you explain why he tells "scan"? Surely, he's scanning the video and not the screen?
(In fact, after displaying the video, resized, onto the screen, there's no need to even load the pixels of the video, he should be loading the pixels of the screen)