From 8de92619e223225aabdca873c02f231d8e941fd1 Mon Sep 17 00:00:00 2001 From: John Richardson Date: Thu, 22 Feb 2018 14:09:31 +0000 Subject: COMPMID-585: Port OpticalFlow to new validation Change-Id: Ia36bd11ca27420d3059eea15df81b237900149ec Reviewed-on: https://eu-gerrit-1.euhpc.arm.com/125175 Tested-by: Jenkins Reviewed-by: John Richardson Reviewed-by: Anthony Barbier --- tests/Utils.h | 54 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) (limited to 'tests/Utils.h') diff --git a/tests/Utils.h b/tests/Utils.h index 4feed4e491..7d960dd08f 100644 --- a/tests/Utils.h +++ b/tests/Utils.h @@ -28,6 +28,7 @@ #include "arm_compute/core/Error.h" #include "arm_compute/core/FixedPoint.h" #include "arm_compute/core/HOGInfo.h" +#include "arm_compute/core/PyramidInfo.h" #include "arm_compute/core/Size2D.h" #include "arm_compute/core/TensorInfo.h" #include "arm_compute/core/TensorShape.h" @@ -548,6 +549,21 @@ inline T create_HOG(const HOGInfo &hog_info) return hog; } +/** Create and initialize a Pyramid of the given type. + * + * @param[in] pyramid_info The PyramidInfo object. + * + * @return Initialized Pyramid of given type. + */ +template +inline T create_pyramid(const PyramidInfo &pyramid_info) +{ + T pyramid; + pyramid.init_auto_padding(pyramid_info); + + return pyramid; +} + /** Create a vector of random ROIs. * * @param[in] shape The shape of the input tensor. @@ -618,6 +634,44 @@ inline std::vector generate_random_real(unsigned int num_values, T min, T max return v; } +/** Create a vector of random keypoints for pyramid representation. + * + * @param[in] shape The shape of the input tensor. + * @param[in] num_keypoints The number of keypoints to be created. + * @param[in] seed The random seed to be used. + * @param[in] num_levels The number of pyramid levels. + * + * @return A vector that contains the requested number of random keypoints + */ +inline std::vector generate_random_keypoints(const TensorShape &shape, size_t num_keypoints, std::random_device::result_type seed, size_t num_levels = 1) +{ + std::vector keypoints; + std::mt19937 gen(seed); + + // Calculate distribution bounds + const auto min = static_cast(std::pow(2, num_levels)); + const auto max_width = static_cast(shape.x()); + const auto max_height = static_cast(shape.y()); + + ARM_COMPUTE_ERROR_ON(min > max_width || min > max_height); + + // Create distributions + std::uniform_int_distribution<> dist_w(min, max_width); + std::uniform_int_distribution<> dist_h(min, max_height); + + for(unsigned int i = 0; i < num_keypoints; i++) + { + KeyPoint keypoint; + keypoint.x = dist_w(gen); + keypoint.y = dist_h(gen); + keypoint.tracking_status = 1; + + keypoints.push_back(keypoint); + } + + return keypoints; +} + template inline void fill_array(ArrayAccessor_T &&array, const std::vector &v) { -- cgit v1.2.1