Interactive Video - Record portion of video and load it in the same program
in
Core Library Questions
•
2 years ago
hey guys, i wonder if anyone can help me. I'm trying to help my girlfriend with a project but i'm not a programmer (never studied much nor had classes on the subject). Basically she was trying to record a portion of video from someone standing in front of a webcam (while mousepressed, and masked with a circle, and afterwards, load it to the right side of the screen where the balls are...is it possible to do in processing? There's an image of what i accomplished so far:
- import processing.video.*;
- Capture cam;
- MovieMaker writer;
- char w = 'w';
- int v = 0;
- int counter = 0;
- int circleSize = 100;
- int shrinkOrGrow = 1;
- int mode = 0;
- int numBalls = 7;
- float spring = 0.05;
- float gravity = 0.8;
- float friction = -0.02;
- Ball[] balls = new Ball[numBalls];
- void setup()
- {
- size(1300, 500);
- frameRate(50);
- background(255);
- noStroke();
- cam = new Capture(this, 640, 480);//for cam image position
- writer = new MovieMaker( this, width, height, "data/" + w + v + ".mov", 30,
- MovieMaker.H263, MovieMaker.WORST );
- for (int i = 0; i < numBalls; i++) {
- balls[i] = new Ball(random(width), random(height), random(100, 20), i, balls);
- }
- }
- void captureEvent( Capture cam ) {
- cam.read();
- }
- void movieEvent( Movie m ) {
- m.read();
- }
- void draw() {
- image( cam, 5,10 );
- println( counter );
- counter++;
- writer.addFrame();
- if (mode == 1)
- {
- making();
- }
- else if (mode == 2)
- {
- collecting();
- }
- //background(255);
- if (cam.available() == true) {
- cam.read();
- image(cam, 5, 10);
- } //for cam image position
- if (mousePressed == true)
- {
- mode = 1;
- }
- fill(130,155,240,200);
- rect(650,0,650,500);
- for (int i = 0; i < numBalls; i++) {
- balls[i].collide();
- balls[i].move();
- balls[i].display();
- }
- if (mode == 1)
- {
- making();
- }
- else if (mode == 2)
- {
- collecting();
- }
- if (mousePressed == true)
- {
- mode = 1;
- }
- }
- void mouseReleased()
- {
- mode =2;
- }
- void making()
- { ellipseMode(CENTER);
- noStroke();
- fill(130,155,240,200);
- smooth();
- if (circleSize > 290) {
- shrinkOrGrow = 0;
- println("circlesize: " + circleSize);
- println("shrinkorgrow " + shrinkOrGrow);
- } else if (circleSize < 50) {
- shrinkOrGrow = 1;
- println("circlesize: " + circleSize);
- println("shrinkorgrow " + shrinkOrGrow);
- }
- if (shrinkOrGrow == 1) {
- circleSize += 1;
- } else if (shrinkOrGrow == 0) {
- circleSize -= 1;
- }
- ellipse(width/6, height/2, circleSize, circleSize);
- }
- void collecting()
- {
- //stop making circle and move it to the bottom
- }
- class Ball {
- float x, y;
- float diameter;
- float vx = 0;
- float vy = 0;
- int id;
- Ball[] others;
- Ball(float xin, float yin, float din, int idin, Ball[] oin) {
- x = xin;
- y = yin;
- diameter = din;
- id = idin;
- others = oin;
- }
- void collide() {
- for (int i = id + 1; i < numBalls; i++) {
- float dx = others[i].x - x;
- float dy = others[i].y - y;
- float distance = sqrt(dx*dx + dy*dy);
- float minDist = others[i].diameter/2 + diameter/2;
- if (distance < minDist) {
- float angle = atan2(dy, dx);
- float targetX = x + cos(angle) * minDist;
- float targetY = y + sin(angle) * minDist;
- float ax = (targetX - others[i].x) * spring;
- float ay = (targetY - others[i].y) * spring;
- vx -= ax;
- vy -= ay;
- others[i].vx += ax;
- others[i].vy += ay;
- }
- }
- }
- void move() {
- vy += gravity;
- x += vx;
- y += vy;
- if (x + diameter/2 > width) {
- x = width - diameter/2;
- vx *= friction;
- }
- else if (x - diameter/2 < 0) {
- x = diameter/2;
- vx *= friction;
- }
- if (y + diameter/2 > height) {
- y = height - diameter/2;
- vy *= friction;
- }
- else if (y - diameter/2 < 0) {
- y = diameter/2;
- vy *= friction;
- }
- }
- void display() {
- fill(255,200);
- //stroke(0);
- float mx = constrain(x, 850, 1220);
- float my = constrain(y, 20, 420);
- ellipse(mx, my, diameter, diameter);
- }
Thank you for any help you can give me!!!
1