use opencv output data/frames for further analysis

edited February 2017 in Kinect

Dear team,

I have an issue regarding the following: I use opencv to perform a first analysis of a video. I also use Daniel S. code on computer vision to analyse pixels.

I would like to take further actions on the processed videodata/frames (generated in draw() by opencv, though it keeps using the original video as input. What is the correct way to use the opencv generated data in draw (the drawed contours + created background) as input for further analysis?

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

Movie video;
OpenCV opencv;


////////////////////new code
int blobCounter = 0;
int framecount= 0;
int maxLife = 50;

color trackColor; 
float threshold = 100;
float distThreshold = 50;   //   the treshold for making a new blob if treshold (distance of pixels) is too big



////////////////////end new code


void setup() {
  size(480, 360);
  video = new Movie(this, "drukke_straat.mp4");    // drukke straat
  

  
  opencv = new OpenCV(this, width, height);
  opencv.startBackgroundSubtraction(20, 3, 0.5);
  
  video.loop();
  video.play();
 
}


void draw() {
  
  if(video.width > 0 && video.height > 0){//check if the cam instance has loaded pixels else do nothing 
  
  //frameRate(25);
  //image(video, 0, 0);  
  background(0);
  
  
  opencv.loadImage(video);
  opencv.updateBackground();
  opencv.dilate();
  opencv.erode();
 
  
  for (Contour contour : opencv.findContours()) {
     fill(255,0,0);
     strokeWeight(1);
     stroke(255, 0, 0);
     contour.draw();
      }
  }
  
  // saveFrame("output2/frames"+framecount+".png");
    framecount ++ ;

}



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

bellow code is the code that uses video as input. I am not sure how to correctly feed the bellow code with the opencv generated data. Currently I have two scripts sepperatly , furst i run opencv scipt and save all the frames, then i make an mp4 file with moviemaker. after it i use it on the second scipt. Some advice would be appreciated.

   void draw() {
  
  if(video.width > 0 && video.height > 0){//check if the cam instance has loaded pixels else do nothing 
  
  frameRate(8);
  image(video, 0, 0);  
 //background(0);
  

ArrayList<Blob> currentBlobs = new ArrayList<Blob>();    // new array is created previous current array is cleared

  // Begin loop to walk through every pixel
  for (int x = 0; x < video.width; x++ ) {
    for (int y = 0; y < video.height; y++ ) {
      int loc = x + y * video.width;
      // What is current color
      color currentColor = video.pixels[loc];
      float r1 = red(currentColor);
      float g1 = green(currentColor);
      float b1 = blue(currentColor);
      float r2 = red(trackColor);
      float g2 = green(trackColor);
      float b2 = blue(trackColor);

      float d = distSq(r1, g1, b1, r2, g2, b2); 

      if (d < threshold*threshold) {       // treshold* treshhold as d is operated in the same way (squared)
Tagged:

Answers

Sign In or Register to comment.