使用openCV的交互式运动捕捉应用程序

时间:2018-11-28 09:18:08

标签: javascript java opencv video processing

我目前正在为uni项目开发程序,该程序将用于帮助舞者表演。我希望我的程序看起来像这样。 https://vimeo.com/3576457

该应用程序是在Processing 3.0中开发的,下面显示了我的原型应用程序的代码。整个代码显示在下面的链接中。这只是一个片段。

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

Capture video, video2;
OpenCV opencv, opencv2;

FlowField flowfield;
ArrayList<Particle> particles;

boolean debug = false;
PVector perlinFlow;
PVector flow = new PVector();
float x, y;
float myX, myY;
int flowScale;
ArrayList<Brushs> brushes, brushes2; 

public void settings() {
  size(640, 480, P2D);
  //smooth(4);
}

void setup() {
  background(255);


  video = new Capture(this, 640/2, 480/2);
  video2 = new Capture(this, 640/2, 480/2);
  opencv = new OpenCV(this, 640/2, 480/2);
  opencv2 = new OpenCV(this, 640, 480);

  flowfield = new FlowField(10);
  flowfield.update();

  particles = new ArrayList<Particle>();
  for (int i = 0; i < 1; i++) {
    //PVector start = n=w PVector(100, 100);
    perlinFlow = new PVector(flow.x, flow.y);
    particles.add(new Particle(perlinFlow, random(5, 15)));
  }

  brushes = new ArrayList<Brushs>();
  for (int i = 0; i < 15; i++) {
    brushes.add(new Brushs());
  }

  video.start();
  frameRate(60);
}

void draw() {
  //background(255);
  scale(2);
  opencv.loadImage(video);
  //opencv.threshold(150);

  opencv.flip(1);
  opencv.calculateOpticalFlow();
  //image(video, 0, 0 );


  stroke(0, 10);
  strokeWeight(1);
  //opencv.drawOpticalFlow();
  flow = opencv.getAverageFlow();
  flowScale = 150;

  //for(int i = 0; i < width; i++) {
  //   for(int j = 0; j < height; j++) {
  //     //println("i: " + i + " j: " + j);
  //      x = abs(flow.x);
  //      y = abs(flow.y);
  ////fill(0, 0, 255);

  //   }
  //}

  fill(255, 0, 0);
  //ellipse(video.width/2 + flow.x * flowScale, video.height/2 + flow.y * flowScale, 5, 5);

  myX = video.width/2 + flow.x * flowScale;
  myY = video.height/2 + flow.y * flowScale;
  // println("x: " + myX + " y: " + myY);


  //println(perlinFlow);

  flowfield.update();

  if (debug) flowfield.display();

  for (Particle p : particles) {
    p.follow(flowfield);
    p.run();
  }

  clr = color(random(200, 255), random(150, 200), random(150, 200), 255);
  if (myX < 100 && myY < 100) {
    clr = color(0, random(150, 200), random(150, 200), 50);
    for (Brushs brush : brushes) {
      brush.paint();
    }
  }


  if (myX > video.width/2 &&  myX < video.width && myY < 100) {
    clr = color(255, random(150, 200), random(150, 200), 50);
    for (Brushs brush : brushes) {
      brush.paint();
    }
  }

  //stroke(255);
  //strokeWeight(2);
  //line(video.width/2, video.height/2, video.width/2 + flow.x * 150, video.height/2 + flow.y * 150);
}



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

您很快就会注意到,我正在处理一些光流,流场和opencv,但对于从此处下一步该如何工作,我并不清楚。该程序无法正常运行。我希望用户能够轻松地使用动作在窗口上“绘画”。我该如何实现?那里的应用程序不多,关于该主题的文档也很少,可以帮助我继续。因此,我希望这个社区中有人可以在我的发展过程中为我提供帮助。任何建议或改进对我来说都是至关重要的。

完整代码可在此处找到。 https://github.com/Skinkelyn/MED3_GROUP3/blob/master/test%202.zip

0 个答案:

没有答案