【问题标题】:Double zooming two sections of a Processing video双倍缩放处理视频的两个部分
【发布时间】:2016-02-18 22:25:28
【问题描述】:

我有一段时间尝试在处理中使用 translate()、scale()、mask() 等来缩放来自摄像机的两个不同部分的视频。我希望第一个 ascii 图像中“X”和“Y”显示的视频区域填充每一侧,如第二个所示。有人可以帮忙吗?

++++++++++++++++++++++++++++++++
+                              +
+                              +
+                              +
+ *   *                 *   *  +
+  * *                   * *   +
+   *                     *    +
+  * *                    *    +
+ *   *                   *    +
+                              +
+                              +
+                              +
++++++++++++++++++++++++++++++++

++++++++++++++++++++++++++++++++
+*          *      *          *+
+ *        *        *        * +
+  *      *          *      *  +
+   *    *            *    *   +
+    *  *              *  *    +
+     **                **     +
+    *  *               *      +
+   *    *              *      +
+  *      *             *      +
+ *        *            *      +
+*          *           *      +
++++++++++++++++++++++++++++++++

【问题讨论】:

    标签: video image-processing processing zooming


    【解决方案1】:

    我听起来你想从中心缩放。 默认情况下,坐标系的原点位于左上角 0,0。

    如果您想从图像的中心缩放,您首先需要在那里平移然后缩放。从中心缩放后,您需要平移回左上角进行渲染。

    这是一个基本示例:

    PGraphics frame;
    
    float scale = 1.0;
    
    void setup(){
      size(640,480);
      //fake a camera/video frame to test with
      frame = createGraphics(width,height);
      frame.beginDraw();
      frame.textSize(700);
      frame.text("X",0,480);
      frame.text("Y",250,480);
      frame.endDraw();
    }
    void draw(){
      background(0);
    
      //move "transformation point" from top left corner to centre
      //by translating by half the frame size
      translate(frame.width/2,frame.height/2);
      //scale from centre
      scale(scale);
      //move coordinate system back to top left and draw the im
      image(frame,-frame.width/2,-frame.height/2);
    
    }
    void keyPressed(){
      if(keyCode == UP) scale += 0.1;
      if(keyCode == DOWN) scale -= 0.1;
    }
    

    frame 变量是一个占位符,它将成为您的相机/电影帧,所以不要太担心setup() 中的内容。重要部分在draw() 中注释。使用向上/向下箭头键更改比例。

    请注意,这将影响在此图像之后绘制的其他对象。如果您想仅针对图像将缩放与中心隔离,您可以将转换放在pushMatrix(),popMatrix() 调用中。这些将隔离一个独立于处理的全局坐标系的坐标系:

    PGraphics frame;
    
    float scale = 1.0;
    
    void setup(){
      size(640,480);
      //fake a camera/video frame to test with
      frame = createGraphics(width,height);
      frame.beginDraw();
      frame.textSize(700);
      frame.text("X",0,480);
      frame.text("Y",250,480);
      frame.endDraw();
    }
    void draw(){
      background(0);
      //isolate coordinate system
      pushMatrix();
        //move "transformation point" from top left corner to centre
        //by translating by half the frame size
        translate(frame.width/2,frame.height/2);
        //scale from centre
        scale(scale);
        //move coordinate system back to top left and draw the im
        image(frame,-frame.width/2,-frame.height/2);
      popMatrix();
    }
    void keyPressed(){
      if(keyCode == UP) scale += 0.1;
      if(keyCode == DOWN) scale -= 0.1;
    }
    

    欲了解更多详情,请务必查看2D Transformations tutorial

    为了更好地了解这是如何工作的,这里有一个版本来说明每个坐标变换:

    PGraphics frame;
    
    float scale = 1.0;
    
    void setup(){
      size(640,480);
      strokeWeight(3);
      //fake a camera/video frame to test with
      frame = createGraphics(width,height);
      frame.beginDraw();
      frame.textSize(700);
      frame.text("X",0,480);
      frame.text("Y",250,480);
      frame.endDraw();
    }
    void draw(){
      background(0);
    
      drawCoordinateSystem("Processing/global CS",100);
    
      //isolate coordinate system
      pushMatrix();
        //move "transformation point" from top left corner to centre
        //by translating by half the frame size
        translate(frame.width * .5,frame.height * .5);
        drawCoordinateSystem("translated to image centre",100);
        //scale from centre
        scale(scale);
        drawCoordinateSystem("scaled from image centre",100);
        //move coordinate system back to top left and draw the im
        pushMatrix();
        translate(-frame.width * .5,-frame.height * .5);
        drawCoordinateSystem("scaled back to image top/left",100);
        image(frame,0,0);
        popMatrix();
      popMatrix();
    }
    void drawCoordinateSystem(String label,float size){
      text(label,15,15);
      stroke(192,0,0);
      line(0,0,size,0);
      stroke(0,192,0);
      line(0,0,0,size);
    }
    void keyPressed(){
      if(keyCode == UP) scale += 0.1;
      if(keyCode == DOWN) scale -= 0.1;
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-02-26
      • 1970-01-01
      • 2020-07-24
      • 2014-11-05
      相关资源
      最近更新 更多