Fix fluid resize operating with zero output size
authorSmirnov Alexey <alexey.smirnov@intel.com>
Wed, 6 May 2020 13:43:06 +0000 (16:43 +0300)
committerSmirnov Alexey <alexey.smirnov@intel.com>
Thu, 7 May 2020 09:24:57 +0000 (12:24 +0300)
modules/gapi/include/opencv2/gapi/core.hpp
modules/gapi/src/backends/fluid/gfluidcore.cpp
modules/gapi/test/cpu/gapi_core_tests_fluid.cpp

index 00400a8..9e765f6 100644 (file)
@@ -392,10 +392,10 @@ namespace core {
             }
             else
             {
-                GAPI_Assert(fx != 0. && fy != 0.);
-                return in.withSize
-                    (Size(static_cast<int>(round(in.size.width  * fx)),
-                          static_cast<int>(round(in.size.height * fy))));
+                int outSz_w = static_cast<int>(round(in.size.width  * fx));
+                int outSz_h = static_cast<int>(round(in.size.height * fy));
+                GAPI_Assert(outSz_w > 0 && outSz_h > 0);
+                return in.withSize(Size(outSz_w, outSz_h));
             }
         }
     };
index 01b9be8..af9d6ec 100644 (file)
@@ -2030,10 +2030,16 @@ GAPI_FLUID_KERNEL(GFluidResize, cv::gapi::core::GResize, true)
     }
 
     static void initScratch(const cv::GMatDesc& in,
-                            cv::Size outSz, double /*fx*/, double /*fy*/, int /*interp*/,
+                            cv::Size outSz, double fx, double fy, int /*interp*/,
                             cv::gapi::fluid::Buffer &scratch)
     {
-        CV_Assert(in.depth == CV_8U && in.chan == 3);
+        GAPI_Assert(in.depth == CV_8U && in.chan == 3);
+
+        if (outSz.area() == 0)
+        {
+            outSz.width  = static_cast<int>(round(in.size.width  * fx));
+            outSz.height = static_cast<int>(round(in.size.height * fy));
+        }
 
         cv::Size scratch_size{static_cast<int>(outSz.width * sizeof(ResizeUnit)), 1};
 
index 8456ec6..da2b986 100644 (file)
@@ -354,6 +354,20 @@ INSTANTIATE_TEST_CASE_P(ResizeTestFluid, ResizeTest,
                                        cv::Size(64, 64),
                                        cv::Size(30, 30))));
 
+INSTANTIATE_TEST_CASE_P(ResizeTestFxFyFluid, ResizeTestFxFy,
+                        Combine(Values(CV_8UC3/*CV_8UC1, CV_16UC1, CV_16SC1*/),
+                                Values(cv::Size(1280, 720),
+                                       cv::Size(640, 480),
+                                       cv::Size(128, 128),
+                                       cv::Size(64, 64),
+                                       cv::Size(30, 30)),
+                                Values(-1),
+                                Values(CORE_FLUID),
+                                Values(AbsExact().to_compare_obj()),
+                                Values(/*cv::INTER_NEAREST,*/ cv::INTER_LINEAR/*, cv::INTER_AREA*/),
+                                Values(0.5, 1, 2),
+                                Values(0.5, 1, 2)));
+
 INSTANTIATE_TEST_CASE_P(BackendOutputAllocationTestFluid, BackendOutputAllocationTest,
                         Combine(Values(CV_8UC3, CV_16SC2, CV_32FC1),
                                 Values(cv::Size(50, 50)),