auto_zoom: optimize auto zoom service 27/314227/6
authorInki Dae <inki.dae@samsung.com>
Tue, 9 Jul 2024 05:19:00 +0000 (14:19 +0900)
committerInki Dae <inki.dae@samsung.com>
Tue, 9 Jul 2024 23:20:45 +0000 (08:20 +0900)
Optimize auto zoom service by
- making RGB image data to be used for GL texture and then dropping
  color space conversion work.
- skipping postprocessing if the zoom-in/out isn't needed.

Change-Id: I624380bdeea7d6dea626a31c85bec249b219603e
Signed-off-by: Inki Dae <inki.dae@samsung.com>
services/auto_zoom/include/Postprocessor.h
services/auto_zoom/src/AutoZoom.cpp
services/auto_zoom/src/Postprocessor.cpp
test/services/test_autozoom_on_screen.cpp
visualizer/src/singleo_util_render_2d.cpp
visualizer/src/singleo_util_visualizer_2d.cpp

index 59124c56d227fe1e9a1c6072a04e9206b1d4b798..d157c8e7963195f48f3a2d875d6c21acb80d55d4 100644 (file)
@@ -53,7 +53,6 @@ private:
        const double _zoom_in_step { 0.02 };
        const double _zoom_out_step { 0.1 };
        const unsigned int _max_loss_cnt { 60 };
-       bool _is_working { false };
        bool _detected { false };
        cv::Point2f _center {};
 
@@ -70,7 +69,12 @@ public:
 
        bool isWorking() override
        {
-               return _is_working;
+               // Invoke the postprocessing if face is detected or zoom scale value is same as min zoom scale(default value).
+               // if zoom scale is different from min zoom scale then it means that we are under the postprocessing.
+               if (_detected || _zoom_scale != _min_zoom_scale)
+                       return true;
+
+               return false;
        }
 };
 
index 8e2f1d5e1e09d7c6ec4b9149bd7c0b0f6019c70b..46241dae6ee723944862198b5ad74c55d6bdebeb 100644 (file)
@@ -164,8 +164,8 @@ void AutoZoom::inputFeedCb(BaseDataType &data)
        copied->is_owned = false;
 
        if (_user_cb) {
-               // if postprocessor isn't in progress, postprocess current camera preview image.
-               if (!_postprocessor->isWorking()) {
+               // if postprocessor is in progress, postprocess current camera preview image.
+               if (_postprocessor->isWorking()) {
                        ImageDataType zoom_data = dynamic_cast<ImageDataType &>(_postprocessor->getOutput(*copied));
 
                        _user_cb(zoom_data.ptr, zoom_data.width, zoom_data.height, zoom_data.byte_per_pixel, _user_data);
index c739108108daa55cab379eb7062a5f596b37b42c..0e0dc6731080eb8756fb47aff8f8495545cc1c42 100644 (file)
@@ -108,10 +108,8 @@ BaseDataType &Postprocessor::getOutput(BaseDataType &data)
        ImageDataType &image_data = dynamic_cast<ImageDataType &>(data);
 
        cv::Mat cv_image(cv::Size(image_data.width, image_data.height), CV_MAKETYPE(CV_8U, 3), image_data.ptr);
-       cv::cvtColor(cv_image, cv_image, cv::COLOR_BGR2RGBA);
 
        std::lock_guard<std::mutex> lock(_mutex);
-       _is_working = true;
 
        // If detection loss has happended for 2 seconds - 60 is 30fps * 2 - while in maximum zoom-in
        // then change the current state to zoom-out.
@@ -145,8 +143,6 @@ BaseDataType &Postprocessor::getOutput(BaseDataType &data)
 
        adjustPreview(cv_image, _cv_image);
 
-       _is_working = false;
-
        _image_data.width = _cv_image.cols;
        _image_data.height = _cv_image.rows;
        _image_data.byte_per_pixel = _cv_image.channels();
index cc2e4109df0279fa027aa4d028caf448853453cc..d031cb99913eb81c8b2c5fc39ab34fa7eb2f4d1c 100644 (file)
@@ -56,7 +56,9 @@ void autozoom_callback(void *user_data)
 void user_callback(unsigned char *buffer, unsigned int width, unsigned int height, unsigned int bytes_per_pixel,
                                   void *user_data)
 {
-       cv::Mat result(cv::Size(width, height), CV_MAKETYPE(CV_8U, 4), buffer);
+       cv::Mat result(cv::Size(width, height), CV_MAKETYPE(CV_8U, 3), buffer);
+
+       cv::cvtColor(result, result, cv::COLOR_BGR2RGB);
 
        singleo_util_visualizer_2d(result, NULL);
 }
index c6a44c420a88f22b808bc0baf166de3f9190f71b..9a41b104978fe19c14b94fd61dbc0734f500b7ac 100644 (file)
@@ -203,7 +203,7 @@ GLuint create_2d_texture(void *imgbuf, int width, int height)
 
        glPixelStorei(GL_UNPACK_ALIGNMENT, 4);
 
-       glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, imgbuf);
+       glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, width, height, 0, GL_RGB, GL_UNSIGNED_BYTE, imgbuf);
 
        return texid;
 }
@@ -574,9 +574,6 @@ int draw_2d_texture(texture_2d_t *tex, int x, int y, int w, int h, int upsidedow
        tparam.color[3] = 1.0f;
        tparam.upsidedown = upsidedown;
 
-       if (tex->format == pixfmt_fourcc('Y', 'U', 'Y', 'V'))
-               tparam.textype = 4;
-
        draw_2d_texture_in(&tparam);
 
        return SINGLEO_ERROR_NONE;
index a9531e2126bb9fa2170432db3cf462c58caff14e..619d69f0d2169d59a8ab572126a6b53464fe4d28 100644 (file)
@@ -39,8 +39,6 @@ public:
 
        void DrawImage(cv::Mat &source)
        {
-               cv::cvtColor(source, source, cv::COLOR_RGBA2BGR);
-
                std::vector<int> qualityType;
                std::vector<uchar> buff;
                qualityType.push_back(cv::IMWRITE_JPEG_QUALITY);
@@ -121,7 +119,7 @@ int singleo_util_visualizer_2d(cv::Mat &source, const char *url)
        captex.texid = texid;
        captex.width = texw;
        captex.height = texh;
-       captex.format = pixfmt_fourcc('R', 'G', 'B', 'A');
+       captex.format = pixfmt_fourcc('R', 'G', 'B', '3');
 
        float scale = (float) win_h / (float) texh;