I am trying to create a type of xRay flashlight experience using computer vision. My code isn't broken at the moment and its very close to what I am looking for I just can't figure out how to get rid of the dark around the image, at the moment I believe I am just using brightness. I've found some code that dealt with this using PGraphics and JAVA2D I just can't seem to transfer it over to PImages. I apologize if my code is messy. Thanks for your help!
- import processing.video.*;
- Capture video;
- //PImage wall;
- PImage sky;
- void setup() {
- size(1500, 997);
- sky = loadImage("sky1_HDR2.png");
- //wall = loadImage("wall.jpg");
- //brightness tracking
- video = new Capture(this, width, height, 30);
- noStroke();
- smooth();
- }
- void draw() {
- //tint(255, 0);
- //image(sky,0,0);
- //background (255);
- loadPixels();
- //tint(255, 0);
- //image(sky, 0, 0);
- //brightness tracking
- 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 the 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;
- }
- index++;
- }
- }
- // Draw a large, yellow circle at the brightest pixel
- //creating image around brightest pixles
- for (int x = 0; x < sky.width; x++) {
- for (int y = 0; y < sky.height; y++) {
- // calculate 1D pixel location
- int loc = x + y*sky.width;
- // get R,G,B values
- float r = red (sky.pixels[loc]);
- float g = green (sky.pixels[loc]);
- float b = blue (sky.pixels[loc]);
- float a = alpha (sky.pixels[loc]);
- //calculate
- float distance = dist(x,y,brightestX, brightestY);
- float adjustAlpha = (200 - distance)/200;
- r *= adjustAlpha;
- g *= adjustAlpha;
- b *= adjustAlpha;
- a *= adjustAlpha;
- float a_value = 100;
- r = constrain(r, 0, 255);
- g = constrain(g, 0, 255);
- b = constrain(b, 0, 255);
- a = constrain(a, 0, 255);
- color c = color(r,g,b,255);
- pixels[loc] = c;
- }
- }
- updatePixels();
- stroke(255, 204, 0);
- strokeWeight(5);
- noFill();
- ellipse(brightestX, brightestY, 400, 400);
- }
- }
1