Niamh
YaBB Newbies
Offline
Posts: 4
Re: Brightness Threshold and video display
Reply #2 - Apr 14th , 2010, 4:35am
I am doing a similar project and am having a similar problem. I am making a sketch that will allow the user to 'draw' via moving their body in view of a webcam. I am overlaying the brightness threshold capture over a live video feed so the user can see themselves. The brightness threshold feed leaves a trail after movement so the user is 'drawing'. So far so good. However, the live feed is also leaving a trail which I do not want to happen. Originally I did which is why the code is there but now when I take out the showImage.blend(...)..., the live feed stops showing up on the screen. I have tried changing the filter and interchanging the various video feeds but nothing doing. Either the live feed disappears completely or it leaves a trail. Here's the code - //----- brightness threshold adapted from Processing Learning Tutorials //----- http://processing.org/learning/libraries/brightnessthresholding.html //----- by Golan Levin import processing.video.*; color black = color(0,1); color white = color(255); int numPixels; Capture video; PImage liveFeed; //live feed from webcam PImage showImage; //needed to display feed to user //PImage = Datatype for storing images. Processing can display .gif, .jpg, .tga, and .png images. //using this means we can export out images of what's on screen so the trail will be visible unlike in movie classes void setup() { size(800,600); strokeWeight(5); video = new Capture(this, width, height, 30); //width, height, frameRate liveFeed = createImage(width, height, RGB); //width/height = defined in SIZE showImage = createImage(width, height, RGB); //need RGB to define as a PImage and not image numPixels = video.width * video.height; noCursor(); smooth(); } void draw() { frameRate(30); if (video.available()) { video.read(); video.loadPixels(); //-----flip video feed AND IT WORKS!!! int increment = 0; for (int y = 0; y < video.height; y++) { for (int x = video.width - 1; x >= 0 ; x--) { liveFeed.pixels[increment] = video.pixels[y*width + x]; increment++; } } //-----threshold int threshold = 200; // Set the threshold value float pixelBrightness; // Declare variable to store a pixel's color // Turn each pixel in the video frame black or white depending on its brightness loadPixels(); for (int i = 0; i < numPixels; i++) { pixelBrightness = brightness(liveFeed.pixels[i]); if (pixelBrightness > threshold) { // If the pixel is brighter than the pixels[i] = white; // threshold value, make it white } else { // Otherwise, pixels[i] = black; // make it black } } updatePixels(); //displays image on screen tint(255,20);//alpha of showImage image(showImage, 0, 0); //image, x co-ord, y co-ord //showImage.filter(GRAY); //other filters still don't make it appear!!! showImage.blend(liveFeed, 0, 0, width, height, 0, 0, width, height, LIGHTEST); //swapping liveFeed, showImage & video doesn't work!!! //(src image,x,y,width,height,x co-ord destinations upper left corner,y co=ord destinations upper left corner, MODE) //Copies a pixel or rectangle of pixels using different blending modes }//end o video available }//end o draw Any help would be greatly appreciated!