Opening saved frames from camera to appear next to live camera on same screen

edited January 2016 in Questions about Code

Hi, i've been working on a script which uses OpenCV for processing and face recognition. I've tried to set it up so that when it recognises a face (and draws a rectangle) it also saves the frame to the data folder. I have the code set up to have the camera on the left of the screen, but is there a way I can load this image so that it appears on the right of the camera image each time a frame is saved?

I've tried below (lines 46 to 48) but each time I get this error "The file "data/Capture-####.png" is missing or inaccessible, make sure the URL is valid or that the file has been added to your sketch and is readable." The code runs until it recognises a face and then freezes and i'm not sure how I can edit the code so it works.

import gab.opencv.*;
import processing.video.*;
import java.awt.*;

Capture video;
OpenCV opencv;

PImage savedframe;

void setup() {
  size(1280, 480);
  background(0);
  video = new Capture(this, width/4, height/2);
  opencv = new OpenCV(this, width/4, height/2);
  opencv.loadCascade(OpenCV.CASCADE_FRONTALFACE);  

  video.start();

}


//ANIMATION
void draw() 
{

    scale(2);
    opencv.loadImage(video);
    video.loadPixels();
    image(video,0,0,width/4,height/2);


      noFill();
      stroke(255, 0, 0);
      strokeWeight(3);
      line(width/4,0,width/4,height);
      Rectangle[] faces = opencv.detect();
      println(faces.length);

      for (int i = 0; i < faces.length; i++) 
      {
        println(faces[i].x + "," + faces[i].y);
        rect(faces[i].x, faces[i].y, faces[i].width, faces[i].height);

          if (faces.length > 0)
         {
          saveFrame("data/Capture-####.png");                           //Saves frame to data file
          savedframe=loadImage("data/Capture-####.png");       //load saved frame from data file
          image(savedframe,width/4,0,width/2,height/2);            //display saved frame next to camera
         }

      }          
}

void captureEvent(Capture c) 
{
 c.read();
}

Thanks.

Answers

  • When i remember correctly, loadImage() expects the image to be inside of your data-folder when you provide a relative path. So if you remove the "data/" from you path it should work.

    savedframe=loadImage("Capture-####.png");

    But in your case i would just store the image directly, it doesn't make sense to save the image and the load it again, you could directly grab the video-image and store it in your variable:

    savedframe=video.get();

Sign In or Register to comment.