OpenCV——面部识别FaceDetector的简单使用
2016-11-29 10:46
295 查看
下面是简单的demo,从我的项目中抽取出来,这个方法可以简单检测出人脸,返回的rect可以进行下一步操作
参数文件lbpcascade_frontalface.xml是可以在文件夹内 ../OpenCV\opencv\sources\data\lbpcascades获得,OpenCV提供了多个不同来别的参数文件,可以逐一尝试玩耍
从我实验的角度来看,我选取的这个比较容易监测到正脸,但是也出现了非人脸的情况,需要进一步改进,有空的话也可以自己训练,但是图片样本要好好找
以上。
import java.util.List;
import org.opencv.core.Core;
import org.opencv.core.Mat;
import org.opencv.core.MatOfRect;
import org.opencv.core.Point;
import org.opencv.core.Rect;
import org.opencv.core.Scalar;
import org.opencv.highgui.Highgui;
import org.opencv.objdetect.CascadeClassifier;
public class TestFace {
public static String filePath="D:\\Logs\\OCR\\TestUse\\test6.png";
public static String outputPath="D:\\Logs\\OCR\\TestUse\\FaceDetect10.png";
public static void main(String[] args){
TestFace testFace=new TestFace();
testFace.faceDetect();
}
public List<Rect> faceDetect(){
Mat image = Highgui.imread(filePath);
String facePath="D:\\Test\\lbpcascade_frontalface.xml";
CascadeClassifier faceDetector = new CascadeClassifier(facePath);
MatOfRect faceDetections = new MatOfRect();
faceDetector.detectMultiScale(image, faceDetections);
for (int i=0;i<faceDetections.toArray().length;i++){
Rect rect=faceDetections.toArray()[i];
Core.rectangle(image, new Point(rect.x, rect.y), new Point(rect.x
+ rect.width, rect.y + rect.height), new Scalar(255, 0, 0));
}
//Piant the Rect of face
Mat srcImg = Highgui.imread(filePath);
int fullW = srcImg.width();
int fullH = srcImg.height();
int FareaX=(int)(fullW*0.75);
int FareaY=fullH/2;
int FareaWid=fullW/4;
int FareaHeight=fullH/4;
int one_thirdH = fullH/3;
Core.rectangle(image, new Point(FareaX, FareaY), new Point(FareaX
+FareaWid, FareaY + FareaHeight), new Scalar(0, 255, 0));
Highgui.imwrite(outputPath, image);
return faceDetections.toList();
}
}
参数文件lbpcascade_frontalface.xml是可以在文件夹内 ../OpenCV\opencv\sources\data\lbpcascades获得,OpenCV提供了多个不同来别的参数文件,可以逐一尝试玩耍
从我实验的角度来看,我选取的这个比较容易监测到正脸,但是也出现了非人脸的情况,需要进一步改进,有空的话也可以自己训练,但是图片样本要好好找
以上。
import java.util.List;
import org.opencv.core.Core;
import org.opencv.core.Mat;
import org.opencv.core.MatOfRect;
import org.opencv.core.Point;
import org.opencv.core.Rect;
import org.opencv.core.Scalar;
import org.opencv.highgui.Highgui;
import org.opencv.objdetect.CascadeClassifier;
public class TestFace {
public static String filePath="D:\\Logs\\OCR\\TestUse\\test6.png";
public static String outputPath="D:\\Logs\\OCR\\TestUse\\FaceDetect10.png";
public static void main(String[] args){
TestFace testFace=new TestFace();
testFace.faceDetect();
}
public List<Rect> faceDetect(){
Mat image = Highgui.imread(filePath);
String facePath="D:\\Test\\lbpcascade_frontalface.xml";
CascadeClassifier faceDetector = new CascadeClassifier(facePath);
MatOfRect faceDetections = new MatOfRect();
faceDetector.detectMultiScale(image, faceDetections);
for (int i=0;i<faceDetections.toArray().length;i++){
Rect rect=faceDetections.toArray()[i];
Core.rectangle(image, new Point(rect.x, rect.y), new Point(rect.x
+ rect.width, rect.y + rect.height), new Scalar(255, 0, 0));
}
//Piant the Rect of face
Mat srcImg = Highgui.imread(filePath);
int fullW = srcImg.width();
int fullH = srcImg.height();
int FareaX=(int)(fullW*0.75);
int FareaY=fullH/2;
int FareaWid=fullW/4;
int FareaHeight=fullH/4;
int one_thirdH = fullH/3;
Core.rectangle(image, new Point(FareaX, FareaY), new Point(FareaX
+FareaWid, FareaY + FareaHeight), new Scalar(0, 255, 0));
Highgui.imwrite(outputPath, image);
return faceDetections.toList();
}
}
相关文章推荐
- 从零使用OpenCV快速实现简单车牌识别系统
- 从零使用OpenCV快速实现简单车牌识别系统
- 从零使用OpenCV快速实现简单车牌识别系统
- 使用Opencv进行轮廓检测,字符提取,简单的直方图字符识别!
- OpenCV中使用Eigenfaces 或 Fisherfaces进行人脸识别
- Qt + Opencv 实现的一个简单文字识别的demo
- android端使用openCV与深度学习实现车牌识别
- 使用pytesseract识别简单验证码
- 世界上最简单的面部识别为Python和命令行api
- python3+pyqt5+opencv3简单使用(慢慢更新中)
- 基于qml创建最简单的图像处理程序(3)-使用opencv&qml进行图像处理
- python+opencv面部识别
- SmileyFace——基于OpenCV的人脸人眼检测、面部识别程序
- 使用opencv的SVM实现车牌区域识别
- 使用OpenCV+PCA+KNN/SVM进行人脸检测和识别-Python
- TensorflowSharp 简单使用与KNN识别MNIST流程
- OpenCV3与深度学习实例-使用GoogLeNet模型进行图片分类识别
- 使用opencv作物件识别(一) —— 积分直方图加速HOG特征计算
- python使用opencv进行人脸识别
- 使用OpenCV进行人脸识别的三种算法(官方网翻译)