我正在尝试实现一种功能,用于检查png图像是否包含人脸。我正在尝试使用OpenImaj,并注意到它有4个检测器(Identity,Haar等)
感谢任何人都可以共享相关的代码段
答案 0 :(得分:0)
import java.io.File;
import java.io.IOException;
import java.util.Iterator;
import java.util.List;
import org.openimaj.image.DisplayUtilities;
import org.openimaj.image.FImage;
import org.openimaj.image.ImageUtilities;
import org.openimaj.image.MBFImage;
import org.openimaj.image.colour.RGBColour;
import org.openimaj.image.colour.Transforms;
import org.openimaj.image.processing.face.detection.DetectedFace;
import org.openimaj.image.processing.face.detection.FaceDetector;
import org.openimaj.image.processing.face.detection.HaarCascadeDetector;
import org.openimaj.math.geometry.shape.Rectangle;
public class App {
public static void main(String[] args) throws Exception, IOException {
final MBFImage image = ImageUtilities.readMBF(new File("d:\\java\\face\\bin.jpeg"));
FaceDetector<DetectedFace, FImage> fd = new HaarCascadeDetector(200);
List<DetectedFace> faces = fd.detectFaces(Transforms.calculateIntensity(image));
System.out.println("# Found faces, one per line.");
System.out.println("# <x>, <y>, <width>, <height>");
for (Iterator<DetectedFace> iterator = faces.iterator(); iterator.hasNext();) {
DetectedFace face = iterator.next();
Rectangle bounds = face.getBounds();
image.drawShape(face.getBounds(), RGBColour.RED);
// System.out.println(bounds.x + ";" + bounds.y + ";" + bounds.width + ";" +
// bounds.height);
}
DisplayUtilities.display(image);
}
}