我正在尝试得到一个实时处理视频流来检测和像素化人脸。我有工作的代码跟踪面和画一个矩形周围的脸,我有一个单独的素描工作像素化的整个框架,但我不能想出如何约束像素化在面对矩形。任何关于如何将两者合并在一起的建议都将不胜感激。
我的面部跟踪代码是:
import processing.video.*;
import java.awt.Rectangle;
import gab.opencv.*;
OpenCV opencv;
Capture video;
Rectangle[] faces;
void setup() {
size( 640, 480 );
String[] cameras = Capture.list();
video = new Capture(this, cameras[0]);
opencv = new OpenCV(this, width, height);
opencv.loadCascade(OpenCV.CASCADE_FRONTALFACE);
faces = opencv.detect();
frameRate(24.0);
video.start();
}
void draw() {
opencv.loadImage(video);
image(video, 0, 0);
video.read();
faces = opencv.detect(1.2, 3, 0, 40, 400); //adjust last two numbers to give min and max for face size
noFill();
stroke(255, 20, 255);
strokeWeight(2);
for (int i = 0; i < faces.length; i++) {
rect(faces[i].x, faces[i].y, faces[i].width, faces[i].height);
}
}
我的像素代码是:
import processing.video.*;
int blockSize = 25;
int numPixelsWide, numPixelsHigh;
Capture video;
color movColors[];
void setup() {
size(640, 480);
noStroke();
String[] cameras = Capture.list();
video = new Capture(this, cameras[0]);
video.start();
numPixelsWide = width;
numPixelsHigh = height;
println(numPixelsWide);
movColors = new color[numPixelsWide * numPixelsHigh];
}
void draw() {
if (video.available() == true) {
video.read();
video.loadPixels();
int count = 0;
for (int j = 0; j < numPixelsHigh; j++) {
for (int i = 0; i < numPixelsWide; i++) {
movColors[count] = video.get(i*blockSize, j*blockSize);
count++;
}
}
}
background(255);
for (int j = 0; j < numPixelsHigh; j++) {
for (int i = 0; i < numPixelsWide; i++) {
fill(movColors[j*numPixelsWide + i]);
rect(i*blockSize, j*blockSize, blockSize, blockSize);
}
}
}
暂无答案!
目前还没有任何答案,快来回答吧!