Self-rulling video reader

Hello everyone !

I have a complex question and i can’t find any answer.
I’m trying to make a code that capture a video with webcam when you click on a specific place and create a video in data when you stop the recording. And i want this video to be “loadable” in the same code.

To be more specific :
what i have :
I created a “folder” and when you click on it, a (closable) window pop with the capture.
what i want :
When you close the window i want it to create a new folder which will lead to a second window with the fresh-taken video (or an array of images, i don’t need sound or good motion quality). I would be pleased if it can be done an infinite time (each time you load the capture again it create a new folder) but i would be satisfied if it work for one time already.

THAT’S MY CODE :

import processing.video.*;
boolean saveRecord = false;
int fenCap =0;
int fenCapX ;
int fenCapY;
int fichCapX;
int fichCapY;
Capture capture;
void setup()
{
 capture = new Capture(this);
 capture.start();
}
void movieEvent(Movie m)
{
  m.read();
}
void draw()
{
//folder
rect(fichCapX, fichCapY, 60, 80);

//window
  if (fenCap==1)
  {
    strokeWeight(5);
    stroke(0);
    fill(255);
    rect(fenCapX, fenCapY, 580, 300);
    rect(fenCapX, fenCapY, 580, 30);
    rect(fenCapX, fenCapY, 30, 30);
    line(fenCapX+6, fenCapY+6, fenCapX+24, fenCapY+24);
    line(fenCapX+6, fenCapY+24, fenCapX+24, fenCapY+6);

    capture.read();
    image(capture, fenCapX+2, fenCapY+32, 576, 266);
  }
}

void mouseClicked()
{
//open capture
if (mouseX>fichCapX && mouseX<fichCapX+60 && mouseY>fichCapY && mouseY<fichCapY+150)
  {
    fenCap=1;
    saveRecord=true;
  }
  //close capture(5)
  if (fenCap==1 && mouseX>fenCapX && mouseX<fenCapX+30 && mouseY>fenCapY && mouseY<fenCapY+30)
  {
    fenCap=0;
    saveRecord=false;
  }

THAT’S WHAT I TRIED WITH IMAGES LIST :
(not working because he expect to find the folder in data)

import processing.video.*;
boolean saveRecord = false;
PImage[] voyeurX ;
int fenCap =0;
int fenPlus =0;

int fenCapX ;
int fenCapY;
int fichCapX;
int fichCapY;

Capture capture;
int Voyeur=0;
int VoyeurCount=0;
float fichPlusX= random(1180);
float fichPlusY= random(600);
float fenPlusX= random(780);
float fenPlusY= random(400);

void setup()
{
 capture = new Capture(this);
  capture.start();

voyeurX=new PImage[200];
  for (int i=0; i<0x200; i++)
  {
    voyeurX[i]=loadImage("voyeur0/voyeur_"+i+".png");
  }
}

void movieEvent(Movie m)
{
  m.read();
}

void draw()
{
//folder
rect(fichCapX, fichCapY, 60, 80);

  if (Voyeur==1)
  {
     rect( fichPlusX, fichPlusY , 60, 80);
  }

//window
  if (fenCap==1)
  {
    strokeWeight(5);
    stroke(0);
    fill(255);
    rect(fenCapX, fenCapY, 580, 300);
    rect(fenCapX, fenCapY, 580, 30);
    rect(fenCapX, fenCapY, 30, 30);
    line(fenCapX+6, fenCapY+6, fenCapX+24, fenCapY+24);
    line(fenCapX+6, fenCapY+24, fenCapX+24, fenCapY+6);

    capture.read();
    image(capture, fenCapX+2, fenCapY+32, 576, 266);
  }

  if (fenPlus==1)
  {
    strokeWeight(5);
    stroke(0);
    fill(255);
    rect(fenPlusX, fenPlusY, 580, 300);
    rect(fenPlusX, fenPlusY, 580, 30);
    rect(fenPlusX, fenPlusY, 30, 30);
    line(fenPlusX+6, fenPlusY+6, fenPlusX+24, fenPlusY+24);
    line(fenPlusX+6, fenPlusY+24, fenPlusX+24, fenPlusY+6);

    image(voyeurX[0000],fen4X+2, fen4Y+32, 576, 266);
 }
   if (saveRecord == true) 
   {
     saveFrame("data/voyeur" +VoyeurCount+"/voyeur_###.png");
     println(VoyeurCount);
   }
}

void mouseClicked()
{
//open capture
if (mouseX>fichCapX && mouseX<fichCapX+60 && mouseY>fichCapY && mouseY<fichCapY+150)
  {
    fenCap=1;
    saveRecord=true;
Voyeur=1;
  }
  //close capture(5)
  if (fenCap==1 && mouseX>fenCapX && mouseX<fenCapX+30 && mouseY>fenCapY && mouseY<fenCapY+30)
  {
    fenCap=0;
    saveRecord=false;
Voyeur=0;
  }

I’m new in this forum, english is not my mother language and even if i use processing a bit i’m not very used to programing, so don’t hesitate to give me tips that you find obvious, they won’t necessarely be for me !

Thanks !

1 Like

Hi! I’ll help with two issues:

  1. If you are declaring functions (like setup, movieEvent, etc) it’s not allowed to have code outside function declarations, but you have a for loop near the beginning of your program. That for-loop should be inside setup, otherwise the program will not run.

  2. Numbers that start with 0 are octal and if they start with 0x they are hexadecimal. So

println(0200, 0x200);

will print

128, 512

I guess you want those two numbers to be equal, right? How many images do you want? 200? 128? 512?

2 Likes

hi thanks ! i missclicked when i paste this line, it was in setup but it still not working !
Actually i put 200 thinking about a high number, i don’t need a special number, just one that will be enought to make a 10 second long animation.
And thanks, i didn’t know about the hexadecimal stuff, i will change it for 200.

I made something inspired by your question. Sorry it’s not an answer, but maybe it’s somehow useful? :slight_smile:

import processing.video.*;

Capture cam;
int x, y;

void setup() {
  size(640, 480);
  background(0);
  String[] cameras = Capture.list();
  cam = new Capture(this, cameras[0]);
  cam.start();
}

void draw() {
  if (cam.available()) {
    cam.read();
  }
  image(cam, x, y, 128, 96);
}

void mousePressed() {
  x = (mouseX / 128) * 128;
  y = (mouseY / 96) * 96;
}
2 Likes

Hi, thanks you for this ! it gives me ideas to change my project a bit :slight_smile: