我通过处理进行虚拟节目播音员。它适用于斑点检测,它可以训练相机从中读取颜色并与之交互。所以我在界面上有一个记录图像作为png所以我希望它将图像旋转为真正的DJ。但是,当我使用旋转时,它会改变图像的位置并且不会旋转,所以我该如何解决这个问题呢? 我提供的代码只是具有Image的部分,它不是应用程序的整个代码。
void setup() {
size(1280, 720);
String[] cameras = Capture.list();
printArray(cameras);
video = new Capture(this, 1280, 720);
video.start();
prev = createImage(video.width, video.height, RGB);
trackColor = color(255, 0, 0);
rec = loadImage("rec.png");
slide = loadImage("slide.png");
slider = loadImage("slider.png");
frameRate(150);
}
void draw() {
video.loadPixels();
image(video, 0, 0);
//this makes the camera flips
image(video,0, 0, width, height);
translate(width, 0);
scale(-1.0, 1.0);
image(video,0, 0, width, height);
//the image That need to be spinning
rotate(millis() * 0.0005);
tint(255, 180);
image(rec,100,200,465,465);
noTint();
}
答案 0 :(得分:0)
您需要使用pushMatrix() / popMatrix()将图像旋转到单独的坐标系中:
//isolate coordinate
pushMatrix();
//the image That need to be spinning
rotate(millis() * 0.0005);
tint(255, 180);
image(rec,100,200,465,465);
noTint();
//exit local coordinate system, return to Processing's global coordinates
popMatrix();
查看2D Transformations Processing tutorial了解详情。
此外,您可能希望从中心旋转图像,在这种情况下,您可以:
示例代码:
//isolate local coordinate system
pushMatrix();
//move local coordinate system to the centre of the image
translate(rec.width * 0.5,rec.width * 0.5);
//rotate
rotate(millis() * 0.0005);
//move local coordinate system back to the top left corner of the image
translate(-rec.width * 0.5,-rec.width * 0.5);
//render image
tint(255, 180);
image(rec,100,200,465,465);
noTint();
//exit local coordinate system, return to Processing's global coordinates
popMatrix();