HI, I'm using following example for motion detection https://github.com/shiffman/LearningProcessing/blob/master/chp16_video/example_16_13_MotionPixels/example_16_13_MotionPixels.pde
This example was performed with camera(320,240) and its work nice but my canvas size is (1280,720) so the frameRate is getting very low near by 8 to 10fps and if i use camera with (640,480) then the feed is displaying twice seems like it duplicating.
i want to display my live feed in full resolution which is (1280,720) so how can i scale up my camera which is (640,480) to (1280,720) ? (frameRate can be better with that resolution?)
// Learning Processing
// Daniel Shiffman
// http://www.learningprocessing.com
// Example 16-13: Simple motion detection
import processing.video.*;
// Variable for capture device
Capture video;
// Previous Frame
PImage prevFrame;
// How different must a pixel be to be a "motion" pixel
float threshold = 50;
void setup() {
size(1280, 720, P3D);
video = new Capture(this, 640,480, 30);
video.start();
// Create an empty image the same size as the video
prevFrame = createImage(video.width, video.height, RGB);
}
void captureEvent(Capture video) {
// Save previous frame for motion detection!!
prevFrame.copy(video, 0, 0, video.width, video.height, 0, 0, video.width, video.height); // Before we read the new frame, we always save the previous frame for comparison!
prevFrame.updatePixels(); // Read image from the camera
video.read();
}
void draw() {
background(255);
//pushMatrix();
//scale(2.0);
loadPixels();
video.loadPixels();
prevFrame.loadPixels();
// Begin loop to walk through every pixel
for (int x = 0; x < video.width; x ++ ) {
for (int y = 0; y < video.height; y ++ ) {
// for (int x = 440; x < 840; x ++ ) {
// for (int y = 0; y < 400; y ++ ) {
int loc = x + y*video.width; // Step 1, what is the 1D pixel location
color current = video.pixels[loc]; // Step 2, what is the current color
color previous = prevFrame.pixels[loc]; // Step 3, what is the previous color
// Step 4, compare colors (previous vs. current)
float r1 = red(current);
float g1 = green(current);
float b1 = blue(current);
float r2 = red(previous);
float g2 = green(previous);
float b2 = blue(previous);
float diff = dist(r1, g1, b1, r2, g2, b2);
// Step 5, How different are the colors?
// If the color at that pixel has changed, then there is motion at that pixel.
if (diff > threshold) {
// If motion, display black
pixels[loc] = color(0);
} else {
// If not, display white
pixels[loc] = color(255);
}
}
}
updatePixels();
//popMatrix();
stroke(255, 0, 0);
rect(440, 0, 400, 400);
surface.setTitle((int) frameRate + " motion");
}