我正在尝试创建一个处理程序,以从Kinect 4win sdk(X-Box)中获取实时视频并创建马赛克表示。该相机可能用于检测图像的明暗部分并显示较亮和较暗的方块。我还探讨了用较小的图像创建马赛克的想法,并参考了Daniel Shiffman教程(https://www.youtube.com/watch?v=nnlAH1zDBDE),但这并未包含Kinect相机。是否有人对如何使用Kinect获取视频供稿并使用该数据创建马赛克有任何想法?我在下面提供了一些未包含Kinect的示例代码。
// interactive miror
// Each pixel from the video source is drawn as a
// rectangle with size based on brightness.
import processing.video.*;
// Size of each cell in the grid
int videoScale =10;
// Number of columns and rows in our system
int cols, rows;
// Variable for capture device
Capture video;
void setup() {
size(740,580);
// Initialize columns and rows
cols = width/videoScale;
rows = height/videoScale;
smooth();
// Construct the Capture object
video = new Capture(this,cols,rows,15);
}
void draw() {
if (video.available()) {
video.read();
}
background(0);
video.loadPixels();
// Begin loop for columns
for (int i = 0; i < cols; i++) {
// Begin loop for rows
for (int j = 0; j < rows; j++) {
// Begin loop for columns
for (int i = 0; i < cols; i++) {
// Begin loop for rows
for (int j = 0; j < rows; j++) {
// Where are we, pixel-wise?
int x = i*videoScale;
int y = j*videoScale;
// Reversing x to mirror the image
// In order to mirror the image, the column is reversed with the following formula:
// mirrored column = width - column - 1
int loc = (video.width - i - 1) + j*video.width;
// Each rect is colored white with a size determined by brightness
color c = video.pixels[loc];
// A rectangle size is calculated as a function of the pixel's brightness.
// A bright pixel is a large rectangle, and a dark pixel is a small one.
float sz = (brightness(c)/255.0)*videoScale;
rectMode(CENTER);
fill(255);
noStroke();
rect(x + videoScale/2,y + videoScale/2,sz,sz);
}
}
}
我希望这段代码能够在处理过程中运行,但是在打开相机并获取视频供稿时进行测试时会出现一些小错误。