資源簡介
基于開源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\n“);
???? ???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\.settings\org.eclipse.jdt.core.prefs
?????文件?????341406??2016-05-11?16:09??facetest\bin\haarcascade_eye.xm
?????文件?????601661??2016-05-11?16:09??facetest\bin\haarcascade_eye_tree_eyeglasses.xm
?????文件?????378600??2016-05-11?16:09??facetest\bin\haarcascade_frontalcatface.xm
?????文件?????361296??2016-05-11?16:09??facetest\bin\haarcascade_frontalcatface_extended.xm
?????文件?????676709??2016-05-11?16:09??facetest\bin\haarcascade_frontalface_alt.xm
?????文件?????540616??2016-05-11?16:09??facetest\bin\haarcascade_frontalface_alt2.xm
?????文件????2689040??2016-05-11?16:09??facetest\bin\haarcascade_frontalface_alt_tree.xm
?????文件?????930127??2016-05-11?16:09??facetest\bin\haarcascade_frontalface_default.xm
?????文件?????476825??2016-05-11?16:09??facetest\bin\haarcascade_fullbody.xm
?????文件?????195369??2016-05-11?16:09??facetest\bin\haarcascade_lefteye_2splits.xm
?????文件??????47775??2016-05-11?16:09??facetest\bin\haarcascade_licence_plate_rus_16stages.xm
?????文件?????395320??2016-05-11?16:09??facetest\bin\haarcascade_lowerbody.xm
?????文件?????828514??2016-05-11?16:09??facetest\bin\haarcascade_profileface.xm
?????文件?????196170??2016-05-11?16:09??facetest\bin\haarcascade_righteye_2splits.xm
?????文件??????75482??2016-05-11?16:09??facetest\bin\haarcascade_russian_plate_number.xm
?????文件?????188650??2016-05-11?16:09??facetest\bin\haarcascade_smile.xm
?????文件?????785817??2016-05-11?16:09??facetest\bin\haarcascade_upperbody.xm
?????文件?????122350??2016-05-11?16:09??facetest\bin\lbpcascade_frontalcatface.xm
?????文件??????51856??2016-05-11?16:09??facetest\bin\lbpcascade_frontalface.xm
?????文件??????47015??2016-05-11?16:09??facetest\bin\lbpcascade_profileface.xm
?????文件??????47027??2016-05-11?16:09??facetest\bin\lbpcascade_silverware.xm
?????文件?????799232??2016-05-12?17:06??facetest\bin\libfacedetect.dll
?????文件???31415808??2016-05-07?11:18??facetest\bin\opencv_java310.dll
?????文件???????9859??2016-08-01?17:26??facetest\bin\SimpleSample.class
?????文件??????10335??2016-08-01?17:22??facetest\bin\SimpleSampleCap.class
?????文件?????313405??2016-05-07?11:18??facetest\libs\opencv-310.jar
?????文件?????341406??2016-05-11?16:09??facetest\src\haarcascade_eye.xm
............此處省略33個文件信息
評論
共有 條評論