video warping with gsvideo

edited October 2016 in Library Questions

Hi, all!

I'm trying to warp a video signal, in order of making a section of it (inside 4 selected points/vectors) expand automatically to fit exactly the width and height of the processing screen image. The portion of the video inside the four vectors area should distort in correspondence of the deformation of that given area. In addition, I need to use gsvideo, dued to the reason that I am working with processing 1.5.1 in mac and I'm not able to install quicktime. Why processing 1.5.1? Because I'm running artoolkit library for augmented reality and only works for me in this old version of processing. Any idea or suggestion would be very welcome!

Tagged:

Answers

  • Responding to my own question: here is an approach, but I'm getting an odd output, video deformation doesn't behave as I expected. Thanks for checking.

        import processing.video.*;
        import codeanticode.gsvideo.*;
    
        GSCapture video;
        int w =1024;
        int h=768;
        boolean warp=false;
        int def = -1000;
    
        PVector [] bounds = {
          new PVector(def, def),
          new PVector(def, def),
          new PVector(def, def),
          new PVector(def, def)
        };
    
        void setup(){
    
          size(w,h,P3D);
         // size(1024,768,P3D);
          video = new GSCapture(this, w, h,30);
          video.start();
        }
    
        void draw(){ 
    
    
          if (video.available()){
              background(0);
    
            video.read();
            video.loadPixels();
    
            beginShape();
            texture(video);
    
            if(warp){
              vertex(bounds[0].x,bounds[0].y,0,0);
              vertex(bounds[1].x,bounds[1].x,w,0);
              vertex(bounds[2].x,bounds[2].x,w,h);
              vertex(bounds[3].x,bounds[3].x,0,h);
    
    
            }else{
               // Top-Left
              // vertex(mouseX,mouseY,0,0);
               vertex(0,0,0,0);
               // Top-Right
               vertex(w,0,w,0);
               // Bottom-Right
               vertex(w,h,w,h);
               // Bottom-Left
               vertex(0,h,0,h);
            }
          }
                 endShape();
    
            boundaries();
    
        }
    
        void boundaries(){
          int gr=20;
              if(keyPressed && key =='1' && mousePressed){
                bounds[0] = new PVector(mouseX,mouseY);
              }      
              if(keyPressed && key =='2' && mousePressed){
                bounds[1] = new PVector(mouseX,mouseY);
              }     
              if(keyPressed && key =='3' && mousePressed){
                bounds[2] = new PVector(mouseX,mouseY);
              }      
              if(keyPressed && key =='4' && mousePressed){
                bounds[3] = new PVector(mouseX,mouseY);
              }
    
    
    
          pushMatrix();
          stroke(255,0,0);
    
          line(bounds[0].x ,bounds[0].y,bounds[1].x ,bounds[1].y);
          line(bounds[1].x ,bounds[1].y,bounds[2].x ,bounds[2].y);
          line(bounds[2].x ,bounds[2].y,bounds[3].x ,bounds[3].y);
          line(bounds[3].x ,bounds[3].y,bounds[0].x ,bounds[0].y);
          popMatrix();
    
          for(int i =0;i<bounds.length;i++){
            ellipse(bounds[i].x,bounds[i].y,gr,gr);
            println("bounds["+i+"].x: "+bounds[i].x +"bounds[i].y: "+ bounds[i].y); 
          }
        }
    
        void keyReleased(){
          if(key=='w'){
            if (!warp)warp=true;
            else warp = false;
          }
        }
    
  • press '1','2','3' or '4' for settings vectors of selected area, clockwise

  • and 'w' for warping

  • It works perfectly now, I expect to help someone with that

        import processing.video.*;
        import codeanticode.gsvideo.*;
    
        GSCapture video;
        int w =1024;
        int h=768;
        boolean warp=false;
        int def = -1000;
    
        PVector [] bounds = {
          new PVector(def, def),
          new PVector(def, def),
          new PVector(def, def),
          new PVector(def, def)
        };
    
        void setup(){
    
          size(w,h,P3D);
         // size(1024,768,P3D);
          video = new GSCapture(this, w, h,30);
          video.start();
        }
    
        void draw(){ 
    
    
          if (video.available()){
              background(0);
    
            video.read();
            video.loadPixels();
    
            beginShape();
            texture(video);
    
            if(warp){
              vertex(bounds[0].x,bounds[0].y,0,0);
              vertex(bounds[1].x,bounds[1].y,w,0);
              vertex(bounds[2].x,bounds[2].y,w,h);
              vertex(bounds[3].x,bounds[3].y,0,h);
            }else{
               vertex(0,0,0,0);
               vertex(w,0,w,0);
               vertex(w,h,w,h);
               vertex(0,h,0,h);
            }
          }
            endShape();
    
            boundaries();
    
        }
    
        void boundaries(){
          int gr=20;
              if(keyPressed && key =='1' && mousePressed){
                bounds[0] = new PVector(mouseX,mouseY);
              }      
              if(keyPressed && key =='2' && mousePressed){
                bounds[1] = new PVector(mouseX,mouseY);
              }     
              if(keyPressed && key =='3' && mousePressed){
                bounds[2] = new PVector(mouseX,mouseY);
              }      
              if(keyPressed && key =='4' && mousePressed){
                bounds[3] = new PVector(mouseX,mouseY);
              }
    
    
    
          pushMatrix();
          stroke(255,0,0);
    
          line(bounds[0].x ,bounds[0].y,bounds[1].x ,bounds[1].y);
          line(bounds[1].x ,bounds[1].y,bounds[2].x ,bounds[2].y);
          line(bounds[2].x ,bounds[2].y,bounds[3].x ,bounds[3].y);
          line(bounds[3].x ,bounds[3].y,bounds[0].x ,bounds[0].y);
          popMatrix();
    
          for(int i =0;i<bounds.length;i++){
            ellipse(bounds[i].x,bounds[i].y,gr,gr);
            println("bounds["+i+"]: "+bounds[i].x +" , " + bounds[i].y); 
          }
        }
    
        void keyReleased(){
          if(key=='w'){
            if (!warp)warp=true;
            else warp = false;
          }
        }
    
  • and inverting the vertex's arguments is how the selected area fits the screen

          if(warp){
            vertex(0,0,bounds[0].x,bounds[0].y);
            vertex(w,0,bounds[1].x,bounds[1].y);
            vertex(w,h,bounds[2].x,bounds[2].y);
            vertex(0,h,bounds[3].x,bounds[3].y);
          }else{
             vertex(0,0,0,0);
             vertex(w,0,w,0);
             vertex(w,h,w,h);
             vertex(0,h,0,h);
          }
    
  • @rojele -- Thanks for sharing your solution!

    Note that rojele wrote this for Processing 1.5.1! I haven't tested compatibility, but some point it might be interesting to adapt this to Processing 3.x +

  • Hi, changing the lines of code related to "gsCapture" by "Capture" make this code fully compatible with processing 3.x. I'm still looking for version of gsVideo for later versions of processing than 1.5.1

  • edited October 2016 Answer ✓

    Thanks!

    I believe that gsVideo was developed by Andrés Colubri until 2012 -- there probably isn't going to be a Processing 3.x version unless somebody takes the publicly available source code and writes one. As the author said in 2012:

    The latest release is 1.0.0 and it should be used exclusively with Processing 1.x (the alpha releases of Processing 2.0 already include a simplified version of GSVideo as the built-in video library).

    So if there is something specific that you can't do with the built-in Processing 3.x video library but that gsVideo can do you might want to consider just extending that part of the official video library -- or a submitting a feature request.

  • Thanks, jeremy. Sure that an updated version of gsvideo will be totally usefull for getting access to certain libraries that, as nyar2 for augmented reality, relies on gsvideo for running. I'll would give it try but im not as confident on my programming skills. Maybe its the time for trying. thanks for the comment

Sign In or Register to comment.