資源簡介
人臉識別檢測opencv簡單java實現要不是畢業好幾年我都不舍得分享出來!!!
CTRL+D收藏一下或者關注走一波-有你所需!不斷更新!
其他相關下載,配套代碼以及PPT。穩妥的小老弟
https://me.csdn.net/download/qq_27500493
加載本地的OpenCV庫,這樣就可以用它來調用Java API。
創建實例CascadeClassifier,將已加載的分類器的文件名傳遞給它。
接下來我們將圖片轉化成Java API能夠接受使用Highui類的格式,鋪墊在OpenCV C++的n維密集數組類上邊。
然后,調用分類器上的detectMultiScale方法傳遞給它圖象和MatOfRect對象。這個過程之后,MatOfRect將有面部檢測。
我們遍歷所有的臉部檢測并用矩形標記圖像。
最后,將圖像寫入輸出的 .png 文件里。
---------------------
作者:your-Mr-Right
來源:CSDN
原文:https://blog.csdn.net/qq_27500493/article/details/78065312
版權聲明:本文為博主原創文章,轉載請附上博文鏈接!

代碼片段和文件信息
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(“lbpcascade_frontalface.xml“).getPath());
????//?Create?a?face?detector?from?the?cascade?file?in?the?resources復雜背景下,alt_tree和LBP的檢測結果都是一致的,但是LBP的用時要短很多,因此LBP相對來說實時性更強。
????//?directory.
????//CascadeClassifier?faceDetector?=?new?CascadeClassifier(getClass().getResource(“lbpcascade_frontalface.xml“).getPath());
????//Mat?image?=?Highgui.imread(getClass().getResource(“lena.png“).getPath());
????//注意:源程序的路徑會多打印一個‘/’,因此總是出現如下錯誤
/*
?*?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(“lbpcascade_frontalface.xml“).getPath().substring(1);
????CascadeClassifier?faceDetector?=?new?CascadeClassifier(xmlfilePath);//從配置文件lbpcascade_frontalface.xml中創建一個人臉識別器;創建實例CascadeClassifier,將已加載的分類器的文件名傳遞給它。
????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);//調用分類器上的detectMultiScale方法傳遞給它圖象和MatOfRect對象。這個過程之后,MatOfRect將有面部檢測。
????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);
??}
}
/*加載本地的OpenCV庫,這樣就可以用它來調用Java?API。
創建實例CascadeClassifier,將已加載的分類器的文件名傳遞給它。
接下來我們將圖片轉化成Java?API能夠接受使用Highui類的格式,鋪墊在OpenCV?C++的n維密集數組類上邊。
然后,調用分類器上的detectMultiScale方法傳遞給它圖象和MatOfRect對象。這個過程之后,MatOfRect將有面部檢測。
我們遍歷所有的臉部檢測并用矩形標記圖像。
最后,將圖像寫入輸出的?.png?文件里。*/
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????文件?????????755??2018-11-19?23:21??說明一下吧.txt
?????文件?????????570??2017-06-24?11:00??.classpath
?????文件?????????389??2017-06-24?10:58??.project
?????目錄???????????0??2017-06-24?10:58??.settings\
?????文件?????????598??2017-06-24?10:58??.settings\org.eclipse.jdt.core.prefs
?????目錄???????????0??2017-06-25?11:14??bin\
?????目錄???????????0??2017-06-25?11:14??bin\com\
?????目錄???????????0??2017-06-25?11:14??bin\com\njupt\
?????目錄???????????0??2017-06-25?11:14??bin\com\njupt\zhb\
?????目錄???????????0??2017-06-25?11:14??bin\com\njupt\zhb\test\
?????文件??????510332??2017-06-24?14:43??bin\com\njupt\zhb\test\33.jpg
?????文件????????2443??2017-06-25?11:14??bin\com\njupt\zhb\test\DetectFaceDemo.class
?????文件?????????694??2017-06-25?11:14??bin\com\njupt\zhb\test\TestMain.class
?????文件???????51856??2017-06-24?10:59??bin\com\njupt\zhb\test\lbpcascade_frontalface.xm
?????文件??????620636??2017-06-24?10:59??bin\com\njupt\zhb\test\lena.png
?????文件???????25922??2017-06-24?11:02??bin\com\njupt\zhb\test\timg.jpg
?????文件??????138070??2017-06-24?10:59??bin\com\njupt\zhb\test\we.jpg
?????文件?????1007175??2017-06-25?11:14??faceDetection.png
?????目錄???????????0??2017-06-24?10:59??libs\
?????文件??????430303??2017-06-24?10:59??libs\opencv-246.jar
?????目錄???????????0??2017-06-24?10:59??libs\x64\
?????文件?????8606208??2017-06-24?10:59??libs\x64\opencv_java246.dll
?????目錄???????????0??2017-06-24?10:59??libs\x86\
?????文件?????7426048??2017-06-24?10:59??libs\x86\opencv_java246.dll
?????目錄???????????0??2017-06-24?14:44??src\
?????目錄???????????0??2017-06-24?10:59??src\com\
?????目錄???????????0??2017-06-24?10:59??src\com\njupt\
?????目錄???????????0??2017-06-24?10:59??src\com\njupt\zhb\
?????目錄???????????0??2017-06-24?14:44??src\com\njupt\zhb\test\
?????文件??????510332??2017-06-24?14:43??src\com\njupt\zhb\test\33.jpg
?????文件????????2927??2017-06-24?20:58??src\com\njupt\zhb\test\DetectFaceDemo.java
............此處省略5個文件信息
- 上一篇:ssm 開發必要的 完整的 jar包
- 下一篇:Android學生信息管理系統
評論
共有 條評論