Hi, I'm working on some code to find the brightest spot on a webcam so that I can trace a double pendulum and plot its position vs time and then angle vs angle.
I've gotten the program to locate the brightest pixel through code found somewhere on the forums (but that is unreliable because it keeps moving around), I don't understand how to extend it so that it tells me the brightest chunk. Rather than finding the brightest pixel, it should find the brightest 5x5 for instance.
Here's what I have:
import processing.video.*;
Capture video;
lightPoint point1;
lightPoint point2;
int DATA_SIZE = 120;
float theta1;
float theta2;
float[] angle1 = new float[DATA_SIZE];
float[] angle2 = new float[DATA_SIZE];
void setup() {
size(1280, 480);
video = new Capture(this, 640, 480, 30);
smooth();
frameRate(28);
//noiseDetail(2);
//noiseSeed(System.currentTimeMillis());
//Create a light point to visualise from the class lightPoint
point1 = new lightPoint(0.0, 0.0, 0);
point2 = new lightPoint(0.0, 0.0, 0);
}
void draw() {
if (video.available()) {
video.read();
background(255);
fill(#005599);
image(video, 0, 0, 640, 480); // Draw the webcam video onto the screen
fill(100,0,0);
text(angle1[DATA_SIZE-1]*180/3.14159, 660, 20);
fill(0,100,0);
text(angle2[DATA_SIZE-1]*180/3.14159, 660, 40);
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
int nextbrightestX = 0 ; // all values to help track the 2nd brightest points in the area.
int nextbrightestY = 0 ;
float nextbrightestValue = 0 ;
// 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;
int radius = 180 ;// closest placement of 2 different brightest spots.
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) && (distance(x, brightestX, y, brightestY) > radius))
{
brightestValue = pixelBrightness;
brightestY = y;
brightestX = x;
point1.x = brightestX;
point1.y = brightestY;
}
else if ((pixelBrightness > nextbrightestValue) && (distance(x, brightestX, y, brightestY) > radius))
I'm trying to write a program that will be able to plot the angle of a pendulum versus time. The program so far detects the bottom of the pendulum by detecting the brightest pixel on screen (the pendulum has an LED attached). I've drawn a stationary ellipse as the starting position of the pendulum.
I have gotten the program to determine theta based on the initial postion. I now have to plot theta versus time and do not know how to do this. I started making an array to record the x,y values but don't know where to go from there. I can print them using the println() command but I want a live plot of theta versus time. My programming knowledge is very basic so please be specific.
import processing.video.*;
Capture video;
lightPoint point1;
void setup() {
size(640, 480);
video = new Capture(this, width, height, 30);
noStroke();
smooth();
//Create a light point to visualise from the class lightPoint
point1 = new lightPoint(0.0, 0.0, 0);
}
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