[PP GAPI] - U16toF32 conversion kernel (#1298)
authorAnton Potapov <potapov.slash.co@gmail.com>
Thu, 6 Aug 2020 03:26:49 +0000 (06:26 +0300)
committerGitHub <noreply@github.com>
Thu, 6 Aug 2020 03:26:49 +0000 (06:26 +0300)
- the kernel itself is not yet used in the Preprocessing graph
- tests

inference-engine/src/preprocessing/ie_preprocess_gapi_kernels.cpp
inference-engine/src/preprocessing/ie_preprocess_gapi_kernels.hpp
inference-engine/tests_deprecated/fluid_preproc/common/fluid_tests.cpp
inference-engine/tests_deprecated/fluid_preproc/common/fluid_tests.hpp
inference-engine/tests_deprecated/fluid_preproc/cpu/fluid_tests_cpu.cpp
inference-engine/tests_deprecated/fluid_preproc/fluid_test_computations/fluid_test_computations.cpp
inference-engine/tests_deprecated/fluid_preproc/fluid_test_computations/fluid_test_computations.hpp

index f36c76f..f1b8e75 100644 (file)
@@ -2208,6 +2208,27 @@ GAPI_FLUID_KERNEL(FI420toRGB, I420toRGB, false) {
         calculate_i420_to_rgb_fallback(y_rows, u_row, v_row, out_rows, buf_width);
     }
 };
+
+GAPI_FLUID_KERNEL(FU16toF32, U16toF32, false) {
+    static const int Window = 1;
+
+    static void run(const cv::gapi::fluid::View& src, cv::gapi::fluid::Buffer& dst) {
+        GAPI_Assert(src.meta().depth == CV_16U);
+        GAPI_Assert(dst.meta().depth == CV_32F);
+        GAPI_Assert(src.meta().chan == 1);
+        GAPI_Assert(dst.meta().chan == 1);
+        GAPI_Assert(src.length() == dst.length());
+
+        const auto *in  = src.InLine<uint16_t>(0);
+              auto *out = dst.OutLine<float>();
+
+        auto const width = dst.length();
+        for (int i = 0; i < width; i++) {
+            out[i] = in[i];
+        }
+    }
+};
+
 }  // namespace kernels
 
 //----------------------------------------------------------------------
@@ -2234,6 +2255,7 @@ cv::gapi::GKernelPackage preprocKernels() {
         , FSplit4
         , FNV12toRGB
         , FI420toRGB
+        , FU16toF32
         >();
 }
 
index 6164e31..8caacd2 100644 (file)
@@ -143,6 +143,16 @@ namespace gapi {
         }
     };
 
+    G_TYPED_KERNEL(U16toF32, <cv::GMat(cv::GMat)>, "com.intel.ie.u16tof32") {
+        static cv::GMatDesc outMeta(const cv::GMatDesc& in) {
+            GAPI_Assert(in.depth == CV_16U);
+
+            return in.withDepth(CV_32F);
+        }
+    };
+
+
+
     cv::gapi::GKernelPackage preprocKernels();
 
 }  // namespace gapi
index 071faa6..479c3e5 100644 (file)
@@ -624,6 +624,34 @@ TEST_P(I420toRGBTestGAPI, AccuracyTest)
         EXPECT_EQ(sz, out_mat_gapi.size());
     }
 }
+
+TEST_P(U16toF32TestGAPI, AccuracyTest)
+{
+    const auto params = GetParam();
+    cv::Size sz      = std::get<0>(params);
+    double tolerance = std::get<1>(params);
+
+    initMatrixRandU(CV_16UC1, sz, CV_32FC1);
+
+    // G-API code //////////////////////////////////////////////////////////////
+    FluidU16ToF32Computation cc(to_test(in_mat1), to_test(out_mat_gapi));
+    cc.warmUp();
+
+#if PERF_TEST
+    // iterate testing, and print performance
+    test_ms([&](){ cc.apply(); },
+        400, "U16ToF32 GAPI %s %dx%d", typeToString(CV_16UC1).c_str(), sz.width, sz.height);
+#endif
+
+    // OpenCV code /////////////////////////////////////////////////////////////
+    {
+        in_mat1.convertTo(out_mat_ocv, CV_32FC1);
+    }
+    // Comparison //////////////////////////////////////////////////////////////
+    {
+        EXPECT_LE(cv::norm(out_mat_ocv, out_mat_gapi, cv::NORM_INF), tolerance);
+    }
+}
 //----------------------------------------------------------------------
 
 TEST_P(ResizeTestIE, AccuracyTest)
index c76f67f..fb4535a 100644 (file)
@@ -19,7 +19,7 @@ struct NV12toRGBTestGAPI: public TestParams<std::tuple<cv::Size, double>> {};
 struct I420toRGBTestGAPI: public TestParams<std::tuple<cv::Size, double>> {};
 struct ResizeRoiTestGAPI: public testing::TestWithParam<std::tuple<int, int, std::pair<cv::Size, cv::Size>, cv::Rect, double>> {};
 struct ResizeRGB8URoiTestGAPI: public testing::TestWithParam<std::tuple<int, int, std::pair<cv::Size, cv::Size>, cv::Rect, double>> {};
-
+struct U16toF32TestGAPI: public TestParams<std::tuple<cv::Size, double>> {};
 //------------------------------------------------------------------------------
 
 struct ResizeTestIE: public testing::TestWithParam<std::tuple<int, int, std::pair<cv::Size, cv::Size>, double>> {};
index 6684cd3..1a41fcc 100644 (file)
@@ -170,6 +170,16 @@ INSTANTIATE_TEST_CASE_P(I420toRGBTestFluid, I420toRGBTestGAPI,
                                        cv::Size( 320,  200)),
                                 Values(0)));
 
+INSTANTIATE_TEST_CASE_P(U16toF32TestGAPIFluid, U16toF32TestGAPI,
+                        Combine(Values(cv::Size(3840, 2160),
+                                       cv::Size(1920, 1080),
+                                       cv::Size(1280,  720),
+                                       cv::Size(1280,  960),
+                                       cv::Size( 960,  720),
+                                       cv::Size( 640,  480),
+                                       cv::Size( 300,  300),
+                                       cv::Size( 320,  200)),
+                                Values(0)));
 
 INSTANTIATE_TEST_CASE_P(ResizeRoiTestFluid, ResizeRoiTestGAPI,
                         Combine(Values(CV_8UC1, CV_8UC3),
index 8ec8bd9..f4afb49 100644 (file)
@@ -213,3 +213,15 @@ FluidI420toRGBComputation::FluidI420toRGBComputation(test::Mat inMat_y, test::Ma
                                ,{to_own(outMat)}
                                })
 {}
+
+FluidU16ToF32Computation::FluidU16ToF32Computation(test::Mat inMatU16, test::Mat outMatF32)
+    : FluidComputation(new Priv{ []()-> cv::GComputation {
+                                    cv::GMat in_U16;
+                                    cv::GMat outf32 = InferenceEngine::gapi::U16toF32::on(in_U16);
+                                    return cv::GComputation(cv::GIn(in_U16), cv::GOut(outf32));
+                                 }()
+                               , {to_own(inMatU16)}
+                               , {to_own(outMatF32)}
+                               })
+{}
+
index 26b9221..39d06a3 100644 (file)
@@ -98,4 +98,10 @@ public:
     FluidI420toRGBComputation(test::Mat inMat_y, test::Mat inMat_u, test::Mat inMat_v, test::Mat outMat);
 };
 
+class FLUID_COMPUTATION_VISIBILITY FluidU16ToF32Computation : public FluidComputation
+{
+public:
+    FluidU16ToF32Computation(test::Mat inMatU16, test::Mat outMatF32);
+};
+
 #endif // FLUID_TEST_COMPUTATIONS_HPP