From ab7be7309241c6eef537bc2218efd4d67557de0b Mon Sep 17 00:00:00 2001 From: Tae-Young Chung Date: Wed, 12 Sep 2018 18:01:03 +0900 Subject: [PATCH] Add codes handling exception thrown by OpenCV In the worst case, the memory size over the limitation is required and then OutOfMemory exception is thrown, resulting crash. This patch handles the exception and prevents crash. Change-Id: Ie9bb0346cf53bc59d8a9da7e4758c2011cda9f1e Signed-off-by: Tae-Young Chung --- mv_face/face/src/FaceDetector.cpp | 8 +++----- mv_face/face/src/mv_face_open.cpp | 14 +++++++++++--- packaging/capi-media-vision.spec | 4 ++-- 3 files changed, 16 insertions(+), 10 deletions(-) diff --git a/mv_face/face/src/FaceDetector.cpp b/mv_face/face/src/FaceDetector.cpp index 9ce2bbe..11d4043 100644 --- a/mv_face/face/src/FaceDetector.cpp +++ b/mv_face/face/src/FaceDetector.cpp @@ -53,8 +53,7 @@ bool FaceDetector::detectFaces( roiIsUsed = true; } - if (minSize.width > 0 && minSize.height > 0 && - minSize.width <= image.cols && minSize.height <= image.rows) { + try { m_faceCascade.detectMultiScale( intrestingRegion, faceLocations, @@ -62,9 +61,8 @@ bool FaceDetector::detectFaces( 3, 0, minSize); - - } else { - m_faceCascade.detectMultiScale(intrestingRegion, faceLocations); + } catch (cv::Exception e) { + return false; } if (roiIsUsed) { diff --git a/mv_face/face/src/mv_face_open.cpp b/mv_face/face/src/mv_face_open.cpp index 56571cb..443fd71 100644 --- a/mv_face/face/src/mv_face_open.cpp +++ b/mv_face/face/src/mv_face_open.cpp @@ -87,11 +87,13 @@ int mv_face_detect_open( } /* default path */ - cv::Size minSize(-1, -1); + cv::Size minSize(0, 0); cv::Rect roi(-1, -1, -1, -1); std::string haarcascadeFilePathStr = "/usr/share/OpenCV/haarcascades/haarcascade_frontalface_alt2.xml"; if (engine_cfg) { + int minWidth, minHeight; + /* set face detection model */ char *haarcascadeFilepath; error = mv_engine_config_get_string_attribute_c( @@ -146,7 +148,7 @@ int mv_face_detect_open( error = mv_engine_config_get_int_attribute_c( engine_cfg, MV_FACE_DETECTION_MIN_SIZE_WIDTH, - &minSize.width); + &minWidth); if (error != MEDIA_VISION_ERROR_NONE) LOGE("Error occurred during face detection minimum width receiving." " (%i)", error); @@ -154,10 +156,16 @@ int mv_face_detect_open( error = mv_engine_config_get_int_attribute_c( engine_cfg, MV_FACE_DETECTION_MIN_SIZE_HEIGHT, - &minSize.height); + &minHeight); if (error != MEDIA_VISION_ERROR_NONE) LOGE("Error occurred during face detection minimum height receiving." " (%i)", error); + + if (minWidth > 0 && minHeight > 0 && + minWidth <= image.cols && minHeight <= image.rows) { + minSize.width = minWidth; + minSize.height = minHeight; + } } static FaceDetector faceDetector; diff --git a/packaging/capi-media-vision.spec b/packaging/capi-media-vision.spec index 0724a00..44d163e 100644 --- a/packaging/capi-media-vision.spec +++ b/packaging/capi-media-vision.spec @@ -1,7 +1,7 @@ Name: capi-media-vision Summary: Media Vision library for Tizen Native API -Version: 0.4.2 -Release: 4 +Version: 0.4.3 +Release: 5 Group: Multimedia/Framework License: Apache-2.0 and BSD-3-Clause Source0: %{name}-%{version}.tar.gz -- 2.7.4