Migration to OpenCV 3.4.1 16/181916/1 accepted/tizen/unified/20180621.141332 submit/tizen/20180620.034203 submit/tizen/20180620.084620
authorTae-Young Chung <ty83.chung@samsung.com>
Tue, 5 Jun 2018 01:17:51 +0000 (10:17 +0900)
committerTae-Young Chung <ty83.chung@samsung.com>
Tue, 19 Jun 2018 03:57:37 +0000 (12:57 +0900)
imgcv has dependency to OpenCV which is upgraded to 3.4.1.
This is a patch for Migration to OpenCV 3.4.1.

Change-Id: I19c988f222c606f3d5084b8b046235c360f1e2dc
Signed-off-by: Tae-Young Chung <ty83.chung@samsung.com>
common/include/mm_util_debug.h
imgcv/CMakeLists.txt
imgcv/include/mm_util_imgcv_internal.h
imgcv/mm_util_imgcv.c [deleted file]
imgcv/mm_util_imgcv.cpp [new file with mode: 0755]
imgcv/test/mm_util_imgcv_testsuite.c
packaging/libmm-utility.spec

index 0ef1599a3167495df9edeee02436d660afb03865..b98ec902e3c66f5f1914fddb0cd20b418fef679d 100755 (executable)
@@ -41,23 +41,23 @@ extern "C"
 #define FONT_COLOR_CYAN     "\033[36m"
 
 #define mm_util_debug(fmt, arg...) do { \
-               LOGD(FONT_COLOR_RESET""fmt"", ##arg);     \
+               LOGD(FONT_COLOR_RESET#fmt, ##arg);     \
        } while (0)
 
 #define mm_util_info(fmt, arg...) do { \
-               LOGI(FONT_COLOR_RESET""fmt"", ##arg);     \
+               LOGI(FONT_COLOR_RESET#fmt, ##arg);     \
        } while (0)
 
 #define mm_util_warn(fmt, arg...) do { \
-               LOGW(FONT_COLOR_RESET""fmt"", ##arg);     \
+               LOGW(FONT_COLOR_RESET#fmt, ##arg);     \
        } while (0)
 
 #define mm_util_error(fmt, arg...) do { \
-               LOGE(FONT_COLOR_RED""fmt""FONT_COLOR_RESET, ##arg);     \
+               LOGE(FONT_COLOR_RED#fmt FONT_COLOR_RESET, ##arg);     \
        } while (0)
 
 #define mm_util_sec_debug(fmt, arg...) do { \
-               SECURE_LOGD(FONT_COLOR_CYAN""fmt""FONT_COLOR_RESET, ##arg);     \
+               SECURE_LOGD(FONT_COLOR_CYAN#fmt FONT_COLOR_RESET, ##arg);     \
        } while (0)
 
 #define mm_util_fenter() do { \
@@ -70,14 +70,14 @@ extern "C"
 
 #define mm_util_retm_if(expr, fmt, arg...) do { \
                if (expr) { \
-                       LOGE(FONT_COLOR_RED""fmt""FONT_COLOR_RESET, ##arg);     \
+                       LOGE(FONT_COLOR_RED#fmt FONT_COLOR_RESET, ##arg);     \
                        return; \
                } \
        } while (0)
 
 #define mm_util_retvm_if(expr, val, fmt, arg...) do { \
                if (expr) { \
-                       LOGE(FONT_COLOR_RED""fmt""FONT_COLOR_RESET, ##arg);     \
+                       LOGE(FONT_COLOR_RED#fmt FONT_COLOR_RESET, ##arg);     \
                        return (val); \
                } \
        } while (0)
@@ -86,7 +86,7 @@ extern "C"
 #define mm_util_stderror(fmt) do { \
                char buf[ERR_BUF_LENGHT] = {0,}; \
                strerror_r(errno, buf, ERR_BUF_LENGHT); \
-               mm_util_error(fmt" : standard error= [%s]", buf); \
+               mm_util_error(#fmt" : standard error= [%s]", buf); \
        } while (0)
 
 /**
index dbc991961e375e8bf4566f58d36d601269c63e5b..39a4288487218902e301e46ecc5a9b7912aee6b4 100755 (executable)
@@ -23,10 +23,13 @@ INCLUDE(FindPkgConfig)
 pkg_check_modules(${fw_name} REQUIRED ${dependents})
 FOREACH(flag ${${fw_name}_CFLAGS})
     SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}")
+    SET(EXTRA_CXXFLAGS "${EXTRA_CXXFLAGS} ${flag}")
 ENDFOREACH(flag)
 
 SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_CFLAGS} -fPIC -Wall -Werror")
 SET(CMAKE_C_FLAGS_DEBUG "-O0 -g")
+SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${EXTRA_CXXFLAGS} -fPIC")
+SET(CMAKE_CXX_FLAGS_DEBUG "-O0 -g --w")
 
 IF("${ARCH}" STREQUAL "arm")
     ADD_DEFINITIONS("-DTARGET")
index edd9fee08380fa43d6ee3a43ec98b5a0eb69d3af..1682cd421c15c6fa2a16a1f58b12036beb91355a 100755 (executable)
 
 #include <stdio.h>
 #include <string.h>
+#include <opencv2/core.hpp>
+#include <opencv2/imgproc.hpp>
 
 #ifdef __cplusplus
        extern "C" {
 #endif
 
-#include <opencv/cv.h>
-#include <opencv2/imgproc/imgproc_c.h>
 
 typedef struct _mm_util_imgcv_s {
        IplImage *inImg;
diff --git a/imgcv/mm_util_imgcv.c b/imgcv/mm_util_imgcv.c
deleted file mode 100755 (executable)
index 2667a8c..0000000
+++ /dev/null
@@ -1,249 +0,0 @@
-/*
- * libmm-utility
- *
- * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
- *
- * Contact: YoungHun Kim <yh8004.kim@samsung.com>
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-#include <limits.h>
-#include <math.h>
-#include "mm_util_private.h"
-#include "mm_util_imgcv.h"
-#include "mm_util_imgcv_internal.h"
-
-#define RGB_COLOR_CHANNELS 3
-#define HSV_COLOR_CHANNELS 3
-
-#define HISTOGRAM_CHANNELS 3
-#define DEFAULT_NUM_HBINS 30
-#define DEFAULT_NUM_SBINS 32
-#define DEFAULT_NUM_VBINS 30
-
-#define DEFAULT_RANGE_HUE 180
-#define DEFAULT_RANGE_SATURATION 256
-#define DEFAULT_RANGE_VALUE 256
-
-static int _mm_util_imgcv_init(mm_util_imgcv_s *handle, int width, int height)
-{
-       mm_util_fenter();
-
-       handle->width = width;
-       handle->height = height;
-
-       handle->inImg = cvCreateImageHeader(cvSize(width, height), IPL_DEPTH_8U, RGB_COLOR_CHANNELS);
-       if (handle->inImg == NULL)
-               return MM_UTIL_ERROR_INVALID_OPERATION;
-
-       handle->hBins = DEFAULT_NUM_HBINS;
-       handle->sBins = DEFAULT_NUM_SBINS;
-       handle->vBins = DEFAULT_NUM_VBINS;
-
-       handle->sizeOfHist[0] = handle->hBins;
-       handle->sizeOfHist[1] = handle->sBins;
-       handle->sizeOfHist[2] = handle->vBins;
-
-       handle->hRanges[0] = 0;
-       handle->hRanges[1] = DEFAULT_RANGE_HUE;
-       handle->sRanges[0] = 0;
-       handle->sRanges[1] = DEFAULT_RANGE_SATURATION;
-       handle->vRanges[0] = 0;
-       handle->vRanges[1] = DEFAULT_RANGE_VALUE;
-
-       mm_util_fleave();
-
-       return MM_UTIL_ERROR_NONE;
-}
-
-static void _mm_util_imgcv_uninit(mm_util_imgcv_s *handle)
-{
-       mm_util_fenter();
-
-       if (handle->inImg != NULL) {
-               cvReleaseImageHeader(&handle->inImg);
-               handle->inImg = NULL;
-       }
-
-       mm_util_fleave();
-}
-
-static int _mm_util_imgcv_set_buffer(mm_util_imgcv_s *handle, void *image_buffer)
-{
-       mm_util_fenter();
-
-       unsigned char *buffer = (unsigned char *)image_buffer;
-
-       mm_util_debug("image_buffer [%p], width [%d]", buffer, handle->width);
-
-       cvSetData(handle->inImg, buffer, RGB_COLOR_CHANNELS*(handle->width));
-       if (handle->inImg == NULL)
-               return  MM_UTIL_ERROR_INVALID_OPERATION;
-
-       mm_util_fleave();
-
-       return MM_UTIL_ERROR_NONE;
-}
-
-static void _convert_hsv_to_rgb(int hVal, int sVal, int vVal, float *rVal, float *gVal, float *bVal)
-{
-       mm_util_fenter();
-
-       CvMat *mat1 = cvCreateMat(1, 1 , CV_8UC3);
-       cvSet2D(mat1, 0, 0, cvScalar((double)hVal, (double)sVal, (double)vVal, 0.0));
-
-       CvMat *mat2 = cvCreateMat(1, 1, CV_8UC3);
-
-       cvCvtColor(mat1, mat2, CV_HSV2BGR);
-
-       CvScalar bgr = cvGet2D(mat2, 0, 0);
-       *bVal = (float)bgr.val[0];
-       *gVal = (float)bgr.val[1];
-       *rVal = (float)bgr.val[2];
-
-       mm_util_debug("from HSV[%f, %f, %f]", (float)hVal, (float)sVal, (float)vVal);
-       mm_util_debug("to BGR[%f, %f, %f]", *bVal, *gVal, *rVal);
-
-}
-
-static int _mm_util_imgcv_calculate_hist(mm_util_imgcv_s *handle, unsigned char *rgb_r, unsigned char *rgb_g, unsigned char *rgb_b)
-{
-       int nh = 0;
-       int ns = 0;
-       int nv = 0;
-
-       int hVal = 0;
-       int sVal = 0;
-       int vVal = 0;
-
-       float rVal = 0.f;
-       float gVal = 0.f;
-       float bVal = 0.f;
-
-       unsigned int maxBinVal = 0;
-       int max_bin_idx[3] = {-1, -1, -1};
-
-       mm_util_fenter();
-
-       IplImage *hsvImg = cvCreateImage(cvSize(handle->width, handle->height), IPL_DEPTH_8U, HSV_COLOR_CHANNELS);
-       IplImage *hImg = cvCreateImage(cvSize(handle->width, handle->height), IPL_DEPTH_8U, 1);
-       IplImage *sImg = cvCreateImage(cvSize(handle->width, handle->height), IPL_DEPTH_8U, 1);
-       IplImage *vImg = cvCreateImage(cvSize(handle->width, handle->height), IPL_DEPTH_8U, 1);
-
-       if (!hsvImg || !hImg || !sImg || !vImg) {
-               mm_util_error("fail to cvCreateImage()");
-               return MM_UTIL_ERROR_INVALID_OPERATION;
-       }
-
-       IplImage *planes[] = {hImg, sImg, vImg};
-
-       cvCvtColor(handle->inImg, hsvImg, CV_RGB2HSV);
-       cvSplit(hsvImg, hImg, sImg, vImg, NULL);
-
-       float *ranges[] = {handle->hRanges, handle->sRanges, handle->vRanges};
-       int histsize[] = {handle->sizeOfHist[0], handle->sizeOfHist[1], handle->sizeOfHist[2]};
-
-       /* create histogram*/
-       CvHistogram *hist = cvCreateHist(HISTOGRAM_CHANNELS, histsize, CV_HIST_ARRAY, ranges, 1);
-       if (hist == NULL)
-               return MM_UTIL_ERROR_INVALID_OPERATION;
-
-       cvCalcHist(planes, hist, 0, NULL);
-
-       for (nh = 0; nh < (handle->hBins); nh++) {
-               for (ns = 0; ns < (handle->sBins); ns++) {
-                       for (nv = 0; nv < (handle->vBins); nv++) {
-                               unsigned int binVal = (unsigned int)cvGetReal3D((hist)->bins, nh, ns, nv);
-                               if (binVal > maxBinVal) {
-                                       maxBinVal = binVal;
-                                       max_bin_idx[0] = nh;
-                                       max_bin_idx[1] = ns;
-                                       max_bin_idx[2] = nv;
-                               }
-                       }
-               }
-       }
-
-       rVal = gVal = bVal = 0.0f;
-       hVal = cvRound((max_bin_idx[0]+1)*(handle->hRanges[1]/(float)handle->hBins));
-       sVal = cvRound((max_bin_idx[1]+1)*(handle->sRanges[1]/(float)handle->sBins));
-       vVal = cvRound((max_bin_idx[2]+1)*(handle->vRanges[1]/(float)handle->vBins));
-
-       _convert_hsv_to_rgb(hVal, sVal, vVal, &rVal, &gVal, &bVal);
-
-       mm_util_debug("nh[%d], ns[%d], nv[%d]", max_bin_idx[0], max_bin_idx[1], max_bin_idx[2]);
-       mm_util_debug("h[%d], s[%d], v[%d]", hVal, sVal, vVal);
-       *rgb_r = rVal;
-       *rgb_g = gVal;
-       *rgb_b = bVal;
-
-       cvReleaseImage(&hsvImg);
-       cvReleaseImage(&hImg);
-       cvReleaseImage(&sImg);
-       cvReleaseImage(&vImg);
-
-       cvReleaseHist(&hist);
-
-       mm_util_fleave();
-
-       return MM_UTIL_ERROR_NONE;
-}
-
-int mm_util_cv_extract_representative_color(void *image_buffer, int width, int height, unsigned char *r_color, unsigned char *g_color, unsigned char *b_color)
-{
-       mm_util_fenter();
-
-       if (image_buffer == NULL) {
-               mm_util_error("#ERROR#: image buffer is NULL");
-               return MM_UTIL_ERROR_INVALID_PARAMETER;
-       }
-
-       mm_util_imgcv_s *handle = (mm_util_imgcv_s *)calloc(1, sizeof(mm_util_imgcv_s));
-       if (handle == NULL) {
-               mm_util_error("#ERROR#: fail to create handle");
-               return MM_UTIL_ERROR_OUT_OF_MEMORY;
-       }
-
-       int ret = _mm_util_imgcv_init(handle, width, height);
-       if (ret != MM_UTIL_ERROR_NONE) {
-               _mm_util_imgcv_uninit(handle);
-               MMUTIL_SAFE_FREE(handle);
-               mm_util_error("#ERROR#: Fail to mm_util_imgcv_init: ret=%d", ret);
-               return ret;
-       }
-
-       ret = _mm_util_imgcv_set_buffer(handle, image_buffer);
-       if (ret != MM_UTIL_ERROR_NONE) {
-               _mm_util_imgcv_uninit(handle);
-               MMUTIL_SAFE_FREE(handle);
-               mm_util_error("#ERROR#: Fail to mm_util_imgcv_set_buffer: ret=%d", ret);
-               return ret;
-       }
-
-       ret = _mm_util_imgcv_calculate_hist(handle, r_color, g_color, b_color);
-       if (ret != MM_UTIL_ERROR_NONE) {
-               _mm_util_imgcv_uninit(handle);
-               MMUTIL_SAFE_FREE(handle);
-               mm_util_error("#ERROR#: Fail to mm_util_imgcv_calculate_hist: ret=%d", ret);
-               return ret;
-       }
-
-       _mm_util_imgcv_uninit(handle);
-
-       MMUTIL_SAFE_FREE(handle);
-
-       mm_util_fleave();
-
-       return MM_UTIL_ERROR_NONE;
-}
diff --git a/imgcv/mm_util_imgcv.cpp b/imgcv/mm_util_imgcv.cpp
new file mode 100755 (executable)
index 0000000..2667a8c
--- /dev/null
@@ -0,0 +1,249 @@
+/*
+ * libmm-utility
+ *
+ * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact: YoungHun Kim <yh8004.kim@samsung.com>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+#include <limits.h>
+#include <math.h>
+#include "mm_util_private.h"
+#include "mm_util_imgcv.h"
+#include "mm_util_imgcv_internal.h"
+
+#define RGB_COLOR_CHANNELS 3
+#define HSV_COLOR_CHANNELS 3
+
+#define HISTOGRAM_CHANNELS 3
+#define DEFAULT_NUM_HBINS 30
+#define DEFAULT_NUM_SBINS 32
+#define DEFAULT_NUM_VBINS 30
+
+#define DEFAULT_RANGE_HUE 180
+#define DEFAULT_RANGE_SATURATION 256
+#define DEFAULT_RANGE_VALUE 256
+
+static int _mm_util_imgcv_init(mm_util_imgcv_s *handle, int width, int height)
+{
+       mm_util_fenter();
+
+       handle->width = width;
+       handle->height = height;
+
+       handle->inImg = cvCreateImageHeader(cvSize(width, height), IPL_DEPTH_8U, RGB_COLOR_CHANNELS);
+       if (handle->inImg == NULL)
+               return MM_UTIL_ERROR_INVALID_OPERATION;
+
+       handle->hBins = DEFAULT_NUM_HBINS;
+       handle->sBins = DEFAULT_NUM_SBINS;
+       handle->vBins = DEFAULT_NUM_VBINS;
+
+       handle->sizeOfHist[0] = handle->hBins;
+       handle->sizeOfHist[1] = handle->sBins;
+       handle->sizeOfHist[2] = handle->vBins;
+
+       handle->hRanges[0] = 0;
+       handle->hRanges[1] = DEFAULT_RANGE_HUE;
+       handle->sRanges[0] = 0;
+       handle->sRanges[1] = DEFAULT_RANGE_SATURATION;
+       handle->vRanges[0] = 0;
+       handle->vRanges[1] = DEFAULT_RANGE_VALUE;
+
+       mm_util_fleave();
+
+       return MM_UTIL_ERROR_NONE;
+}
+
+static void _mm_util_imgcv_uninit(mm_util_imgcv_s *handle)
+{
+       mm_util_fenter();
+
+       if (handle->inImg != NULL) {
+               cvReleaseImageHeader(&handle->inImg);
+               handle->inImg = NULL;
+       }
+
+       mm_util_fleave();
+}
+
+static int _mm_util_imgcv_set_buffer(mm_util_imgcv_s *handle, void *image_buffer)
+{
+       mm_util_fenter();
+
+       unsigned char *buffer = (unsigned char *)image_buffer;
+
+       mm_util_debug("image_buffer [%p], width [%d]", buffer, handle->width);
+
+       cvSetData(handle->inImg, buffer, RGB_COLOR_CHANNELS*(handle->width));
+       if (handle->inImg == NULL)
+               return  MM_UTIL_ERROR_INVALID_OPERATION;
+
+       mm_util_fleave();
+
+       return MM_UTIL_ERROR_NONE;
+}
+
+static void _convert_hsv_to_rgb(int hVal, int sVal, int vVal, float *rVal, float *gVal, float *bVal)
+{
+       mm_util_fenter();
+
+       CvMat *mat1 = cvCreateMat(1, 1 , CV_8UC3);
+       cvSet2D(mat1, 0, 0, cvScalar((double)hVal, (double)sVal, (double)vVal, 0.0));
+
+       CvMat *mat2 = cvCreateMat(1, 1, CV_8UC3);
+
+       cvCvtColor(mat1, mat2, CV_HSV2BGR);
+
+       CvScalar bgr = cvGet2D(mat2, 0, 0);
+       *bVal = (float)bgr.val[0];
+       *gVal = (float)bgr.val[1];
+       *rVal = (float)bgr.val[2];
+
+       mm_util_debug("from HSV[%f, %f, %f]", (float)hVal, (float)sVal, (float)vVal);
+       mm_util_debug("to BGR[%f, %f, %f]", *bVal, *gVal, *rVal);
+
+}
+
+static int _mm_util_imgcv_calculate_hist(mm_util_imgcv_s *handle, unsigned char *rgb_r, unsigned char *rgb_g, unsigned char *rgb_b)
+{
+       int nh = 0;
+       int ns = 0;
+       int nv = 0;
+
+       int hVal = 0;
+       int sVal = 0;
+       int vVal = 0;
+
+       float rVal = 0.f;
+       float gVal = 0.f;
+       float bVal = 0.f;
+
+       unsigned int maxBinVal = 0;
+       int max_bin_idx[3] = {-1, -1, -1};
+
+       mm_util_fenter();
+
+       IplImage *hsvImg = cvCreateImage(cvSize(handle->width, handle->height), IPL_DEPTH_8U, HSV_COLOR_CHANNELS);
+       IplImage *hImg = cvCreateImage(cvSize(handle->width, handle->height), IPL_DEPTH_8U, 1);
+       IplImage *sImg = cvCreateImage(cvSize(handle->width, handle->height), IPL_DEPTH_8U, 1);
+       IplImage *vImg = cvCreateImage(cvSize(handle->width, handle->height), IPL_DEPTH_8U, 1);
+
+       if (!hsvImg || !hImg || !sImg || !vImg) {
+               mm_util_error("fail to cvCreateImage()");
+               return MM_UTIL_ERROR_INVALID_OPERATION;
+       }
+
+       IplImage *planes[] = {hImg, sImg, vImg};
+
+       cvCvtColor(handle->inImg, hsvImg, CV_RGB2HSV);
+       cvSplit(hsvImg, hImg, sImg, vImg, NULL);
+
+       float *ranges[] = {handle->hRanges, handle->sRanges, handle->vRanges};
+       int histsize[] = {handle->sizeOfHist[0], handle->sizeOfHist[1], handle->sizeOfHist[2]};
+
+       /* create histogram*/
+       CvHistogram *hist = cvCreateHist(HISTOGRAM_CHANNELS, histsize, CV_HIST_ARRAY, ranges, 1);
+       if (hist == NULL)
+               return MM_UTIL_ERROR_INVALID_OPERATION;
+
+       cvCalcHist(planes, hist, 0, NULL);
+
+       for (nh = 0; nh < (handle->hBins); nh++) {
+               for (ns = 0; ns < (handle->sBins); ns++) {
+                       for (nv = 0; nv < (handle->vBins); nv++) {
+                               unsigned int binVal = (unsigned int)cvGetReal3D((hist)->bins, nh, ns, nv);
+                               if (binVal > maxBinVal) {
+                                       maxBinVal = binVal;
+                                       max_bin_idx[0] = nh;
+                                       max_bin_idx[1] = ns;
+                                       max_bin_idx[2] = nv;
+                               }
+                       }
+               }
+       }
+
+       rVal = gVal = bVal = 0.0f;
+       hVal = cvRound((max_bin_idx[0]+1)*(handle->hRanges[1]/(float)handle->hBins));
+       sVal = cvRound((max_bin_idx[1]+1)*(handle->sRanges[1]/(float)handle->sBins));
+       vVal = cvRound((max_bin_idx[2]+1)*(handle->vRanges[1]/(float)handle->vBins));
+
+       _convert_hsv_to_rgb(hVal, sVal, vVal, &rVal, &gVal, &bVal);
+
+       mm_util_debug("nh[%d], ns[%d], nv[%d]", max_bin_idx[0], max_bin_idx[1], max_bin_idx[2]);
+       mm_util_debug("h[%d], s[%d], v[%d]", hVal, sVal, vVal);
+       *rgb_r = rVal;
+       *rgb_g = gVal;
+       *rgb_b = bVal;
+
+       cvReleaseImage(&hsvImg);
+       cvReleaseImage(&hImg);
+       cvReleaseImage(&sImg);
+       cvReleaseImage(&vImg);
+
+       cvReleaseHist(&hist);
+
+       mm_util_fleave();
+
+       return MM_UTIL_ERROR_NONE;
+}
+
+int mm_util_cv_extract_representative_color(void *image_buffer, int width, int height, unsigned char *r_color, unsigned char *g_color, unsigned char *b_color)
+{
+       mm_util_fenter();
+
+       if (image_buffer == NULL) {
+               mm_util_error("#ERROR#: image buffer is NULL");
+               return MM_UTIL_ERROR_INVALID_PARAMETER;
+       }
+
+       mm_util_imgcv_s *handle = (mm_util_imgcv_s *)calloc(1, sizeof(mm_util_imgcv_s));
+       if (handle == NULL) {
+               mm_util_error("#ERROR#: fail to create handle");
+               return MM_UTIL_ERROR_OUT_OF_MEMORY;
+       }
+
+       int ret = _mm_util_imgcv_init(handle, width, height);
+       if (ret != MM_UTIL_ERROR_NONE) {
+               _mm_util_imgcv_uninit(handle);
+               MMUTIL_SAFE_FREE(handle);
+               mm_util_error("#ERROR#: Fail to mm_util_imgcv_init: ret=%d", ret);
+               return ret;
+       }
+
+       ret = _mm_util_imgcv_set_buffer(handle, image_buffer);
+       if (ret != MM_UTIL_ERROR_NONE) {
+               _mm_util_imgcv_uninit(handle);
+               MMUTIL_SAFE_FREE(handle);
+               mm_util_error("#ERROR#: Fail to mm_util_imgcv_set_buffer: ret=%d", ret);
+               return ret;
+       }
+
+       ret = _mm_util_imgcv_calculate_hist(handle, r_color, g_color, b_color);
+       if (ret != MM_UTIL_ERROR_NONE) {
+               _mm_util_imgcv_uninit(handle);
+               MMUTIL_SAFE_FREE(handle);
+               mm_util_error("#ERROR#: Fail to mm_util_imgcv_calculate_hist: ret=%d", ret);
+               return ret;
+       }
+
+       _mm_util_imgcv_uninit(handle);
+
+       MMUTIL_SAFE_FREE(handle);
+
+       mm_util_fleave();
+
+       return MM_UTIL_ERROR_NONE;
+}
index 89623af6e7f07e809eebe7169679065d9463ea50..fced574008e4d568a4e77a9c5063615ee62282c3 100755 (executable)
  *
  */
 #include <stdio.h>
+#include <stdlib.h>
 #include <string.h>
 
 #include <mm_util_jpeg.h>
 #include <mm_util_imgcv.h>
-#include <mm_util_imgcv_internal.h>
 
 #define MAX_FILENAME_LEN 1024
 
index e1663346803df6b0973ad0ca7b964b43c339e038..493e2a4dbf83c0a1b15ed702c9384d92e5198515 100755 (executable)
@@ -1,6 +1,6 @@
 Name:       libmm-utility
 Summary:    Multimedia Framework Utility Library
-Version:    0.1.23
+Version:    0.1.24
 Release:    0
 Group:      System/Libraries
 License:    Apache-2.0
@@ -17,7 +17,7 @@ BuildRequires:  pkgconfig(gio-2.0)
 BuildRequires:  pkgconfig(gmodule-2.0)
 BuildRequires:  libjpeg-turbo-devel
 BuildRequires:  pkgconfig(libtzplatform-config)
-BuildRequires:  pkgconfig(opencv)
+BuildRequires:  pkgconfig(opencv) >= 3.4.1
 BuildRequires:  pkgconfig(libpng)
 BuildRequires:  giflib-devel
 BuildRequires:  pkgconfig(libbmp)