本文整理匯總了Java中org.opencv.objdetect.CascadeClassifier.empty方法的典型用法代碼示例。如果您正苦於以下問題:Java CascadeClassifier.empty方法的具體用法?Java CascadeClassifier.empty怎麽用?Java CascadeClassifier.empty使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.opencv.objdetect.CascadeClassifier
的用法示例。
在下文中一共展示了CascadeClassifier.empty方法的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: detectMany
import org.opencv.objdetect.CascadeClassifier; //導入方法依賴的package包/類
/**
*
* @Title: detectMany
* @Description: 檢測多人圖片,返回檢測的人臉區域對象
* @param mImgSRC
* @return
* MatOfRect
*/
public static MatOfRect detectMany(Mat mImgSRC) {
if(mImgSRC.empty()) {
LOG.info("檢測多人圖片檢測時沒有找到圖片");
return null;
}
// 人臉檢測器文件的所在路徑的文件夾名稱數組
String [] pathKey = {ServletContextHolder.getOpenCVHaarcascades(), "haarcascade_frontalface_alt.xml"};
CascadeClassifier cascade = new CascadeClassifier(FileUtils.buildFilePath(pathKey));
if(cascade.empty()) {
LOG.info("人臉檢測級聯加載器為null");
return null;
}
// 記錄搜索到的人臉區域
MatOfRect mOfRect = new MatOfRect();
// 用於計算縮放比例
int scaledWidth = mImgSRC.width();
detectManyObject(mImgSRC, cascade, mOfRect, scaledWidth);
if(mOfRect.toArray().length <= 0) {
LOG.info("沒有檢測到人臉...");
return null;
}
return mOfRect;
}
示例2: detectLeftEye
import org.opencv.objdetect.CascadeClassifier; //導入方法依賴的package包/類
/**
* 檢測左眼
* @param faceImg
* @param leftEyePoint
* @param searchedLeftEye
* @param scaledWidth
*/
protected static void detectLeftEye(Mat faceImg, Rect leftEyeRect, int scaledWidth) {
CascadeClassifier cascade = new CascadeClassifier();
cascade.load(DetectorXMLPath + HAARCASCADE_MCS_LEFTEYE);
// 第一次檢測左眼
if(!cascade.empty()) {
DetectObject.detectLargestObject(faceImg, cascade, leftEyeRect, scaledWidth);
}
// 如果沒有檢測到眼睛,使用不同的級聯加載器繼續嘗試
if(leftEyeRect.width <= 0) {
cascade.load(DetectorXMLPath+HAARCASCADE_EYE_TREE_EYEGLASSES);
if(!cascade.empty()) {
DetectObject.detectLargestObject(faceImg, cascade, leftEyeRect, scaledWidth);
}
}
if(leftEyeRect.width <= 0) {
cascade.load(DetectorXMLPath+HAARCASCADE_EYE);
if(!cascade.empty()) {
DetectObject.detectLargestObject(faceImg, cascade, leftEyeRect, scaledWidth);
}
}
}
示例3: detectRightEye
import org.opencv.objdetect.CascadeClassifier; //導入方法依賴的package包/類
protected static void detectRightEye(Mat faceImg, Rect rightEyeRect, int scaledWidth) {
CascadeClassifier cascade = new CascadeClassifier();
cascade.load(DetectorXMLPath+HAARCASCADE_MCS_RIGHTEYE);
// 第一次檢測右眼
if(!cascade.empty()) {
DetectObject.detectLargestObject(faceImg, cascade, rightEyeRect, scaledWidth);
}
if(rightEyeRect.width <= 0) {
cascade.load(DetectorXMLPath+HAARCASCADE_EYE_TREE_EYEGLASSES);
if(!cascade.empty()) {
DetectObject.detectLargestObject(faceImg, cascade, rightEyeRect, scaledWidth);
}
}
if(rightEyeRect.width <= 0) {
cascade.load(DetectorXMLPath+HAARCASCADE_EYE);
if(!cascade.empty()) {
DetectObject.detectLargestObject(faceImg, cascade, rightEyeRect, scaledWidth);
}
}
}
示例4: FrcFaceDetector
import org.opencv.objdetect.CascadeClassifier; //導入方法依賴的package包/類
/**
* Constructor: Create an instance of the object.
*
* @param instanceName specifies the instance name.
* @param classifierPath specifies the file path for the classifier.
* @param videoIn specifies the video input stream.
* @param videoOut specifies the video output stream.
*/
public FrcFaceDetector(
final String instanceName, final String classifierPath, CvSink videoIn, CvSource videoOut)
{
super(instanceName, videoIn, videoOut, NUM_IMAGE_BUFFERS, detectedFacesBuffers);
if (debugEnabled)
{
dbgTrace = new TrcDbgTrace(moduleName, tracingEnabled, traceLevel, msgLevel);
}
//
// Preallocate two MatOfRects for ping pong processing.
//
for (int i = 0; i < detectedFacesBuffers.length; i++)
{
detectedFacesBuffers[i] = new MatOfRect();
}
faceDetector = new CascadeClassifier(classifierPath);
if (faceDetector.empty())
{
throw new RuntimeException("Failed to load Cascade Classifier <" + classifierPath + ">");
}
}
示例5: initializeJavaDetector
import org.opencv.objdetect.CascadeClassifier; //導入方法依賴的package包/類
private synchronized CascadeClassifier initializeJavaDetector(File cascadeFile) {
CascadeClassifier detector = new CascadeClassifier(cascadeFile.getAbsolutePath());
detector.load(cascadeFile.getAbsolutePath());
if (detector.empty()) {
Log.e(TAG, "Failed to load cascade classifier");
detector = null;
} else {
Log.i(TAG, "Loaded cascade classifier from " + cascadeFile.getAbsolutePath());
}
return detector;
}
示例6: onManagerConnected
import org.opencv.objdetect.CascadeClassifier; //導入方法依賴的package包/類
@Override
public void onManagerConnected(int status) {
switch (status) {
case LoaderCallbackInterface.SUCCESS:
{
Log.i(TAG, "OpenCV成功加載");
try{
InputStream is = getResources().openRawResource(R.raw.haarcascade_frontalface_alt2);
File cascadeDir = getDir("cascade",
Context.MODE_PRIVATE);
File mCascadeFile = new File(cascadeDir,"cascade.xml");
FileOutputStream os = new
FileOutputStream(mCascadeFile);
byte[] buffer = new byte[4096];
int bytesRead;
while((bytesRead = is.read(buffer)) != -1)
{
os.write(buffer, 0, bytesRead);
}
is.close();
os.close();
haarCascade = new CascadeClassifier(
mCascadeFile.getAbsolutePath());
if (haarCascade.empty())
{
Log.i("Cascade Error", "級聯分類器加載失敗");
haarCascade = null;
}
}
catch(Exception e)
{
Log.i("Cascade Error: ","找不到級聯分類器文件");
}
mOpenCvCameraView.enableView();
} break;
default:
{
super.onManagerConnected(status);
} break;
}
}