From 95e2a70c47d661b1f6879cc99dc904f3fbcc6bd2 Mon Sep 17 00:00:00 2001 From: Michael Platings Date: Fri, 22 Mar 2024 14:20:29 +0000 Subject: [PATCH] Enable 2*2 resize in OpenCV HAL --- adapters/opencv/doc-opencv.md | 9 +++++++++ adapters/opencv/intrinsiccv_hal.cpp | 30 +++++++++++++++++++++++++++++ adapters/opencv/intrinsiccv_hal.h | 18 +++++++++++++++++ 3 files changed, 57 insertions(+) diff --git a/adapters/opencv/doc-opencv.md b/adapters/opencv/doc-opencv.md index a197c78f0..a6c531a40 100644 --- a/adapters/opencv/doc-opencv.md +++ b/adapters/opencv/doc-opencv.md @@ -92,6 +92,15 @@ The rest of parameters for `morphology_operation` function are currently not sup ### `morphology_free` Release context set up by [`morphology_init`](#morphology_init). +### `resize` +Notes on parameters: +* In-place operation not supported. +* `src_type` - only supports single-channel `CV_8U`. +* `dst_width` - must be `src_width * 2`. +* `dst_height` - must be `src_height * 2`. +* `inv_scale_x`,`inv_scale_y` - must be 0 or 2. +* `border_type` - Must be `INTER_LINEAR`. + ### `sobel` Applies Sobel gradient filter to a given image. diff --git a/adapters/opencv/intrinsiccv_hal.cpp b/adapters/opencv/intrinsiccv_hal.cpp index dacc42e41..3076ea6d5 100644 --- a/adapters/opencv/intrinsiccv_hal.cpp +++ b/adapters/opencv/intrinsiccv_hal.cpp @@ -439,6 +439,36 @@ int morphology_free(cvhalFilter2D *cvcontext) { return convert_error(intrinsiccv_morphology_release(params->context)); } +int resize(int src_type, const uchar *src_data, size_t src_step, int src_width, + int src_height, uchar *dst_data, size_t dst_step, int dst_width, + int dst_height, double inv_scale_x, double inv_scale_y, + int interpolation) { + if (src_data == dst_data) { + return CV_HAL_ERROR_NOT_IMPLEMENTED; + } + + size_t channels = (src_type >> CV_CN_SHIFT) + 1; + if (channels != 1) { + return CV_HAL_ERROR_NOT_IMPLEMENTED; + } + + if (CV_MAT_DEPTH(src_type) != CV_8U) { + return CV_HAL_ERROR_NOT_IMPLEMENTED; + } + + switch (interpolation) { + case CV_HAL_INTER_LINEAR: + if ((inv_scale_x == 0 || inv_scale_x == 2) && + (inv_scale_y == 0 || inv_scale_y == 2)) { + return convert_error(intrinsiccv_resize_linear_u8( + src_data, src_step, src_width, src_height, dst_data, dst_step, + dst_width, dst_height)); + } + break; + } + return CV_HAL_ERROR_NOT_IMPLEMENTED; +} + int sobel(const uchar *src_data, size_t src_step, uchar *dst_data, size_t dst_step, int width, int height, int src_depth, int dst_depth, int cn, int margin_left, int margin_top, int margin_right, diff --git a/adapters/opencv/intrinsiccv_hal.h b/adapters/opencv/intrinsiccv_hal.h index 1eab08d6e..150fd34ed 100644 --- a/adapters/opencv/intrinsiccv_hal.h +++ b/adapters/opencv/intrinsiccv_hal.h @@ -64,6 +64,11 @@ int morphology_operation(cvhalFilter2D *context, uchar *src_data, int morphology_free(cvhalFilter2D *context); +int resize(int src_type, const uchar *src_data, size_t src_step, int src_width, + int src_height, uchar *dst_data, size_t dst_step, int dst_width, + int dst_height, double inv_scale_x, double inv_scale_y, + int interpolation); + int sobel(const uchar *src_data, size_t src_step, uchar *dst_data, size_t dst_step, int width, int height, int src_depth, int dst_depth, int cn, int margin_left, int margin_top, int margin_right, @@ -212,6 +217,19 @@ static inline int intrinsiccv_morphology_free_with_fallback( #undef cv_hal_morphFree #define cv_hal_morphFree intrinsiccv_morphology_free_with_fallback +// resize +static inline int intrinsiccv_resize_with_fallback( + int src_type, const uchar *src_data, size_t src_step, int src_width, + int src_height, uchar *dst_data, size_t dst_step, int dst_width, + int dst_height, double inv_scale_x, double inv_scale_y, int interpolation) { + return INTRINSICCV_HAL_FALLBACK_FORWARD( + resize, cv_hal_resize, src_type, src_data, src_step, src_width, + src_height, dst_data, dst_step, dst_width, dst_height, inv_scale_x, + inv_scale_y, interpolation); +} +#undef cv_hal_resize +#define cv_hal_resize intrinsiccv_resize_with_fallback + // sobel static inline int intrinsiccv_sobel_with_fallback( const uchar *src_data, size_t src_step, uchar *dst_data, size_t dst_step, -- GitLab