OpenCV Video in custom class - problems

edited December 2013 in Library Questions

Hi,

in my sketch i created a custom class, of which every created instance should load a video, and then display it on a different area on the screen.

now that i have created two instances, i only see one video which is playing at double framerate, maybe because the call to each of the two objects' display() function calls the read function on the same video.

i am not sure if i did everything correctly in the class constructor with PApplet parent etc. never really managed to understand that. i would like every video to be inside ('encapsulated') in its respective Channel-instance.

best regards, florian.

import hypermedia.video.*;

int newFrame = 0;
int movFrameRate = 25;
int videoX = 480;
int videoY = 270;
float vidScale = 0.7;
Channel c1, c2;

void setup() {
  size(800, 450);
  background(0);
  frameRate(25); 
  c1 = new Channel(this, 1, "/Users/monopuce/Desktop/chan_klein_h264/A-01K.mov", 0, 0);
  c2 = new Channel(this, 1, "/Users/monopuce/Desktop/chan_klein_h264/A-02K.mov", 400, 0);
}

void draw() {
  background(0);
  c1.display();
  c2.display();
}

class Channel {

  OpenCV clip; // Movie clip;
  int vidX, vidY, vidXsize, vidYsize, screen;
  float vidScale;
  String filename;

  Channel(PApplet parent, int clScreen, String clFilename, int vidX, int vidY){
    screen = clScreen;
    filename = clFilename;
    vidX = 0; vidY = 0;
    vidXsize = 480; vidYsize = 270;
    vidScale = 0.7;
    clip = new OpenCV( parent ); // clip = new Movie(parent, filename);
    clip.movie( filename, int(vidXsize*vidScale), int(vidYsize*vidScale) );
  }

  void display(){
    print(frameCount + " ");
    clip.read();
    image( clip.image(), vidX, vidY );
  }
}
Tagged:

Answers

  • Sorry, made a mistake, bad variable handover to the class. i see the same video with double speed at two areas on screen. pretty sure the two instances of my class somehow address the same loaded video.

    here's the updated code:

    import hypermedia.video.*;
    
    int videoX = 480;
    int videoY = 270;
    float vidScale = 0.7;
    Channel c1, c2;
    
    void setup() {
      size(800, 450);
      background(0);
      frameRate(25); 
      c1 = new Channel(this, 1, "/Users/monopuce/Desktop/chan_klein_h264/A-01K.mov", 0, 0);
      c2 = new Channel(this, 1, "/Users/monopuce/Desktop/chan_klein_h264/A-02K.mov", 400, 0);
    }
    
    void draw() {
      background(0);
      c1.display();
      c2.display();
    }
    
    class Channel {
    
      OpenCV clip; // Movie clip;
      int vidX, vidY, vidXsize, vidYsize, screen;
      float vidScale;
      String filename;
    
      Channel(PApplet parent, int clScreen, String clFilename, int clVidX, int clVidY){
        screen = clScreen;
        filename = clFilename;
        vidX = clVidX; vidY = clVidY;
        vidXsize = 480; vidYsize = 270;
        vidScale = 0.7;
        clip = new OpenCV( parent ); // clip = new Movie(parent, filename);
        clip.movie( filename, int(vidXsize*vidScale), int(vidYsize*vidScale) );
      }
    
      void display(){
        print(frameCount + " ");
        clip.read();
        image( clip.image(), vidX, vidY );
      } 
    }
    
Sign In or Register to comment.