我试图加载一个视频,然后以像素化的方式显示它。它在加载了很长一段时间后才工作了一次,但随后就停止工作了--只是一个黑色的屏幕,没有任何错误信息,我想知道哪里出了问题。谢谢。
import processing.video.*;
Movie movie;
int videoScale = 8;
int cols, rows;
void setup() {
size(640, 360);
background(0);
movie = new Movie(this, "movie.mp4");
movie.loop();
cols = width / videoScale;
rows = height / videoScale;
}
void draw() {
movie.loadPixels();
for (int i = 0; i < cols; i++) {
for (int j = 0; j < rows; j++) {
int x = i * videoScale;
int y = j * videoScale;
color c = movie.pixels[i + j * movie.width];
fill(c);
noStroke();
rect(x, y, videoScale, videoScale);
}
}
}
// Called every time a new frame is available to read
void movieEvent(Movie movie) {
movie.read();
}发布于 2016-04-19 14:56:08
你可能在错误的地方取样:
color c = movie.pixels[i + j * movie.width];首先,i是您的cols计数器,它是x维,j是行计数器,y维。其次,您可能想要在相同的规模上采样,因此需要乘以videoScale。您已经有了用于此的x,y变量,因此尝试这样的抽样:
color c = movie.pixels[y * movie.width + x];或者,您可以使用PGraphics实例作为框架缓冲区,在较小的比例尺(重采样)中绘制,然后在更大的比例尺上绘制小缓冲区:
import processing.video.*;
Movie movie;
int videoScale = 8;
int cols, rows;
PGraphics resized;
void setup() {
size(640, 360);
background(0);
noSmooth();//remove aliasing
movie = new Movie(this, "transit.mov");
movie.loop();
cols = width / videoScale;
rows = height / videoScale;
//setup a smaller sized buffer to draw into
resized = createGraphics(cols, rows);
resized.beginDraw();
resized.noSmooth();//remove aliasing
resized.endDraw();
}
void draw() {
//draw video resized smaller into a buffer
resized.beginDraw();
resized.image(movie,0,0,cols,rows);
resized.endDraw();
//draw the small buffer resized bigger
image(resized,0,0,movie.width,movie.height);
}
// Called every time a new frame is available to read
void movieEvent(Movie movie) {
movie.read();
}https://stackoverflow.com/questions/36721464
复制相似问题