双倍缩放处理视频的两个部分

时间:2016-02-18 22:25:29

标签: video image-processing processing zooming

我有一段时间试图在Processing中使用translate(),scale(),mask()等来缩放来自相机的两个不同视频部分。我想要" X"显示的视频区域。和" Y"在第一个ascii图像中填充每一面,出现在第二个。有人可以帮忙吗?

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

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

1 个答案:

答案 0 :(得分:0)

我听起来你想要从中心扩展。 默认情况下,坐标系统为'原点是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()中有所评论。使用上/下箭头键更改比例。

xy scaled up

xy scaled down

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

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;
}

Coordinate System Visualisation