带处理的像素化视频
Pixelated Video with Processing
我正在尝试加载视频,然后以像素化方式显示它。它在加载很长时间后工作了一次,但随后停止工作 - 只是黑屏,没有任何反应,也没有错误消息,我想知道出了什么问题。谢谢
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();
}
您可能从错误的地方采样:
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();
}
我正在尝试加载视频,然后以像素化方式显示它。它在加载很长时间后工作了一次,但随后停止工作 - 只是黑屏,没有任何反应,也没有错误消息,我想知道出了什么问题。谢谢
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();
}
您可能从错误的地方采样:
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();
}