資源簡介
Eclipse+Java+OpenCV246人臉識別。具體詳見;http://blog.csdn.net/nupt123456789/article/details/10011693/

代碼片段和文件信息
package?com.njupt.zhb.test;
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;
//
//?Detects?faces?in?an?image?draws?boxes?around?them?and?writes?the?results
//?to?“faceDetection.png“.
//
public?class?DetectFaceDemo?{
??public?void?run()?{
????System.out.println(“\nRunning?DetectFaceDemo“);
????System.out.println(getClass().getResource(“l(fā)bpcascade_frontalface.xml“).getPath());
????//?Create?a?face?detector?from?the?cascade?file?in?the?resources
????//?directory.
????//CascadeClassifier?faceDetector?=?new?CascadeClassifier(getClass().getResource(“l(fā)bpcascade_frontalface.xml“).getPath());
????//Mat?image?=?Highgui.imread(getClass().getResource(“l(fā)ena.png“).getPath());
????//注意:源程序的路徑會多打印一個‘/’,因此總是出現(xiàn)如下錯誤
/*
?*?Detected?0?faces?Writing?faceDetection.png?libpng?warning:?Image
?*?width?is?zero?in?IHDR?libpng?warning:?Image?height?is?zero?in?IHDR
?*?libpng?error:?Invalid?IHDR?data
?*/
????//因此,我們將第一個字符去掉
????String?xmlfilePath=getClass().getResource(“l(fā)bpcascade_frontalface.xml“).getPath().substring(1);
????CascadeClassifier?faceDetector?=?new?CascadeClassifier(xmlfilePath);
????Mat?image?=?Highgui.imread(getClass().getResource(“we.jpg“).getPath().substring(1));
????//?Detect?faces?in?the?image.
????//?MatOfRect?is?a?special?container?class?for?Rect.
????MatOfRect?faceDetections?=?new?MatOfRect();
????faceDetector.detectMultiScale(image?faceDetections);
????System.out.println(String.format(“Detected?%s?faces“?faceDetections.toArray().length));
????//?Draw?a?bounding?box?around?each?face.
????for?(Rect?rect?:?faceDetections.toArray())?{
????????Core.rectangle(image?new?Point(rect.x?rect.y)?new?Point(rect.x?+?rect.width?rect.y?+?rect.height)?new?Scalar(0?255?0));
????}
????//?Save?the?visualized?detection.
????String?filename?=?“faceDetection.png“;
????System.out.println(String.format(“Writing?%s“?filename));
????Highgui.imwrite(filename?image);
??}
}
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????目錄???????????0??2013-08-16?21:34??JavaOpenCV246\
?????文件?????????564??2013-08-16?20:34??JavaOpenCV246\.classpath
?????文件?????????389??2013-08-16?20:30??JavaOpenCV246\.project
?????目錄???????????0??2013-08-16?20:30??JavaOpenCV246\.settings\
?????文件?????????598??2013-08-16?20:30??JavaOpenCV246\.settings\org.eclipse.jdt.core.prefs
?????目錄???????????0??2013-08-16?20:34??JavaOpenCV246\bin\
?????目錄???????????0??2013-08-16?20:34??JavaOpenCV246\bin\com\
?????目錄???????????0??2013-08-16?20:34??JavaOpenCV246\bin\com\njupt\
?????目錄???????????0??2013-08-16?20:34??JavaOpenCV246\bin\com\njupt\zhb\
?????目錄???????????0??2013-08-16?21:29??JavaOpenCV246\bin\com\njupt\zhb\test\
?????文件????????2443??2013-08-16?21:33??JavaOpenCV246\bin\com\njupt\zhb\test\DetectFaceDemo.class
?????文件?????????694??2013-08-16?21:35??JavaOpenCV246\bin\com\njupt\zhb\test\TestMain.class
?????文件???????51856??2013-01-28?07:17??JavaOpenCV246\bin\com\njupt\zhb\test\lbpcascade_frontalface.xm
?????文件??????620636??2013-02-16?06:55??JavaOpenCV246\bin\com\njupt\zhb\test\lena.png
?????文件??????138070??2013-04-05?13:37??JavaOpenCV246\bin\com\njupt\zhb\test\we.jpg
?????文件?????1007175??2013-08-16?21:34??JavaOpenCV246\faceDetection.png
?????目錄???????????0??2013-08-16?20:44??JavaOpenCV246\libs\
?????文件??????430303??2013-07-02?13:19??JavaOpenCV246\libs\opencv-246.jar
?????目錄???????????0??2013-08-16?20:44??JavaOpenCV246\libs\x64\
?????文件?????8606208??2013-07-02?13:14??JavaOpenCV246\libs\x64\opencv_java246.dll
?????目錄???????????0??2013-08-16?20:44??JavaOpenCV246\libs\x86\
?????文件?????7368192??2013-07-02?13:19??JavaOpenCV246\libs\x86\opencv_java246.dll
?????目錄???????????0??2013-08-16?20:31??JavaOpenCV246\src\
?????目錄???????????0??2013-08-16?20:31??JavaOpenCV246\src\com\
?????目錄???????????0??2013-08-16?20:31??JavaOpenCV246\src\com\njupt\
?????目錄???????????0??2013-08-16?20:31??JavaOpenCV246\src\com\njupt\zhb\
?????目錄???????????0??2013-08-16?21:29??JavaOpenCV246\src\com\njupt\zhb\test\
?????文件????????2202??2013-08-16?21:33??JavaOpenCV246\src\com\njupt\zhb\test\DetectFaceDemo.java
?????文件?????????459??2013-08-16?21:35??JavaOpenCV246\src\com\njupt\zhb\test\TestMain.java
?????文件???????51856??2013-01-28?07:17??JavaOpenCV246\src\com\njupt\zhb\test\lbpcascade_frontalface.xm
?????文件??????620636??2013-02-16?06:55??JavaOpenCV246\src\com\njupt\zhb\test\lena.png
............此處省略1個文件信息
評論
共有 條評論