基于开源OPENCV人脸识别java版


基于开源OPENCV3.1做人脸识别,该程序是一个简单的demo版本,可以实现如下功能:1.识别人脸和人眼;2.调用摄像头录制avi;3.可以对图片进行高斯处理。
资源截图
代码片段和文件信息
import java.util.List;
import java.util.Vector;

import org.opencv.core.Core;
import org.opencv.core.CvType;
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.core.Size;
import org.opencv.imgcodecs.Imgcodecs;
import org.opencv.imgproc.Imgproc;
import org.opencv.objdetect.CascadeClassifier;
import org.opencv.videoio.VideoCapture;
import org.opencv.videoio.Videoio;


class SimpleSample {
  final static int CV_HAAR_DO_CANNY_PRUNING =   1;
  final static int CV_HAAR_SCALE_IMAGE    =      2;
  final static int CV_HAAR_FIND_BIGGEST_object =  4;
  final static int CV_HAAR_DO_ROUGH_SEARCH  =    8;
  static{ System.loadLibrary(Core.NATIVE_LIBRARY_NAME); }
  public void FaceDetection(String fileinname) {  
     double scale = 1.3;
      CascadeClassifier faceDetector = new CascadeClassifier(“E://workspace//facetest//bin//haarcascade_frontalface_alt2.xml“);
      CascadeClassifier eyeDetector = new CascadeClassifier(“E://workspace//facetest//bin//haarcascade_eye.xml“);
      Mat image = Imgcodecs.imread(fileinname);
      
      // Detect faces in the image.
      // MatOfRect is a special container class for Rect.
      //MatOfRect faceDetections = new MatOfRect();
      //faceDetector.detectMultiScale(image faceDetections);
       if( !image.empty() )//读取图片数据不能为空
      {
        int i = 0;
        double t = 0;
        MatOfRect faceDetections = new MatOfRect();
         Scalar colors[] =  { new Scalar(00255)new Scalar(0128255)new Scalar(0255255)
           new Scalar(02550)new Scalar(2551280)new Scalar(2552550)
           new Scalar(25500)new Scalar(2550255)} ;
        // Imgproc.
         Mat gray = new Mat();
         Mat smallImg = new Mat((int)(image.rows()/scale) (int)(image.cols()/scale) CvType.CV_8UC1 );
         Imgproc.cvtColor( image gray Imgproc.COLOR_BGR2GRAY );//因为用的是类haar特征,所以都是基于灰度图像的,这里要转换成灰度图像  
         Imgproc.resize( gray smallImg smallImg.size() 0 0 Imgproc.INTER_LINEAR );//将尺寸缩小到1/scale用线性插值  
         Imgproc.equalizeHist( smallImg smallImg );//直方图均衡
         t = (double)Core.getTickCount();//用来计算算法执行时间

         faceDetector.detectMultiScale( smallImg faceDetections1.1 2 0|CV_HAAR_SCALE_IMAGEnew Size(100 100)new Size(200 200) );
           t = (double)Core.getTickCount() - t;//相减为算法执行的时间
           //System.out.println(“detection time = “+t/((double)Core.getTickCount()*1000.)+“ ms
“);
        List  rects =  faceDetections.toList();
        for(int m=0;m         Rect rect = rects.get(m);
        Mat smallImgROI = new Mat();
        MatOfRect nestedobjects =  new MatOfRect();
        Point center = new Point();
        Scalar color = colors[i%8];
        int radius;
        center.x = (int)((rect.x + rect.width*0.5)*scale);
        center.y = (int)((rect.y + rect.height*0.5)*scale);
        

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----

     文件        529  2016-05-12 14:28  facetest.classpath

     文件        384  2016-05-07 11:09  facetest.project

     文件        598  2016-05-07 11:10  facetest.settingsorg.eclipse.jdt.core.prefs

     文件     341406  2016-05-11 16:09  facetestinhaarcascade_eye.xml

     文件     601661  2016-05-11 16:09  facetestinhaarcascade_eye_tree_eyeglasses.xml

     文件     378600  2016-05-11 16:09  facetestinhaarcascade_frontalcatface.xml

     文件     361296  2016-05-11 16:09  facetestinhaarcascade_frontalcatface_extended.xml

     文件     676709  2016-05-11 16:09  facetestinhaarcascade_frontalface_alt.xml

     文件     540616  2016-05-11 16:09  facetestinhaarcascade_frontalface_alt2.xml

     文件    2689040  2016-05-11 16:09  facetestinhaarcascade_frontalface_alt_tree.xml

     文件     930127  2016-05-11 16:09  facetestinhaarcascade_frontalface_default.xml

     文件     476825  2016-05-11 16:09  facetestinhaarcascade_fullbody.xml

     文件     195369  2016-05-11 16:09  facetestinhaarcascade_lefteye_2splits.xml

     文件      47775  2016-05-11 16:09  facetestinhaarcascade_licence_plate_rus_16stages.xml

     文件     395320  2016-05-11 16:09  facetestinhaarcascade_lowerbody.xml

     文件     828514  2016-05-11 16:09  facetestinhaarcascade_profileface.xml

     文件     196170  2016-05-11 16:09  facetestinhaarcascade_righteye_2splits.xml

     文件      75482  2016-05-11 16:09  facetestinhaarcascade_russian_plate_number.xml

     文件     188650  2016-05-11 16:09  facetestinhaarcascade_smile.xml

     文件     785817  2016-05-11 16:09  facetestinhaarcascade_upperbody.xml

     文件     122350  2016-05-11 16:09  facetestinlbpcascade_frontalcatface.xml

     文件      51856  2016-05-11 16:09  facetestinlbpcascade_frontalface.xml

     文件      47015  2016-05-11 16:09  facetestinlbpcascade_profileface.xml

     文件      47027  2016-05-11 16:09  facetestinlbpcascade_silverware.xml

     文件     799232  2016-05-12 17:06  facetestinlibfacedetect.dll

     文件   31415808  2016-05-07 11:18  facetestinopencv_java310.dll

     文件       9859  2016-08-01 17:26  facetestinSimpleSample.class

     文件      10335  2016-08-01 17:22  facetestinSimpleSampleCap.class

     文件     313405  2016-05-07 11:18  facetestlibsopencv-310.jar

     文件     341406  2016-05-11 16:09  facetestsrchaarcascade_eye.xml

............此处省略33个文件信息

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容, 请发送邮件举报,一经查实,本站将立刻删除。

发表评论

评论列表(条)