【Android】Face Recognition on Android(OpenCV)
http://stackoverflow.com/questions/11699744/face-recognition-on-android
import com.googlecode.javacv.cpp.opencv_core;import static com.googlecode.javacv.cpp.opencv_highgui.*;import static com.googlecode.javacv.cpp.opencv_core.*;import static com.googlecode.javacv.cpp.opencv_imgproc.*;import static com.googlecode.javacv.cpp.opencv_contrib.*;import java.io.File;import java.io.FilenameFilter;public class OpenCVFaceRecognizer { public static void main(String[] args) { String trainingDir = args[0]; IplImage testImage = cvLoadImage(args[1]); File root = new File(trainingDir); FilenameFilter pngFilter = new FilenameFilter() { public boolean accept(File dir, String name) { return name.toLowerCase().endsWith(".png"); } }; File[] imageFiles = root.listFiles(pngFilter); MatVector images = new MatVector(imageFiles.length); int[] labels = new int[imageFiles.length]; int counter = 0; int label; IplImage img; IplImage grayImg; for (File image : imageFiles) { // Get image and label: img = cvLoadImage(image.getAbsolutePath()); label = Integer.parseInt(image.getName().split("\\-")[0]); // Convert image to grayscale: grayImg = IplImage.create(img.width(), img.height(), IPL_DEPTH_8U, 1); cvCvtColor(img, grayImg, CV_BGR2GRAY); // Append it in the image list: images.put(counter, grayImg); // And in the labels list: labels[counter] = label; // Increase counter for next image: counter++; } FaceRecognizer faceRecognizer = createFisherFaceRecognizer(); // FaceRecognizer faceRecognizer = createEigenFaceRecognizer(); // FaceRecognizer faceRecognizer = createLBPHFaceRecognizer() faceRecognizer.train(images, labels); // Load the test image: IplImage greyTestImage = IplImage.create(testImage.width(), testImage.height(), IPL_DEPTH_8U, 1); cvCvtColor(testImage, greyTestImage, CV_BGR2GRAY); // And get a prediction: int predictedLabel = faceRecognizer.predict(greyTestImage); System.out.println("Predicted label: " + predictedLabel); }}
4.0.0 com.pcbje opencvfacerecognizer 0.1-SNAPSHOT jar opencvfacerecognizer http://pcbje.com com.googlecode.javacv javacv 0.3 com.googlecode.javacv javacv linux-x86_64 0.3 com.googlecode.javacv javacv macosx-x86_64 0.3 javacv JavaCV http://maven2.javacv.googlecode.com/git/
Face Recognition on Android
up vote 5 down vote favorite 9 | I'm trying to develop a Face Recognition app on Android and since I don't want to use NDK on the project (simply don't have the time to switch), I'm sticking to develop the whole app with Java and therefor I'm having some problems :
Does anyone know how to change my ArrayList to CvArr ?! This is my first post and I wasn't sure whether to ask all three questions in one post or in three posts so sorry for any inconveniences... If you need any other Information about the project, feel free to ask. android opencv javacv face-recognition
| ||||||||
|
2 Answers
active oldest votesup vote 5 down vote | UpdateThe following article was written by Petter Christian Bjelland, so all credit is his. I am posting it here, because his blog seems to be in Maintenance mode at the moment, but I think it is worth sharing. Doing face recognition with JavaCV (from http://pcbje.com)I couldn’t find any tutorial on how to perform face recognition using OpenCV and Java, so I decided to share a viable solution here. The solution is very inefficient in its current form as the training model is built at each run, however it shows what’s needed to make it work. The class below takes two arguments: The path to the directory containing the training faces and the path to the image you want to classify. Not that all images has to be of the same size and that the faces already has to be cropped out of their original images (Take a look here if you haven’t done the face detection yet). For the simplicity of this post, the class also requires that the training images have filename format: 1-jon_doe_1.png1-jon_doe_2.png2-jane_doe_1.png2-jane_doe_2.png ... and so on. The code: The class requires the OpenCV Java interface. If you’re using Maven, you can retrieve the required libraries with the following pom.xml: Original PostQuoting from my reply on http://answers.opencv.org/question/865/the-contrib-module-problem. Without ever having used javacv, let's see how far we can get by just looking at the interfaces! The project is on googlecode, which makes it easy to browse the code: http://code.google.com/p/javacv. First have a look at how Aha, so you need to pass a Again just by looking at the code, I guess it can be used like this: You probably want to write yourself a method that does the conversion from a Java Now to your second question. The interface of So you can either get a So once you have got the FaceRecognizerPtr, you can do things like: This learns you an Eigenfaces model. And that's it!
| ||||||||||||||||||||
|
更多相关文章
- 代码中设置drawableleft
- android 3.0 隐藏 系统标题栏
- Android开发中activity切换动画的实现
- Android(安卓)学习 笔记_05. 文件下载
- Android中直播视频技术探究之—摄像头Camera视频源数据采集解析
- 技术博客汇总
- android 2.3 wifi (一)
- AndRoid Notification的清空和修改
- Android中的Chronometer