return error;
}
- char *haarcascadeFilepath;
- error = mv_engine_config_get_string_attribute_c(
- engine_cfg,
- "MV_FACE_DETECTION_MODEL_FILE_PATH",
- &haarcascadeFilepath);
-
/* default path */
+ cv::Size minSize(-1, -1);
+ cv::Rect roi(-1, -1, -1, -1);
std::string haarcascadeFilePathStr =
"/usr/share/OpenCV/haarcascades/haarcascade_frontalface_alt2.xml";
-
- if (error == MEDIA_VISION_ERROR_NONE) {
- LOGI("Haarcascade file was set as default");
- haarcascadeFilePathStr = std::string(haarcascadeFilepath);
-
- free(haarcascadeFilepath);
- haarcascadeFilepath = NULL;
- } else {
- LOGE("Error occurred during face detection haarcascade file receiving."
+ if (engine_cfg) {
+ /* set face detection model */
+ char *haarcascadeFilepath;
+ error = mv_engine_config_get_string_attribute_c(
+ engine_cfg,
+ "MV_FACE_DETECTION_MODEL_FILE_PATH",
+ &haarcascadeFilepath);
+ if (error == MEDIA_VISION_ERROR_NONE) {
+ LOGI("Haarcascade file was set as default");
+ haarcascadeFilePathStr = std::string(haarcascadeFilepath);
+
+ free(haarcascadeFilepath);
+ haarcascadeFilepath = NULL;
+ } else {
+ LOGE("Error occurred during face detection haarcascade file receiving."
" (%i)", error);
- }
-
- static FaceDetector faceDetector;
-
- if (!faceDetector.loadHaarcascade(haarcascadeFilePathStr)) {
- LOGE("Loading Haarcascade failed");
- return MEDIA_VISION_ERROR_INVALID_PARAMETER;
- }
+ }
- cv::Rect roi(-1, -1, -1, -1);
- error = mv_engine_config_get_int_attribute_c(
+ /* Ser roi to be detected */
+ error = mv_engine_config_get_int_attribute_c(
engine_cfg,
MV_FACE_DETECTION_ROI_X,
&roi.x);
- if (error != MEDIA_VISION_ERROR_NONE)
- LOGE("Error occurred during face detection roi (x) receiving."
+ if (error != MEDIA_VISION_ERROR_NONE)
+ LOGE("Error occurred during face detection roi (x) receiving."
" (%i)", error);
- error = mv_engine_config_get_int_attribute_c(
- engine_cfg,
- MV_FACE_DETECTION_ROI_Y,
- &roi.y);
- if (error != MEDIA_VISION_ERROR_NONE)
- LOGE("Error occurred during face detection roi (y) receiving."
- " (%i)", error);
+ error = mv_engine_config_get_int_attribute_c(
+ engine_cfg,
+ MV_FACE_DETECTION_ROI_Y,
+ &roi.y);
+ if (error != MEDIA_VISION_ERROR_NONE)
+ LOGE("Error occurred during face detection roi (y) receiving."
+ " (%i)", error);
- error = mv_engine_config_get_int_attribute_c(
- engine_cfg,
- MV_FACE_DETECTION_ROI_WIDTH,
- &roi.width);
- if (error != MEDIA_VISION_ERROR_NONE)
- LOGE("Error occurred during face detection roi (width) receiving."
- " (%i)", error);
+ error = mv_engine_config_get_int_attribute_c(
+ engine_cfg,
+ MV_FACE_DETECTION_ROI_WIDTH,
+ &roi.width);
+ if (error != MEDIA_VISION_ERROR_NONE)
+ LOGE("Error occurred during face detection roi (width) receiving."
+ " (%i)", error);
- error = mv_engine_config_get_int_attribute_c(
- engine_cfg,
- MV_FACE_DETECTION_ROI_HEIGHT,
- &roi.height);
- if (error != MEDIA_VISION_ERROR_NONE)
- LOGE("Error occurred during face detection roi (height) receiving."
- " (%i)", error);
+ error = mv_engine_config_get_int_attribute_c(
+ engine_cfg,
+ MV_FACE_DETECTION_ROI_HEIGHT,
+ &roi.height);
+ if (error != MEDIA_VISION_ERROR_NONE)
+ LOGE("Error occurred during face detection roi (height) receiving."
+ " (%i)", error);
+
+ /* Set minimum size to be detected */
+ error = mv_engine_config_get_int_attribute_c(
+ engine_cfg,
+ MV_FACE_DETECTION_MIN_SIZE_WIDTH,
+ &minSize.width);
+ if (error != MEDIA_VISION_ERROR_NONE)
+ LOGE("Error occurred during face detection minimum width receiving."
+ " (%i)", error);
- cv::Size minSize(-1, -1);
- error = mv_engine_config_get_int_attribute_c(
- engine_cfg,
- MV_FACE_DETECTION_MIN_SIZE_WIDTH,
- &minSize.width);
- if (error != MEDIA_VISION_ERROR_NONE)
- LOGE("Error occurred during face detection minimum width receiving."
- " (%i)", error);
+ error = mv_engine_config_get_int_attribute_c(
+ engine_cfg,
+ MV_FACE_DETECTION_MIN_SIZE_HEIGHT,
+ &minSize.height);
+ if (error != MEDIA_VISION_ERROR_NONE)
+ LOGE("Error occurred during face detection minimum height receiving."
+ " (%i)", error);
+ }
- error = mv_engine_config_get_int_attribute_c(
- engine_cfg,
- MV_FACE_DETECTION_MIN_SIZE_HEIGHT,
- &minSize.height);
- if (error != MEDIA_VISION_ERROR_NONE)
- LOGE("Error occurred during face detection minimum height receiving."
- " (%i)", error);
+ static FaceDetector faceDetector;
+
+ if (!faceDetector.loadHaarcascade(haarcascadeFilePathStr)) {
+ LOGE("Loading Haarcascade failed");
+ return MEDIA_VISION_ERROR_INVALID_PARAMETER;
+ }
std::vector<cv::Rect> faceLocations;
if (!faceDetector.detectFaces(image, roi, minSize, faceLocations)) {