Add codes handling exception thrown by OpenCV 89/188989/1 accepted/tizen/5.0/unified/20181102.013603 accepted/tizen/unified/20180913.063950 accepted/tizen/unified/20180913.064039 submit/tizen/20180912.094346 submit/tizen/20180913.015906 submit/tizen_5.0/20181101.000002
authorTae-Young Chung <ty83.chung@samsung.com>
Wed, 12 Sep 2018 09:01:03 +0000 (18:01 +0900)
committerTae-Young Chung <ty83.chung@samsung.com>
Wed, 12 Sep 2018 09:01:09 +0000 (18:01 +0900)
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 <ty83.chung@samsung.com>
mv_face/face/src/FaceDetector.cpp
mv_face/face/src/mv_face_open.cpp
packaging/capi-media-vision.spec

index 9ce2bbe..11d4043 100644 (file)
@@ -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) {
index 56571cb..443fd71 100644 (file)
@@ -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;
index 0724a00..44d163e 100644 (file)
@@ -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