gpt4 book ai didi

java - 如何使用OpenCV和Java来挽回面子和识别?

转载 作者:太空宇宙 更新时间:2023-11-03 22:21:08 24 4
gpt4 key购买 nike

我是 OpenCV 的新手。我能够从网络摄像头检测到人脸。我有点困惑如何保存检测到的人脸,如果那个人再次出现在镜头前如何保存和识别。

检测代码

private void detectAndDisplay(Mat frame)
{
MatOfRect faces = new MatOfRect();
Mat grayFrame = new Mat();

// convert the frame in gray scale
Imgproc.cvtColor(frame, grayFrame, Imgproc.COLOR_BGR2GRAY);
// equalize the frame histogram to improve the result
Imgproc.equalizeHist(grayFrame, grayFrame);

// compute minimum face size (20% of the frame height, in our case)
if (this.absoluteFaceSize == 0)
{
int height = grayFrame.rows();
if (Math.round(height * 0.2f) > 0)
{
this.absoluteFaceSize = Math.round(height * 0.2f);
}
}

// detect faces
this.faceCascade.detectMultiScale(grayFrame, faces, 1.1, 2, 0 | Objdetect.CASCADE_SCALE_IMAGE,
new Size(this.absoluteFaceSize, this.absoluteFaceSize), new Size());

// each rectangle in faces is a face: draw them!
Rect[] facesArray = faces.toArray();
for (int i = 0; i < facesArray.length; i++)
Imgproc.rectangle(frame, facesArray[i].tl(), facesArray[i].br(), new Scalar(0, 255, 0), 3);

}

最佳答案

如果你想保存检测到的人脸图像,也许你可以试试这样

for (int i = 0; i < facesArray.length; i++)
{
Imgproc.rectangle(frame, facesArray[i].tl(), facesArray[i].br(), new Scalar(0, 255, 0), 3);
Rect rect(facesArray[i].tl().x, facesArray[i].tl().y, facesArray[i].br().x - facesArray[i].tl().x, facesArray[i].br().y - facesArray[i].tl().y);
Mat cropFace = frame(rect);
imwrite("./face"+i+".jpg", cropFace);
}

关于java - 如何使用OpenCV和Java来挽回面子和识别?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49248943/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com