diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..aae4acb --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,24 @@ +# Copyright (c) 2015 Advanced Micro Devices, Inc. All rights reserved. +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to deal +# in the Software without restriction, including without limitation the rights +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +# copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in +# all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +# THE SOFTWARE. + +cmake_minimum_required (VERSION 3.1) +project (amdovx-modules) + +add_subdirectory (vx_ext_cv) diff --git a/README.md b/README.md new file mode 100644 index 0000000..4fa925e --- /dev/null +++ b/README.md @@ -0,0 +1,21 @@ +# AMD OpenVX modules (amdovx-modules) +Each subfolder contains a separate OpenVX module. Look into the subfolder for more details of individual module pre-requisites and special build setup requirements. + +The current release verion is 0.9 (beta preview). + +## List of modules +* **vx_ext_cv**: OpenVX module that implemented a mechanism to access OpenCV functionality as OpenVX kernels + +## Build Instructions + +#### Pre-requisites +* OpenCV 3.0 [download](http://opencv.org/downloads.html). +* CMake 3.1 or newer [download](http://cmake.org/download/). +* Download and build [amdovx-core](https://github.com/GPUOpen-ProfessionalCompute-Libraries/amdovx-core) project at the same level folder as amdovx-modules build folder +* OpenCV_DIR environment variable should point to OpenCV/build folder + +#### Build using Visual Studio Professional 2013 on 64-bit Windows 10/8.1/7 +* Use amdovx-modules/amdovx-solution.sln to build for x64 platform + +#### Build using CMake on Linux (Ubuntu 15.10 64-bit) +* Use CMake to configure and generate Makefile diff --git a/amdovx-modules.sln b/amdovx-modules.sln new file mode 100644 index 0000000..968c104 --- /dev/null +++ b/amdovx-modules.sln @@ -0,0 +1,22 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio 2013 +VisualStudioVersion = 12.0.31101.0 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "vx_ext_cv", "vx_ext_cv\vx_ext_cv.vcxproj", "{C5F3ED68-728A-4610-A37F-89323A93DD81}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|x64 = Debug|x64 + Release|x64 = Release|x64 + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {C5F3ED68-728A-4610-A37F-89323A93DD81}.Debug|x64.ActiveCfg = Debug|x64 + {C5F3ED68-728A-4610-A37F-89323A93DD81}.Debug|x64.Build.0 = Debug|x64 + {C5F3ED68-728A-4610-A37F-89323A93DD81}.Release|x64.ActiveCfg = Release|x64 + {C5F3ED68-728A-4610-A37F-89323A93DD81}.Release|x64.Build.0 = Release|x64 + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection +EndGlobal diff --git a/vx_ext_cv/CMakeLists.txt b/vx_ext_cv/CMakeLists.txt new file mode 100644 index 0000000..22a2890 --- /dev/null +++ b/vx_ext_cv/CMakeLists.txt @@ -0,0 +1,114 @@ +# Copyright (c) 2015 Advanced Micro Devices, Inc. All rights reserved. +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to deal +# in the Software without restriction, including without limitation the rights +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +# copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in +# all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +# THE SOFTWARE. + +cmake_minimum_required (VERSION 3.1) +project (vx_ext_cv) + +set (CMAKE_CXX_STANDARD 11) + +find_package (OpenCV REQUIRED) +find_package (OpenCL) + +include_directories (include) + +list (APPEND SOURCES + OpenCV_absdiff.cpp + OpenCV_adaptiveThreshold.cpp + OpenCV_add.cpp + OpenCV_AddWeighted.cpp + OpenCV_bilateralFilter.cpp + OpenCV_bitwise_and.cpp + OpenCV_bitwise_not.cpp + OpenCV_bitwise_or.cpp + OpenCV_bitwise_xor.cpp + OpenCV_Blur.cpp + OpenCV_Boxfilter.cpp + OpenCV_brisk_compute.cpp + OpenCV_BRISK_detector.cpp + OpenCV_buildOpticalFlowPyramid.cpp + OpenCV_buildPyramid.cpp + OpenCV_Canny.cpp + OpenCV_compare.cpp + OpenCV_convertScaleAbs.cpp + OpenCV_cornerHarris.cpp + OpenCV_cornerMinEigenVal.cpp + OpenCV_countNonZero.cpp + OpenCV_cvtColor.cpp + OpenCV_data_translator.cpp + OpenCV_dilate.cpp + OpenCV_distanceTransform.cpp + OpenCV_divide.cpp + OpenCV_erode.cpp + OpenCV_FAST_feature_detector.cpp + OpenCV_fastNlMeansDenoising.cpp + OpenCV_fastNlMeansDenoisingColored.cpp + OpenCV_filter2D.cpp + OpenCV_flip.cpp + OpenCV_Gaussianblur.cpp + OpenCV_Good_Features_to_Track_detector.cpp + OpenCV_integral.cpp + OpenCV_Laplacian.cpp + OpenCV_Medianblur.cpp + OpenCV_morphologyEx.cpp + OpenCV_MSER_feature_detector.cpp + OpenCV_multiply.cpp + OpenCV_norm.cpp + OpenCV_orb_compute.cpp + OpenCV_ORB_detector.cpp + OpenCV_pyrdown.cpp + OpenCV_pyrup.cpp + OpenCV_resize.cpp + OpenCV_Scharr.cpp + OpenCV_sepFilter2D.cpp + OpenCV_SIFT_Compute.cpp + OpenCV_SIFT_Detect.cpp + OpenCV_simple_blob_detector.cpp + OpenCV_Sobel.cpp + OpenCV_Star_feature_detector.cpp + OpenCV_subtract.cpp + OpenCV_SURF_Compute.cpp + OpenCV_SURF_Detect.cpp + OpenCV_threshold.cpp + OpenCV_transpose.cpp + OpenCV_VX_Nodes.cpp + OpenCV_warpAffine.cpp + OpenCV_warpPerspective.cpp + publishkernels.cpp + ) + +add_library(vx_ext_cv SHARED ${SOURCES}) +target_link_libraries(vx_ext_cv ${OpenVX_LIBRARY}) + +include_directories(${OpenCV_INCLUDE_DIRS}) +target_link_libraries(vx_ext_cv ${OpenCV_LIBRARIES}) +target_compile_definitions(vx_ext_cv PUBLIC USE_OPENCV_CONTRIB=0) + +if (OpenCL_FOUND) + include_directories(${OpenCL_INCLUDE_DIRS}) + target_link_libraries(vx_ext_cv ${OpenCL_LIBRARIES}) +endif(OpenCL_FOUND) + +if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fdata-sections") +elseif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC") + set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} /MT") + set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} /MTd") +endif() + diff --git a/vx_ext_cv/COPYRIGHT.txt b/vx_ext_cv/COPYRIGHT.txt new file mode 100644 index 0000000..548cb05 --- /dev/null +++ b/vx_ext_cv/COPYRIGHT.txt @@ -0,0 +1,19 @@ +Copyright (c) 2015 Advanced Micro Devices, Inc. All rights reserved. + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. diff --git a/vx_ext_cv/OpenCV_AddWeighted.cpp b/vx_ext_cv/OpenCV_AddWeighted.cpp new file mode 100644 index 0000000..dd1dfa5 --- /dev/null +++ b/vx_ext_cv/OpenCV_AddWeighted.cpp @@ -0,0 +1,221 @@ +/* +Copyright (c) 2015 Advanced Micro Devices, Inc. All rights reserved. + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. +*/ + + +#include"publishkernels.h" + +/************************************************************************************************************ +input parameter validator. +param [in] node The handle to the node. +param [in] index The index of the parameter to validate. +*************************************************************************************************************/ +vx_status VX_CALLBACK CV_AddWeighted_InputValidator(vx_node node, vx_uint32 index) +{ + vx_status status = VX_SUCCESS; + vx_parameter param = vxGetParameterByIndex(node, index); + + if (index == 0) + { + vx_image image; + vx_df_image df_image = VX_DF_IMAGE_VIRT; + STATUS_ERROR_CHECK(vxQueryParameter(param, VX_PARAMETER_ATTRIBUTE_REF, &image, sizeof(vx_image))); + STATUS_ERROR_CHECK(vxQueryImage(image, VX_IMAGE_ATTRIBUTE_FORMAT, &df_image, sizeof(df_image))); + if (df_image != VX_DF_IMAGE_U8 && df_image != VX_DF_IMAGE_U16 && df_image != VX_DF_IMAGE_S16) + status = VX_ERROR_INVALID_VALUE; + vxReleaseImage(&image); + } + + if (index == 2) + { + vx_image image; + vx_df_image df_image = VX_DF_IMAGE_VIRT; + STATUS_ERROR_CHECK(vxQueryParameter(param, VX_PARAMETER_ATTRIBUTE_REF, &image, sizeof(vx_image))); + STATUS_ERROR_CHECK(vxQueryImage(image, VX_IMAGE_ATTRIBUTE_FORMAT, &df_image, sizeof(df_image))); + if (df_image != VX_DF_IMAGE_U8 && df_image != VX_DF_IMAGE_U16 && df_image != VX_DF_IMAGE_S16) + status = VX_ERROR_INVALID_VALUE; + vxReleaseImage(&image); + } + else if (index == 5) + { + vx_image image; + vx_df_image df_image = VX_DF_IMAGE_VIRT; + STATUS_ERROR_CHECK(vxQueryParameter(param, VX_PARAMETER_ATTRIBUTE_REF, &image, sizeof(vx_image))); + STATUS_ERROR_CHECK(vxQueryImage(image, VX_IMAGE_ATTRIBUTE_FORMAT, &df_image, sizeof(df_image))); + if (df_image != VX_DF_IMAGE_U8 && df_image != VX_DF_IMAGE_U16 && df_image != VX_DF_IMAGE_S16) + status = VX_ERROR_INVALID_VALUE; + vxReleaseImage(&image); + } + + else if (index == 1) + { + vx_scalar scalar = 0; vx_enum type = 0; vx_float32 value = 0; + STATUS_ERROR_CHECK(vxQueryParameter(param, VX_PARAMETER_ATTRIBUTE_REF, &scalar, sizeof(scalar))); + STATUS_ERROR_CHECK(vxQueryScalar(scalar, VX_SCALAR_ATTRIBUTE_TYPE, &type, sizeof(type))); + STATUS_ERROR_CHECK(vxReadScalarValue(scalar, &value)); + if (value < 0 || type != VX_TYPE_FLOAT32) + status = VX_ERROR_INVALID_VALUE; + vxReleaseScalar(&scalar); + } + + else if (index == 3) + { + vx_scalar scalar = 0; vx_enum type = 0; vx_float32 value = 0; + STATUS_ERROR_CHECK(vxQueryParameter(param, VX_PARAMETER_ATTRIBUTE_REF, &scalar, sizeof(scalar))); + STATUS_ERROR_CHECK(vxQueryScalar(scalar, VX_SCALAR_ATTRIBUTE_TYPE, &type, sizeof(type))); + STATUS_ERROR_CHECK(vxReadScalarValue(scalar, &value)); + if (value < 0 || type != VX_TYPE_FLOAT32) + status = VX_ERROR_INVALID_VALUE; + vxReleaseScalar(&scalar); + } + + else if (index == 4) + { + vx_scalar scalar = 0; vx_enum type = 0; vx_float32 value = 0; + STATUS_ERROR_CHECK(vxQueryParameter(param, VX_PARAMETER_ATTRIBUTE_REF, &scalar, sizeof(scalar))); + STATUS_ERROR_CHECK(vxQueryScalar(scalar, VX_SCALAR_ATTRIBUTE_TYPE, &type, sizeof(type))); + STATUS_ERROR_CHECK(vxReadScalarValue(scalar, &value)); + if (value < 0 || type != VX_TYPE_FLOAT32) + status = VX_ERROR_INVALID_VALUE; + vxReleaseScalar(&scalar); + } + + else if (index == 6) + { + vx_scalar scalar = 0; vx_enum type = 0; vx_int32 value = 0; + STATUS_ERROR_CHECK(vxQueryParameter(param, VX_PARAMETER_ATTRIBUTE_REF, &scalar, sizeof(scalar))); + STATUS_ERROR_CHECK(vxQueryScalar(scalar, VX_SCALAR_ATTRIBUTE_TYPE, &type, sizeof(type))); + STATUS_ERROR_CHECK(vxReadScalarValue(scalar, &value)); + if (value < 0 || type != VX_TYPE_INT32) + status = VX_ERROR_INVALID_VALUE; + vxReleaseScalar(&scalar); + } + + vxReleaseParameter(¶m); + return status; +} + +/************************************************************************************************************ +output parameter validator. +*************************************************************************************************************/ +vx_status VX_CALLBACK CV_AddWeighted_OutputValidator(vx_node node, vx_uint32 index, vx_meta_format meta) +{ + vx_status status = VX_SUCCESS; + if (index == 5) + { + vx_parameter output_param = vxGetParameterByIndex(node, 5); + vx_image output; vx_uint32 width = 0, height = 0; vx_df_image format = VX_DF_IMAGE_VIRT; + + STATUS_ERROR_CHECK(vxQueryParameter(output_param, VX_PARAMETER_ATTRIBUTE_REF, &output, sizeof(vx_image))); + STATUS_ERROR_CHECK(vxQueryImage(output, VX_IMAGE_ATTRIBUTE_FORMAT, &format, sizeof(format))); + STATUS_ERROR_CHECK(vxQueryImage(output, VX_IMAGE_ATTRIBUTE_WIDTH, &width, sizeof(width))); + STATUS_ERROR_CHECK(vxQueryImage(output, VX_IMAGE_ATTRIBUTE_HEIGHT, &height, sizeof(height))); + + if (format != VX_DF_IMAGE_U8) + status = VX_ERROR_INVALID_VALUE; + + STATUS_ERROR_CHECK(vxSetMetaFormatAttribute(meta, VX_IMAGE_ATTRIBUTE_WIDTH, &width, sizeof(width))); + STATUS_ERROR_CHECK(vxSetMetaFormatAttribute(meta, VX_IMAGE_ATTRIBUTE_HEIGHT, &height, sizeof(height))); + STATUS_ERROR_CHECK(vxSetMetaFormatAttribute(meta, VX_IMAGE_ATTRIBUTE_FORMAT, &format, sizeof(format))); + + vxReleaseImage(&output); + vxReleaseParameter(&output_param); + } + return status; +} + +/************************************************************************************************************ +Execution Kernel +*************************************************************************************************************/ +vx_status VX_CALLBACK CV_AddWeighted_Kernel(vx_node node, const vx_reference *parameters, vx_uint32 num) +{ + vx_status status = VX_SUCCESS; + + vx_image image_in_1 = (vx_image) parameters[0]; + vx_scalar Alpha = (vx_scalar) parameters[1]; + vx_image image_in_2 = (vx_image) parameters[2]; + vx_scalar Beta = (vx_scalar) parameters[3]; + vx_scalar Gamma = (vx_scalar) parameters[4]; + vx_image image_out = (vx_image) parameters[5]; + vx_scalar Dtype = (vx_scalar) parameters[6]; + + Mat *mat_1, *mat_2, bl; + double aplha, beta, gamma; + int dtype; + vx_float32 value = 0; + vx_int32 value1 = 0; + + //Extracting Values from the Scalar into Ksize and Ddepth + STATUS_ERROR_CHECK(vxReadScalarValue(Alpha, &value)); aplha = value; + STATUS_ERROR_CHECK(vxReadScalarValue(Beta, &value)); beta = value; + STATUS_ERROR_CHECK(vxReadScalarValue(Gamma, &value)); gamma = value; + STATUS_ERROR_CHECK(vxReadScalarValue(Dtype, &value1)); dtype = value1; + + //Converting VX Image_1 to OpenCV Mat + STATUS_ERROR_CHECK(match_vx_image_parameters(image_in_1, image_in_2)); + STATUS_ERROR_CHECK(match_vx_image_parameters(image_in_1, image_out)); + STATUS_ERROR_CHECK(VX_to_CV_Image(&mat_1, image_in_1)); + STATUS_ERROR_CHECK(VX_to_CV_Image(&mat_2, image_in_2)); + + //Compute using OpenCV + cv::addWeighted(*mat_1, aplha, *mat_2, beta, gamma, bl, dtype); + + //Converting OpenCV Mat into VX Image + STATUS_ERROR_CHECK(CV_to_VX_Image(image_out, &bl)); + + return status; +} + +/************************************************************************************************************ +Function to Register the Kernel for Publish +*************************************************************************************************************/ +vx_status CV_AddWeighted_Register(vx_context context) +{ + vx_status status = VX_SUCCESS; + vx_kernel kernel = vxAddKernel(context, + "org.opencv.addweighted", + VX_KERNEL_EXT_CV_ADDWEIGHTED, + CV_AddWeighted_Kernel, + 7, + CV_AddWeighted_InputValidator, + CV_AddWeighted_OutputValidator, + nullptr, + nullptr); + + if (kernel) + { + PARAM_ERROR_CHECK(vxAddParameterToKernel(kernel, 0, VX_INPUT, VX_TYPE_IMAGE, VX_PARAMETER_STATE_REQUIRED)); + PARAM_ERROR_CHECK(vxAddParameterToKernel(kernel, 1, VX_INPUT, VX_TYPE_SCALAR, VX_PARAMETER_STATE_REQUIRED)); + PARAM_ERROR_CHECK(vxAddParameterToKernel(kernel, 2, VX_INPUT, VX_TYPE_IMAGE, VX_PARAMETER_STATE_REQUIRED)); + PARAM_ERROR_CHECK(vxAddParameterToKernel(kernel, 3, VX_INPUT, VX_TYPE_SCALAR, VX_PARAMETER_STATE_REQUIRED)); + PARAM_ERROR_CHECK(vxAddParameterToKernel(kernel, 4, VX_INPUT, VX_TYPE_SCALAR, VX_PARAMETER_STATE_REQUIRED)); + PARAM_ERROR_CHECK(vxAddParameterToKernel(kernel, 5, VX_OUTPUT, VX_TYPE_IMAGE, VX_PARAMETER_STATE_REQUIRED)); + PARAM_ERROR_CHECK(vxAddParameterToKernel(kernel, 6, VX_INPUT, VX_TYPE_SCALAR, VX_PARAMETER_STATE_REQUIRED)); + PARAM_ERROR_CHECK(vxFinalizeKernel(kernel)); + } + + if (status != VX_SUCCESS) + { + exit: vxRemoveKernel(kernel); return VX_FAILURE; + } + + return status; +} \ No newline at end of file diff --git a/vx_ext_cv/OpenCV_BRISK_detector.cpp b/vx_ext_cv/OpenCV_BRISK_detector.cpp new file mode 100644 index 0000000..f07d3c7 --- /dev/null +++ b/vx_ext_cv/OpenCV_BRISK_detector.cpp @@ -0,0 +1,200 @@ +/* +Copyright (c) 2015 Advanced Micro Devices, Inc. All rights reserved. + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. +*/ + + +#include"publishkernels.h" + +/*!*********************************************************************************************************** +input parameter validator. +param [in] node The handle to the node. +param [in] index The index of the parameter to validate. +*************************************************************************************************************/ +static vx_status VX_CALLBACK CV_brisk_detector_InputValidator(vx_node node, vx_uint32 index) +{ + vx_status status = VX_SUCCESS ; + vx_parameter param = vxGetParameterByIndex(node, index); + + if (index == 0) + { + vx_image image; + vx_df_image df_image = VX_DF_IMAGE_VIRT; + STATUS_ERROR_CHECK(vxQueryParameter(param, VX_PARAMETER_ATTRIBUTE_REF, &image, sizeof(vx_image))); + STATUS_ERROR_CHECK(vxQueryImage(image, VX_IMAGE_ATTRIBUTE_FORMAT, &df_image, sizeof(df_image))); + if (df_image != VX_DF_IMAGE_U8) + status = VX_ERROR_INVALID_VALUE; + vxReleaseImage(&image); + } + + if (index == 1) + { + vx_image image; + vx_df_image df_image = VX_DF_IMAGE_VIRT; + STATUS_ERROR_CHECK(vxQueryParameter(param, VX_PARAMETER_ATTRIBUTE_REF, &image, sizeof(vx_image))); + STATUS_ERROR_CHECK(vxQueryImage(image, VX_IMAGE_ATTRIBUTE_FORMAT, &df_image, sizeof(df_image))); + if (df_image != VX_DF_IMAGE_U8) + status = VX_ERROR_INVALID_VALUE; + vxReleaseImage(&image); + } + + else if (index == 2) + { + vx_array array; vx_size size = 0; + STATUS_ERROR_CHECK(vxQueryParameter(param, VX_PARAMETER_ATTRIBUTE_REF, &array, sizeof(array))); + STATUS_ERROR_CHECK(vxQueryArray(array, VX_ARRAY_ATTRIBUTE_CAPACITY, &size, sizeof(size))); + vxReleaseArray(&array); + } + + else if (index == 3) + { + vx_scalar scalar = 0; vx_enum type = 0; vx_int32 value = 0; + STATUS_ERROR_CHECK(vxQueryParameter(param, VX_PARAMETER_ATTRIBUTE_REF, &scalar, sizeof(scalar))); + STATUS_ERROR_CHECK(vxQueryScalar(scalar, VX_SCALAR_ATTRIBUTE_TYPE, &type, sizeof(type))); + STATUS_ERROR_CHECK(vxReadScalarValue(scalar, &value)); + if (value < 0 || type != VX_TYPE_INT32) + status = VX_ERROR_INVALID_VALUE; + vxReleaseScalar(&scalar); + } + + else if (index == 4) + { + vx_scalar scalar = 0; vx_enum type = 0; vx_int32 value = 0; + STATUS_ERROR_CHECK(vxQueryParameter(param, VX_PARAMETER_ATTRIBUTE_REF, &scalar, sizeof(scalar))); + STATUS_ERROR_CHECK(vxQueryScalar(scalar, VX_SCALAR_ATTRIBUTE_TYPE, &type, sizeof(type))); + STATUS_ERROR_CHECK(vxReadScalarValue(scalar, &value)); + if (value < 0 || type != VX_TYPE_INT32) + status = VX_ERROR_INVALID_VALUE; + vxReleaseScalar(&scalar); + } + + else if (index == 5) + { + vx_scalar scalar = 0; vx_enum type = 0; vx_float32 value = 0; + STATUS_ERROR_CHECK(vxQueryParameter(param, VX_PARAMETER_ATTRIBUTE_REF, &scalar, sizeof(scalar))); + STATUS_ERROR_CHECK(vxQueryScalar(scalar, VX_SCALAR_ATTRIBUTE_TYPE, &type, sizeof(type))); + STATUS_ERROR_CHECK(vxReadScalarValue(scalar, &value)); + if (value < 0 || type != VX_TYPE_FLOAT32) + status = VX_ERROR_INVALID_VALUE; + vxReleaseScalar(&scalar); + } + + vxReleaseParameter(¶m); + return status; +} + +/*!*********************************************************************************************************** +output parameter validator. +*************************************************************************************************************/ +static vx_status VX_CALLBACK CV_brisk_detector_OutputValidator(vx_node node, vx_uint32 index, vx_meta_format meta) +{ + vx_status status = VX_SUCCESS ; + if (index == 2) + { + vx_parameter output_param = vxGetParameterByIndex(node, 2); + vx_array output; vx_size size = 0; + + STATUS_ERROR_CHECK(vxQueryParameter(output_param, VX_PARAMETER_ATTRIBUTE_REF, &output, sizeof(vx_array))); + STATUS_ERROR_CHECK(vxQueryArray(output, VX_ARRAY_ATTRIBUTE_CAPACITY, &size, sizeof(size))); + + if (size <= 0) + status = VX_ERROR_INVALID_VALUE; + + vxReleaseArray(&output); + vxReleaseParameter(&output_param); + } + + return status; +} + +/*!*********************************************************************************************************** +Execution Kernel +*************************************************************************************************************/ +static vx_status VX_CALLBACK CV_brisk_detector_Kernel(vx_node node, const vx_reference *parameters, vx_uint32 num) +{ + vx_status status = VX_SUCCESS; + + vx_image image_in = (vx_image) parameters[0]; + vx_image mask = (vx_image) parameters[1]; + vx_array array = (vx_array) parameters[2]; + vx_scalar THRESH = (vx_scalar) parameters[3]; + vx_scalar OCTAVES = (vx_scalar) parameters[4]; + vx_scalar SCALE = (vx_scalar) parameters[5]; + + Mat *mat, *mask_mat, Img; + int thresh, octaves; + float patternscale; + vx_float32 FloatValue = 0; + vx_int32 value = 0; + + //Extracting Values from the Scalar + STATUS_ERROR_CHECK(vxReadScalarValue(SCALE, &FloatValue));patternscale = FloatValue; + STATUS_ERROR_CHECK(vxReadScalarValue(THRESH, &value));thresh = value; + STATUS_ERROR_CHECK(vxReadScalarValue(OCTAVES, &value));octaves = value; + + //Converting VX Image to OpenCV Mat + STATUS_ERROR_CHECK(VX_to_CV_Image(&mat, image_in)); + STATUS_ERROR_CHECK(VX_to_CV_Image(&mask_mat, mask)); + + //Compute using OpenCV + vector key_points; + Ptr brisk = BRISK::create(thresh, octaves, patternscale); + brisk->detect(*mat, key_points, *mask_mat); + + //Converting OpenCV Keypoints to OpenVX Keypoints + STATUS_ERROR_CHECK(CV_to_VX_keypoints(key_points, array)); + + return status; +} + +/************************************************************************************************************ +Function to Register the Kernel for Publish +*************************************************************************************************************/ +vx_status CV_brisk_detect_Register(vx_context context) +{ + vx_status status = VX_SUCCESS; + vx_kernel Kernel = vxAddKernel(context, + "org.opencv.brisk_detect", + VX_KERNEL_EXT_CV_BRISK_DETECT, + CV_brisk_detector_Kernel, + 6, + CV_brisk_detector_InputValidator, + CV_brisk_detector_OutputValidator, + nullptr, + nullptr); + + if (Kernel) + { + PARAM_ERROR_CHECK(vxAddParameterToKernel(Kernel, 0, VX_INPUT, VX_TYPE_IMAGE, VX_PARAMETER_STATE_REQUIRED)); + PARAM_ERROR_CHECK(vxAddParameterToKernel(Kernel, 1, VX_INPUT, VX_TYPE_IMAGE, VX_PARAMETER_STATE_REQUIRED)); + PARAM_ERROR_CHECK(vxAddParameterToKernel(Kernel, 2, VX_BIDIRECTIONAL, VX_TYPE_ARRAY, VX_PARAMETER_STATE_REQUIRED)); + PARAM_ERROR_CHECK(vxAddParameterToKernel(Kernel, 3, VX_INPUT, VX_TYPE_SCALAR, VX_PARAMETER_STATE_REQUIRED)); + PARAM_ERROR_CHECK(vxAddParameterToKernel(Kernel, 4, VX_INPUT, VX_TYPE_SCALAR, VX_PARAMETER_STATE_REQUIRED)); + PARAM_ERROR_CHECK(vxAddParameterToKernel(Kernel, 5, VX_INPUT, VX_TYPE_SCALAR, VX_PARAMETER_STATE_REQUIRED)); + PARAM_ERROR_CHECK(vxFinalizeKernel(Kernel)); + } + + if (status != VX_SUCCESS) + { + exit: vxRemoveKernel(Kernel); return VX_FAILURE; + } + + return status; +} diff --git a/vx_ext_cv/OpenCV_Blur.cpp b/vx_ext_cv/OpenCV_Blur.cpp new file mode 100644 index 0000000..7747488 --- /dev/null +++ b/vx_ext_cv/OpenCV_Blur.cpp @@ -0,0 +1,272 @@ +/* +Copyright (c) 2015 Advanced Micro Devices, Inc. All rights reserved. + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. +*/ + + +#include"publishkernels.h" + +/*! \brief *********************************************************************************************************** +Input parameter validator. + +This function checks all the inputs to see if they are of the correct data type and is passing a valid argument. +The input validator is a required function to create any node. + +param [in] node -->The handle to the node. +param [in] index -->The index of the parameter to validate. +*************************************************************************************************************/ +static vx_status VX_CALLBACK CV_Blur_InputValidator(vx_node node, vx_uint32 index) +{ + vx_status status = VX_SUCCESS; + vx_parameter param = vxGetParameterByIndex(node, index); + + if (index == 0) + { + vx_image image; + vx_df_image df_image = VX_DF_IMAGE_VIRT; + STATUS_ERROR_CHECK(vxQueryParameter(param, VX_PARAMETER_ATTRIBUTE_REF, &image, sizeof(vx_image))); + STATUS_ERROR_CHECK(vxQueryImage(image, VX_IMAGE_ATTRIBUTE_FORMAT, &df_image, sizeof(df_image))); + if (df_image != VX_DF_IMAGE_U8) + status = VX_ERROR_INVALID_VALUE; + vxReleaseImage(&image); + } + + else if (index == 1) + { + vx_image image; + vx_df_image df_image = VX_DF_IMAGE_VIRT; + STATUS_ERROR_CHECK(vxQueryParameter(param, VX_PARAMETER_ATTRIBUTE_REF, &image, sizeof(vx_image))); + STATUS_ERROR_CHECK(vxQueryImage(image, VX_IMAGE_ATTRIBUTE_FORMAT, &df_image, sizeof(df_image))); + if (df_image != VX_DF_IMAGE_U8) + status = VX_ERROR_INVALID_VALUE; + vxReleaseImage(&image); + } + + else if (index == 2) + { + vx_scalar scalar = 0; vx_enum type = 0; vx_int32 value = 0; + STATUS_ERROR_CHECK(vxQueryParameter(param, VX_PARAMETER_ATTRIBUTE_REF, &scalar, sizeof(scalar))); + STATUS_ERROR_CHECK(vxQueryScalar(scalar, VX_SCALAR_ATTRIBUTE_TYPE, &type, sizeof(type))); + STATUS_ERROR_CHECK(vxReadScalarValue(scalar, &value)); + if (value < 0 || type != VX_TYPE_INT32) + status = VX_ERROR_INVALID_VALUE; + vxReleaseScalar(&scalar); + } + + else if (index == 3) + { + vx_scalar scalar = 0; vx_enum type = 0; vx_int32 value = 0; + STATUS_ERROR_CHECK(vxQueryParameter(param, VX_PARAMETER_ATTRIBUTE_REF, &scalar, sizeof(scalar))); + STATUS_ERROR_CHECK(vxQueryScalar(scalar, VX_SCALAR_ATTRIBUTE_TYPE, &type, sizeof(type))); + STATUS_ERROR_CHECK(vxReadScalarValue(scalar, &value)); + if (value < 0 || type != VX_TYPE_INT32) + status = VX_ERROR_INVALID_VALUE; + vxReleaseScalar(&scalar); + } + + else if (index == 4) + { + vx_scalar scalar = 0; vx_enum type = 0; vx_int32 value = 0; + STATUS_ERROR_CHECK(vxQueryParameter(param, VX_PARAMETER_ATTRIBUTE_REF, &scalar, sizeof(scalar))); + STATUS_ERROR_CHECK(vxQueryScalar(scalar, VX_SCALAR_ATTRIBUTE_TYPE, &type, sizeof(type))); + STATUS_ERROR_CHECK(vxReadScalarValue(scalar, &value)); + if (value < -1 || type != VX_TYPE_INT32) + status = VX_ERROR_INVALID_VALUE; + vxReleaseScalar(&scalar); + } + + else if (index == 5) + { + vx_scalar scalar = 0; vx_enum type = 0; vx_int32 value = 0; + STATUS_ERROR_CHECK(vxQueryParameter(param, VX_PARAMETER_ATTRIBUTE_REF, &scalar, sizeof(scalar))); + STATUS_ERROR_CHECK(vxQueryScalar(scalar, VX_SCALAR_ATTRIBUTE_TYPE, &type, sizeof(type))); + STATUS_ERROR_CHECK(vxReadScalarValue(scalar, &value)); + if (value < -1 || type != VX_TYPE_INT32) + status = VX_ERROR_INVALID_VALUE; + vxReleaseScalar(&scalar); + } + + else if (index == 6) + { + vx_scalar scalar = 0; vx_enum type = 0; vx_int32 value = 0; + STATUS_ERROR_CHECK(vxQueryParameter(param, VX_PARAMETER_ATTRIBUTE_REF, &scalar, sizeof(scalar))); + STATUS_ERROR_CHECK(vxQueryScalar(scalar, VX_SCALAR_ATTRIBUTE_TYPE, &type, sizeof(type))); + STATUS_ERROR_CHECK(vxReadScalarValue(scalar, &value)); + if (value < 0 || type != VX_TYPE_INT32) + status = VX_ERROR_INVALID_VALUE; + vxReleaseScalar(&scalar); + } + + vxReleaseParameter(¶m); + return status; +} + +/*! \brief *********************************************************************************************************** +Output parameter validator. + +This function checks all the outputs to see if they are of the correct data type and has the required parameters set +to return the correct output. +The Output validator is a required function to create any node. + +param [in] node -->The handle to the node. +param [in] index -->The index of the parameter to validate. +param [in] meta -->The meta data for the output is set. +*************************************************************************************************************/ +static vx_status VX_CALLBACK CV_Blur_OutputValidator(vx_node node, vx_uint32 index, vx_meta_format meta) +{ + vx_status status = VX_SUCCESS; + if (index == 1) + { + vx_parameter output_param = vxGetParameterByIndex(node, 1); + vx_image output; vx_uint32 width = 0, height = 0; vx_df_image format = VX_DF_IMAGE_VIRT; + + STATUS_ERROR_CHECK(vxQueryParameter(output_param, VX_PARAMETER_ATTRIBUTE_REF, &output, sizeof(vx_image))); + STATUS_ERROR_CHECK(vxQueryImage(output, VX_IMAGE_ATTRIBUTE_FORMAT, &format, sizeof(format))); + STATUS_ERROR_CHECK(vxQueryImage(output, VX_IMAGE_ATTRIBUTE_WIDTH, &width, sizeof(width))); + STATUS_ERROR_CHECK(vxQueryImage(output, VX_IMAGE_ATTRIBUTE_HEIGHT, &height, sizeof(height))); + + if (format != VX_DF_IMAGE_U8) + status = VX_ERROR_INVALID_VALUE; + + STATUS_ERROR_CHECK(vxSetMetaFormatAttribute(meta, VX_IMAGE_ATTRIBUTE_WIDTH, &width, sizeof(width))); + STATUS_ERROR_CHECK(vxSetMetaFormatAttribute(meta, VX_IMAGE_ATTRIBUTE_HEIGHT, &height, sizeof(height))); + STATUS_ERROR_CHECK(vxSetMetaFormatAttribute(meta, VX_IMAGE_ATTRIBUTE_FORMAT, &format, sizeof(format))); + + vxReleaseImage(&output); + vxReleaseParameter(&output_param); + } + return status; +} + +/*! \brief *********************************************************************************************************** +Execution Kernel + +This function is the exection kernel of the node, it gets the inputs for the i/p validator and returns to output + +param [in] node -->The handle to the node. +param [in] parameters -->The index of the parameter. +param [in] num -->Number of parameters. +*************************************************************************************************************/ +static vx_status VX_CALLBACK CV_Blur_Kernel(vx_node node, const vx_reference *parameters, vx_uint32 num) +{ + vx_status status = VX_SUCCESS; + + vx_image image_in = (vx_image) parameters[0]; + vx_image image_out = (vx_image) parameters[1]; + vx_scalar S_width = (vx_scalar) parameters[2]; + vx_scalar S_height = (vx_scalar) parameters[3]; + vx_scalar A_X = (vx_scalar) parameters[4]; + vx_scalar A_Y = (vx_scalar) parameters[5]; + vx_scalar BORDER = (vx_scalar) parameters[6]; + + Mat *mat, bl; + int W, H, a_x, a_y, border; + vx_int32 value = 0; + + //Extracting Values from the Scalar into Ksize and Ddepth + STATUS_ERROR_CHECK(vxReadScalarValue(S_width, &value));W = value; + STATUS_ERROR_CHECK(vxReadScalarValue(S_height, &value));H = value; + STATUS_ERROR_CHECK(vxReadScalarValue(A_X, &value));a_x = value; + STATUS_ERROR_CHECK(vxReadScalarValue(A_Y, &value));a_y = value; + STATUS_ERROR_CHECK(vxReadScalarValue(BORDER, &value));border = value; + + //Converting VX Image to OpenCV Mat + STATUS_ERROR_CHECK(match_vx_image_parameters(image_in, image_out)); + STATUS_ERROR_CHECK(VX_to_CV_Image(&mat, image_in)); + + //Compute using OpenCV + Point point; + point.x = a_x; + point.y = a_y; + cv::blur(*mat, bl, Size(W, H), point, border); + + //Converting OpenCV Mat into VX Image + STATUS_ERROR_CHECK(CV_to_VX_Image(image_out, &bl)); + + return status; +} + +/*! \brief *********************************************************************************************************** +Initializer function. + +This function is an optional function, if the inputs are needed to be intitialized. This function can be ignored and +a nullptr can be passed to vxAddKernel + +param [in] node -->The handle to the node. +param [in] parameters -->The index of the parameter. +param [in] num -->Number of parameters. +*************************************************************************************************************/ +static vx_status VX_CALLBACK CV_Blur_Initialize(vx_node node, const vx_reference *parameters, vx_uint32 num) +{ + /* Requires no initialization of memory or resources */ + return VX_SUCCESS; +} + +/*! \brief *********************************************************************************************************** +De-Initializer function. + +This function is an optional function, if the outputs are needed to be de-intitialized. This function can be ignored and +a nullptr can be passed to vxAddKernel + +param [in] node -->The handle to the node. +param [in] parameters -->The index of the parameter. +param [in] num -->Number of parameters. +*************************************************************************************************************/ +static vx_status VX_CALLBACK CV_Blur_Deinitialize(vx_node node, const vx_reference *parameters, vx_uint32 num) +{ + /* Requires no de-initialization of memory or resources */ + return VX_SUCCESS; +} + +/*! \brief*************************************************************************************************** +Function to Register the Kernel for Publish +*************************************************************************************************************/ +vx_status CV_blur_Register(vx_context context) +{ + vx_status status = VX_SUCCESS; + vx_kernel Kernel = vxAddKernel(context, + "org.opencv.blur", + VX_KERNEL_EXT_CV_BLUR, + CV_Blur_Kernel, + 7, + CV_Blur_InputValidator, + CV_Blur_OutputValidator, + CV_Blur_Initialize, + CV_Blur_Deinitialize); + + if (Kernel) + { + PARAM_ERROR_CHECK(vxAddParameterToKernel(Kernel, 0, VX_INPUT, VX_TYPE_IMAGE, VX_PARAMETER_STATE_REQUIRED)); + PARAM_ERROR_CHECK(vxAddParameterToKernel(Kernel, 1, VX_OUTPUT, VX_TYPE_IMAGE, VX_PARAMETER_STATE_REQUIRED)); + PARAM_ERROR_CHECK(vxAddParameterToKernel(Kernel, 2, VX_INPUT, VX_TYPE_SCALAR, VX_PARAMETER_STATE_REQUIRED)); + PARAM_ERROR_CHECK(vxAddParameterToKernel(Kernel, 3, VX_INPUT, VX_TYPE_SCALAR, VX_PARAMETER_STATE_REQUIRED)); + PARAM_ERROR_CHECK(vxAddParameterToKernel(Kernel, 4, VX_INPUT, VX_TYPE_SCALAR, VX_PARAMETER_STATE_REQUIRED)); + PARAM_ERROR_CHECK(vxAddParameterToKernel(Kernel, 5, VX_INPUT, VX_TYPE_SCALAR, VX_PARAMETER_STATE_REQUIRED)); + PARAM_ERROR_CHECK(vxAddParameterToKernel(Kernel, 6, VX_INPUT, VX_TYPE_SCALAR, VX_PARAMETER_STATE_REQUIRED)); + PARAM_ERROR_CHECK(vxFinalizeKernel(Kernel)); + } + + if (status != VX_SUCCESS) + { + exit: vxRemoveKernel(Kernel); return VX_FAILURE; + } + + return status; +} \ No newline at end of file diff --git a/vx_ext_cv/OpenCV_Boxfilter.cpp b/vx_ext_cv/OpenCV_Boxfilter.cpp new file mode 100644 index 0000000..c184428 --- /dev/null +++ b/vx_ext_cv/OpenCV_Boxfilter.cpp @@ -0,0 +1,255 @@ +/* +Copyright (c) 2015 Advanced Micro Devices, Inc. All rights reserved. + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. +*/ + + +#include"publishkernels.h" + +/************************************************************************************************************ +input parameter validator. +param [in] node The handle to the node. +param [in] index The index of the parameter to validate. +*************************************************************************************************************/ +static vx_status VX_CALLBACK CV_Boxfilter_InputValidator(vx_node node, vx_uint32 index) +{ + vx_status status = VX_SUCCESS; + vx_parameter param = vxGetParameterByIndex(node, index); + + if (index == 0) + { + vx_image image; + vx_df_image df_image = VX_DF_IMAGE_VIRT; + STATUS_ERROR_CHECK(vxQueryParameter(param, VX_PARAMETER_ATTRIBUTE_REF, &image, sizeof(vx_image))); + STATUS_ERROR_CHECK(vxQueryImage(image, VX_IMAGE_ATTRIBUTE_FORMAT, &df_image, sizeof(df_image))); + if (df_image != VX_DF_IMAGE_U8) + status = VX_ERROR_INVALID_VALUE; + vxReleaseImage(&image); + } + + else if (index == 1) + { + vx_image image; + vx_df_image df_image = VX_DF_IMAGE_VIRT; + STATUS_ERROR_CHECK(vxQueryParameter(param, VX_PARAMETER_ATTRIBUTE_REF, &image, sizeof(vx_image))); + STATUS_ERROR_CHECK(vxQueryImage(image, VX_IMAGE_ATTRIBUTE_FORMAT, &df_image, sizeof(df_image))); + if (df_image != VX_DF_IMAGE_U8) + status = VX_ERROR_INVALID_VALUE; + vxReleaseImage(&image); + } + + else if (index == 2) + { + vx_scalar scalar = 0; vx_enum type = 0; vx_int32 value = 0; + STATUS_ERROR_CHECK(vxQueryParameter(param, VX_PARAMETER_ATTRIBUTE_REF, &scalar, sizeof(scalar))); + STATUS_ERROR_CHECK(vxQueryScalar(scalar, VX_SCALAR_ATTRIBUTE_TYPE, &type, sizeof(type))); + STATUS_ERROR_CHECK(vxReadScalarValue(scalar, &value)); + if (value < -1 || type != VX_TYPE_INT32) + status = VX_ERROR_INVALID_VALUE; + vxReleaseScalar(&scalar); + } + + else if (index == 3) + { + vx_scalar scalar = 0; vx_enum type = 0; vx_int32 value = 0; + STATUS_ERROR_CHECK(vxQueryParameter(param, VX_PARAMETER_ATTRIBUTE_REF, &scalar, sizeof(scalar))); + STATUS_ERROR_CHECK(vxQueryScalar(scalar, VX_SCALAR_ATTRIBUTE_TYPE, &type, sizeof(type))); + STATUS_ERROR_CHECK(vxReadScalarValue(scalar, &value)); + if (value < 0 || type != VX_TYPE_INT32) + status = VX_ERROR_INVALID_VALUE; + vxReleaseScalar(&scalar); + } + + else if (index == 4) + { + vx_scalar scalar = 0; vx_enum type = 0; vx_int32 value = 0; + STATUS_ERROR_CHECK(vxQueryParameter(param, VX_PARAMETER_ATTRIBUTE_REF, &scalar, sizeof(scalar))); + STATUS_ERROR_CHECK(vxQueryScalar(scalar, VX_SCALAR_ATTRIBUTE_TYPE, &type, sizeof(type))); + STATUS_ERROR_CHECK(vxReadScalarValue(scalar, &value)); + if (value < 0 || type != VX_TYPE_INT32) + status = VX_ERROR_INVALID_VALUE; + vxReleaseScalar(&scalar); + } + + else if (index == 5) + { + vx_scalar scalar = 0; vx_enum type = 0; vx_int32 value = 0; + STATUS_ERROR_CHECK(vxQueryParameter(param, VX_PARAMETER_ATTRIBUTE_REF, &scalar, sizeof(scalar))); + STATUS_ERROR_CHECK(vxQueryScalar(scalar, VX_SCALAR_ATTRIBUTE_TYPE, &type, sizeof(type))); + STATUS_ERROR_CHECK(vxReadScalarValue(scalar, &value)); + if (value < -1 || type != VX_TYPE_INT32) + status = VX_ERROR_INVALID_VALUE; + vxReleaseScalar(&scalar); + } + + else if (index == 6) + { + vx_scalar scalar = 0; vx_enum type = 0; vx_int32 value = 0; + STATUS_ERROR_CHECK(vxQueryParameter(param, VX_PARAMETER_ATTRIBUTE_REF, &scalar, sizeof(scalar))); + STATUS_ERROR_CHECK(vxQueryScalar(scalar, VX_SCALAR_ATTRIBUTE_TYPE, &type, sizeof(type))); + STATUS_ERROR_CHECK(vxReadScalarValue(scalar, &value)); + if (value < -1 || type != VX_TYPE_INT32) + status = VX_ERROR_INVALID_VALUE; + vxReleaseScalar(&scalar); + } + + else if (index == 7) + { + vx_scalar scalar = 0; vx_enum type = 0; vx_bool value = vx_true_e; + STATUS_ERROR_CHECK(vxQueryParameter(param, VX_PARAMETER_ATTRIBUTE_REF, &scalar, sizeof(scalar))); + STATUS_ERROR_CHECK(vxQueryScalar(scalar, VX_SCALAR_ATTRIBUTE_TYPE, &type, sizeof(type))); + STATUS_ERROR_CHECK(vxReadScalarValue(scalar, &value)); + if ((value != vx_true_e && value != vx_false_e) || type != VX_TYPE_BOOL) + status = VX_ERROR_INVALID_VALUE; + vxReleaseScalar(&scalar); + } + + else if (index == 8) + { + vx_scalar scalar = 0; vx_enum type = 0; vx_int32 value = 0; + STATUS_ERROR_CHECK(vxQueryParameter(param, VX_PARAMETER_ATTRIBUTE_REF, &scalar, sizeof(scalar))); + STATUS_ERROR_CHECK(vxQueryScalar(scalar, VX_SCALAR_ATTRIBUTE_TYPE, &type, sizeof(type))); + STATUS_ERROR_CHECK(vxReadScalarValue(scalar, &value)); + if (value < 0 || type != VX_TYPE_INT32) + status = VX_ERROR_INVALID_VALUE; + vxReleaseScalar(&scalar); + } + + vxReleaseParameter(¶m); + return status; +} + +/************************************************************************************************************ +output parameter validator. +*************************************************************************************************************/ +static vx_status VX_CALLBACK CV_Boxfilter_OutputValidator(vx_node node, vx_uint32 index, vx_meta_format meta) +{ + vx_status status = VX_SUCCESS; + if (index == 1) + { + vx_parameter output_param = vxGetParameterByIndex(node, 1); + vx_image output; vx_uint32 width = 0, height = 0; vx_df_image format = VX_DF_IMAGE_VIRT; + + STATUS_ERROR_CHECK(vxQueryParameter(output_param, VX_PARAMETER_ATTRIBUTE_REF, &output, sizeof(vx_image))); + STATUS_ERROR_CHECK(vxQueryImage(output, VX_IMAGE_ATTRIBUTE_FORMAT, &format, sizeof(format))); + STATUS_ERROR_CHECK(vxQueryImage(output, VX_IMAGE_ATTRIBUTE_WIDTH, &width, sizeof(width))); + STATUS_ERROR_CHECK(vxQueryImage(output, VX_IMAGE_ATTRIBUTE_HEIGHT, &height, sizeof(height))); + + if (format != VX_DF_IMAGE_U8) + status = VX_ERROR_INVALID_VALUE; + + STATUS_ERROR_CHECK(vxSetMetaFormatAttribute(meta, VX_IMAGE_ATTRIBUTE_WIDTH, &width, sizeof(width))); + STATUS_ERROR_CHECK(vxSetMetaFormatAttribute(meta, VX_IMAGE_ATTRIBUTE_HEIGHT, &height, sizeof(height))); + STATUS_ERROR_CHECK(vxSetMetaFormatAttribute(meta, VX_IMAGE_ATTRIBUTE_FORMAT, &format, sizeof(format))); + + vxReleaseImage(&output); + vxReleaseParameter(&output_param); + } + return status; +} + +/************************************************************************************************************ +Execution Kernel +*************************************************************************************************************/ +static vx_status VX_CALLBACK CV_Boxfilter_Kernel(vx_node node, const vx_reference *parameters, vx_uint32 num) +{ + vx_status status = VX_SUCCESS; + + vx_image image_in = (vx_image) parameters[0]; + vx_image image_out = (vx_image) parameters[1]; + vx_scalar scalar = (vx_scalar) parameters[2]; + vx_scalar S_width = (vx_scalar) parameters[3]; + vx_scalar S_height = (vx_scalar) parameters[4]; + vx_scalar A_X = (vx_scalar) parameters[5]; + vx_scalar A_Y = (vx_scalar) parameters[6]; + vx_scalar NORM = (vx_scalar) parameters[7]; + vx_scalar BORDER = (vx_scalar) parameters[8]; + + Mat *mat, bl; + int ddepth, W, H, a_x = -1, a_y = -1, border = 4; + + vx_int32 value = 0; + vx_bool value_b, norm; + + //Extracting Values from the Scalar into Ksize and Ddepth + STATUS_ERROR_CHECK(vxReadScalarValue(scalar, &value));ddepth = value; + STATUS_ERROR_CHECK(vxReadScalarValue(S_width, &value));W = value; + STATUS_ERROR_CHECK(vxReadScalarValue(S_height, &value));H = value; + STATUS_ERROR_CHECK(vxReadScalarValue(A_X, &value));a_x = value; + STATUS_ERROR_CHECK(vxReadScalarValue(A_Y, &value));a_y = value; + STATUS_ERROR_CHECK(vxReadScalarValue(NORM, &value_b));norm = value_b; + STATUS_ERROR_CHECK(vxReadScalarValue(BORDER, &value));border = value; + + //Converting VX Image to OpenCV Mat + STATUS_ERROR_CHECK(match_vx_image_parameters(image_in, image_out)); + STATUS_ERROR_CHECK(VX_to_CV_Image(&mat, image_in)); + + //Compute using OpenCV + Point point; + bool Normalized; + if (norm == vx_true_e) Normalized = true; else Normalized = false; + point.x = a_x; + point.y = a_y; + cv::boxFilter(*mat, bl, ddepth, Size(W, H), point, Normalized, border); + + //Converting OpenCV Mat into VX Image + STATUS_ERROR_CHECK(CV_to_VX_Image(image_out, &bl)); + + return status; +} + +/************************************************************************************************************ +Function to Register the Kernel for Publish +*************************************************************************************************************/ +vx_status CV_Boxfilter_Register(vx_context context) +{ + vx_status status = VX_SUCCESS; + vx_kernel kernel = vxAddKernel(context, + "org.opencv.boxfilter", + VX_KERNEL_EXT_CV_BOXFILTER, + CV_Boxfilter_Kernel, + 9, + CV_Boxfilter_InputValidator, + CV_Boxfilter_OutputValidator, + nullptr, + nullptr); + + if (kernel) + { + PARAM_ERROR_CHECK(vxAddParameterToKernel(kernel, 0, VX_INPUT, VX_TYPE_IMAGE, VX_PARAMETER_STATE_REQUIRED)); + PARAM_ERROR_CHECK(vxAddParameterToKernel(kernel, 1, VX_OUTPUT, VX_TYPE_IMAGE, VX_PARAMETER_STATE_REQUIRED)); + PARAM_ERROR_CHECK(vxAddParameterToKernel(kernel, 2, VX_INPUT, VX_TYPE_SCALAR, VX_PARAMETER_STATE_REQUIRED)); + PARAM_ERROR_CHECK(vxAddParameterToKernel(kernel, 3, VX_INPUT, VX_TYPE_SCALAR, VX_PARAMETER_STATE_REQUIRED)); + PARAM_ERROR_CHECK(vxAddParameterToKernel(kernel, 4, VX_INPUT, VX_TYPE_SCALAR, VX_PARAMETER_STATE_REQUIRED)); + PARAM_ERROR_CHECK(vxAddParameterToKernel(kernel, 5, VX_INPUT, VX_TYPE_SCALAR, VX_PARAMETER_STATE_REQUIRED)); + PARAM_ERROR_CHECK(vxAddParameterToKernel(kernel, 6, VX_INPUT, VX_TYPE_SCALAR, VX_PARAMETER_STATE_REQUIRED)); + PARAM_ERROR_CHECK(vxAddParameterToKernel(kernel, 7, VX_INPUT, VX_TYPE_SCALAR, VX_PARAMETER_STATE_REQUIRED)); + PARAM_ERROR_CHECK(vxAddParameterToKernel(kernel, 8, VX_INPUT, VX_TYPE_SCALAR, VX_PARAMETER_STATE_REQUIRED)); + PARAM_ERROR_CHECK(vxFinalizeKernel(kernel)); + } + + if (status != VX_SUCCESS) + { + exit: vxRemoveKernel(kernel); return VX_FAILURE; + } + + return status; +} + diff --git a/vx_ext_cv/OpenCV_Canny.cpp b/vx_ext_cv/OpenCV_Canny.cpp new file mode 100644 index 0000000..35e8b00 --- /dev/null +++ b/vx_ext_cv/OpenCV_Canny.cpp @@ -0,0 +1,211 @@ +/* +Copyright (c) 2015 Advanced Micro Devices, Inc. All rights reserved. + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. +*/ + + +#include"publishkernels.h" + +/************************************************************************************************************ +input parameter validator. +param [in] node The handle to the node. +param [in] index The index of the parameter to validate. +*************************************************************************************************************/ +static vx_status VX_CALLBACK CV_Canny_InputValidator(vx_node node, vx_uint32 index) +{ + vx_status status = VX_SUCCESS; + vx_parameter param = vxGetParameterByIndex(node, index); + + if (index == 0) + { + vx_image image; + vx_df_image df_image = VX_DF_IMAGE_VIRT; + STATUS_ERROR_CHECK(vxQueryParameter(param, VX_PARAMETER_ATTRIBUTE_REF, &image, sizeof(vx_image))); + STATUS_ERROR_CHECK(vxQueryImage(image, VX_IMAGE_ATTRIBUTE_FORMAT, &df_image, sizeof(df_image))); + if (df_image != VX_DF_IMAGE_U8) + status = VX_ERROR_INVALID_VALUE; + vxReleaseImage(&image); + } + + else if (index == 1) + { + vx_image image; + vx_df_image df_image = VX_DF_IMAGE_VIRT; + STATUS_ERROR_CHECK(vxQueryParameter(param, VX_PARAMETER_ATTRIBUTE_REF, &image, sizeof(vx_image))); + STATUS_ERROR_CHECK(vxQueryImage(image, VX_IMAGE_ATTRIBUTE_FORMAT, &df_image, sizeof(df_image))); + if (df_image != VX_DF_IMAGE_U8) + status = VX_ERROR_INVALID_VALUE; + vxReleaseImage(&image); + } + + else if (index == 2) + { + vx_scalar scalar = 0; vx_enum type = 0; vx_float32 value = 0; + STATUS_ERROR_CHECK(vxQueryParameter(param, VX_PARAMETER_ATTRIBUTE_REF, &scalar, sizeof(scalar))); + STATUS_ERROR_CHECK(vxQueryScalar(scalar, VX_SCALAR_ATTRIBUTE_TYPE, &type, sizeof(type))); + STATUS_ERROR_CHECK(vxReadScalarValue(scalar, &value)); + if (value < 0 || type != VX_TYPE_FLOAT32) + status = VX_ERROR_INVALID_VALUE; + vxReleaseScalar(&scalar); + } + + else if (index == 3) + { + vx_scalar scalar = 0; vx_enum type = 0; vx_float32 value = 0; + STATUS_ERROR_CHECK(vxQueryParameter(param, VX_PARAMETER_ATTRIBUTE_REF, &scalar, sizeof(scalar))); + STATUS_ERROR_CHECK(vxQueryScalar(scalar, VX_SCALAR_ATTRIBUTE_TYPE, &type, sizeof(type))); + STATUS_ERROR_CHECK(vxReadScalarValue(scalar, &value)); + if (value < 0 || type != VX_TYPE_FLOAT32) + status = VX_ERROR_INVALID_VALUE; + vxReleaseScalar(&scalar); + } + + else if (index == 4) + { + vx_scalar scalar = 0; vx_enum type = 0; vx_int32 value = 0; + STATUS_ERROR_CHECK(vxQueryParameter(param, VX_PARAMETER_ATTRIBUTE_REF, &scalar, sizeof(scalar))); + STATUS_ERROR_CHECK(vxQueryScalar(scalar, VX_SCALAR_ATTRIBUTE_TYPE, &type, sizeof(type))); + STATUS_ERROR_CHECK(vxReadScalarValue(scalar, &value)); + if (value < 0 || type != VX_TYPE_INT32) + status = VX_ERROR_INVALID_VALUE; + vxReleaseScalar(&scalar); + } + + else if (index == 5) + { + vx_scalar scalar = 0; vx_enum type = 0; vx_bool value = vx_true_e; + STATUS_ERROR_CHECK(vxQueryParameter(param, VX_PARAMETER_ATTRIBUTE_REF, &scalar, sizeof(scalar))); + STATUS_ERROR_CHECK(vxQueryScalar(scalar, VX_SCALAR_ATTRIBUTE_TYPE, &type, sizeof(type))); + STATUS_ERROR_CHECK(vxReadScalarValue(scalar, &value)); + if ((value != vx_true_e && value != vx_false_e) || type != VX_TYPE_BOOL) + status = VX_ERROR_INVALID_VALUE; + vxReleaseScalar(&scalar); + } + + vxReleaseParameter(¶m); + return status; +} + +/************************************************************************************************************ +output parameter validator. +*************************************************************************************************************/ +static vx_status VX_CALLBACK CV_Canny_OutputValidator(vx_node node, vx_uint32 index, vx_meta_format meta) +{ + vx_status status = VX_SUCCESS; + if (index == 1) + { + vx_parameter output_param = vxGetParameterByIndex(node, 1); + vx_image output; vx_uint32 width = 0, height = 0; vx_df_image format = VX_DF_IMAGE_VIRT; + + STATUS_ERROR_CHECK(vxQueryParameter(output_param, VX_PARAMETER_ATTRIBUTE_REF, &output, sizeof(vx_image))); + STATUS_ERROR_CHECK(vxQueryImage(output, VX_IMAGE_ATTRIBUTE_FORMAT, &format, sizeof(format))); + STATUS_ERROR_CHECK(vxQueryImage(output, VX_IMAGE_ATTRIBUTE_WIDTH, &width, sizeof(width))); + STATUS_ERROR_CHECK(vxQueryImage(output, VX_IMAGE_ATTRIBUTE_HEIGHT, &height, sizeof(height))); + + if (format != VX_DF_IMAGE_U8 && format != VX_DF_IMAGE_S16) + status = VX_ERROR_INVALID_VALUE; + + STATUS_ERROR_CHECK(vxSetMetaFormatAttribute(meta, VX_IMAGE_ATTRIBUTE_WIDTH, &width, sizeof(width))); + STATUS_ERROR_CHECK(vxSetMetaFormatAttribute(meta, VX_IMAGE_ATTRIBUTE_HEIGHT, &height, sizeof(height))); + STATUS_ERROR_CHECK(vxSetMetaFormatAttribute(meta, VX_IMAGE_ATTRIBUTE_FORMAT, &format, sizeof(format))); + + vxReleaseImage(&output); + vxReleaseParameter(&output_param); + } + return status; +} + +/************************************************************************************************************ +Execution Kernel +*************************************************************************************************************/ +static vx_status VX_CALLBACK CV_Canny_Kernel(vx_node node, const vx_reference *parameters, vx_uint32 num) +{ + vx_status status = VX_SUCCESS; + + vx_image image_in = (vx_image) parameters[0]; + vx_image image_out = (vx_image) parameters[1]; + vx_scalar THRESHOLD1 = (vx_scalar) parameters[2]; + vx_scalar THRESHOLD2 = (vx_scalar) parameters[3]; + vx_scalar APERSIZE = (vx_scalar) parameters[4]; + vx_scalar L2GRAD = (vx_scalar) parameters[5]; + + Mat *mat, bl; + + float threshold1, threshold2; + int aperture_size; + vx_int32 value = 0; + vx_float32 value_f = 0; + vx_bool value_b, l2grad; + + //Extracting Values from the Scalar into Ksize and Ddepth + STATUS_ERROR_CHECK(vxReadScalarValue(THRESHOLD1, &value_f)); threshold1 = value_f; + STATUS_ERROR_CHECK(vxReadScalarValue(THRESHOLD2, &value_f)); threshold2 = value_f; + STATUS_ERROR_CHECK(vxReadScalarValue(APERSIZE, &value)); aperture_size = value; + STATUS_ERROR_CHECK(vxReadScalarValue(L2GRAD, &value_b)); l2grad = value_b; + + //Converting VX Image to OpenCV Mat + STATUS_ERROR_CHECK(match_vx_image_parameters(image_in, image_out)); + STATUS_ERROR_CHECK(VX_to_CV_Image(&mat, image_in)); + + //Compute using OpenCV + bool L2_Gradient; + if (l2grad == vx_true_e) L2_Gradient = true; else L2_Gradient = false; + cv::Canny(*mat, bl, threshold1, threshold2, aperture_size, L2_Gradient); + + //Converting OpenCV Mat into VX Image + STATUS_ERROR_CHECK(CV_to_VX_Image(image_out, &bl)); + + return status; +} + +/************************************************************************************************************ +Function to Register the Kernel for Publish +*************************************************************************************************************/ +vx_status CV_Canny_Register(vx_context context) +{ + vx_status status = VX_SUCCESS; + vx_kernel kernel = vxAddKernel(context, + "org.opencv.canny", + VX_KERNEL_EXT_CV_CANNY, + CV_Canny_Kernel, + 6, + CV_Canny_InputValidator, + CV_Canny_OutputValidator, + nullptr, + nullptr); + + if (kernel) + { + PARAM_ERROR_CHECK(vxAddParameterToKernel(kernel, 0, VX_INPUT, VX_TYPE_IMAGE, VX_PARAMETER_STATE_REQUIRED)); + PARAM_ERROR_CHECK(vxAddParameterToKernel(kernel, 1, VX_OUTPUT, VX_TYPE_IMAGE, VX_PARAMETER_STATE_REQUIRED)); + PARAM_ERROR_CHECK(vxAddParameterToKernel(kernel, 2, VX_INPUT, VX_TYPE_SCALAR, VX_PARAMETER_STATE_REQUIRED)); + PARAM_ERROR_CHECK(vxAddParameterToKernel(kernel, 3, VX_INPUT, VX_TYPE_SCALAR, VX_PARAMETER_STATE_REQUIRED)); + PARAM_ERROR_CHECK(vxAddParameterToKernel(kernel, 4, VX_INPUT, VX_TYPE_SCALAR, VX_PARAMETER_STATE_REQUIRED)); + PARAM_ERROR_CHECK(vxAddParameterToKernel(kernel, 5, VX_INPUT, VX_TYPE_SCALAR, VX_PARAMETER_STATE_REQUIRED)); + PARAM_ERROR_CHECK(vxFinalizeKernel(kernel)); + } + + if (status != VX_SUCCESS) + { + exit: vxRemoveKernel(kernel); return VX_FAILURE; + } + + return status; +} \ No newline at end of file diff --git a/vx_ext_cv/OpenCV_FAST_feature_detector.cpp b/vx_ext_cv/OpenCV_FAST_feature_detector.cpp new file mode 100644 index 0000000..b024da9 --- /dev/null +++ b/vx_ext_cv/OpenCV_FAST_feature_detector.cpp @@ -0,0 +1,171 @@ +/* +Copyright (c) 2015 Advanced Micro Devices, Inc. All rights reserved. + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. +*/ + + +#include"publishkernels.h" + +/*!*********************************************************************************************************** +input parameter validator. +param [in] node The handle to the node. +param [in] index The index of the parameter to validate. +*************************************************************************************************************/ +static vx_status VX_CALLBACK CV_FAST_detector_InputValidator(vx_node node, vx_uint32 index) +{ + vx_status status = VX_SUCCESS; + vx_parameter param = vxGetParameterByIndex(node, index); + + if (index == 0) + { + vx_image image; + vx_df_image df_image = VX_DF_IMAGE_VIRT; + STATUS_ERROR_CHECK(vxQueryParameter(param, VX_PARAMETER_ATTRIBUTE_REF, &image, sizeof(vx_image))); + STATUS_ERROR_CHECK(vxQueryImage(image, VX_IMAGE_ATTRIBUTE_FORMAT, &df_image, sizeof(df_image))); + if (df_image != VX_DF_IMAGE_U8) + status = VX_ERROR_INVALID_VALUE; + vxReleaseImage(&image); + } + + else if (index == 1) + { + vx_array array; vx_size size = 0; + STATUS_ERROR_CHECK(vxQueryParameter(param, VX_PARAMETER_ATTRIBUTE_REF, &array, sizeof(array))); + STATUS_ERROR_CHECK(vxQueryArray(array, VX_ARRAY_ATTRIBUTE_CAPACITY, &size, sizeof(size))); + vxReleaseArray(&array); + } + + else if (index == 2) + { + vx_scalar scalar = 0; vx_enum type = 0; vx_int32 value = 0; + STATUS_ERROR_CHECK(vxQueryParameter(param, VX_PARAMETER_ATTRIBUTE_REF, &scalar, sizeof(scalar))); + STATUS_ERROR_CHECK(vxQueryScalar(scalar, VX_SCALAR_ATTRIBUTE_TYPE, &type, sizeof(type))); + STATUS_ERROR_CHECK(vxReadScalarValue(scalar, &value)); + if (value < 0 || type != VX_TYPE_INT32) + status = VX_ERROR_INVALID_VALUE; + vxReleaseScalar(&scalar); + } + + else if (index == 3) + { + vx_scalar scalar = 0; vx_enum type = 0; vx_bool value = vx_true_e; + STATUS_ERROR_CHECK(vxQueryParameter(param, VX_PARAMETER_ATTRIBUTE_REF, &scalar, sizeof(scalar))); + STATUS_ERROR_CHECK(vxQueryScalar(scalar, VX_SCALAR_ATTRIBUTE_TYPE, &type, sizeof(type))); + STATUS_ERROR_CHECK(vxReadScalarValue(scalar, &value)); + if ((value != vx_true_e && value != vx_false_e) || type != VX_TYPE_BOOL) + status = VX_ERROR_INVALID_VALUE; + vxReleaseScalar(&scalar); + } + + vxReleaseParameter(¶m); + return status; +} + +/*!*********************************************************************************************************** +output parameter validator. +*************************************************************************************************************/ +static vx_status VX_CALLBACK CV_FAST_detector_OutputValidator(vx_node node, vx_uint32 index, vx_meta_format meta) +{ + vx_status status = VX_SUCCESS; + if (index == 1) + { + vx_parameter output_param = vxGetParameterByIndex(node, 1); + vx_array output; vx_size size = 0; + + STATUS_ERROR_CHECK(vxQueryParameter(output_param, VX_PARAMETER_ATTRIBUTE_REF, &output, sizeof(vx_array))); + STATUS_ERROR_CHECK(vxQueryArray(output, VX_ARRAY_ATTRIBUTE_CAPACITY, &size, sizeof(size))); + + if (size <= 0) + status = VX_ERROR_INVALID_VALUE; + + vxReleaseArray(&output); + vxReleaseParameter(&output_param); + } + + return status; +} + +/*!*********************************************************************************************************** +Execution Kernel +*************************************************************************************************************/ +static vx_status VX_CALLBACK CV_FAST_detector_Kernel(vx_node node, const vx_reference *parameters, vx_uint32 num) +{ + vx_status status = VX_SUCCESS; + + vx_image image_in = (vx_image) parameters[0]; + vx_array array = (vx_array) parameters[1]; + vx_scalar Threshold = (vx_scalar) parameters[2]; + vx_scalar NonMAXSuppression = (vx_scalar) parameters[3]; + Mat *mat, Img; + vx_int32 value = 0; + vx_bool value_b, nonmax; + int threshold = 0; + + //Extracting Values from the Scalar + STATUS_ERROR_CHECK(vxReadScalarValue(Threshold, &value)); threshold = value; + STATUS_ERROR_CHECK(vxReadScalarValue(NonMAXSuppression, &value_b)); nonmax = value_b; + + //Converting VX Image to OpenCV Mat + STATUS_ERROR_CHECK(VX_to_CV_Image(&mat, image_in)); + + //Compute using OpenCV + vector key_points; + bool nonmax_bool = false; + if (nonmax == vx_true_e) nonmax_bool = true; else nonmax_bool = false; + cv::FAST(*mat, key_points, threshold, nonmax_bool); + + //Converting OpenCV Keypoints to OpenVX Keypoints + STATUS_ERROR_CHECK(CV_to_VX_keypoints(key_points, array)); + + return status; +} + +/************************************************************************************************************ +Function to Register the Kernel for Publish +*************************************************************************************************************/ +vx_status CV_FAST_detector_Register(vx_context context) +{ + vx_status status = VX_SUCCESS; + vx_kernel Kernel = vxAddKernel(context, + "org.opencv.fast", + VX_KERNEL_EXT_CV_FAST, + CV_FAST_detector_Kernel, + 4, + CV_FAST_detector_InputValidator, + CV_FAST_detector_OutputValidator, + nullptr, + nullptr); + + if (Kernel) + { + PARAM_ERROR_CHECK(vxAddParameterToKernel(Kernel, 0, VX_INPUT, VX_TYPE_IMAGE, VX_PARAMETER_STATE_REQUIRED)); + PARAM_ERROR_CHECK(vxAddParameterToKernel(Kernel, 1, VX_BIDIRECTIONAL, VX_TYPE_ARRAY, VX_PARAMETER_STATE_REQUIRED)); + PARAM_ERROR_CHECK(vxAddParameterToKernel(Kernel, 2, VX_INPUT, VX_TYPE_SCALAR, VX_PARAMETER_STATE_REQUIRED)); + PARAM_ERROR_CHECK(vxAddParameterToKernel(Kernel, 3, VX_INPUT, VX_TYPE_SCALAR, VX_PARAMETER_STATE_REQUIRED)); + PARAM_ERROR_CHECK(vxFinalizeKernel(Kernel)); + } + + if (status != VX_SUCCESS) + { + exit: vxRemoveKernel(Kernel); return VX_FAILURE; + } + + return status; +} \ No newline at end of file diff --git a/vx_ext_cv/OpenCV_Gaussianblur.cpp b/vx_ext_cv/OpenCV_Gaussianblur.cpp new file mode 100644 index 0000000..6b5c3de --- /dev/null +++ b/vx_ext_cv/OpenCV_Gaussianblur.cpp @@ -0,0 +1,221 @@ +/* +Copyright (c) 2015 Advanced Micro Devices, Inc. All rights reserved. + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. +*/ + + +#include"publishkernels.h" + +/************************************************************************************************************ +input parameter validator. +param [in] node The handle to the node. +param [in] index The index of the parameter to validate. +*************************************************************************************************************/ +static vx_status VX_CALLBACK CV_Gaussianblur_InputValidator(vx_node node, vx_uint32 index) +{ + vx_status status = VX_SUCCESS; + vx_parameter param = vxGetParameterByIndex(node, index); + + if (index == 0) + { + vx_image image; + vx_df_image df_image = VX_DF_IMAGE_VIRT; + STATUS_ERROR_CHECK(vxQueryParameter(param, VX_PARAMETER_ATTRIBUTE_REF, &image, sizeof(vx_image))); + STATUS_ERROR_CHECK(vxQueryImage(image, VX_IMAGE_ATTRIBUTE_FORMAT, &df_image, sizeof(df_image))); + if (df_image != VX_DF_IMAGE_U8) + status = VX_ERROR_INVALID_VALUE; + vxReleaseImage(&image); + } + + else if (index == 1) + { + vx_image image; + vx_df_image df_image = VX_DF_IMAGE_VIRT; + STATUS_ERROR_CHECK(vxQueryParameter(param, VX_PARAMETER_ATTRIBUTE_REF, &image, sizeof(vx_image))); + STATUS_ERROR_CHECK(vxQueryImage(image, VX_IMAGE_ATTRIBUTE_FORMAT, &df_image, sizeof(df_image))); + if (df_image != VX_DF_IMAGE_U8) + status = VX_ERROR_INVALID_VALUE; + vxReleaseImage(&image); + } + + else if (index == 2) + { + vx_scalar scalar = 0; vx_enum type = 0; vx_int32 value = 0; + STATUS_ERROR_CHECK(vxQueryParameter(param, VX_PARAMETER_ATTRIBUTE_REF, &scalar, sizeof(scalar))); + STATUS_ERROR_CHECK(vxQueryScalar(scalar, VX_SCALAR_ATTRIBUTE_TYPE, &type, sizeof(type))); + STATUS_ERROR_CHECK(vxReadScalarValue(scalar, &value)); + if (value < 0 || (value % 2 == 0) || type != VX_TYPE_INT32) + status = VX_ERROR_INVALID_VALUE; + vxReleaseScalar(&scalar); + } + + else if (index == 3) + { + vx_scalar scalar = 0; vx_enum type = 0; vx_int32 value = 0; + STATUS_ERROR_CHECK(vxQueryParameter(param, VX_PARAMETER_ATTRIBUTE_REF, &scalar, sizeof(scalar))); + STATUS_ERROR_CHECK(vxQueryScalar(scalar, VX_SCALAR_ATTRIBUTE_TYPE, &type, sizeof(type))); + STATUS_ERROR_CHECK(vxReadScalarValue(scalar, &value)); + if (value < 0 || (value % 2 == 0) || type != VX_TYPE_INT32) + status = VX_ERROR_INVALID_VALUE; + vxReleaseScalar(&scalar); + } + + else if (index == 4) + { + vx_scalar scalar = 0; vx_enum type = 0; vx_float32 value = 0; + STATUS_ERROR_CHECK(vxQueryParameter(param, VX_PARAMETER_ATTRIBUTE_REF, &scalar, sizeof(scalar))); + STATUS_ERROR_CHECK(vxQueryScalar(scalar, VX_SCALAR_ATTRIBUTE_TYPE, &type, sizeof(type))); + STATUS_ERROR_CHECK(vxReadScalarValue(scalar, &value)); + if (value < 0 || type != VX_TYPE_FLOAT32) + status = VX_ERROR_INVALID_VALUE; + vxReleaseScalar(&scalar); + } + + else if (index == 5) + { + vx_scalar scalar = 0; vx_enum type = 0; vx_float32 value = 0; + STATUS_ERROR_CHECK(vxQueryParameter(param, VX_PARAMETER_ATTRIBUTE_REF, &scalar, sizeof(scalar))); + STATUS_ERROR_CHECK(vxQueryScalar(scalar, VX_SCALAR_ATTRIBUTE_TYPE, &type, sizeof(type))); + STATUS_ERROR_CHECK(vxReadScalarValue(scalar, &value)); + if (value < 0 || type != VX_TYPE_FLOAT32) + status = VX_ERROR_INVALID_VALUE; + vxReleaseScalar(&scalar); + } + + else if (index == 6) + { + vx_scalar scalar = 0; vx_enum type = 0; vx_int32 value = 0; + STATUS_ERROR_CHECK(vxQueryParameter(param, VX_PARAMETER_ATTRIBUTE_REF, &scalar, sizeof(scalar))); + STATUS_ERROR_CHECK(vxQueryScalar(scalar, VX_SCALAR_ATTRIBUTE_TYPE, &type, sizeof(type))); + STATUS_ERROR_CHECK(vxReadScalarValue(scalar, &value)); + if (value < 0 || type != VX_TYPE_INT32) + status = VX_ERROR_INVALID_VALUE; + vxReleaseScalar(&scalar); + } + + vxReleaseParameter(¶m); + return status; +} + +/************************************************************************************************************ +output parameter validator. +*************************************************************************************************************/ +static vx_status VX_CALLBACK CV_Gaussianblur_OutputValidator(vx_node node, vx_uint32 index, vx_meta_format meta) +{ + vx_status status = VX_SUCCESS; + if (index == 1) + { + vx_parameter output_param = vxGetParameterByIndex(node, 1); + vx_image output; vx_uint32 width = 0, height = 0; vx_df_image format = VX_DF_IMAGE_VIRT; + + STATUS_ERROR_CHECK(vxQueryParameter(output_param, VX_PARAMETER_ATTRIBUTE_REF, &output, sizeof(vx_image))); + STATUS_ERROR_CHECK(vxQueryImage(output, VX_IMAGE_ATTRIBUTE_FORMAT, &format, sizeof(format))); + STATUS_ERROR_CHECK(vxQueryImage(output, VX_IMAGE_ATTRIBUTE_WIDTH, &width, sizeof(width))); + STATUS_ERROR_CHECK(vxQueryImage(output, VX_IMAGE_ATTRIBUTE_HEIGHT, &height, sizeof(height))); + + if (format != VX_DF_IMAGE_U8) + status = VX_ERROR_INVALID_VALUE; + + STATUS_ERROR_CHECK(vxSetMetaFormatAttribute(meta, VX_IMAGE_ATTRIBUTE_WIDTH, &width, sizeof(width))); + STATUS_ERROR_CHECK(vxSetMetaFormatAttribute(meta, VX_IMAGE_ATTRIBUTE_HEIGHT, &height, sizeof(height))); + STATUS_ERROR_CHECK(vxSetMetaFormatAttribute(meta, VX_IMAGE_ATTRIBUTE_FORMAT, &format, sizeof(format))); + + vxReleaseImage(&output); + vxReleaseParameter(&output_param); + } + return status; +} + +/************************************************************************************************************ +Execution Kernel +*************************************************************************************************************/ +static vx_status VX_CALLBACK CV_Gaussianblur_Kernel(vx_node node, const vx_reference *parameters, vx_uint32 num) +{ + vx_status status = VX_SUCCESS; + + vx_image image_in = (vx_image) parameters[0]; + vx_image image_out = (vx_image) parameters[1]; + vx_scalar S_width = (vx_scalar) parameters[2]; + vx_scalar S_height = (vx_scalar) parameters[3]; + vx_scalar scalar = (vx_scalar) parameters[4]; + vx_scalar scalar_1 = (vx_scalar) parameters[5]; + vx_scalar scalar_2 = (vx_scalar) parameters[6]; + + Mat *mat, bl; + int W, H, Border; + float Sigma_X, Sigma_Y; + vx_int32 value = 0; + vx_float32 value_f = 0; + + //Extracting Values from the Scalar into Ksize and Ddepth + STATUS_ERROR_CHECK(vxReadScalarValue(S_width, &value)); W = value; + STATUS_ERROR_CHECK(vxReadScalarValue(S_height, &value)); H = value; + STATUS_ERROR_CHECK(vxReadScalarValue(scalar, &value_f)); Sigma_X = value_f; + STATUS_ERROR_CHECK(vxReadScalarValue(scalar_1, &value_f)); Sigma_Y = value_f; + STATUS_ERROR_CHECK(vxReadScalarValue(scalar_2, &value)); Border = value; + + //Converting VX Image to OpenCV Mat + STATUS_ERROR_CHECK(match_vx_image_parameters(image_in, image_out)); + STATUS_ERROR_CHECK(VX_to_CV_Image(&mat, image_in)); + + //Compute using OpenCV + cv::GaussianBlur(*mat, bl, Size(W, H), Sigma_X, Sigma_Y, Border); + + //Converting OpenCV Mat into VX Image + STATUS_ERROR_CHECK(CV_to_VX_Image(image_out, &bl)); + + return status; +} + +/************************************************************************************************************ +Function to Register the Kernel for Publish +*************************************************************************************************************/ +vx_status CV_Gaussianblur_Register(vx_context context) +{ + vx_status status = VX_SUCCESS; + vx_kernel kernel = vxAddKernel(context, + "org.opencv.gaussianblur", + VX_KERNEL_EXT_CV_GAUSSIAN_BLUR, + CV_Gaussianblur_Kernel, + 7, + CV_Gaussianblur_InputValidator, + CV_Gaussianblur_OutputValidator, + nullptr, + nullptr); + + if (kernel) + { + PARAM_ERROR_CHECK(vxAddParameterToKernel(kernel, 0, VX_INPUT, VX_TYPE_IMAGE, VX_PARAMETER_STATE_REQUIRED)); + PARAM_ERROR_CHECK(vxAddParameterToKernel(kernel, 1, VX_OUTPUT, VX_TYPE_IMAGE, VX_PARAMETER_STATE_REQUIRED)); + PARAM_ERROR_CHECK(vxAddParameterToKernel(kernel, 2, VX_INPUT, VX_TYPE_SCALAR, VX_PARAMETER_STATE_REQUIRED)); + PARAM_ERROR_CHECK(vxAddParameterToKernel(kernel, 3, VX_INPUT, VX_TYPE_SCALAR, VX_PARAMETER_STATE_REQUIRED)); + PARAM_ERROR_CHECK(vxAddParameterToKernel(kernel, 4, VX_INPUT, VX_TYPE_SCALAR, VX_PARAMETER_STATE_REQUIRED)); + PARAM_ERROR_CHECK(vxAddParameterToKernel(kernel, 5, VX_INPUT, VX_TYPE_SCALAR, VX_PARAMETER_STATE_REQUIRED)); + PARAM_ERROR_CHECK(vxAddParameterToKernel(kernel, 6, VX_INPUT, VX_TYPE_SCALAR, VX_PARAMETER_STATE_REQUIRED)); + PARAM_ERROR_CHECK(vxFinalizeKernel(kernel)); + } + + if (status != VX_SUCCESS) + { + exit: vxRemoveKernel(kernel); return VX_FAILURE; + } + + return status; +} diff --git a/vx_ext_cv/OpenCV_Good_Features_to_Track_detector.cpp b/vx_ext_cv/OpenCV_Good_Features_to_Track_detector.cpp new file mode 100644 index 0000000..d358a53 --- /dev/null +++ b/vx_ext_cv/OpenCV_Good_Features_to_Track_detector.cpp @@ -0,0 +1,245 @@ +/* +Copyright (c) 2015 Advanced Micro Devices, Inc. All rights reserved. + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. +*/ + + +#include"publishkernels.h" + +/*!*********************************************************************************************************** +input parameter validator. +param [in] node The handle to the node. +param [in] index The index of the parameter to validate. +*************************************************************************************************************/ +static vx_status VX_CALLBACK CV_good_feature_detector_InputValidator(vx_node node, vx_uint32 index) +{ + + vx_status status = VX_SUCCESS; + + vx_parameter param = vxGetParameterByIndex(node, index); + + if (index == 0) + { + vx_image image; + vx_df_image df_image = VX_DF_IMAGE_VIRT; + STATUS_ERROR_CHECK(vxQueryParameter(param, VX_PARAMETER_ATTRIBUTE_REF, &image, sizeof(vx_image))); + STATUS_ERROR_CHECK(vxQueryImage(image, VX_IMAGE_ATTRIBUTE_FORMAT, &df_image, sizeof(df_image))); + if (df_image != VX_DF_IMAGE_U8) + status = VX_ERROR_INVALID_VALUE; + vxReleaseImage(&image); + } + + else if (index == 1) + { + vx_array array; vx_size size = 0; + STATUS_ERROR_CHECK(vxQueryParameter(param, VX_PARAMETER_ATTRIBUTE_REF, &array, sizeof(array))); + STATUS_ERROR_CHECK(vxQueryArray(array, VX_ARRAY_ATTRIBUTE_CAPACITY, &size, sizeof(size))); + vxReleaseArray(&array); + } + + else if (index == 2) + { + vx_scalar scalar = 0; vx_enum type = 0; vx_int32 value = 0; + STATUS_ERROR_CHECK(vxQueryParameter(param, VX_PARAMETER_ATTRIBUTE_REF, &scalar, sizeof(scalar))); + STATUS_ERROR_CHECK(vxQueryScalar(scalar, VX_SCALAR_ATTRIBUTE_TYPE, &type, sizeof(type))); + STATUS_ERROR_CHECK(vxReadScalarValue(scalar, &value)); + if (value < 0 || type != VX_TYPE_INT32) + status = VX_ERROR_INVALID_VALUE; + vxReleaseScalar(&scalar); + } + + else if (index == 3) + { + vx_scalar scalar = 0; vx_enum type = 0; vx_float32 value = 0; + STATUS_ERROR_CHECK(vxQueryParameter(param, VX_PARAMETER_ATTRIBUTE_REF, &scalar, sizeof(scalar))); + STATUS_ERROR_CHECK(vxQueryScalar(scalar, VX_SCALAR_ATTRIBUTE_TYPE, &type, sizeof(type))); + STATUS_ERROR_CHECK(vxReadScalarValue(scalar, &value)); + if (value < 0 || type != VX_TYPE_FLOAT32) + status = VX_ERROR_INVALID_VALUE; + vxReleaseScalar(&scalar); + } + + else if (index == 4) + { + vx_scalar scalar = 0; vx_enum type = 0; vx_float32 value = 0; + STATUS_ERROR_CHECK(vxQueryParameter(param, VX_PARAMETER_ATTRIBUTE_REF, &scalar, sizeof(scalar))); + STATUS_ERROR_CHECK(vxQueryScalar(scalar, VX_SCALAR_ATTRIBUTE_TYPE, &type, sizeof(type))); + STATUS_ERROR_CHECK(vxReadScalarValue(scalar, &value)); + if (value < 0 || type != VX_TYPE_FLOAT32) + status = VX_ERROR_INVALID_VALUE; + vxReleaseScalar(&scalar); + } + + if (index == 5) + { + vx_image image; + vx_df_image df_image = VX_DF_IMAGE_VIRT; + STATUS_ERROR_CHECK(vxQueryParameter(param, VX_PARAMETER_ATTRIBUTE_REF, &image, sizeof(vx_image))); + STATUS_ERROR_CHECK(vxQueryImage(image, VX_IMAGE_ATTRIBUTE_FORMAT, &df_image, sizeof(df_image))); + if (df_image != VX_DF_IMAGE_U8) + status = VX_ERROR_INVALID_VALUE; + vxReleaseImage(&image); + } + + else if (index == 6) + { + vx_scalar scalar = 0; vx_enum type = 0; vx_int32 value = 0; + STATUS_ERROR_CHECK(vxQueryParameter(param, VX_PARAMETER_ATTRIBUTE_REF, &scalar, sizeof(scalar))); + STATUS_ERROR_CHECK(vxQueryScalar(scalar, VX_SCALAR_ATTRIBUTE_TYPE, &type, sizeof(type))); + STATUS_ERROR_CHECK(vxReadScalarValue(scalar, &value)); + if (value < 0 || type != VX_TYPE_INT32) + status = VX_ERROR_INVALID_VALUE; + vxReleaseScalar(&scalar); + } + + else if (index == 7) + { + vx_scalar scalar = 0; vx_enum type = 0; vx_bool value = vx_true_e; + STATUS_ERROR_CHECK(vxQueryParameter(param, VX_PARAMETER_ATTRIBUTE_REF, &scalar, sizeof(scalar))); + STATUS_ERROR_CHECK(vxQueryScalar(scalar, VX_SCALAR_ATTRIBUTE_TYPE, &type, sizeof(type))); + STATUS_ERROR_CHECK(vxReadScalarValue(scalar, &value)); + if ((value != vx_true_e && value != vx_false_e) || type != VX_TYPE_BOOL) + status = VX_ERROR_INVALID_VALUE; + vxReleaseScalar(&scalar); + } + + else if (index == 8) + { + vx_scalar scalar = 0; vx_enum type = 0; vx_float32 value = 0; + STATUS_ERROR_CHECK(vxQueryParameter(param, VX_PARAMETER_ATTRIBUTE_REF, &scalar, sizeof(scalar))); + STATUS_ERROR_CHECK(vxQueryScalar(scalar, VX_SCALAR_ATTRIBUTE_TYPE, &type, sizeof(type))); + STATUS_ERROR_CHECK(vxReadScalarValue(scalar, &value)); + if (value < 0 || type != VX_TYPE_FLOAT32) + status = VX_ERROR_INVALID_VALUE; + vxReleaseScalar(&scalar); + } + + vxReleaseParameter(¶m); + return status; +} + +/*!*********************************************************************************************************** +output parameter validator. +*************************************************************************************************************/ +static vx_status VX_CALLBACK CV_good_feature_detector_OutputValidator(vx_node node, vx_uint32 index, vx_meta_format meta) +{ + vx_status status = VX_SUCCESS; + if (index == 1) + { + vx_parameter output_param = vxGetParameterByIndex(node, 1); + vx_array output; vx_size size = 0; + + STATUS_ERROR_CHECK(vxQueryParameter(output_param, VX_PARAMETER_ATTRIBUTE_REF, &output, sizeof(vx_array))); + STATUS_ERROR_CHECK(vxQueryArray(output, VX_ARRAY_ATTRIBUTE_CAPACITY, &size, sizeof(size))); + + if (size <= 0) + status = VX_ERROR_INVALID_VALUE; + + vxReleaseArray(&output); + vxReleaseParameter(&output_param); + } + + return status; +} + +/*!*********************************************************************************************************** +Execution Kernel +*************************************************************************************************************/ +static vx_status VX_CALLBACK CV_good_feature_detector_Kernel(vx_node node, const vx_reference *parameters, vx_uint32 num) +{ + vx_status status = VX_SUCCESS; + + vx_image image_in = (vx_image) parameters[0]; + vx_array array = (vx_array) parameters[1]; + vx_scalar MAXCORNERS = (vx_scalar) parameters[2]; + vx_scalar QUALITYLEVEL = (vx_scalar) parameters[3]; + vx_scalar MINDISTANCE = (vx_scalar) parameters[4]; + vx_image mask = (vx_image) parameters[5]; + vx_scalar BLOCKSIZE = (vx_scalar) parameters[6]; + vx_scalar USEHARRISDETECTOR = (vx_scalar) parameters[7]; + vx_scalar K = (vx_scalar) parameters[8]; + + Mat *mat, *mask_mat, Img; + int maxCorners, blockSize; + float qualityLevel, minDistance, k; + vx_float32 FloatValue = 0; + vx_int32 value = 0; + vx_bool useHarris, value_b; + + //Extracting Values from the Scalar + STATUS_ERROR_CHECK(vxReadScalarValue(QUALITYLEVEL, &FloatValue)); qualityLevel = FloatValue; + STATUS_ERROR_CHECK(vxReadScalarValue(MINDISTANCE, &FloatValue)); minDistance = FloatValue; + STATUS_ERROR_CHECK(vxReadScalarValue(K, &FloatValue)); k = FloatValue; + STATUS_ERROR_CHECK(vxReadScalarValue(MAXCORNERS, &value)); maxCorners = value; + STATUS_ERROR_CHECK(vxReadScalarValue(BLOCKSIZE, &value)); blockSize = value; + STATUS_ERROR_CHECK(vxReadScalarValue(USEHARRISDETECTOR, &value_b)); useHarris = value_b; + + //Converting VX Image to OpenCV Mat + STATUS_ERROR_CHECK(VX_to_CV_Image(&mat, image_in)); + STATUS_ERROR_CHECK(VX_to_CV_Image(&mask_mat, mask)); + + //Compute using OpenCV + vector Points2; + bool useHarrisDetector; + if (useHarris == 1) useHarrisDetector = true; else useHarrisDetector = false; + cv::goodFeaturesToTrack(*mat, Points2, maxCorners, qualityLevel, minDistance, *mask_mat, blockSize, useHarrisDetector, k); ////Compute using OpenCV + + //Converting OpenCV Keypoints to OpenVX Keypoints + STATUS_ERROR_CHECK(CVPoints2f_to_VX_keypoints(Points2, array)); + + return status; +} + +/************************************************************************************************************ +Function to Register the Kernel for Publish +*************************************************************************************************************/ +vx_status CV_good_features_to_track_Register(vx_context context) +{ + vx_status status = VX_SUCCESS; + vx_kernel Kernel = vxAddKernel(context, + "org.opencv.good_features_to_track", + VX_KERNEL_EXT_CV_GOOD_FEATURE_TO_TRACK, + CV_good_feature_detector_Kernel, + 9, + CV_good_feature_detector_InputValidator, + CV_good_feature_detector_OutputValidator, + nullptr, + nullptr); + + if (Kernel) + { + PARAM_ERROR_CHECK(vxAddParameterToKernel(Kernel, 0, VX_INPUT, VX_TYPE_IMAGE, VX_PARAMETER_STATE_REQUIRED)); + PARAM_ERROR_CHECK(vxAddParameterToKernel(Kernel, 1, VX_BIDIRECTIONAL, VX_TYPE_ARRAY, VX_PARAMETER_STATE_REQUIRED)); + PARAM_ERROR_CHECK(vxAddParameterToKernel(Kernel, 2, VX_INPUT, VX_TYPE_SCALAR, VX_PARAMETER_STATE_REQUIRED)); + PARAM_ERROR_CHECK(vxAddParameterToKernel(Kernel, 3, VX_INPUT, VX_TYPE_SCALAR, VX_PARAMETER_STATE_REQUIRED)); + PARAM_ERROR_CHECK(vxAddParameterToKernel(Kernel, 4, VX_INPUT, VX_TYPE_SCALAR, VX_PARAMETER_STATE_REQUIRED)); + PARAM_ERROR_CHECK(vxAddParameterToKernel(Kernel, 5, VX_INPUT, VX_TYPE_IMAGE, VX_PARAMETER_STATE_REQUIRED)); + PARAM_ERROR_CHECK(vxAddParameterToKernel(Kernel, 6, VX_INPUT, VX_TYPE_SCALAR, VX_PARAMETER_STATE_REQUIRED)); + PARAM_ERROR_CHECK(vxAddParameterToKernel(Kernel, 7, VX_INPUT, VX_TYPE_SCALAR, VX_PARAMETER_STATE_REQUIRED)); + PARAM_ERROR_CHECK(vxAddParameterToKernel(Kernel, 8, VX_INPUT, VX_TYPE_SCALAR, VX_PARAMETER_STATE_REQUIRED)); + PARAM_ERROR_CHECK(vxFinalizeKernel(Kernel)); + } + if (status != VX_SUCCESS) + { + exit: vxRemoveKernel(Kernel); return VX_FAILURE; + } + + return status; +} diff --git a/vx_ext_cv/OpenCV_Laplacian.cpp b/vx_ext_cv/OpenCV_Laplacian.cpp new file mode 100644 index 0000000..16b1bed --- /dev/null +++ b/vx_ext_cv/OpenCV_Laplacian.cpp @@ -0,0 +1,221 @@ +/* +Copyright (c) 2015 Advanced Micro Devices, Inc. All rights reserved. + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. +*/ + + +#include"publishkernels.h" + +/************************************************************************************************************ +input parameter validator. +param [in] node The handle to the node. +param [in] index The index of the parameter to validate. +*************************************************************************************************************/ +static vx_status VX_CALLBACK CV_Laplacian_InputValidator(vx_node node, vx_uint32 index) +{ + vx_status status = VX_SUCCESS; + vx_parameter param = vxGetParameterByIndex(node, index); + + if (index == 0) + { + vx_image image; + vx_df_image df_image = VX_DF_IMAGE_VIRT; + STATUS_ERROR_CHECK(vxQueryParameter(param, VX_PARAMETER_ATTRIBUTE_REF, &image, sizeof(vx_image))); + STATUS_ERROR_CHECK(vxQueryImage(image, VX_IMAGE_ATTRIBUTE_FORMAT, &df_image, sizeof(df_image))); + if (df_image != VX_DF_IMAGE_U8) + status = VX_ERROR_INVALID_VALUE; + vxReleaseImage(&image); + } + + else if (index == 1) + { + vx_image image; + vx_df_image df_image = VX_DF_IMAGE_VIRT; + STATUS_ERROR_CHECK(vxQueryParameter(param, VX_PARAMETER_ATTRIBUTE_REF, &image, sizeof(vx_image))); + STATUS_ERROR_CHECK(vxQueryImage(image, VX_IMAGE_ATTRIBUTE_FORMAT, &df_image, sizeof(df_image))); + if (df_image != VX_DF_IMAGE_U8) + status = VX_ERROR_INVALID_VALUE; + vxReleaseImage(&image); + } + + else if (index == 2) + { + vx_scalar scalar = 0; vx_enum type = 0; vx_int32 value = 0; + STATUS_ERROR_CHECK(vxQueryParameter(param, VX_PARAMETER_ATTRIBUTE_REF, &scalar, sizeof(scalar))); + STATUS_ERROR_CHECK(vxQueryScalar(scalar, VX_SCALAR_ATTRIBUTE_TYPE, &type, sizeof(type))); + STATUS_ERROR_CHECK(vxReadScalarValue(scalar, &value)); + if ((value != -1 && value != 0 && value != 5 && value != 6) || type != VX_TYPE_INT32) + status = VX_ERROR_INVALID_VALUE; + vxReleaseScalar(&scalar); + } + + else if (index == 3) + { + vx_scalar scalar = 0; vx_enum type = 0; vx_int32 value = 0; + STATUS_ERROR_CHECK(vxQueryParameter(param, VX_PARAMETER_ATTRIBUTE_REF, &scalar, sizeof(scalar))); + STATUS_ERROR_CHECK(vxQueryScalar(scalar, VX_SCALAR_ATTRIBUTE_TYPE, &type, sizeof(type))); + STATUS_ERROR_CHECK(vxReadScalarValue(scalar, &value)); + if (value < 0 || (value % 2 == 0) || type != VX_TYPE_INT32) + status = VX_ERROR_INVALID_VALUE; + vxReleaseScalar(&scalar); + } + + else if (index == 4) + { + vx_scalar scalar = 0; vx_enum type = 0; vx_float32 value = 0; + STATUS_ERROR_CHECK(vxQueryParameter(param, VX_PARAMETER_ATTRIBUTE_REF, &scalar, sizeof(scalar))); + STATUS_ERROR_CHECK(vxQueryScalar(scalar, VX_SCALAR_ATTRIBUTE_TYPE, &type, sizeof(type))); + STATUS_ERROR_CHECK(vxReadScalarValue(scalar, &value)); + if (value < 0 || type != VX_TYPE_FLOAT32) + status = VX_ERROR_INVALID_VALUE; + vxReleaseScalar(&scalar); + } + + else if (index == 5) + { + vx_scalar scalar = 0; vx_enum type = 0; vx_float32 value = 0; + STATUS_ERROR_CHECK(vxQueryParameter(param, VX_PARAMETER_ATTRIBUTE_REF, &scalar, sizeof(scalar))); + STATUS_ERROR_CHECK(vxQueryScalar(scalar, VX_SCALAR_ATTRIBUTE_TYPE, &type, sizeof(type))); + STATUS_ERROR_CHECK(vxReadScalarValue(scalar, &value)); + if (value < 0 || type != VX_TYPE_FLOAT32) + status = VX_ERROR_INVALID_VALUE; + vxReleaseScalar(&scalar); + } + + else if (index == 6) + { + vx_scalar scalar = 0; vx_enum type = 0; vx_int32 value = 0; + STATUS_ERROR_CHECK(vxQueryParameter(param, VX_PARAMETER_ATTRIBUTE_REF, &scalar, sizeof(scalar))); + STATUS_ERROR_CHECK(vxQueryScalar(scalar, VX_SCALAR_ATTRIBUTE_TYPE, &type, sizeof(type))); + STATUS_ERROR_CHECK(vxReadScalarValue(scalar, &value)); + if (value < 0 || type != VX_TYPE_INT32) + status = VX_ERROR_INVALID_VALUE; + vxReleaseScalar(&scalar); + } + + vxReleaseParameter(¶m); + return status; +} + +/************************************************************************************************************ +output parameter validator. +*************************************************************************************************************/ +static vx_status VX_CALLBACK CV_Laplacian_OutputValidator(vx_node node, vx_uint32 index, vx_meta_format meta) +{ + vx_status status = VX_SUCCESS; + if (index == 1) + { + vx_parameter output_param = vxGetParameterByIndex(node, 1); + vx_image output; vx_uint32 width = 0, height = 0; vx_df_image format = VX_DF_IMAGE_VIRT; + + STATUS_ERROR_CHECK(vxQueryParameter(output_param, VX_PARAMETER_ATTRIBUTE_REF, &output, sizeof(vx_image))); + STATUS_ERROR_CHECK(vxQueryImage(output, VX_IMAGE_ATTRIBUTE_FORMAT, &format, sizeof(format))); + STATUS_ERROR_CHECK(vxQueryImage(output, VX_IMAGE_ATTRIBUTE_WIDTH, &width, sizeof(width))); + STATUS_ERROR_CHECK(vxQueryImage(output, VX_IMAGE_ATTRIBUTE_HEIGHT, &height, sizeof(height))); + + if (format != VX_DF_IMAGE_U8) + status = VX_ERROR_INVALID_VALUE; + + STATUS_ERROR_CHECK(vxSetMetaFormatAttribute(meta, VX_IMAGE_ATTRIBUTE_WIDTH, &width, sizeof(width))); + STATUS_ERROR_CHECK(vxSetMetaFormatAttribute(meta, VX_IMAGE_ATTRIBUTE_HEIGHT, &height, sizeof(height))); + STATUS_ERROR_CHECK(vxSetMetaFormatAttribute(meta, VX_IMAGE_ATTRIBUTE_FORMAT, &format, sizeof(format))); + + vxReleaseImage(&output); + vxReleaseParameter(&output_param); + } + return status; +} + +/************************************************************************************************************ +Execution Kernel +*************************************************************************************************************/ +static vx_status VX_CALLBACK CV_Laplacian_Kernel(vx_node node, const vx_reference *parameters, vx_uint32 num) +{ + vx_status status = VX_SUCCESS; + + vx_image image_in = (vx_image) parameters[0]; + vx_image image_out = (vx_image) parameters[1]; + vx_scalar DDEPTH = (vx_scalar) parameters[2]; + vx_scalar KSIZE = (vx_scalar) parameters[3]; + vx_scalar SCALE = (vx_scalar) parameters[4]; + vx_scalar DELTA = (vx_scalar) parameters[5]; + vx_scalar BORDER = (vx_scalar) parameters[6]; + + Mat *mat, bl; + int ddepth, ksize, Border; + float scale, delta; + vx_int32 value = 0; + vx_float32 value_f = 0; + + //Extracting Values from the Scalar into Ksize and Ddepth + STATUS_ERROR_CHECK(vxReadScalarValue(DDEPTH, &value)); ddepth = value; + STATUS_ERROR_CHECK(vxReadScalarValue(KSIZE, &value)); ksize = value; + STATUS_ERROR_CHECK(vxReadScalarValue(SCALE, &value_f)); scale = value_f; + STATUS_ERROR_CHECK(vxReadScalarValue(DELTA, &value_f)); delta = value_f; + STATUS_ERROR_CHECK(vxReadScalarValue(BORDER, &value)); Border = value; + + //Converting VX Image to OpenCV Mat + STATUS_ERROR_CHECK(match_vx_image_parameters(image_in, image_out)); + STATUS_ERROR_CHECK(VX_to_CV_Image(&mat, image_in)); + + //Compute using OpenCV + cv::Laplacian(*mat, bl, ddepth, ksize, scale, delta, Border); + + //Converting OpenCV Mat into VX Image + STATUS_ERROR_CHECK(CV_to_VX_Image(image_out, &bl)); + + return status; +} + +/************************************************************************************************************ +Function to Register the Kernel for Publish +*************************************************************************************************************/ +vx_status CV_Laplacian_Register(vx_context context) +{ + vx_status status = VX_SUCCESS; + vx_kernel kernel = vxAddKernel(context, + "org.opencv.laplacian", + VX_KERNEL_EXT_CV_LAPLACIAN, + CV_Laplacian_Kernel, + 7, + CV_Laplacian_InputValidator, + CV_Laplacian_OutputValidator, + nullptr, + nullptr); + + if (kernel) + { + PARAM_ERROR_CHECK(vxAddParameterToKernel(kernel, 0, VX_INPUT, VX_TYPE_IMAGE, VX_PARAMETER_STATE_REQUIRED)); + PARAM_ERROR_CHECK(vxAddParameterToKernel(kernel, 1, VX_OUTPUT, VX_TYPE_IMAGE, VX_PARAMETER_STATE_REQUIRED)); + PARAM_ERROR_CHECK(vxAddParameterToKernel(kernel, 2, VX_INPUT, VX_TYPE_SCALAR, VX_PARAMETER_STATE_REQUIRED)); + PARAM_ERROR_CHECK(vxAddParameterToKernel(kernel, 3, VX_INPUT, VX_TYPE_SCALAR, VX_PARAMETER_STATE_REQUIRED)); + PARAM_ERROR_CHECK(vxAddParameterToKernel(kernel, 4, VX_INPUT, VX_TYPE_SCALAR, VX_PARAMETER_STATE_REQUIRED)); + PARAM_ERROR_CHECK(vxAddParameterToKernel(kernel, 5, VX_INPUT, VX_TYPE_SCALAR, VX_PARAMETER_STATE_REQUIRED)); + PARAM_ERROR_CHECK(vxAddParameterToKernel(kernel, 6, VX_INPUT, VX_TYPE_SCALAR, VX_PARAMETER_STATE_REQUIRED)); + PARAM_ERROR_CHECK(vxFinalizeKernel(kernel)); + } + + if (status != VX_SUCCESS) + { + exit: vxRemoveKernel(kernel); return VX_FAILURE; + } + + return status; +} \ No newline at end of file diff --git a/vx_ext_cv/OpenCV_MSER_feature_detector.cpp b/vx_ext_cv/OpenCV_MSER_feature_detector.cpp new file mode 100644 index 0000000..dda09a9 --- /dev/null +++ b/vx_ext_cv/OpenCV_MSER_feature_detector.cpp @@ -0,0 +1,286 @@ +/* +Copyright (c) 2015 Advanced Micro Devices, Inc. All rights reserved. + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. +*/ + + +#include"publishkernels.h" + +/*!*********************************************************************************************************** +input parameter validator. +param [in] node The handle to the node. +param [in] index The index of the parameter to validate. +*************************************************************************************************************/ +static vx_status VX_CALLBACK CV_MSER_feature_detector_InputValidator(vx_node node, vx_uint32 index) +{ + vx_status status = VX_SUCCESS; + vx_parameter param = vxGetParameterByIndex(node, index); + + if (index == 0) + { + vx_image image; + vx_df_image df_image = VX_DF_IMAGE_VIRT; + STATUS_ERROR_CHECK(vxQueryParameter(param, VX_PARAMETER_ATTRIBUTE_REF, &image, sizeof(vx_image))); + STATUS_ERROR_CHECK(vxQueryImage(image, VX_IMAGE_ATTRIBUTE_FORMAT, &df_image, sizeof(df_image))); + if (df_image != VX_DF_IMAGE_U8) + status = VX_ERROR_INVALID_VALUE; + vxReleaseImage(&image); + } + + else if (index == 1) + { + vx_array array; vx_size size = 0; + STATUS_ERROR_CHECK(vxQueryParameter(param, VX_PARAMETER_ATTRIBUTE_REF, &array, sizeof(array))); + STATUS_ERROR_CHECK(vxQueryArray(array, VX_ARRAY_ATTRIBUTE_CAPACITY, &size, sizeof(size))); + vxReleaseArray(&array); + } + + if (index == 2) + { + vx_image image; + vx_df_image df_image = VX_DF_IMAGE_VIRT; + STATUS_ERROR_CHECK(vxQueryParameter(param, VX_PARAMETER_ATTRIBUTE_REF, &image, sizeof(vx_image))); + STATUS_ERROR_CHECK(vxQueryImage(image, VX_IMAGE_ATTRIBUTE_FORMAT, &df_image, sizeof(df_image))); + if (df_image != VX_DF_IMAGE_U8) + status = VX_ERROR_INVALID_VALUE; + vxReleaseImage(&image); + } + + else if (index == 3) + { + vx_scalar scalar = 0; vx_enum type = 0; vx_int32 value = 0; + STATUS_ERROR_CHECK(vxQueryParameter(param, VX_PARAMETER_ATTRIBUTE_REF, &scalar, sizeof(scalar))); + STATUS_ERROR_CHECK(vxQueryScalar(scalar, VX_SCALAR_ATTRIBUTE_TYPE, &type, sizeof(type))); + STATUS_ERROR_CHECK(vxReadScalarValue(scalar, &value)); + if (value < 0 || type != VX_TYPE_INT32) + status = VX_ERROR_INVALID_VALUE; + vxReleaseScalar(&scalar); + } + else if (index == 4) + { + vx_scalar scalar = 0; vx_enum type = 0; vx_int32 value = 0; + STATUS_ERROR_CHECK(vxQueryParameter(param, VX_PARAMETER_ATTRIBUTE_REF, &scalar, sizeof(scalar))); + STATUS_ERROR_CHECK(vxQueryScalar(scalar, VX_SCALAR_ATTRIBUTE_TYPE, &type, sizeof(type))); + STATUS_ERROR_CHECK(vxReadScalarValue(scalar, &value)); + if (value < 0 || type != VX_TYPE_INT32) + status = VX_ERROR_INVALID_VALUE; + vxReleaseScalar(&scalar); + } + else if (index == 5) + { + vx_scalar scalar = 0; vx_enum type = 0; vx_int32 value = 0; + STATUS_ERROR_CHECK(vxQueryParameter(param, VX_PARAMETER_ATTRIBUTE_REF, &scalar, sizeof(scalar))); + STATUS_ERROR_CHECK(vxQueryScalar(scalar, VX_SCALAR_ATTRIBUTE_TYPE, &type, sizeof(type))); + STATUS_ERROR_CHECK(vxReadScalarValue(scalar, &value)); + if (value < 0 || type != VX_TYPE_INT32) + status = VX_ERROR_INVALID_VALUE; + vxReleaseScalar(&scalar); + } + + else if (index == 6) + { + vx_scalar scalar = 0; vx_enum type = 0; vx_float32 value = 0; + STATUS_ERROR_CHECK(vxQueryParameter(param, VX_PARAMETER_ATTRIBUTE_REF, &scalar, sizeof(scalar))); + STATUS_ERROR_CHECK(vxQueryScalar(scalar, VX_SCALAR_ATTRIBUTE_TYPE, &type, sizeof(type))); + STATUS_ERROR_CHECK(vxReadScalarValue(scalar, &value)); + if (value < 0 || type != VX_TYPE_FLOAT32) + status = VX_ERROR_INVALID_VALUE; + vxReleaseScalar(&scalar); + } + + else if (index == 7) + { + vx_scalar scalar = 0; vx_enum type = 0; vx_float32 value = 0; + STATUS_ERROR_CHECK(vxQueryParameter(param, VX_PARAMETER_ATTRIBUTE_REF, &scalar, sizeof(scalar))); + STATUS_ERROR_CHECK(vxQueryScalar(scalar, VX_SCALAR_ATTRIBUTE_TYPE, &type, sizeof(type))); + STATUS_ERROR_CHECK(vxReadScalarValue(scalar, &value)); + if (value < 0 || type != VX_TYPE_FLOAT32) + status = VX_ERROR_INVALID_VALUE; + vxReleaseScalar(&scalar); + } + + else if (index == 8) + { + vx_scalar scalar = 0; vx_enum type = 0; vx_int32 value = 0; + STATUS_ERROR_CHECK(vxQueryParameter(param, VX_PARAMETER_ATTRIBUTE_REF, &scalar, sizeof(scalar))); + STATUS_ERROR_CHECK(vxQueryScalar(scalar, VX_SCALAR_ATTRIBUTE_TYPE, &type, sizeof(type))); + STATUS_ERROR_CHECK(vxReadScalarValue(scalar, &value)); + if (value < 0 || type != VX_TYPE_INT32) + status = VX_ERROR_INVALID_VALUE; + vxReleaseScalar(&scalar); + } + + else if (index == 9) + { + vx_scalar scalar = 0; vx_enum type = 0; vx_float32 value = 0; + STATUS_ERROR_CHECK(vxQueryParameter(param, VX_PARAMETER_ATTRIBUTE_REF, &scalar, sizeof(scalar))); + STATUS_ERROR_CHECK(vxQueryScalar(scalar, VX_SCALAR_ATTRIBUTE_TYPE, &type, sizeof(type))); + STATUS_ERROR_CHECK(vxReadScalarValue(scalar, &value)); + if (value < 0 || type != VX_TYPE_FLOAT32) + status = VX_ERROR_INVALID_VALUE; + vxReleaseScalar(&scalar); + } + + else if (index == 10) + { + vx_scalar scalar = 0; vx_enum type = 0; vx_float32 value = 0; + STATUS_ERROR_CHECK(vxQueryParameter(param, VX_PARAMETER_ATTRIBUTE_REF, &scalar, sizeof(scalar))); + STATUS_ERROR_CHECK(vxQueryScalar(scalar, VX_SCALAR_ATTRIBUTE_TYPE, &type, sizeof(type))); + STATUS_ERROR_CHECK(vxReadScalarValue(scalar, &value)); + if (value < 0 || type != VX_TYPE_FLOAT32) + status = VX_ERROR_INVALID_VALUE; + vxReleaseScalar(&scalar); + } + + else if (index == 11) + { + vx_scalar scalar = 0; vx_enum type = 0; vx_int32 value = 0; + STATUS_ERROR_CHECK(vxQueryParameter(param, VX_PARAMETER_ATTRIBUTE_REF, &scalar, sizeof(scalar))); + STATUS_ERROR_CHECK(vxQueryScalar(scalar, VX_SCALAR_ATTRIBUTE_TYPE, &type, sizeof(type))); + STATUS_ERROR_CHECK(vxReadScalarValue(scalar, &value)); + if (value < 0 || type != VX_TYPE_INT32) + status = VX_ERROR_INVALID_VALUE; + vxReleaseScalar(&scalar); + } + + vxReleaseParameter(¶m); + return status; +} + +/*!*********************************************************************************************************** +output parameter validator. +*************************************************************************************************************/ +static vx_status VX_CALLBACK CV_MSER_feature_detector_OutputValidator(vx_node node, vx_uint32 index, vx_meta_format meta) +{ + vx_status status = VX_SUCCESS; + if (index == 1) + { + vx_parameter output_param = vxGetParameterByIndex(node, 1); + vx_array output; vx_size size = 0; + + STATUS_ERROR_CHECK(vxQueryParameter(output_param, VX_PARAMETER_ATTRIBUTE_REF, &output, sizeof(vx_array))); + STATUS_ERROR_CHECK(vxQueryArray(output, VX_ARRAY_ATTRIBUTE_CAPACITY, &size, sizeof(size))); + + if (size <= 0) + status = VX_ERROR_INVALID_VALUE; + + vxReleaseArray(&output); + vxReleaseParameter(&output_param); + } + return status; +} + +/*!*********************************************************************************************************** +Execution Kernel +*************************************************************************************************************/ +static vx_status VX_CALLBACK CV_MSER_feature_detector_Kernel(vx_node node, const vx_reference *parameters, vx_uint32 num) +{ + vx_status status = VX_SUCCESS; + + vx_image image_in = (vx_image) parameters[0]; + vx_array array = (vx_array) parameters[1]; + vx_image mask = (vx_image) parameters[2]; + vx_scalar DELTA = (vx_scalar) parameters[3]; + vx_scalar MINAREA = (vx_scalar) parameters[4]; + vx_scalar MAXAREA = (vx_scalar) parameters[5]; + vx_scalar MAXVAR = (vx_scalar) parameters[6]; + vx_scalar MINDIV = (vx_scalar) parameters[7]; + vx_scalar MAXEVO = (vx_scalar) parameters[8]; + vx_scalar AREATHRES = (vx_scalar) parameters[9]; + vx_scalar MINMAR = (vx_scalar) parameters[10]; + vx_scalar EDGEBLUR = (vx_scalar) parameters[11]; + + Mat *mat, *mask_mat, Img; + vector key_points; + int delta, min_area, max_area, max_evolution, edge_blur_size; + float max_variation, min_diversity, area_threshold, min_margin; + vx_float32 FloatValue = 0; + vx_int32 value = 0; + + //Extracting Values from the Scalar + STATUS_ERROR_CHECK(vxReadScalarValue(MAXVAR, &FloatValue)); max_variation = FloatValue; + STATUS_ERROR_CHECK(vxReadScalarValue(MINDIV, &FloatValue)); min_diversity = FloatValue; + STATUS_ERROR_CHECK(vxReadScalarValue(AREATHRES, &FloatValue)); area_threshold = FloatValue; + STATUS_ERROR_CHECK(vxReadScalarValue(MINMAR, &FloatValue)); min_margin = FloatValue; + STATUS_ERROR_CHECK(vxReadScalarValue(DELTA, &value)); delta = value; + STATUS_ERROR_CHECK(vxReadScalarValue(MINAREA, &value)); min_area = value; + STATUS_ERROR_CHECK(vxReadScalarValue(MAXEVO, &value)); max_evolution = value; + STATUS_ERROR_CHECK(vxReadScalarValue(MAXAREA, &value)); max_area = value; + STATUS_ERROR_CHECK(vxReadScalarValue(EDGEBLUR, &value)); edge_blur_size = value; + + //Converting VX Image to OpenCV Mat + STATUS_ERROR_CHECK(VX_to_CV_Image(&mat, image_in)); + STATUS_ERROR_CHECK(VX_to_CV_Image(&mask_mat, mask)); + + //Compute using OpenCV + Ptr mser = MSER::create(delta, min_area, max_area, max_variation, min_diversity, max_evolution, area_threshold, min_margin, edge_blur_size); + mser->detect(*mat, key_points, *mask_mat); + + //OpenCV 2.4.11 Call + //MSER MSER(delta, min_area, max_area, max_variation, min_diversity, max_evolution, area_threshold, min_margin, edge_blur_size); + //MSER.detect(*mat, key_points, *mask_mat); ////Compute using OpenCV + + //Converting OpenCV Keypoints to OpenVX Keypoints + STATUS_ERROR_CHECK(CV_to_VX_keypoints(key_points, array)); + + + return status; +} + +/************************************************************************************************************ +Function to Register the Kernel for Publish +*************************************************************************************************************/ +vx_status CV_MSER_detect_Register(vx_context context) +{ + vx_status status = VX_SUCCESS; + vx_kernel Kernel = vxAddKernel(context, + "org.opencv.mser_detect", + VX_KERNEL_EXT_CV_MSER_DETECT, + CV_MSER_feature_detector_Kernel, + 12, + CV_MSER_feature_detector_InputValidator, + CV_MSER_feature_detector_OutputValidator, + nullptr, + nullptr); + + if (Kernel) + { + PARAM_ERROR_CHECK(vxAddParameterToKernel(Kernel, 0, VX_INPUT, VX_TYPE_IMAGE, VX_PARAMETER_STATE_REQUIRED)); + PARAM_ERROR_CHECK(vxAddParameterToKernel(Kernel, 1, VX_BIDIRECTIONAL, VX_TYPE_ARRAY, VX_PARAMETER_STATE_REQUIRED)); + PARAM_ERROR_CHECK(vxAddParameterToKernel(Kernel, 2, VX_INPUT, VX_TYPE_IMAGE, VX_PARAMETER_STATE_REQUIRED)); + PARAM_ERROR_CHECK(vxAddParameterToKernel(Kernel, 3, VX_INPUT, VX_TYPE_SCALAR, VX_PARAMETER_STATE_REQUIRED)); + PARAM_ERROR_CHECK(vxAddParameterToKernel(Kernel, 4, VX_INPUT, VX_TYPE_SCALAR, VX_PARAMETER_STATE_REQUIRED)); + PARAM_ERROR_CHECK(vxAddParameterToKernel(Kernel, 5, VX_INPUT, VX_TYPE_SCALAR, VX_PARAMETER_STATE_REQUIRED)); + PARAM_ERROR_CHECK(vxAddParameterToKernel(Kernel, 6, VX_INPUT, VX_TYPE_SCALAR, VX_PARAMETER_STATE_REQUIRED)); + PARAM_ERROR_CHECK(vxAddParameterToKernel(Kernel, 7, VX_INPUT, VX_TYPE_SCALAR, VX_PARAMETER_STATE_REQUIRED)); + PARAM_ERROR_CHECK(vxAddParameterToKernel(Kernel, 8, VX_INPUT, VX_TYPE_SCALAR, VX_PARAMETER_STATE_REQUIRED)); + PARAM_ERROR_CHECK(vxAddParameterToKernel(Kernel, 9, VX_INPUT, VX_TYPE_SCALAR, VX_PARAMETER_STATE_REQUIRED)); + PARAM_ERROR_CHECK(vxAddParameterToKernel(Kernel, 10, VX_INPUT, VX_TYPE_SCALAR, VX_PARAMETER_STATE_REQUIRED)); + PARAM_ERROR_CHECK(vxAddParameterToKernel(Kernel, 11, VX_INPUT, VX_TYPE_SCALAR, VX_PARAMETER_STATE_REQUIRED)); + PARAM_ERROR_CHECK(vxFinalizeKernel(Kernel)); + } + + if (status != VX_SUCCESS) + { + exit: vxRemoveKernel(Kernel); return VX_FAILURE; + } + + return status; +} diff --git a/vx_ext_cv/OpenCV_Medianblur.cpp b/vx_ext_cv/OpenCV_Medianblur.cpp new file mode 100644 index 0000000..184f3f1 --- /dev/null +++ b/vx_ext_cv/OpenCV_Medianblur.cpp @@ -0,0 +1,221 @@ +/* +Copyright (c) 2015 Advanced Micro Devices, Inc. All rights reserved. + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. +*/ + + +#include"publishkernels.h" + +/*! \brief *********************************************************************************************************** +Input parameter validator. + +This function checks all the inputs to see if they are of the correct data type and is passing a valid argument. +The input validator is a required function to create any node. + +param [in] node -->The handle to the node. +param [in] index -->The index of the parameter to validate. +*************************************************************************************************************/ +static vx_status VX_CALLBACK CV_MedianBlur_InputValidator(vx_node node, vx_uint32 index) +{ + vx_status status = VX_SUCCESS; + vx_parameter param = vxGetParameterByIndex(node, index); + + if (index == 0) + { + vx_image image; + vx_df_image df_image = VX_DF_IMAGE_VIRT; + STATUS_ERROR_CHECK(vxQueryParameter(param, VX_PARAMETER_ATTRIBUTE_REF, &image, sizeof(vx_image))); + STATUS_ERROR_CHECK(vxQueryImage(image, VX_IMAGE_ATTRIBUTE_FORMAT, &df_image, sizeof(df_image))); + if (df_image != VX_DF_IMAGE_U8) + status = VX_ERROR_INVALID_VALUE; + vxReleaseImage(&image); + } + + else if (index == 1) + { + vx_image image; + vx_df_image df_image = VX_DF_IMAGE_VIRT; + STATUS_ERROR_CHECK(vxQueryParameter(param, VX_PARAMETER_ATTRIBUTE_REF, &image, sizeof(vx_image))); + STATUS_ERROR_CHECK(vxQueryImage(image, VX_IMAGE_ATTRIBUTE_FORMAT, &df_image, sizeof(df_image))); + if (df_image != VX_DF_IMAGE_U8) + status = VX_ERROR_INVALID_VALUE; + vxReleaseImage(&image); + } + + else if (index == 2) + { + vx_scalar scalar = 0; vx_enum type = 0; vx_int32 value = 0; + STATUS_ERROR_CHECK(vxQueryParameter(param, VX_PARAMETER_ATTRIBUTE_REF, &scalar, sizeof(scalar))); + STATUS_ERROR_CHECK(vxQueryScalar(scalar, VX_SCALAR_ATTRIBUTE_TYPE, &type, sizeof(type))); + STATUS_ERROR_CHECK(vxReadScalarValue(scalar, &value)); + if (value < 1 || (value % 2 == 0) || type != VX_TYPE_INT32) + status = VX_ERROR_INVALID_VALUE; + vxReleaseScalar(&scalar); + } + + vxReleaseParameter(¶m); + return status; +} + +/*! \brief *********************************************************************************************************** +Output parameter validator. + +This function checks all the outputs to see if they are of the correct data type and has the required parameters set +to return the correct output. +The Output validator is a required function to create any node. + +param [in] node -->The handle to the node. +param [in] index -->The index of the parameter to validate. +param [in] meta -->The meta data for the output is set. +*************************************************************************************************************/ +static vx_status VX_CALLBACK CV_MedianBlur_OutputValidator(vx_node node, vx_uint32 index, vx_meta_format meta) +{ + vx_status status = VX_SUCCESS; + if (index == 1) + { + vx_parameter output_param = vxGetParameterByIndex(node, 1); + vx_image output; vx_uint32 width = 0, height = 0; vx_df_image format = VX_DF_IMAGE_VIRT; + + STATUS_ERROR_CHECK(vxQueryParameter(output_param, VX_PARAMETER_ATTRIBUTE_REF, &output, sizeof(vx_image))); + STATUS_ERROR_CHECK(vxQueryImage(output, VX_IMAGE_ATTRIBUTE_FORMAT, &format, sizeof(format))); + STATUS_ERROR_CHECK(vxQueryImage(output, VX_IMAGE_ATTRIBUTE_WIDTH, &width, sizeof(width))); + STATUS_ERROR_CHECK(vxQueryImage(output, VX_IMAGE_ATTRIBUTE_HEIGHT, &height, sizeof(height))); + + if (format != VX_DF_IMAGE_U8) + status = VX_ERROR_INVALID_VALUE; + + STATUS_ERROR_CHECK(vxSetMetaFormatAttribute(meta, VX_IMAGE_ATTRIBUTE_WIDTH, &width, sizeof(width))); + STATUS_ERROR_CHECK(vxSetMetaFormatAttribute(meta, VX_IMAGE_ATTRIBUTE_HEIGHT, &height, sizeof(height))); + STATUS_ERROR_CHECK(vxSetMetaFormatAttribute(meta, VX_IMAGE_ATTRIBUTE_FORMAT, &format, sizeof(format))); + + vxReleaseImage(&output); + vxReleaseParameter(&output_param); + } + return status; +} + +/*! \brief **************************************************************************************************** +Execution Kernel + +This function is the exection kernel of the node, it gets the inputs for the i/p validator and returns to output + +The Execution Kernel is a required function to create any node. + +param [in] node -->The handle to the node. +param [in] parameters -->The index of the parameter. +param [in] num -->Number of parameters. +*************************************************************************************************************/ +static vx_status VX_CALLBACK CV_MedianBlur_Kernel(vx_node node, const vx_reference *parameters, vx_uint32 num) +{ + vx_status status = VX_SUCCESS; + + vx_image image_in = (vx_image) parameters[0]; + vx_image image_out = (vx_image) parameters[1]; + vx_scalar scalar = (vx_scalar) parameters[2]; + + Mat *mat, bl; + int Ksize; + vx_int32 value = 0; + + //Extracting Values from the Scalar into Ksize and Ddepth + STATUS_ERROR_CHECK(vxReadScalarValue(scalar, &value)); Ksize = value; + + //Converting VX Image to OpenCV Mat + STATUS_ERROR_CHECK(match_vx_image_parameters(image_in, image_out)); + STATUS_ERROR_CHECK(VX_to_CV_Image(&mat, image_in)); + + //Compute using OpenCV + cv::medianBlur(*mat, bl, Ksize); + + //Converting OpenCV Mat into VX Image + STATUS_ERROR_CHECK(CV_to_VX_Image(image_out, &bl)); + + return status; +} + + +/*! \brief ************************************************************************************************** +Initializer function. + +This function is an optional function, if the inputs are needed to be intitialized. This function can be +ignored and a nullptr can be passed to vxAddKernel + +param [in] node -->The handle to the node. +param [in] parameters -->The index of the parameter. +param [in] num -->Number of parameters. + +This Node does not require any parameters to be intizalized +static vx_status VX_CALLBACK CV_MedianBlur_Initialize(vx_node node, const vx_reference *parameters, vx_uint32 num) +{ +return VX_SUCCESS; +} + +*************************************************************************************************************/ + + +/*! \brief ************************************************************************************************** +De-Initializer function. + +This function is an optional function, if the outputs are needed to be de-intitialized. This function can be +ignored and a nullptr can be passed to vxAddKernel + +param [in] node -->The handle to the node. +param [in] parameters -->The index of the parameter. +param [in] num -->Number of parameters. + +This Node does not require any parameters to be de-intizalized +static vx_status VX_CALLBACK CV_MedianBlur_Deinitialize(vx_node node, const vx_reference *parameters, vx_uint32 num) +{ +return VX_SUCCESS; +} +*************************************************************************************************************/ + + +/*! \brief*************************************************************************************************** +Function to Register the Kernel for Publish +*************************************************************************************************************/ +vx_status CV_MedianBlur_Register(vx_context context) +{ + vx_status status = VX_SUCCESS; + vx_kernel kernel = vxAddKernel(context, + "org.opencv.medianblur", + VX_KERNEL_EXT_CV_MEDIAN_BLUR, + CV_MedianBlur_Kernel, + 3, + CV_MedianBlur_InputValidator, + CV_MedianBlur_OutputValidator, + nullptr,//Initializer function. + nullptr);//De-Initializer function. + + if (kernel) + { + PARAM_ERROR_CHECK(vxAddParameterToKernel(kernel, 0, VX_INPUT, VX_TYPE_IMAGE, VX_PARAMETER_STATE_REQUIRED)); + PARAM_ERROR_CHECK(vxAddParameterToKernel(kernel, 1, VX_OUTPUT, VX_TYPE_IMAGE, VX_PARAMETER_STATE_REQUIRED)); + PARAM_ERROR_CHECK(vxAddParameterToKernel(kernel, 2, VX_INPUT, VX_TYPE_SCALAR, VX_PARAMETER_STATE_REQUIRED)); + PARAM_ERROR_CHECK(vxFinalizeKernel(kernel)); + } + + if (status != VX_SUCCESS) + { + exit: vxRemoveKernel(kernel); return VX_FAILURE; + } + + return status; +} diff --git a/vx_ext_cv/OpenCV_ORB_detector.cpp b/vx_ext_cv/OpenCV_ORB_detector.cpp new file mode 100644 index 0000000..a500588 --- /dev/null +++ b/vx_ext_cv/OpenCV_ORB_detector.cpp @@ -0,0 +1,272 @@ +/* +Copyright (c) 2015 Advanced Micro Devices, Inc. All rights reserved. + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. +*/ + + +#include"publishkernels.h" + +/*!*********************************************************************************************************** +input parameter validator. +param [in] node The handle to the node. +param [in] index The index of the parameter to validate. +*************************************************************************************************************/ +static vx_status VX_CALLBACK CV_orb_detector_InputValidator(vx_node node, vx_uint32 index) +{ + vx_status status = VX_SUCCESS; + vx_parameter param = vxGetParameterByIndex(node, index); + + if (index == 0) + { + vx_image image; + vx_df_image df_image = VX_DF_IMAGE_VIRT; + STATUS_ERROR_CHECK(vxQueryParameter(param, VX_PARAMETER_ATTRIBUTE_REF, &image, sizeof(vx_image))); + STATUS_ERROR_CHECK(vxQueryImage(image, VX_IMAGE_ATTRIBUTE_FORMAT, &df_image, sizeof(df_image))); + if (df_image != VX_DF_IMAGE_U8) + status = VX_ERROR_INVALID_VALUE; + vxReleaseImage(&image); + } + + else if(index == 1) + { + vx_image image; + vx_df_image df_image = VX_DF_IMAGE_VIRT; + STATUS_ERROR_CHECK(vxQueryParameter(param, VX_PARAMETER_ATTRIBUTE_REF, &image, sizeof(vx_image))); + STATUS_ERROR_CHECK(vxQueryImage(image, VX_IMAGE_ATTRIBUTE_FORMAT, &df_image, sizeof(df_image))); + if (df_image != VX_DF_IMAGE_U8) + status = VX_ERROR_INVALID_VALUE; + vxReleaseImage(&image); + } + + else if (index == 2) + { + vx_array array; vx_size size = 0; + STATUS_ERROR_CHECK(vxQueryParameter(param, VX_PARAMETER_ATTRIBUTE_REF, &array, sizeof(array))); + STATUS_ERROR_CHECK(vxQueryArray(array, VX_ARRAY_ATTRIBUTE_CAPACITY, &size, sizeof(size))); + vxReleaseArray(&array); + } + + else if (index == 3) + { + vx_scalar scalar = 0; vx_enum type = 0; vx_int32 value = 0; + STATUS_ERROR_CHECK(vxQueryParameter(param, VX_PARAMETER_ATTRIBUTE_REF, &scalar, sizeof(scalar))); + STATUS_ERROR_CHECK(vxQueryScalar(scalar, VX_SCALAR_ATTRIBUTE_TYPE, &type, sizeof(type))); + STATUS_ERROR_CHECK(vxReadScalarValue(scalar, &value)); + if (value < 0 || type != VX_TYPE_INT32) + status = VX_ERROR_INVALID_VALUE; + vxReleaseScalar(&scalar); + } + + else if (index == 4) + { + vx_scalar scalar = 0; vx_enum type = 0; vx_float32 value = 0; + STATUS_ERROR_CHECK(vxQueryParameter(param, VX_PARAMETER_ATTRIBUTE_REF, &scalar, sizeof(scalar))); + STATUS_ERROR_CHECK(vxQueryScalar(scalar, VX_SCALAR_ATTRIBUTE_TYPE, &type, sizeof(type))); + STATUS_ERROR_CHECK(vxReadScalarValue(scalar, &value)); + if (value < 0 || type != VX_TYPE_FLOAT32) + status = VX_ERROR_INVALID_VALUE; + vxReleaseScalar(&scalar); + } + + else if (index == 5) + { + vx_scalar scalar = 0; vx_enum type = 0; vx_int32 value = 0; + STATUS_ERROR_CHECK(vxQueryParameter(param, VX_PARAMETER_ATTRIBUTE_REF, &scalar, sizeof(scalar))); + STATUS_ERROR_CHECK(vxQueryScalar(scalar, VX_SCALAR_ATTRIBUTE_TYPE, &type, sizeof(type))); + STATUS_ERROR_CHECK(vxReadScalarValue(scalar, &value)); + if (value < 0 || type != VX_TYPE_INT32) + status = VX_ERROR_INVALID_VALUE; + vxReleaseScalar(&scalar); + } + + else if (index == 6) + { + vx_scalar scalar = 0; vx_enum type = 0; vx_int32 value = 0; + STATUS_ERROR_CHECK(vxQueryParameter(param, VX_PARAMETER_ATTRIBUTE_REF, &scalar, sizeof(scalar))); + STATUS_ERROR_CHECK(vxQueryScalar(scalar, VX_SCALAR_ATTRIBUTE_TYPE, &type, sizeof(type))); + STATUS_ERROR_CHECK(vxReadScalarValue(scalar, &value)); + if (value < 0 || type != VX_TYPE_INT32) + status = VX_ERROR_INVALID_VALUE; + vxReleaseScalar(&scalar); + } + + else if (index == 7) + { + vx_scalar scalar = 0; vx_enum type = 0; vx_int32 value = 0; + STATUS_ERROR_CHECK(vxQueryParameter(param, VX_PARAMETER_ATTRIBUTE_REF, &scalar, sizeof(scalar))); + STATUS_ERROR_CHECK(vxQueryScalar(scalar, VX_SCALAR_ATTRIBUTE_TYPE, &type, sizeof(type))); + STATUS_ERROR_CHECK(vxReadScalarValue(scalar, &value)); + if (value != 0 || type != VX_TYPE_INT32) + status = VX_ERROR_INVALID_VALUE; + vxReleaseScalar(&scalar); + } + + else if (index == 8) + { + vx_scalar scalar = 0; vx_enum type = 0; vx_int32 value = 0; + STATUS_ERROR_CHECK(vxQueryParameter(param, VX_PARAMETER_ATTRIBUTE_REF, &scalar, sizeof(scalar))); + STATUS_ERROR_CHECK(vxQueryScalar(scalar, VX_SCALAR_ATTRIBUTE_TYPE, &type, sizeof(type))); + STATUS_ERROR_CHECK(vxReadScalarValue(scalar, &value)); + if ( (value < 0 || value > 3) || type != VX_TYPE_INT32) + status = VX_ERROR_INVALID_VALUE; + vxReleaseScalar(&scalar); + } + + else if (index == 9) + { + vx_scalar scalar = 0; vx_enum type = 0; vx_int32 value = 0; + STATUS_ERROR_CHECK(vxQueryParameter(param, VX_PARAMETER_ATTRIBUTE_REF, &scalar, sizeof(scalar))); + STATUS_ERROR_CHECK(vxQueryScalar(scalar, VX_SCALAR_ATTRIBUTE_TYPE, &type, sizeof(type))); + STATUS_ERROR_CHECK(vxReadScalarValue(scalar, &value)); + if ((value != 0 && value != 1) || type != VX_TYPE_INT32) + status = VX_ERROR_INVALID_VALUE; + vxReleaseScalar(&scalar); + } + + else if (index == 10) + { + vx_scalar scalar = 0; vx_enum type = 0; vx_int32 value = 0; + STATUS_ERROR_CHECK(vxQueryParameter(param, VX_PARAMETER_ATTRIBUTE_REF, &scalar, sizeof(scalar))); + STATUS_ERROR_CHECK(vxQueryScalar(scalar, VX_SCALAR_ATTRIBUTE_TYPE, &type, sizeof(type))); + STATUS_ERROR_CHECK(vxReadScalarValue(scalar, &value)); + if (value < 0 || type != VX_TYPE_INT32) + status = VX_ERROR_INVALID_VALUE; + vxReleaseScalar(&scalar); + } + + vxReleaseParameter(¶m); + return status; +} + +/*!*********************************************************************************************************** +output parameter validator. +*************************************************************************************************************/ +static vx_status VX_CALLBACK CV_orb_detector_OutputValidator(vx_node node, vx_uint32 index, vx_meta_format meta) +{ + vx_status status = VX_SUCCESS; + if (index == 2) + { + vx_parameter output_param = vxGetParameterByIndex(node, 2); + vx_array output; vx_size size = 0; + + STATUS_ERROR_CHECK(vxQueryParameter(output_param, VX_PARAMETER_ATTRIBUTE_REF, &output, sizeof(vx_array))); + STATUS_ERROR_CHECK(vxQueryArray(output, VX_ARRAY_ATTRIBUTE_CAPACITY, &size, sizeof(size))); + + if (size <= 0) + status = VX_ERROR_INVALID_VALUE; + + vxReleaseArray(&output); + vxReleaseParameter(&output_param); + } + return status; +} + +/*!*********************************************************************************************************** +Execution Kernel +*************************************************************************************************************/ +static vx_status VX_CALLBACK CV_orb_detector_Kernel(vx_node node, const vx_reference *parameters, vx_uint32 num) +{ + vx_status status = VX_SUCCESS; + vx_image image_in = (vx_image) parameters[0]; + vx_image mask = (vx_image) parameters[1]; + vx_array array = (vx_array) parameters[2]; + vx_scalar NFEATURES = (vx_scalar) parameters[3]; + vx_scalar SCALEFAC = (vx_scalar) parameters[4]; + vx_scalar NLEVELS = (vx_scalar) parameters[5]; + vx_scalar EDGETHRES = (vx_scalar) parameters[6]; + vx_scalar FIRSTLEVEL = (vx_scalar) parameters[7]; + vx_scalar WTA_k = (vx_scalar) parameters[8]; + vx_scalar SCORETYPE = (vx_scalar) parameters[9]; + vx_scalar PATCHSIZE = (vx_scalar) parameters[10]; + + Mat *mat, *mask_mat, Img; + int nFeatures, nLevels, edgeThreshold, firstLevel, WTA_K, scoreType, patchSize; + float ScaleFactor; + vector key_points; + vx_int32 value = 0; + vx_float32 value_F = 0; + + //Extracting Values from the Scalar + STATUS_ERROR_CHECK(vxReadScalarValue(NFEATURES, &value));nFeatures = value; + STATUS_ERROR_CHECK(vxReadScalarValue(SCALEFAC, &value_F));ScaleFactor = value_F; + STATUS_ERROR_CHECK(vxReadScalarValue(NLEVELS, &value));nLevels = value; + STATUS_ERROR_CHECK(vxReadScalarValue(EDGETHRES, &value));edgeThreshold = value; + STATUS_ERROR_CHECK(vxReadScalarValue(FIRSTLEVEL, &value));firstLevel = value; + STATUS_ERROR_CHECK(vxReadScalarValue(WTA_k, &value));WTA_K = value; + STATUS_ERROR_CHECK(vxReadScalarValue(SCORETYPE, &value));scoreType = value; + STATUS_ERROR_CHECK(vxReadScalarValue(PATCHSIZE, &value));patchSize = value; + + //Converting VX Image to OpenCV Mat + STATUS_ERROR_CHECK(VX_to_CV_Image(&mat, image_in)); + STATUS_ERROR_CHECK(VX_to_CV_Image(&mask_mat, mask)); + + //Compute using OpenCV + Ptr orb = ORB::create(nFeatures, ScaleFactor, nLevels, edgeThreshold, firstLevel, WTA_K, scoreType, patchSize); + orb->detect(*mat, key_points, *mask_mat); + + //OpenCV 2.4 Call + //ORB orb(nFeatures, ScaleFactor, nLevels, edgeThreshold, firstLevel, WTA_K, scoreType, patchSize); + //orb(*mat, *mask_mat, key_points); ////Compute using OpenCV + + //Converting OpenCV Keypoints to OpenVX Keypoints + STATUS_ERROR_CHECK(CV_to_VX_keypoints(key_points, array)); + + return status; +} + +/************************************************************************************************************ +Function to Register the Kernel for Publish +*************************************************************************************************************/ +vx_status CV_ORB_detect_Register(vx_context context) +{ + vx_status status = VX_SUCCESS; + vx_kernel Kernel = vxAddKernel(context, + "org.opencv.orb_detect", + VX_KERNEL_EXT_CV_ORB_DETECT, + CV_orb_detector_Kernel, + 11, + CV_orb_detector_InputValidator, + CV_orb_detector_OutputValidator, + nullptr, + nullptr); + + if (Kernel) + { + PARAM_ERROR_CHECK(vxAddParameterToKernel(Kernel, 0, VX_INPUT, VX_TYPE_IMAGE, VX_PARAMETER_STATE_REQUIRED)); + PARAM_ERROR_CHECK(vxAddParameterToKernel(Kernel, 1, VX_INPUT, VX_TYPE_IMAGE, VX_PARAMETER_STATE_REQUIRED)); + PARAM_ERROR_CHECK(vxAddParameterToKernel(Kernel, 2, VX_BIDIRECTIONAL, VX_TYPE_ARRAY, VX_PARAMETER_STATE_REQUIRED)); + PARAM_ERROR_CHECK(vxAddParameterToKernel(Kernel, 3, VX_INPUT, VX_TYPE_SCALAR, VX_PARAMETER_STATE_REQUIRED)); + PARAM_ERROR_CHECK(vxAddParameterToKernel(Kernel, 4, VX_INPUT, VX_TYPE_SCALAR, VX_PARAMETER_STATE_REQUIRED)); + PARAM_ERROR_CHECK(vxAddParameterToKernel(Kernel, 5, VX_INPUT, VX_TYPE_SCALAR, VX_PARAMETER_STATE_REQUIRED)); + PARAM_ERROR_CHECK(vxAddParameterToKernel(Kernel, 6, VX_INPUT, VX_TYPE_SCALAR, VX_PARAMETER_STATE_REQUIRED)); + PARAM_ERROR_CHECK(vxAddParameterToKernel(Kernel, 7, VX_INPUT, VX_TYPE_SCALAR, VX_PARAMETER_STATE_REQUIRED)); + PARAM_ERROR_CHECK(vxAddParameterToKernel(Kernel, 8, VX_INPUT, VX_TYPE_SCALAR, VX_PARAMETER_STATE_REQUIRED)); + PARAM_ERROR_CHECK(vxAddParameterToKernel(Kernel, 9, VX_INPUT, VX_TYPE_SCALAR, VX_PARAMETER_STATE_REQUIRED)); + PARAM_ERROR_CHECK(vxAddParameterToKernel(Kernel, 10, VX_INPUT, VX_TYPE_SCALAR, VX_PARAMETER_STATE_REQUIRED)); + PARAM_ERROR_CHECK(vxFinalizeKernel(Kernel)); + } + + if (status != VX_SUCCESS) + { + exit: vxRemoveKernel(Kernel); return VX_FAILURE; + } + + return status; +} \ No newline at end of file diff --git a/vx_ext_cv/OpenCV_SIFT_Compute.cpp b/vx_ext_cv/OpenCV_SIFT_Compute.cpp new file mode 100644 index 0000000..9003b9d --- /dev/null +++ b/vx_ext_cv/OpenCV_SIFT_Compute.cpp @@ -0,0 +1,246 @@ +/* +Copyright (c) 2015 Advanced Micro Devices, Inc. All rights reserved. + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. +*/ + + +#if USE_OPENCV_CONTRIB +#include"publishkernels.h" + +/*!*********************************************************************************************************** +input parameter validator. +param [in] node The handle to the node. +param [in] index The index of the parameter to validate. +*************************************************************************************************************/ +static vx_status VX_CALLBACK CV_SIFT_Compute_InputValidator(vx_node node, vx_uint32 index) +{ + vx_status status = VX_SUCCESS; + vx_parameter param = vxGetParameterByIndex(node, index); + + if (index == 0) + { + vx_image image; + vx_df_image df_image = VX_DF_IMAGE_VIRT; + STATUS_ERROR_CHECK(vxQueryParameter(param, VX_PARAMETER_ATTRIBUTE_REF, &image, sizeof(vx_image))); + STATUS_ERROR_CHECK(vxQueryImage(image, VX_IMAGE_ATTRIBUTE_FORMAT, &df_image, sizeof(df_image))); + if (df_image != VX_DF_IMAGE_U8) + status = VX_ERROR_INVALID_VALUE; + vxReleaseImage(&image); + } + + if (index == 1) + { + vx_image image; + vx_df_image df_image = VX_DF_IMAGE_VIRT; + STATUS_ERROR_CHECK(vxQueryParameter(param, VX_PARAMETER_ATTRIBUTE_REF, &image, sizeof(vx_image))); + STATUS_ERROR_CHECK(vxQueryImage(image, VX_IMAGE_ATTRIBUTE_FORMAT, &df_image, sizeof(df_image))); + if (df_image != VX_DF_IMAGE_U8) + status = VX_ERROR_INVALID_VALUE; + vxReleaseImage(&image); + } + + else if (index == 2) + { + vx_array array; vx_size size = 0; + STATUS_ERROR_CHECK(vxQueryParameter(param, VX_PARAMETER_ATTRIBUTE_REF, &array, sizeof(array))); + STATUS_ERROR_CHECK(vxQueryArray(array, VX_ARRAY_ATTRIBUTE_CAPACITY, &size, sizeof(size))); + vxReleaseArray(&array); + } + + else if (index == 3) + { + vx_array array; vx_size size = 0; + STATUS_ERROR_CHECK(vxQueryParameter(param, VX_PARAMETER_ATTRIBUTE_REF, &array, sizeof(array))); + STATUS_ERROR_CHECK(vxQueryArray(array, VX_ARRAY_ATTRIBUTE_CAPACITY, &size, sizeof(size))); + vxReleaseArray(&array); + } + + else if (index == 4) + { + vx_scalar scalar = 0; vx_enum type = 0; vx_int32 value = 0; + STATUS_ERROR_CHECK(vxQueryParameter(param, VX_PARAMETER_ATTRIBUTE_REF, &scalar, sizeof(scalar))); + STATUS_ERROR_CHECK(vxQueryScalar(scalar, VX_SCALAR_ATTRIBUTE_TYPE, &type, sizeof(type))); + STATUS_ERROR_CHECK(vxReadScalarValue(scalar, &value)); + if (value < 0 || type != VX_TYPE_INT32) + status = VX_ERROR_INVALID_VALUE; + vxReleaseScalar(&scalar); + } + + else if (index == 5) + { + vx_scalar scalar = 0; vx_enum type = 0; vx_int32 value = 0; + STATUS_ERROR_CHECK(vxQueryParameter(param, VX_PARAMETER_ATTRIBUTE_REF, &scalar, sizeof(scalar))); + STATUS_ERROR_CHECK(vxQueryScalar(scalar, VX_SCALAR_ATTRIBUTE_TYPE, &type, sizeof(type))); + STATUS_ERROR_CHECK(vxReadScalarValue(scalar, &value)); + if (value < 0 || type != VX_TYPE_INT32) + status = VX_ERROR_INVALID_VALUE; + vxReleaseScalar(&scalar); + } + + else if (index == 6) + { + vx_scalar scalar = 0; vx_enum type = 0; vx_float32 value = 0; + STATUS_ERROR_CHECK(vxQueryParameter(param, VX_PARAMETER_ATTRIBUTE_REF, &scalar, sizeof(scalar))); + STATUS_ERROR_CHECK(vxQueryScalar(scalar, VX_SCALAR_ATTRIBUTE_TYPE, &type, sizeof(type))); + STATUS_ERROR_CHECK(vxReadScalarValue(scalar, &value)); + if (value < 0 || type != VX_TYPE_FLOAT32) + status = VX_ERROR_INVALID_VALUE; + vxReleaseScalar(&scalar); + + } + + else if (index == 7) + { + vx_scalar scalar = 0; vx_enum type = 0; vx_float32 value = 0; + STATUS_ERROR_CHECK(vxQueryParameter(param, VX_PARAMETER_ATTRIBUTE_REF, &scalar, sizeof(scalar))); + STATUS_ERROR_CHECK(vxQueryScalar(scalar, VX_SCALAR_ATTRIBUTE_TYPE, &type, sizeof(type))); + STATUS_ERROR_CHECK(vxReadScalarValue(scalar, &value)); + if (value < 0 || type != VX_TYPE_FLOAT32) + status = VX_ERROR_INVALID_VALUE; + vxReleaseScalar(&scalar); + + } + + else if (index == 8) + { + vx_scalar scalar = 0; vx_enum type = 0; vx_float32 value = 0; + STATUS_ERROR_CHECK(vxQueryParameter(param, VX_PARAMETER_ATTRIBUTE_REF, &scalar, sizeof(scalar))); + STATUS_ERROR_CHECK(vxQueryScalar(scalar, VX_SCALAR_ATTRIBUTE_TYPE, &type, sizeof(type))); + STATUS_ERROR_CHECK(vxReadScalarValue(scalar, &value)); + if (value < 0 || type != VX_TYPE_FLOAT32) + status = VX_ERROR_INVALID_VALUE; + vxReleaseScalar(&scalar); + + } + + vxReleaseParameter(¶m); + return status; +} + +/*!*********************************************************************************************************** +output parameter validator. +*************************************************************************************************************/ +static vx_status VX_CALLBACK CV_SIFT_Compute_OutputValidator(vx_node node, vx_uint32 index, vx_meta_format meta) +{ + vx_status status = VX_SUCCESS; + if (index == 2) + { + vx_parameter output_param = vxGetParameterByIndex(node, 2); + vx_array output; vx_size size = 0; + + STATUS_ERROR_CHECK(vxQueryParameter(output_param, VX_PARAMETER_ATTRIBUTE_REF, &output, sizeof(vx_array))); + STATUS_ERROR_CHECK(vxQueryArray(output, VX_ARRAY_ATTRIBUTE_CAPACITY, &size, sizeof(size))); + + if (size <= 0) + status = VX_ERROR_INVALID_VALUE; + + vxReleaseArray(&output); + vxReleaseParameter(&output_param); + } + + return status; +} + +/*!*********************************************************************************************************** +Execution Kernel +*************************************************************************************************************/ +static vx_status VX_CALLBACK CV_SIFT_Compute_Kernel(vx_node node, const vx_reference *parameters, vx_uint32 num) +{ + vx_status status = VX_SUCCESS; + + vx_image image_in = (vx_image) parameters[0]; + vx_image mask = (vx_image) parameters[1]; + vx_array array = (vx_array) parameters[2]; + vx_array DESP = (vx_array) parameters[3]; + vx_scalar nFEATURES = (vx_scalar) parameters[4]; + vx_scalar nOCTAVELAYERS = (vx_scalar) parameters[5]; + vx_scalar ContrastTHRESHOLD = (vx_scalar) parameters[6]; + vx_scalar EdgeTHRESHOLD = (vx_scalar) parameters[7]; + vx_scalar SIGMA = (vx_scalar) parameters[8]; + + Mat *mat, *mask_mat, Img; + std::vector key_points; + Mat Desp; + vx_float32 FloatValue = 0; + vx_int32 value = 0; + float CTHRESHOLD, ETHRESHOLD, Sigma; + int NFEATURES, NOctaveLayers; + + //Extracting Values from the Scalar + STATUS_ERROR_CHECK(vxReadScalarValue(nFEATURES, &value)); NFEATURES = value; + STATUS_ERROR_CHECK(vxReadScalarValue(nOCTAVELAYERS, &value)); NOctaveLayers = value; + STATUS_ERROR_CHECK(vxReadScalarValue(ContrastTHRESHOLD, &FloatValue)); CTHRESHOLD = FloatValue; + STATUS_ERROR_CHECK(vxReadScalarValue(EdgeTHRESHOLD, &FloatValue)); ETHRESHOLD = FloatValue; + STATUS_ERROR_CHECK(vxReadScalarValue(SIGMA, &FloatValue)); Sigma = FloatValue; + + //Converting VX Image to OpenCV Mat + STATUS_ERROR_CHECK(VX_to_CV_Image(&mat, image_in)); + STATUS_ERROR_CHECK(VX_to_CV_Image(&mask_mat, mask)); + + //Compute using OpenCV + Ptr sift = xfeatures2d::SIFT::create(NFEATURES, NOctaveLayers, CTHRESHOLD, ETHRESHOLD, Sigma); + sift->detectAndCompute(*mat, *mask_mat, key_points, Desp); + + //Converting OpenCV Keypoints to OpenVX Keypoints + STATUS_ERROR_CHECK(CV_to_VX_keypoints(key_points, array)); + STATUS_ERROR_CHECK(CV_DESP_to_VX_DESP(Desp, DESP, 512));// 512 Desp supported in this release + + return status; +} + +/************************************************************************************************************ +Function to Register the Kernel for Publish +*************************************************************************************************************/ +vx_status CV_SIFT_compute_Register(vx_context context) +{ + vx_status status = VX_SUCCESS; + vx_kernel Kernel = vxAddKernel(context, + "org.opencv.sift_compute", + VX_KERNEL_EXT_CV_SIFT_COMPUTE, + CV_SIFT_Compute_Kernel, + 9, + CV_SIFT_Compute_InputValidator, + CV_SIFT_Compute_OutputValidator, + nullptr, + nullptr); + + if (Kernel) + { + PARAM_ERROR_CHECK(vxAddParameterToKernel(Kernel, 0, VX_INPUT, VX_TYPE_IMAGE, VX_PARAMETER_STATE_REQUIRED)); + PARAM_ERROR_CHECK(vxAddParameterToKernel(Kernel, 1, VX_INPUT, VX_TYPE_IMAGE, VX_PARAMETER_STATE_REQUIRED)); + PARAM_ERROR_CHECK(vxAddParameterToKernel(Kernel, 2, VX_BIDIRECTIONAL, VX_TYPE_ARRAY, VX_PARAMETER_STATE_REQUIRED)); + PARAM_ERROR_CHECK(vxAddParameterToKernel(Kernel, 3, VX_BIDIRECTIONAL, VX_TYPE_ARRAY, VX_PARAMETER_STATE_REQUIRED)); + PARAM_ERROR_CHECK(vxAddParameterToKernel(Kernel, 4, VX_INPUT, VX_TYPE_SCALAR, VX_PARAMETER_STATE_REQUIRED)); + PARAM_ERROR_CHECK(vxAddParameterToKernel(Kernel, 5, VX_INPUT, VX_TYPE_SCALAR, VX_PARAMETER_STATE_REQUIRED)); + PARAM_ERROR_CHECK(vxAddParameterToKernel(Kernel, 6, VX_INPUT, VX_TYPE_SCALAR, VX_PARAMETER_STATE_REQUIRED)); + PARAM_ERROR_CHECK(vxAddParameterToKernel(Kernel, 7, VX_INPUT, VX_TYPE_SCALAR, VX_PARAMETER_STATE_REQUIRED)); + PARAM_ERROR_CHECK(vxAddParameterToKernel(Kernel, 8, VX_INPUT, VX_TYPE_SCALAR, VX_PARAMETER_STATE_REQUIRED)); + PARAM_ERROR_CHECK(vxFinalizeKernel(Kernel)); + } + + if (status != VX_SUCCESS) + { + exit: vxRemoveKernel(Kernel); return VX_FAILURE; + } + + return status; +} + +#endif \ No newline at end of file diff --git a/vx_ext_cv/OpenCV_SIFT_Detect.cpp b/vx_ext_cv/OpenCV_SIFT_Detect.cpp new file mode 100644 index 0000000..2c4d5ef --- /dev/null +++ b/vx_ext_cv/OpenCV_SIFT_Detect.cpp @@ -0,0 +1,230 @@ +/* +Copyright (c) 2015 Advanced Micro Devices, Inc. All rights reserved. + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. +*/ + + +#if USE_OPENCV_CONTRIB +#include"publishkernels.h" + +/*!*********************************************************************************************************** +input parameter validator. +param [in] node The handle to the node. +param [in] index The index of the parameter to validate. +*************************************************************************************************************/ +static vx_status VX_CALLBACK CV_SIFT_Detect_InputValidator(vx_node node, vx_uint32 index) +{ + vx_status status = VX_SUCCESS; + vx_parameter param = vxGetParameterByIndex(node, index); + + if (index == 0) + { + vx_image image; + vx_df_image df_image = VX_DF_IMAGE_VIRT; + STATUS_ERROR_CHECK(vxQueryParameter(param, VX_PARAMETER_ATTRIBUTE_REF, &image, sizeof(vx_image))); + STATUS_ERROR_CHECK(vxQueryImage(image, VX_IMAGE_ATTRIBUTE_FORMAT, &df_image, sizeof(df_image))); + if (df_image != VX_DF_IMAGE_U8) + status = VX_ERROR_INVALID_VALUE; + vxReleaseImage(&image); + } + + if (index == 1) + { + vx_image image; + vx_df_image df_image = VX_DF_IMAGE_VIRT; + STATUS_ERROR_CHECK(vxQueryParameter(param, VX_PARAMETER_ATTRIBUTE_REF, &image, sizeof(vx_image))); + STATUS_ERROR_CHECK(vxQueryImage(image, VX_IMAGE_ATTRIBUTE_FORMAT, &df_image, sizeof(df_image))); + if (df_image != VX_DF_IMAGE_U8) + status = VX_ERROR_INVALID_VALUE; + vxReleaseImage(&image); + } + + else if (index == 2) + { + vx_array array; vx_size size = 0; + STATUS_ERROR_CHECK(vxQueryParameter(param, VX_PARAMETER_ATTRIBUTE_REF, &array, sizeof(array))); + STATUS_ERROR_CHECK(vxQueryArray(array, VX_ARRAY_ATTRIBUTE_CAPACITY, &size, sizeof(size))); + vxReleaseArray(&array); + } + + else if (index == 3) + { + vx_scalar scalar = 0; vx_enum type = 0; vx_int32 value = 0; + STATUS_ERROR_CHECK(vxQueryParameter(param, VX_PARAMETER_ATTRIBUTE_REF, &scalar, sizeof(scalar))); + STATUS_ERROR_CHECK(vxQueryScalar(scalar, VX_SCALAR_ATTRIBUTE_TYPE, &type, sizeof(type))); + STATUS_ERROR_CHECK(vxReadScalarValue(scalar, &value)); + if (value < 0 || type != VX_TYPE_INT32) + status = VX_ERROR_INVALID_VALUE; + vxReleaseScalar(&scalar); + } + + else if (index == 4) + { + vx_scalar scalar = 0; vx_enum type = 0; vx_int32 value = 0; + STATUS_ERROR_CHECK(vxQueryParameter(param, VX_PARAMETER_ATTRIBUTE_REF, &scalar, sizeof(scalar))); + STATUS_ERROR_CHECK(vxQueryScalar(scalar, VX_SCALAR_ATTRIBUTE_TYPE, &type, sizeof(type))); + STATUS_ERROR_CHECK(vxReadScalarValue(scalar, &value)); + if (value < 0 || type != VX_TYPE_INT32) + status = VX_ERROR_INVALID_VALUE; + vxReleaseScalar(&scalar); + } + + else if (index == 5) + { + vx_scalar scalar = 0; vx_enum type = 0; vx_float32 value = 0; + STATUS_ERROR_CHECK(vxQueryParameter(param, VX_PARAMETER_ATTRIBUTE_REF, &scalar, sizeof(scalar))); + STATUS_ERROR_CHECK(vxQueryScalar(scalar, VX_SCALAR_ATTRIBUTE_TYPE, &type, sizeof(type))); + STATUS_ERROR_CHECK(vxReadScalarValue(scalar, &value)); + if (value < 0 || type != VX_TYPE_FLOAT32) + status = VX_ERROR_INVALID_VALUE; + vxReleaseScalar(&scalar); + } + + else if (index == 6) + { + vx_scalar scalar = 0; vx_enum type = 0; vx_float32 value = 0; + STATUS_ERROR_CHECK(vxQueryParameter(param, VX_PARAMETER_ATTRIBUTE_REF, &scalar, sizeof(scalar))); + STATUS_ERROR_CHECK(vxQueryScalar(scalar, VX_SCALAR_ATTRIBUTE_TYPE, &type, sizeof(type))); + STATUS_ERROR_CHECK(vxReadScalarValue(scalar, &value)); + if (value < 0 || type != VX_TYPE_FLOAT32) + status = VX_ERROR_INVALID_VALUE; + vxReleaseScalar(&scalar); + } + + else if (index == 7) + { + vx_scalar scalar = 0; vx_enum type = 0; vx_float32 value = 0; + STATUS_ERROR_CHECK(vxQueryParameter(param, VX_PARAMETER_ATTRIBUTE_REF, &scalar, sizeof(scalar))); + STATUS_ERROR_CHECK(vxQueryScalar(scalar, VX_SCALAR_ATTRIBUTE_TYPE, &type, sizeof(type))); + STATUS_ERROR_CHECK(vxReadScalarValue(scalar, &value)); + if (value < 0 || type != VX_TYPE_FLOAT32) + status = VX_ERROR_INVALID_VALUE; + vxReleaseScalar(&scalar); + } + + vxReleaseParameter(¶m); + return status; +} + +/*!*********************************************************************************************************** +output parameter validator. +*************************************************************************************************************/ +static vx_status VX_CALLBACK CV_SIFT_Detect_OutputValidator(vx_node node, vx_uint32 index, vx_meta_format meta) +{ + vx_status status = VX_SUCCESS; + if (index == 2) + { + vx_parameter output_param = vxGetParameterByIndex(node, 2); + vx_array output; vx_size size = 0; + + STATUS_ERROR_CHECK(vxQueryParameter(output_param, VX_PARAMETER_ATTRIBUTE_REF, &output, sizeof(vx_array))); + STATUS_ERROR_CHECK(vxQueryArray(output, VX_ARRAY_ATTRIBUTE_CAPACITY, &size, sizeof(size))); + + if (size <= 0) + status = VX_ERROR_INVALID_VALUE; + + vxReleaseArray(&output); + vxReleaseParameter(&output_param); + } + return status; +} + +/*!*********************************************************************************************************** +Execution Kernel +*************************************************************************************************************/ +static vx_status VX_CALLBACK CV_SIFT_Detect_Kernel(vx_node node, const vx_reference *parameters, vx_uint32 num) +{ + vx_status status = VX_SUCCESS; + + vx_image image_in = (vx_image) parameters[0]; + vx_image mask = (vx_image) parameters[1]; + vx_array array = (vx_array) parameters[2]; + vx_scalar nFEATURES = (vx_scalar) parameters[3]; + vx_scalar nOCTAVELAYERS = (vx_scalar) parameters[4]; + vx_scalar ContrastTHRESHOLD = (vx_scalar) parameters[5]; + vx_scalar EdgeTHRESHOLD = (vx_scalar) parameters[6]; + vx_scalar SIGMA = (vx_scalar) parameters[7]; + + Mat *mat, *mask_mat, Img; + vector key_points; + vx_float32 FloatValue = 0; + vx_int32 value = 0; + float CTHRESHOLD, ETHRESHOLD, Sigma; + int NFEATURES, NOctaveLayers; + + //Extracting Values from the Scalar + STATUS_ERROR_CHECK(vxReadScalarValue(nFEATURES, &value)); NFEATURES = value; + STATUS_ERROR_CHECK(vxReadScalarValue(nOCTAVELAYERS, &value)); NOctaveLayers = value; + STATUS_ERROR_CHECK(vxReadScalarValue(ContrastTHRESHOLD, &FloatValue)); CTHRESHOLD = FloatValue; + STATUS_ERROR_CHECK(vxReadScalarValue(EdgeTHRESHOLD, &FloatValue)); ETHRESHOLD = FloatValue; + STATUS_ERROR_CHECK(vxReadScalarValue(SIGMA, &FloatValue)); Sigma = FloatValue; + + //Converting VX Image to OpenCV Mat + STATUS_ERROR_CHECK(VX_to_CV_Image(&mat, image_in)); + STATUS_ERROR_CHECK(VX_to_CV_Image(&mask_mat, mask)); + + //Compute using OpenCV + Ptr sift = xfeatures2d::SIFT::create(NFEATURES, NOctaveLayers, CTHRESHOLD, ETHRESHOLD, Sigma); + sift->detect(*mat, key_points, *mask_mat); + + //Converting OpenCV Keypoints to OpenVX Keypoints + STATUS_ERROR_CHECK(CV_to_VX_keypoints(key_points, array)); + + return status; +} + +/************************************************************************************************************ +Function to Register the Kernel for Publish +*************************************************************************************************************/ +vx_status CV_SIFT_detect_Register(vx_context context) +{ + vx_status status = VX_SUCCESS; + vx_kernel Kernel = vxAddKernel(context, + "org.opencv.sift_detect", + VX_KERNEL_EXT_CV_SIFT_DETECT, + CV_SIFT_Detect_Kernel, + 8, + CV_SIFT_Detect_InputValidator, + CV_SIFT_Detect_OutputValidator, + nullptr, + nullptr); + + if (Kernel) + { + PARAM_ERROR_CHECK(vxAddParameterToKernel(Kernel, 0, VX_INPUT, VX_TYPE_IMAGE, VX_PARAMETER_STATE_REQUIRED)); + PARAM_ERROR_CHECK(vxAddParameterToKernel(Kernel, 1, VX_INPUT, VX_TYPE_IMAGE, VX_PARAMETER_STATE_REQUIRED)); + PARAM_ERROR_CHECK(vxAddParameterToKernel(Kernel, 2, VX_BIDIRECTIONAL, VX_TYPE_ARRAY, VX_PARAMETER_STATE_REQUIRED)); + PARAM_ERROR_CHECK(vxAddParameterToKernel(Kernel, 3, VX_INPUT, VX_TYPE_SCALAR, VX_PARAMETER_STATE_REQUIRED)); + PARAM_ERROR_CHECK(vxAddParameterToKernel(Kernel, 4, VX_INPUT, VX_TYPE_SCALAR, VX_PARAMETER_STATE_REQUIRED)); + PARAM_ERROR_CHECK(vxAddParameterToKernel(Kernel, 5, VX_INPUT, VX_TYPE_SCALAR, VX_PARAMETER_STATE_REQUIRED)); + PARAM_ERROR_CHECK(vxAddParameterToKernel(Kernel, 6, VX_INPUT, VX_TYPE_SCALAR, VX_PARAMETER_STATE_REQUIRED)); + PARAM_ERROR_CHECK(vxAddParameterToKernel(Kernel, 7, VX_INPUT, VX_TYPE_SCALAR, VX_PARAMETER_STATE_REQUIRED)); + PARAM_ERROR_CHECK(vxFinalizeKernel(Kernel)); + } + + if (status != VX_SUCCESS) + { + exit: vxRemoveKernel(Kernel); return VX_FAILURE; + } + + return status; +} + +#endif diff --git a/vx_ext_cv/OpenCV_SURF_Compute.cpp b/vx_ext_cv/OpenCV_SURF_Compute.cpp new file mode 100644 index 0000000..61d4e1b --- /dev/null +++ b/vx_ext_cv/OpenCV_SURF_Compute.cpp @@ -0,0 +1,250 @@ +/* +Copyright (c) 2015 Advanced Micro Devices, Inc. All rights reserved. + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. +*/ + + +#if USE_OPENCV_CONTRIB +#include"publishkernels.h" + +/*!*********************************************************************************************************** +input parameter validator. +param [in] node The handle to the node. +param [in] index The index of the parameter to validate. +*************************************************************************************************************/ +static vx_status VX_CALLBACK CV_SURF_Compute_InputValidator(vx_node node, vx_uint32 index) +{ + vx_status status = VX_SUCCESS; + vx_parameter param = vxGetParameterByIndex(node, index); + + if (index == 0) + { + vx_image image; + vx_df_image df_image = VX_DF_IMAGE_VIRT; + STATUS_ERROR_CHECK(vxQueryParameter(param, VX_PARAMETER_ATTRIBUTE_REF, &image, sizeof(vx_image))); + STATUS_ERROR_CHECK(vxQueryImage(image, VX_IMAGE_ATTRIBUTE_FORMAT, &df_image, sizeof(df_image))); + if (df_image != VX_DF_IMAGE_U8) + status = VX_ERROR_INVALID_VALUE; + vxReleaseImage(&image); + } + + if (index == 1) + { + vx_image image; + vx_df_image df_image = VX_DF_IMAGE_VIRT; + STATUS_ERROR_CHECK(vxQueryParameter(param, VX_PARAMETER_ATTRIBUTE_REF, &image, sizeof(vx_image))); + STATUS_ERROR_CHECK(vxQueryImage(image, VX_IMAGE_ATTRIBUTE_FORMAT, &df_image, sizeof(df_image))); + if (df_image != VX_DF_IMAGE_U8) + status = VX_ERROR_INVALID_VALUE; + vxReleaseImage(&image); + } + + else if (index == 2) + { + vx_array array; vx_size size = 0; + STATUS_ERROR_CHECK(vxQueryParameter(param, VX_PARAMETER_ATTRIBUTE_REF, &array, sizeof(array))); + STATUS_ERROR_CHECK(vxQueryArray(array, VX_ARRAY_ATTRIBUTE_CAPACITY, &size, sizeof(size))); + vxReleaseArray(&array); + } + + else if (index == 3) + { + vx_array array; vx_size size = 0; + STATUS_ERROR_CHECK(vxQueryParameter(param, VX_PARAMETER_ATTRIBUTE_REF, &array, sizeof(array))); + STATUS_ERROR_CHECK(vxQueryArray(array, VX_ARRAY_ATTRIBUTE_CAPACITY, &size, sizeof(size))); + vxReleaseArray(&array); + } + + else if (index == 4) + { + vx_scalar scalar = 0; vx_enum type = 0; vx_float32 value = 0; + STATUS_ERROR_CHECK(vxQueryParameter(param, VX_PARAMETER_ATTRIBUTE_REF, &scalar, sizeof(scalar))); + STATUS_ERROR_CHECK(vxQueryScalar(scalar, VX_SCALAR_ATTRIBUTE_TYPE, &type, sizeof(type))); + STATUS_ERROR_CHECK(vxReadScalarValue(scalar, &value)); + if (value < 0 || type != VX_TYPE_FLOAT32) + status = VX_ERROR_INVALID_VALUE; + vxReleaseScalar(&scalar); + } + + else if (index == 5) + { + vx_scalar scalar = 0; vx_enum type = 0; vx_int32 value = 0; + STATUS_ERROR_CHECK(vxQueryParameter(param, VX_PARAMETER_ATTRIBUTE_REF, &scalar, sizeof(scalar))); + STATUS_ERROR_CHECK(vxQueryScalar(scalar, VX_SCALAR_ATTRIBUTE_TYPE, &type, sizeof(type))); + STATUS_ERROR_CHECK(vxReadScalarValue(scalar, &value)); + if (value < 0 || type != VX_TYPE_INT32) + status = VX_ERROR_INVALID_VALUE; + vxReleaseScalar(&scalar); + } + + else if (index == 6) + { + vx_scalar scalar = 0; vx_enum type = 0; vx_int32 value = 0; + STATUS_ERROR_CHECK(vxQueryParameter(param, VX_PARAMETER_ATTRIBUTE_REF, &scalar, sizeof(scalar))); + STATUS_ERROR_CHECK(vxQueryScalar(scalar, VX_SCALAR_ATTRIBUTE_TYPE, &type, sizeof(type))); + STATUS_ERROR_CHECK(vxReadScalarValue(scalar, &value)); + if (value < 0 || type != VX_TYPE_INT32) + status = VX_ERROR_INVALID_VALUE; + vxReleaseScalar(&scalar); + } + + else if (index == 7) + { + vx_scalar scalar = 0; vx_enum type = 0; vx_bool value = vx_true_e; + STATUS_ERROR_CHECK(vxQueryParameter(param, VX_PARAMETER_ATTRIBUTE_REF, &scalar, sizeof(scalar))); + STATUS_ERROR_CHECK(vxQueryScalar(scalar, VX_SCALAR_ATTRIBUTE_TYPE, &type, sizeof(type))); + STATUS_ERROR_CHECK(vxReadScalarValue(scalar, &value)); + if ((value != vx_true_e && value != vx_false_e) || type != VX_TYPE_BOOL) + status = VX_ERROR_INVALID_VALUE; + vxReleaseScalar(&scalar); + } + + else if (index == 8) + { + vx_scalar scalar = 0; vx_enum type = 0; vx_bool value = vx_true_e; + STATUS_ERROR_CHECK(vxQueryParameter(param, VX_PARAMETER_ATTRIBUTE_REF, &scalar, sizeof(scalar))); + STATUS_ERROR_CHECK(vxQueryScalar(scalar, VX_SCALAR_ATTRIBUTE_TYPE, &type, sizeof(type))); + STATUS_ERROR_CHECK(vxReadScalarValue(scalar, &value)); + if ((value != vx_true_e && value != vx_false_e) || type != VX_TYPE_BOOL) + status = VX_ERROR_INVALID_VALUE; + vxReleaseScalar(&scalar); + } + + vxReleaseParameter(¶m); + return status; +} + +/*!*********************************************************************************************************** +output parameter validator. +*************************************************************************************************************/ +static vx_status VX_CALLBACK CV_SURF_Compute_OutputValidator(vx_node node, vx_uint32 index, vx_meta_format meta) +{ + vx_status status = VX_SUCCESS; + if (index == 2) + { + vx_parameter output_param = vxGetParameterByIndex(node, 2); + vx_array output; vx_size size = 0; + + STATUS_ERROR_CHECK(vxQueryParameter(output_param, VX_PARAMETER_ATTRIBUTE_REF, &output, sizeof(vx_array))); + STATUS_ERROR_CHECK(vxQueryArray(output, VX_ARRAY_ATTRIBUTE_CAPACITY, &size, sizeof(size))); + + if (size <= 0) + status = VX_ERROR_INVALID_VALUE; + + vxReleaseArray(&output); + vxReleaseParameter(&output_param); + } + return status; +} + +/*!*********************************************************************************************************** +Execution Kernel +*************************************************************************************************************/ +static vx_status VX_CALLBACK CV_SURF_Compute_Kernel(vx_node node, const vx_reference *parameters, vx_uint32 num) +{ + vx_status status = VX_SUCCESS; + + vx_image image_in = (vx_image) parameters[0]; + vx_image mask = (vx_image) parameters[1]; + vx_array array = (vx_array) parameters[2]; + vx_array DESP = (vx_array) parameters[3]; + vx_scalar hessianThreshold = (vx_scalar) parameters[4]; + vx_scalar nOctaves = (vx_scalar) parameters[5]; + vx_scalar nOctaveLayers = (vx_scalar) parameters[6]; + vx_scalar EXTENDED = (vx_scalar) parameters[7]; + vx_scalar UPRIGHT = (vx_scalar) parameters[8]; + + Mat *mat, *mask_mat, Img; + vx_float32 FloatValue = 0; + vx_int32 value = 0; + vx_bool extend, upright, value_b; + float HessianThreshold; + int NOctaves, NOctaveLayers; + + //Extracting Values from the Scalar + STATUS_ERROR_CHECK(vxReadScalarValue(hessianThreshold, &FloatValue)); HessianThreshold = FloatValue; + STATUS_ERROR_CHECK(vxReadScalarValue(nOctaves, &value)); NOctaves = value; + STATUS_ERROR_CHECK(vxReadScalarValue(nOctaveLayers, &value)); NOctaveLayers = value; + STATUS_ERROR_CHECK(vxReadScalarValue(EXTENDED, &value_b)); extend = value_b; + STATUS_ERROR_CHECK(vxReadScalarValue(UPRIGHT, &value_b)); upright = value_b; + + //Converting VX Image to OpenCV Mat + STATUS_ERROR_CHECK(VX_to_CV_Image(&mat, image_in)); + STATUS_ERROR_CHECK(VX_to_CV_Image(&mask_mat, mask)); + + //Compute using OpenCV + bool extended_B, upright_b; + if (extend == vx_true_e) extended_B = true; else extended_B = false; + if (upright == vx_true_e) upright_b = true; else upright_b = false; + vector key_points; + Mat Desp; + Ptr surf = xfeatures2d::SURF::create(HessianThreshold, NOctaves, NOctaveLayers); + surf->detectAndCompute(*mat, *mask_mat, key_points, Desp); + + //Converting OpenCV Keypoints to OpenVX Keypoints + STATUS_ERROR_CHECK(CV_to_VX_keypoints(key_points, array)); + + if (extend == 1) + STATUS_ERROR_CHECK(CV_DESP_to_VX_DESP(Desp, DESP, 512)); + if (extend != 1) + STATUS_ERROR_CHECK(CV_DESP_to_VX_DESP(Desp, DESP, 256)); + + return status; +} + +/************************************************************************************************************ +Function to Register the Kernel for Publish +*************************************************************************************************************/ +vx_status CV_SURF_compute_Register(vx_context context) +{ + vx_status status = VX_SUCCESS; + vx_kernel Kernel = vxAddKernel(context, + "org.opencv.surf_compute", + VX_KERNEL_EXT_CV_SURF_COMPUTE, + CV_SURF_Compute_Kernel, + 9, + CV_SURF_Compute_InputValidator, + CV_SURF_Compute_OutputValidator, + nullptr, + nullptr); + + if (Kernel) + { + PARAM_ERROR_CHECK(vxAddParameterToKernel(Kernel, 0, VX_INPUT, VX_TYPE_IMAGE, VX_PARAMETER_STATE_REQUIRED)); + PARAM_ERROR_CHECK(vxAddParameterToKernel(Kernel, 1, VX_INPUT, VX_TYPE_IMAGE, VX_PARAMETER_STATE_REQUIRED)); + PARAM_ERROR_CHECK(vxAddParameterToKernel(Kernel, 2, VX_BIDIRECTIONAL, VX_TYPE_ARRAY, VX_PARAMETER_STATE_REQUIRED)); + PARAM_ERROR_CHECK(vxAddParameterToKernel(Kernel, 3, VX_BIDIRECTIONAL, VX_TYPE_ARRAY, VX_PARAMETER_STATE_REQUIRED)); + PARAM_ERROR_CHECK(vxAddParameterToKernel(Kernel, 4, VX_INPUT, VX_TYPE_SCALAR, VX_PARAMETER_STATE_REQUIRED)); + PARAM_ERROR_CHECK(vxAddParameterToKernel(Kernel, 5, VX_INPUT, VX_TYPE_SCALAR, VX_PARAMETER_STATE_REQUIRED)); + PARAM_ERROR_CHECK(vxAddParameterToKernel(Kernel, 6, VX_INPUT, VX_TYPE_SCALAR, VX_PARAMETER_STATE_REQUIRED)); + PARAM_ERROR_CHECK(vxAddParameterToKernel(Kernel, 7, VX_INPUT, VX_TYPE_SCALAR, VX_PARAMETER_STATE_REQUIRED)); + PARAM_ERROR_CHECK(vxAddParameterToKernel(Kernel, 8, VX_INPUT, VX_TYPE_SCALAR, VX_PARAMETER_STATE_REQUIRED)); + PARAM_ERROR_CHECK(vxFinalizeKernel(Kernel)); + } + + if (status != VX_SUCCESS) + { + exit: vxRemoveKernel(Kernel); return VX_FAILURE; + } + + return status; +} + +#endif diff --git a/vx_ext_cv/OpenCV_SURF_Detect.cpp b/vx_ext_cv/OpenCV_SURF_Detect.cpp new file mode 100644 index 0000000..6348925 --- /dev/null +++ b/vx_ext_cv/OpenCV_SURF_Detect.cpp @@ -0,0 +1,206 @@ +/* +Copyright (c) 2015 Advanced Micro Devices, Inc. All rights reserved. + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. +*/ + + +#if USE_OPENCV_CONTRIB +#include"publishkernels.h" + +/*!*********************************************************************************************************** +input parameter validator. +param [in] node The handle to the node. +param [in] index The index of the parameter to validate. +*************************************************************************************************************/ +static vx_status VX_CALLBACK CV_SURF_Detect_InputValidator(vx_node node, vx_uint32 index) +{ + vx_status status = VX_SUCCESS; + vx_parameter param = vxGetParameterByIndex(node, index); + + if (index == 0) + { + vx_image image; + vx_df_image df_image = VX_DF_IMAGE_VIRT; + STATUS_ERROR_CHECK(vxQueryParameter(param, VX_PARAMETER_ATTRIBUTE_REF, &image, sizeof(vx_image))); + STATUS_ERROR_CHECK(vxQueryImage(image, VX_IMAGE_ATTRIBUTE_FORMAT, &df_image, sizeof(df_image))); + if (df_image != VX_DF_IMAGE_U8) + status = VX_ERROR_INVALID_VALUE; + vxReleaseImage(&image); + } + + if (index == 1) + { + vx_image image; + vx_df_image df_image = VX_DF_IMAGE_VIRT; + STATUS_ERROR_CHECK(vxQueryParameter(param, VX_PARAMETER_ATTRIBUTE_REF, &image, sizeof(vx_image))); + STATUS_ERROR_CHECK(vxQueryImage(image, VX_IMAGE_ATTRIBUTE_FORMAT, &df_image, sizeof(df_image))); + if (df_image != VX_DF_IMAGE_U8) + status = VX_ERROR_INVALID_VALUE; + vxReleaseImage(&image); + } + + else if (index == 2) + { + vx_array array; vx_size size = 0; + STATUS_ERROR_CHECK(vxQueryParameter(param, VX_PARAMETER_ATTRIBUTE_REF, &array, sizeof(array))); + STATUS_ERROR_CHECK(vxQueryArray(array, VX_ARRAY_ATTRIBUTE_CAPACITY, &size, sizeof(size))); + vxReleaseArray(&array); + } + + else if (index == 3) + { + vx_scalar scalar = 0; vx_enum type = 0; vx_float32 value = 0; + STATUS_ERROR_CHECK(vxQueryParameter(param, VX_PARAMETER_ATTRIBUTE_REF, &scalar, sizeof(scalar))); + STATUS_ERROR_CHECK(vxQueryScalar(scalar, VX_SCALAR_ATTRIBUTE_TYPE, &type, sizeof(type))); + STATUS_ERROR_CHECK(vxReadScalarValue(scalar, &value)); + if (value < 0 || type != VX_TYPE_FLOAT32) + status = VX_ERROR_INVALID_VALUE; + vxReleaseScalar(&scalar); + } + + else if (index == 4) + { + vx_scalar scalar = 0; vx_enum type = 0; vx_int32 value = 0; + STATUS_ERROR_CHECK(vxQueryParameter(param, VX_PARAMETER_ATTRIBUTE_REF, &scalar, sizeof(scalar))); + STATUS_ERROR_CHECK(vxQueryScalar(scalar, VX_SCALAR_ATTRIBUTE_TYPE, &type, sizeof(type))); + STATUS_ERROR_CHECK(vxReadScalarValue(scalar, &value)); + if (value < 0 || type != VX_TYPE_INT32) + status = VX_ERROR_INVALID_VALUE; + vxReleaseScalar(&scalar); + } + + else if (index == 5) + { + vx_scalar scalar = 0; vx_enum type = 0; vx_int32 value = 0; + STATUS_ERROR_CHECK(vxQueryParameter(param, VX_PARAMETER_ATTRIBUTE_REF, &scalar, sizeof(scalar))); + STATUS_ERROR_CHECK(vxQueryScalar(scalar, VX_SCALAR_ATTRIBUTE_TYPE, &type, sizeof(type))); + STATUS_ERROR_CHECK(vxReadScalarValue(scalar, &value)); + if (value < 0 || type != VX_TYPE_INT32) + status = VX_ERROR_INVALID_VALUE; + vxReleaseScalar(&scalar); + } + + vxReleaseParameter(¶m); + return status; +} + +/*!*********************************************************************************************************** +output parameter validator. +*************************************************************************************************************/ +static vx_status VX_CALLBACK CV_SURF_Detect_OutputValidator(vx_node node, vx_uint32 index, vx_meta_format meta) +{ + vx_status status = VX_SUCCESS; + if (index == 2) + { + vx_parameter output_param = vxGetParameterByIndex(node, 2); + vx_array output; vx_size size = 0; + + STATUS_ERROR_CHECK(vxQueryParameter(output_param, VX_PARAMETER_ATTRIBUTE_REF, &output, sizeof(vx_array))); + STATUS_ERROR_CHECK(vxQueryArray(output, VX_ARRAY_ATTRIBUTE_CAPACITY, &size, sizeof(size))); + + if (size <= 0) + status = VX_ERROR_INVALID_VALUE; + + vxReleaseArray(&output); + vxReleaseParameter(&output_param); + } + + return status; +} + +/*!*********************************************************************************************************** +Execution Kernel +*************************************************************************************************************/ +static vx_status VX_CALLBACK CV_SURF_Detect_Kernel(vx_node node, const vx_reference *parameters, vx_uint32 num) +{ + vx_status status = VX_SUCCESS; + vx_image image_in = (vx_image) parameters[0]; + vx_image mask = (vx_image) parameters[1]; + vx_array array = (vx_array) parameters[2]; + vx_scalar hessianThreshold = (vx_scalar) parameters[3]; + vx_scalar nOctaves = (vx_scalar) parameters[4]; + vx_scalar nOctaveLayers = (vx_scalar) parameters[5]; + + Mat *mat, *mask_mat, Img; + vx_uint32 width = 0; + vx_uint32 height = 0; + + vx_float32 FloatValue = 0; + vx_int32 value = 0; + + float HessianThreshold; + int NOctaves, NOctaveLayers; + + //Extracting Values from the Scalar + STATUS_ERROR_CHECK(vxReadScalarValue(hessianThreshold, &FloatValue)); HessianThreshold = FloatValue; + STATUS_ERROR_CHECK(vxReadScalarValue(nOctaves, &value)); NOctaves = value; + STATUS_ERROR_CHECK(vxReadScalarValue(nOctaveLayers, &value)); NOctaveLayers = value; + + //Converting VX Image to OpenCV Mat + STATUS_ERROR_CHECK(VX_to_CV_Image(&mat, image_in)); + STATUS_ERROR_CHECK(VX_to_CV_Image(&mask_mat, mask)); + + //Compute using OpenCV + vector key_points; + Ptr surf = xfeatures2d::SURF::create(HessianThreshold, NOctaves, NOctaveLayers); + surf->detect(*mat, key_points, *mask_mat); + + //Converting OpenCV Keypoints to OpenVX Keypoints + STATUS_ERROR_CHECK(CV_to_VX_keypoints(key_points, array)); + + return status; +} + +/************************************************************************************************************ +Function to Register the Kernel for Publish +*************************************************************************************************************/ +vx_status CV_SURF_detect_Register(vx_context context) +{ + vx_status status = VX_SUCCESS; + vx_kernel Kernel = vxAddKernel(context, + "org.opencv.surf_detect", + VX_KERNEL_EXT_CV_SURF_DETECT, + CV_SURF_Detect_Kernel, + 6, + CV_SURF_Detect_InputValidator, + CV_SURF_Detect_OutputValidator, + nullptr, + nullptr); + + if (Kernel) + { + PARAM_ERROR_CHECK(vxAddParameterToKernel(Kernel, 0, VX_INPUT, VX_TYPE_IMAGE, VX_PARAMETER_STATE_REQUIRED)); + PARAM_ERROR_CHECK(vxAddParameterToKernel(Kernel, 1, VX_INPUT, VX_TYPE_IMAGE, VX_PARAMETER_STATE_REQUIRED)); + PARAM_ERROR_CHECK(vxAddParameterToKernel(Kernel, 2, VX_BIDIRECTIONAL, VX_TYPE_ARRAY, VX_PARAMETER_STATE_REQUIRED)); + PARAM_ERROR_CHECK(vxAddParameterToKernel(Kernel, 3, VX_INPUT, VX_TYPE_SCALAR, VX_PARAMETER_STATE_REQUIRED)); + PARAM_ERROR_CHECK(vxAddParameterToKernel(Kernel, 4, VX_INPUT, VX_TYPE_SCALAR, VX_PARAMETER_STATE_REQUIRED)); + PARAM_ERROR_CHECK(vxAddParameterToKernel(Kernel, 5, VX_INPUT, VX_TYPE_SCALAR, VX_PARAMETER_STATE_REQUIRED)); + PARAM_ERROR_CHECK(vxFinalizeKernel(Kernel)); + } + + if (status != VX_SUCCESS) + { + exit: vxRemoveKernel(Kernel); return VX_FAILURE; + } + + return status; +} + +#endif diff --git a/vx_ext_cv/OpenCV_Scharr.cpp b/vx_ext_cv/OpenCV_Scharr.cpp new file mode 100644 index 0000000..4efbbd9 --- /dev/null +++ b/vx_ext_cv/OpenCV_Scharr.cpp @@ -0,0 +1,236 @@ +/* +Copyright (c) 2015 Advanced Micro Devices, Inc. All rights reserved. + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. +*/ + + +#include"publishkernels.h" + +/************************************************************************************************************ +input parameter validator. +param [in] node The handle to the node. +param [in] index The index of the parameter to validate. +*************************************************************************************************************/ +static vx_status VX_CALLBACK CV_Scharr_InputValidator(vx_node node, vx_uint32 index) +{ + vx_status status = VX_SUCCESS; + vx_parameter param = vxGetParameterByIndex(node, index); + + if (index == 0) + { + vx_image image; + vx_df_image df_image = VX_DF_IMAGE_VIRT; + STATUS_ERROR_CHECK(vxQueryParameter(param, VX_PARAMETER_ATTRIBUTE_REF, &image, sizeof(vx_image))); + STATUS_ERROR_CHECK(vxQueryImage(image, VX_IMAGE_ATTRIBUTE_FORMAT, &df_image, sizeof(df_image))); + if (df_image != VX_DF_IMAGE_U8) + status = VX_ERROR_INVALID_VALUE; + vxReleaseImage(&image); + } + + else if (index == 1) + { + vx_image image; + vx_df_image df_image = VX_DF_IMAGE_VIRT; + STATUS_ERROR_CHECK(vxQueryParameter(param, VX_PARAMETER_ATTRIBUTE_REF, &image, sizeof(vx_image))); + STATUS_ERROR_CHECK(vxQueryImage(image, VX_IMAGE_ATTRIBUTE_FORMAT, &df_image, sizeof(df_image))); + if (df_image != VX_DF_IMAGE_U8) + status = VX_ERROR_INVALID_VALUE; + vxReleaseImage(&image); + } + + else if (index == 2) + { + vx_scalar scalar = 0; vx_enum type = 0; vx_int32 value = 0; + STATUS_ERROR_CHECK(vxQueryParameter(param, VX_PARAMETER_ATTRIBUTE_REF, &scalar, sizeof(scalar))); + STATUS_ERROR_CHECK(vxQueryScalar(scalar, VX_SCALAR_ATTRIBUTE_TYPE, &type, sizeof(type))); + STATUS_ERROR_CHECK(vxReadScalarValue(scalar, &value)); + if (value < -1 || type != VX_TYPE_INT32) + status = VX_ERROR_INVALID_VALUE; + vxReleaseScalar(&scalar); + } + + else if (index == 3) + { + vx_scalar scalar = 0; vx_enum type = 0; vx_int32 value = 0; + STATUS_ERROR_CHECK(vxQueryParameter(param, VX_PARAMETER_ATTRIBUTE_REF, &scalar, sizeof(scalar))); + STATUS_ERROR_CHECK(vxQueryScalar(scalar, VX_SCALAR_ATTRIBUTE_TYPE, &type, sizeof(type))); + STATUS_ERROR_CHECK(vxReadScalarValue(scalar, &value)); + if (value < 0 || type != VX_TYPE_INT32) + status = VX_ERROR_INVALID_VALUE; + vxReleaseScalar(&scalar); + } + + else if (index == 4) + { + vx_scalar scalar = 0; vx_enum type = 0; vx_int32 value = 0; + STATUS_ERROR_CHECK(vxQueryParameter(param, VX_PARAMETER_ATTRIBUTE_REF, &scalar, sizeof(scalar))); + STATUS_ERROR_CHECK(vxQueryScalar(scalar, VX_SCALAR_ATTRIBUTE_TYPE, &type, sizeof(type))); + STATUS_ERROR_CHECK(vxReadScalarValue(scalar, &value)); + if (value < 0 || type != VX_TYPE_INT32) + status = VX_ERROR_INVALID_VALUE; + vxReleaseScalar(&scalar); + } + + else if (index == 5) + { + vx_scalar scalar = 0; vx_enum type = 0; vx_float32 value = 0; + STATUS_ERROR_CHECK(vxQueryParameter(param, VX_PARAMETER_ATTRIBUTE_REF, &scalar, sizeof(scalar))); + STATUS_ERROR_CHECK(vxQueryScalar(scalar, VX_SCALAR_ATTRIBUTE_TYPE, &type, sizeof(type))); + STATUS_ERROR_CHECK(vxReadScalarValue(scalar, &value)); + if (value < 0 || type != VX_TYPE_FLOAT32) + status = VX_ERROR_INVALID_VALUE; + vxReleaseScalar(&scalar); + } + + else if (index == 6) + { + vx_scalar scalar = 0; vx_enum type = 0; vx_float32 value = 0; + STATUS_ERROR_CHECK(vxQueryParameter(param, VX_PARAMETER_ATTRIBUTE_REF, &scalar, sizeof(scalar))); + STATUS_ERROR_CHECK(vxQueryScalar(scalar, VX_SCALAR_ATTRIBUTE_TYPE, &type, sizeof(type))); + STATUS_ERROR_CHECK(vxReadScalarValue(scalar, &value)); + if (type != VX_TYPE_FLOAT32) + status = VX_ERROR_INVALID_VALUE; + vxReleaseScalar(&scalar); + } + + else if (index == 7) + { + vx_scalar scalar = 0; vx_enum type = 0; vx_int32 value = 0; + STATUS_ERROR_CHECK(vxQueryParameter(param, VX_PARAMETER_ATTRIBUTE_REF, &scalar, sizeof(scalar))); + STATUS_ERROR_CHECK(vxQueryScalar(scalar, VX_SCALAR_ATTRIBUTE_TYPE, &type, sizeof(type))); + STATUS_ERROR_CHECK(vxReadScalarValue(scalar, &value)); + if (type != VX_TYPE_INT32) + status = VX_ERROR_INVALID_VALUE; + vxReleaseScalar(&scalar); + } + + vxReleaseParameter(¶m); + return status; +} + +/************************************************************************************************************ +output parameter validator. +*************************************************************************************************************/ +static vx_status VX_CALLBACK CV_Scharr_OutputValidator(vx_node node, vx_uint32 index, vx_meta_format meta) +{ + vx_status status = VX_SUCCESS; + if (index == 1) + { + vx_parameter output_param = vxGetParameterByIndex(node, 1); + vx_image output; vx_uint32 width = 0, height = 0; vx_df_image format = VX_DF_IMAGE_VIRT; + + STATUS_ERROR_CHECK(vxQueryParameter(output_param, VX_PARAMETER_ATTRIBUTE_REF, &output, sizeof(vx_image))); + STATUS_ERROR_CHECK(vxQueryImage(output, VX_IMAGE_ATTRIBUTE_FORMAT, &format, sizeof(format))); + STATUS_ERROR_CHECK(vxQueryImage(output, VX_IMAGE_ATTRIBUTE_WIDTH, &width, sizeof(width))); + STATUS_ERROR_CHECK(vxQueryImage(output, VX_IMAGE_ATTRIBUTE_HEIGHT, &height, sizeof(height))); + + if (format != VX_DF_IMAGE_U8) + status = VX_ERROR_INVALID_VALUE; + + STATUS_ERROR_CHECK(vxSetMetaFormatAttribute(meta, VX_IMAGE_ATTRIBUTE_WIDTH, &width, sizeof(width))); + STATUS_ERROR_CHECK(vxSetMetaFormatAttribute(meta, VX_IMAGE_ATTRIBUTE_HEIGHT, &height, sizeof(height))); + STATUS_ERROR_CHECK(vxSetMetaFormatAttribute(meta, VX_IMAGE_ATTRIBUTE_FORMAT, &format, sizeof(format))); + + vxReleaseImage(&output); + vxReleaseParameter(&output_param); + } + return status; +} + +/************************************************************************************************************ +Execution Kernel +*************************************************************************************************************/ +static vx_status VX_CALLBACK CV_Scharr_Kernel(vx_node node, const vx_reference *parameters, vx_uint32 num) +{ + vx_status status = VX_SUCCESS; + + vx_image image_in = (vx_image) parameters[0]; + vx_image image_out = (vx_image) parameters[1]; + vx_scalar scalar = (vx_scalar) parameters[2]; + vx_scalar Dx = (vx_scalar) parameters[3]; + vx_scalar Dy = (vx_scalar) parameters[4]; + vx_scalar Scale = (vx_scalar) parameters[5]; + vx_scalar Delta = (vx_scalar) parameters[6]; + vx_scalar Bordertype = (vx_scalar) parameters[7]; + + Mat *mat, bl; + int ddepth, dx, dy, bordertype; + double scale, delta; + vx_int32 value = 0; + vx_float32 value_1 = 0; + + //Extracting Values from the Scalar into Ksize and Ddepth + STATUS_ERROR_CHECK(vxReadScalarValue(scalar, &value)); ddepth = value; + STATUS_ERROR_CHECK(vxReadScalarValue(Dx, &value)); dx = value; + STATUS_ERROR_CHECK(vxReadScalarValue(Dy, &value)); dy = value; + STATUS_ERROR_CHECK(vxReadScalarValue(Scale, &value_1)); scale = value_1; + STATUS_ERROR_CHECK(vxReadScalarValue(Delta, &value_1)); delta = value_1; + STATUS_ERROR_CHECK(vxReadScalarValue(Bordertype, &value)); bordertype = value; + + //Converting VX Image to OpenCV Mat + STATUS_ERROR_CHECK(match_vx_image_parameters(image_in, image_out)); + STATUS_ERROR_CHECK(VX_to_CV_Image(&mat, image_in)); + + //Compute using OpenCV + cv::Scharr(*mat, bl, ddepth, dx, dy, scale, delta, bordertype); + + //Converting OpenCV Mat into VX Image + STATUS_ERROR_CHECK(CV_to_VX_Image(image_out, &bl)); + + return status; +} + +/************************************************************************************************************ +Function to Register the Kernel for Publish +*************************************************************************************************************/ +vx_status CV_Scharr_Register(vx_context context) +{ + vx_status status = VX_SUCCESS; + vx_kernel kernel = vxAddKernel(context, + "org.opencv.scharr", + VX_KERNEL_EXT_CV_SCHARR, + CV_Scharr_Kernel, + 8, + CV_Scharr_InputValidator, + CV_Scharr_OutputValidator, + nullptr, + nullptr); + + if (kernel) + { + PARAM_ERROR_CHECK(vxAddParameterToKernel(kernel, 0, VX_INPUT, VX_TYPE_IMAGE, VX_PARAMETER_STATE_REQUIRED)); + PARAM_ERROR_CHECK(vxAddParameterToKernel(kernel, 1, VX_OUTPUT, VX_TYPE_IMAGE, VX_PARAMETER_STATE_REQUIRED)); + PARAM_ERROR_CHECK(vxAddParameterToKernel(kernel, 2, VX_INPUT, VX_TYPE_SCALAR, VX_PARAMETER_STATE_REQUIRED)); + PARAM_ERROR_CHECK(vxAddParameterToKernel(kernel, 3, VX_INPUT, VX_TYPE_SCALAR, VX_PARAMETER_STATE_REQUIRED)); + PARAM_ERROR_CHECK(vxAddParameterToKernel(kernel, 4, VX_INPUT, VX_TYPE_SCALAR, VX_PARAMETER_STATE_REQUIRED)); + PARAM_ERROR_CHECK(vxAddParameterToKernel(kernel, 5, VX_INPUT, VX_TYPE_SCALAR, VX_PARAMETER_STATE_REQUIRED)); + PARAM_ERROR_CHECK(vxAddParameterToKernel(kernel, 6, VX_INPUT, VX_TYPE_SCALAR, VX_PARAMETER_STATE_REQUIRED)); + PARAM_ERROR_CHECK(vxAddParameterToKernel(kernel, 7, VX_INPUT, VX_TYPE_SCALAR, VX_PARAMETER_STATE_REQUIRED)); + PARAM_ERROR_CHECK(vxFinalizeKernel(kernel)); + } + + if (status != VX_SUCCESS) + { + exit: vxRemoveKernel(kernel); return VX_FAILURE; + } + + return status; +} + diff --git a/vx_ext_cv/OpenCV_Sobel.cpp b/vx_ext_cv/OpenCV_Sobel.cpp new file mode 100644 index 0000000..fbcc98b --- /dev/null +++ b/vx_ext_cv/OpenCV_Sobel.cpp @@ -0,0 +1,252 @@ +/* +Copyright (c) 2015 Advanced Micro Devices, Inc. All rights reserved. + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. +*/ + + +#include"publishkernels.h" + +/************************************************************************************************************ +input parameter validator. +param [in] node The handle to the node. +param [in] index The index of the parameter to validate. +*************************************************************************************************************/ +static vx_status VX_CALLBACK CV_Sobel_InputValidator(vx_node node, vx_uint32 index) +{ + vx_status status = VX_SUCCESS; + vx_parameter param = vxGetParameterByIndex(node, index); + + if (index == 0) + { + vx_image image; + vx_df_image df_image = VX_DF_IMAGE_VIRT; + STATUS_ERROR_CHECK(vxQueryParameter(param, VX_PARAMETER_ATTRIBUTE_REF, &image, sizeof(vx_image))); + STATUS_ERROR_CHECK(vxQueryImage(image, VX_IMAGE_ATTRIBUTE_FORMAT, &df_image, sizeof(df_image))); + if (df_image != VX_DF_IMAGE_U8) + status = VX_ERROR_INVALID_VALUE; + vxReleaseImage(&image); + } + + else if (index == 1) + { + vx_image image; + vx_df_image df_image = VX_DF_IMAGE_VIRT; + STATUS_ERROR_CHECK(vxQueryParameter(param, VX_PARAMETER_ATTRIBUTE_REF, &image, sizeof(vx_image))); + STATUS_ERROR_CHECK(vxQueryImage(image, VX_IMAGE_ATTRIBUTE_FORMAT, &df_image, sizeof(df_image))); + if (df_image != VX_DF_IMAGE_U8) + status = VX_ERROR_INVALID_VALUE; + vxReleaseImage(&image); + } + + else if (index == 2) + { + vx_scalar scalar = 0; vx_enum type = 0; vx_int32 value = 0; + STATUS_ERROR_CHECK(vxQueryParameter(param, VX_PARAMETER_ATTRIBUTE_REF, &scalar, sizeof(scalar))); + STATUS_ERROR_CHECK(vxQueryScalar(scalar, VX_SCALAR_ATTRIBUTE_TYPE, &type, sizeof(type))); + STATUS_ERROR_CHECK(vxReadScalarValue(scalar, &value)); + if (value < -1 || type != VX_TYPE_INT32) + status = VX_ERROR_INVALID_VALUE; + vxReleaseScalar(&scalar); + } + + else if (index == 3) + { + vx_scalar scalar = 0; vx_enum type = 0; vx_int32 value = 0; + STATUS_ERROR_CHECK(vxQueryParameter(param, VX_PARAMETER_ATTRIBUTE_REF, &scalar, sizeof(scalar))); + STATUS_ERROR_CHECK(vxQueryScalar(scalar, VX_SCALAR_ATTRIBUTE_TYPE, &type, sizeof(type))); + STATUS_ERROR_CHECK(vxReadScalarValue(scalar, &value)); + if (value < 0 || type != VX_TYPE_INT32) + status = VX_ERROR_INVALID_VALUE; + vxReleaseScalar(&scalar); + } + + else if (index == 4) + { + vx_scalar scalar = 0; vx_enum type = 0; vx_int32 value = 0; + STATUS_ERROR_CHECK(vxQueryParameter(param, VX_PARAMETER_ATTRIBUTE_REF, &scalar, sizeof(scalar))); + STATUS_ERROR_CHECK(vxQueryScalar(scalar, VX_SCALAR_ATTRIBUTE_TYPE, &type, sizeof(type))); + STATUS_ERROR_CHECK(vxReadScalarValue(scalar, &value)); + if (value < 0 || type != VX_TYPE_INT32) + status = VX_ERROR_INVALID_VALUE; + vxReleaseScalar(&scalar); + } + + else if (index == 5) + { + vx_scalar scalar = 0; vx_enum type = 0; vx_int32 value = 0; + STATUS_ERROR_CHECK(vxQueryParameter(param, VX_PARAMETER_ATTRIBUTE_REF, &scalar, sizeof(scalar))); + STATUS_ERROR_CHECK(vxQueryScalar(scalar, VX_SCALAR_ATTRIBUTE_TYPE, &type, sizeof(type))); + STATUS_ERROR_CHECK(vxReadScalarValue(scalar, &value)); + if ((value != 1 && value != 3 && value != 5 && value != 7) || type != VX_TYPE_INT32) + status = VX_ERROR_INVALID_VALUE; + vxReleaseScalar(&scalar); + } + + else if (index == 6) + { + vx_scalar scalar = 0; vx_enum type = 0; vx_float32 value = 0; + STATUS_ERROR_CHECK(vxQueryParameter(param, VX_PARAMETER_ATTRIBUTE_REF, &scalar, sizeof(scalar))); + STATUS_ERROR_CHECK(vxQueryScalar(scalar, VX_SCALAR_ATTRIBUTE_TYPE, &type, sizeof(type))); + STATUS_ERROR_CHECK(vxReadScalarValue(scalar, &value)); + if (value < 0 || type != VX_TYPE_FLOAT32) + status = VX_ERROR_INVALID_VALUE; + vxReleaseScalar(&scalar); + } + + else if (index == 7) + { + vx_scalar scalar = 0; vx_enum type = 0; vx_float32 value = 0; + STATUS_ERROR_CHECK(vxQueryParameter(param, VX_PARAMETER_ATTRIBUTE_REF, &scalar, sizeof(scalar))); + STATUS_ERROR_CHECK(vxQueryScalar(scalar, VX_SCALAR_ATTRIBUTE_TYPE, &type, sizeof(type))); + STATUS_ERROR_CHECK(vxReadScalarValue(scalar, &value)); + if (value < 0 || type != VX_TYPE_FLOAT32) + status = VX_ERROR_INVALID_VALUE; + vxReleaseScalar(&scalar); + } + + else if (index == 8) + { + vx_scalar scalar = 0; vx_enum type = 0; vx_int32 value = 0; + STATUS_ERROR_CHECK(vxQueryParameter(param, VX_PARAMETER_ATTRIBUTE_REF, &scalar, sizeof(scalar))); + STATUS_ERROR_CHECK(vxQueryScalar(scalar, VX_SCALAR_ATTRIBUTE_TYPE, &type, sizeof(type))); + STATUS_ERROR_CHECK(vxReadScalarValue(scalar, &value)); + if (value < 0 || type != VX_TYPE_INT32) + status = VX_ERROR_INVALID_VALUE; + vxReleaseScalar(&scalar); + } + + vxReleaseParameter(¶m); + return status; +} + +/************************************************************************************************************ +output parameter validator. +*************************************************************************************************************/ +static vx_status VX_CALLBACK CV_Sobel_OutputValidator(vx_node node, vx_uint32 index, vx_meta_format meta) +{ + vx_status status = VX_SUCCESS; + if (index == 1) + { + vx_parameter output_param = vxGetParameterByIndex(node, 1); + vx_image output; vx_uint32 width = 0, height = 0; vx_df_image format = VX_DF_IMAGE_VIRT; + + STATUS_ERROR_CHECK(vxQueryParameter(output_param, VX_PARAMETER_ATTRIBUTE_REF, &output, sizeof(vx_image))); + STATUS_ERROR_CHECK(vxQueryImage(output, VX_IMAGE_ATTRIBUTE_FORMAT, &format, sizeof(format))); + STATUS_ERROR_CHECK(vxQueryImage(output, VX_IMAGE_ATTRIBUTE_WIDTH, &width, sizeof(width))); + STATUS_ERROR_CHECK(vxQueryImage(output, VX_IMAGE_ATTRIBUTE_HEIGHT, &height, sizeof(height))); + + if (format != VX_DF_IMAGE_U8) + status = VX_ERROR_INVALID_VALUE; + + STATUS_ERROR_CHECK(vxSetMetaFormatAttribute(meta, VX_IMAGE_ATTRIBUTE_WIDTH, &width, sizeof(width))); + STATUS_ERROR_CHECK(vxSetMetaFormatAttribute(meta, VX_IMAGE_ATTRIBUTE_HEIGHT, &height, sizeof(height))); + STATUS_ERROR_CHECK(vxSetMetaFormatAttribute(meta, VX_IMAGE_ATTRIBUTE_FORMAT, &format, sizeof(format))); + + vxReleaseImage(&output); + vxReleaseParameter(&output_param); + } + return status; +} + +/************************************************************************************************************ +Execution Kernel +*************************************************************************************************************/ +static vx_status VX_CALLBACK CV_Sobel_Kernel(vx_node node, const vx_reference *parameters, vx_uint32 num) +{ + vx_status status = VX_SUCCESS; + + vx_image image_in = (vx_image) parameters[0]; + vx_image image_out = (vx_image) parameters[1]; + vx_scalar scalar = (vx_scalar) parameters[2]; + vx_scalar Dx = (vx_scalar) parameters[3]; + vx_scalar Dy = (vx_scalar) parameters[4]; + vx_scalar Ksize = (vx_scalar) parameters[5]; + vx_scalar Scale = (vx_scalar) parameters[6]; + vx_scalar Delta = (vx_scalar) parameters[7]; + vx_scalar Bordertype = (vx_scalar) parameters[8]; + + Mat *mat, bl; + int ddepth, dx, dy, ksize, bordertype; + double scale, delta; + vx_int32 value = 0; + vx_float32 value_1 = 0; + + //Extracting Values from the Scalar into Ksize and Ddepth + STATUS_ERROR_CHECK(vxReadScalarValue(scalar, &value)); ddepth = value; + STATUS_ERROR_CHECK(vxReadScalarValue(Dx, &value)); dx = value; + STATUS_ERROR_CHECK(vxReadScalarValue(Dy, &value)); dy = value; + STATUS_ERROR_CHECK(vxReadScalarValue(Ksize, &value)); ksize = value; + STATUS_ERROR_CHECK(vxReadScalarValue(Scale, &value_1)); scale = (double) value_1; + STATUS_ERROR_CHECK(vxReadScalarValue(Delta, &value_1)); delta = (double) value_1; + STATUS_ERROR_CHECK(vxReadScalarValue(Bordertype, &value)); bordertype = value; + + //Converting VX Image to OpenCV Mat + STATUS_ERROR_CHECK(match_vx_image_parameters(image_in, image_out)); + STATUS_ERROR_CHECK(VX_to_CV_Image(&mat, image_in)); + + //Compute using OpenCV + cv::Sobel(*mat, bl, ddepth, dx, dy, ksize, scale, delta, bordertype); + + //Converting OpenCV Mat into VX Image + STATUS_ERROR_CHECK(CV_to_VX_Image(image_out, &bl)); + + return status; + +} + +/************************************************************************************************************ +Function to Register the Kernel for Publish +*************************************************************************************************************/ +vx_status CV_Sobel_Register(vx_context context) +{ + vx_status status = VX_SUCCESS; + vx_kernel kernel = vxAddKernel(context, + "org.opencv.sobel", + VX_KERNEL_EXT_CV_SOBEL, + CV_Sobel_Kernel, + 9, + CV_Sobel_InputValidator, + CV_Sobel_OutputValidator, + nullptr, + nullptr); + + if (kernel) + { + PARAM_ERROR_CHECK(vxAddParameterToKernel(kernel, 0, VX_INPUT, VX_TYPE_IMAGE, VX_PARAMETER_STATE_REQUIRED)); + PARAM_ERROR_CHECK(vxAddParameterToKernel(kernel, 1, VX_OUTPUT, VX_TYPE_IMAGE, VX_PARAMETER_STATE_REQUIRED)); + PARAM_ERROR_CHECK(vxAddParameterToKernel(kernel, 2, VX_INPUT, VX_TYPE_SCALAR, VX_PARAMETER_STATE_REQUIRED)); + PARAM_ERROR_CHECK(vxAddParameterToKernel(kernel, 3, VX_INPUT, VX_TYPE_SCALAR, VX_PARAMETER_STATE_REQUIRED)); + PARAM_ERROR_CHECK(vxAddParameterToKernel(kernel, 4, VX_INPUT, VX_TYPE_SCALAR, VX_PARAMETER_STATE_REQUIRED)); + PARAM_ERROR_CHECK(vxAddParameterToKernel(kernel, 5, VX_INPUT, VX_TYPE_SCALAR, VX_PARAMETER_STATE_REQUIRED)); + PARAM_ERROR_CHECK(vxAddParameterToKernel(kernel, 6, VX_INPUT, VX_TYPE_SCALAR, VX_PARAMETER_STATE_REQUIRED)); + PARAM_ERROR_CHECK(vxAddParameterToKernel(kernel, 7, VX_INPUT, VX_TYPE_SCALAR, VX_PARAMETER_STATE_REQUIRED)); + PARAM_ERROR_CHECK(vxAddParameterToKernel(kernel, 8, VX_INPUT, VX_TYPE_SCALAR, VX_PARAMETER_STATE_REQUIRED)); + PARAM_ERROR_CHECK(vxFinalizeKernel(kernel)); + } + + if (status != VX_SUCCESS) + { + exit: vxRemoveKernel(kernel); return VX_FAILURE; + } + + return status; +} + + diff --git a/vx_ext_cv/OpenCV_Star_feature_detector.cpp b/vx_ext_cv/OpenCV_Star_feature_detector.cpp new file mode 100644 index 0000000..2f10718 --- /dev/null +++ b/vx_ext_cv/OpenCV_Star_feature_detector.cpp @@ -0,0 +1,228 @@ +/* +Copyright (c) 2015 Advanced Micro Devices, Inc. All rights reserved. + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. +*/ + + +#if USE_OPENCV_CONTRIB +#include"publishkernels.h" + +/*!*********************************************************************************************************** +input parameter validator. +param [in] node The handle to the node. +param [in] index The index of the parameter to validate. +*************************************************************************************************************/ +static vx_status VX_CALLBACK CV_star_feature_detector_InputValidator(vx_node node, vx_uint32 index) +{ + vx_status status = VX_SUCCESS; + vx_parameter param = vxGetParameterByIndex(node, index); + + if (index == 0) + { + vx_image image; + vx_df_image df_image = VX_DF_IMAGE_VIRT; + STATUS_ERROR_CHECK(vxQueryParameter(param, VX_PARAMETER_ATTRIBUTE_REF, &image, sizeof(vx_image))); + STATUS_ERROR_CHECK(vxQueryImage(image, VX_IMAGE_ATTRIBUTE_FORMAT, &df_image, sizeof(df_image))); + if (df_image != VX_DF_IMAGE_U8) + status = VX_ERROR_INVALID_VALUE; + vxReleaseImage(&image); + } + + else if (index == 1) + { + vx_array array; vx_size size = 0; + STATUS_ERROR_CHECK(vxQueryParameter(param, VX_PARAMETER_ATTRIBUTE_REF, &array, sizeof(array))); + STATUS_ERROR_CHECK(vxQueryArray(array, VX_ARRAY_ATTRIBUTE_CAPACITY, &size, sizeof(size))); + vxReleaseArray(&array); + } + + if (index == 2) + { + vx_image image; + vx_df_image df_image = VX_DF_IMAGE_VIRT; + STATUS_ERROR_CHECK(vxQueryParameter(param, VX_PARAMETER_ATTRIBUTE_REF, &image, sizeof(vx_image))); + STATUS_ERROR_CHECK(vxQueryImage(image, VX_IMAGE_ATTRIBUTE_FORMAT, &df_image, sizeof(df_image))); + if (df_image != VX_DF_IMAGE_U8) + status = VX_ERROR_INVALID_VALUE; + vxReleaseImage(&image); + } + + if (index == 3) + { + vx_scalar scalar = 0; vx_enum type = 0; vx_int32 value = 0; + STATUS_ERROR_CHECK(vxQueryParameter(param, VX_PARAMETER_ATTRIBUTE_REF, &scalar, sizeof(scalar))); + STATUS_ERROR_CHECK(vxQueryScalar(scalar, VX_SCALAR_ATTRIBUTE_TYPE, &type, sizeof(type))); + STATUS_ERROR_CHECK(vxReadScalarValue(scalar, &value)); + if (value < 0 || type != VX_TYPE_INT32) + status = VX_ERROR_INVALID_VALUE; + vxReleaseScalar(&scalar); + } + + if (index == 4) + { + vx_scalar scalar = 0; vx_enum type = 0; vx_int32 value = 0; + STATUS_ERROR_CHECK(vxQueryParameter(param, VX_PARAMETER_ATTRIBUTE_REF, &scalar, sizeof(scalar))); + STATUS_ERROR_CHECK(vxQueryScalar(scalar, VX_SCALAR_ATTRIBUTE_TYPE, &type, sizeof(type))); + STATUS_ERROR_CHECK(vxReadScalarValue(scalar, &value)); + if (value < 0 || type != VX_TYPE_INT32) + status = VX_ERROR_INVALID_VALUE; + vxReleaseScalar(&scalar); + } + if (index == 5) + { + vx_scalar scalar = 0; vx_enum type = 0; vx_int32 value = 0; + STATUS_ERROR_CHECK(vxQueryParameter(param, VX_PARAMETER_ATTRIBUTE_REF, &scalar, sizeof(scalar))); + STATUS_ERROR_CHECK(vxQueryScalar(scalar, VX_SCALAR_ATTRIBUTE_TYPE, &type, sizeof(type))); + STATUS_ERROR_CHECK(vxReadScalarValue(scalar, &value)); + if (value < 0 || type != VX_TYPE_INT32) + status = VX_ERROR_INVALID_VALUE; + vxReleaseScalar(&scalar); + } + if (index == 6) + { + vx_scalar scalar = 0; vx_enum type = 0; vx_int32 value = 0; + STATUS_ERROR_CHECK(vxQueryParameter(param, VX_PARAMETER_ATTRIBUTE_REF, &scalar, sizeof(scalar))); + STATUS_ERROR_CHECK(vxQueryScalar(scalar, VX_SCALAR_ATTRIBUTE_TYPE, &type, sizeof(type))); + STATUS_ERROR_CHECK(vxReadScalarValue(scalar, &value)); + if (value < 0 || type != VX_TYPE_INT32) + status = VX_ERROR_INVALID_VALUE; + vxReleaseScalar(&scalar); + } + if (index == 7) + { + vx_scalar scalar = 0; vx_enum type = 0; vx_int32 value = 0; + STATUS_ERROR_CHECK(vxQueryParameter(param, VX_PARAMETER_ATTRIBUTE_REF, &scalar, sizeof(scalar))); + STATUS_ERROR_CHECK(vxQueryScalar(scalar, VX_SCALAR_ATTRIBUTE_TYPE, &type, sizeof(type))); + STATUS_ERROR_CHECK(vxReadScalarValue(scalar, &value)); + if (value < 0 || type != VX_TYPE_INT32) + status = VX_ERROR_INVALID_VALUE; + vxReleaseScalar(&scalar); + } + + vxReleaseParameter(¶m); + return status; +} + +/*!*********************************************************************************************************** +output parameter validator. +*************************************************************************************************************/ +static vx_status VX_CALLBACK CV_star_feature_detector_OutputValidator(vx_node node, vx_uint32 index, vx_meta_format meta) +{ + vx_status status = VX_SUCCESS; + if (index == 1) + { + vx_parameter output_param = vxGetParameterByIndex(node, 1); + vx_array output; vx_size size = 0; + + STATUS_ERROR_CHECK(vxQueryParameter(output_param, VX_PARAMETER_ATTRIBUTE_REF, &output, sizeof(vx_array))); + STATUS_ERROR_CHECK(vxQueryArray(output, VX_ARRAY_ATTRIBUTE_CAPACITY, &size, sizeof(size))); + + if (size <= 0) + status = VX_ERROR_INVALID_VALUE; + + vxReleaseArray(&output); + vxReleaseParameter(&output_param); + } + + return status; +} + +/*!*********************************************************************************************************** +Execution Kernel +*************************************************************************************************************/ +static vx_status VX_CALLBACK CV_star_feature_detector_Kernel(vx_node node, const vx_reference *parameters, vx_uint32 num) +{ + vx_status status = VX_SUCCESS; + + vx_image image_in = (vx_image) parameters[0]; + vx_array array = (vx_array) parameters[1]; + vx_image mask = (vx_image) parameters[2]; + vx_scalar maxS = (vx_scalar) parameters[3]; + vx_scalar responseT = (vx_scalar) parameters[4]; + vx_scalar lineT = (vx_scalar) parameters[5]; + vx_scalar lineThresholdB = (vx_scalar) parameters[6]; + vx_scalar suppressN = (vx_scalar) parameters[7]; + + Mat *mat, *mask_mat, Img; + vx_uint32 width = 0; + vx_uint32 height = 0; + vector key_points; + int maxSize, responseThreshold, lineThresholdProjected, lineThresholdBinarized, suppressNonmaxSize; + vx_int32 value = 0; + + //Extracting Values from the Scalar + STATUS_ERROR_CHECK(vxReadScalarValue(maxS, &value)); maxSize = value; + STATUS_ERROR_CHECK(vxReadScalarValue(responseT, &value)); responseThreshold = value; + STATUS_ERROR_CHECK(vxReadScalarValue(lineT, &value)); lineThresholdProjected = value; + STATUS_ERROR_CHECK(vxReadScalarValue(lineThresholdB, &value)); lineThresholdBinarized = value; + STATUS_ERROR_CHECK(vxReadScalarValue(suppressN, &value)); suppressNonmaxSize = value; + + //Converting VX Image to OpenCV Mat + STATUS_ERROR_CHECK(VX_to_CV_Image(&mat, image_in)); + STATUS_ERROR_CHECK(VX_to_CV_Image(&mask_mat, mask)); + + //Compute using OpenCV + Ptr star = xfeatures2d::StarDetector::create(maxSize, responseThreshold, lineThresholdProjected, lineThresholdBinarized, suppressNonmaxSize); + star->detect(*mat, key_points, *mask_mat); + + //Converting OpenCV Keypoints to OpenVX Keypoints + STATUS_ERROR_CHECK(CV_to_VX_keypoints(key_points, array)); + + return status; +} + +/************************************************************************************************************ +Function to Register the Kernel for Publish +*************************************************************************************************************/ +vx_status CV_star_detect_Register(vx_context context) +{ + vx_status status = VX_SUCCESS; + vx_kernel Kernel = vxAddKernel(context, + "org.opencv.star_detect", + VX_KERNEL_EXT_CV_STAR_FEATURE_DETECT, + CV_star_feature_detector_Kernel, + 8, + CV_star_feature_detector_InputValidator, + CV_star_feature_detector_OutputValidator, + nullptr, + nullptr); + + if (Kernel) + { + PARAM_ERROR_CHECK(vxAddParameterToKernel(Kernel, 0, VX_INPUT, VX_TYPE_IMAGE, VX_PARAMETER_STATE_REQUIRED)); + PARAM_ERROR_CHECK(vxAddParameterToKernel(Kernel, 1, VX_BIDIRECTIONAL, VX_TYPE_ARRAY, VX_PARAMETER_STATE_REQUIRED)); + PARAM_ERROR_CHECK(vxAddParameterToKernel(Kernel, 2, VX_INPUT, VX_TYPE_IMAGE, VX_PARAMETER_STATE_REQUIRED)); + PARAM_ERROR_CHECK(vxAddParameterToKernel(Kernel, 3, VX_INPUT, VX_TYPE_SCALAR, VX_PARAMETER_STATE_REQUIRED)); + PARAM_ERROR_CHECK(vxAddParameterToKernel(Kernel, 4, VX_INPUT, VX_TYPE_SCALAR, VX_PARAMETER_STATE_REQUIRED)); + PARAM_ERROR_CHECK(vxAddParameterToKernel(Kernel, 5, VX_INPUT, VX_TYPE_SCALAR, VX_PARAMETER_STATE_REQUIRED)); + PARAM_ERROR_CHECK(vxAddParameterToKernel(Kernel, 6, VX_INPUT, VX_TYPE_SCALAR, VX_PARAMETER_STATE_REQUIRED)); + PARAM_ERROR_CHECK(vxAddParameterToKernel(Kernel, 7, VX_INPUT, VX_TYPE_SCALAR, VX_PARAMETER_STATE_REQUIRED)); + PARAM_ERROR_CHECK(vxFinalizeKernel(Kernel)); + } + + if (status != VX_SUCCESS) + { + exit: vxRemoveKernel(Kernel); return VX_FAILURE; + } + + return status; +} + +#endif diff --git a/vx_ext_cv/OpenCV_Tunnel.h b/vx_ext_cv/OpenCV_Tunnel.h new file mode 100644 index 0000000..5e70f54 --- /dev/null +++ b/vx_ext_cv/OpenCV_Tunnel.h @@ -0,0 +1,110 @@ +/* +Copyright (c) 2015 Advanced Micro Devices, Inc. All rights reserved. + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. +*/ + + +#ifndef _CV_TUNNEL_ +#define _CV_TUNNEL_ + +#include"opencv2/opencv.hpp" +#if USE_OPENCV_CONTRIB +#include"opencv2/xfeatures2d.hpp" +#endif + +#include"VX/vx.h" +#include"vx_ext_cv.h" + +#include +#include +#include +#include +#include +#include +#include + +using namespace cv; +using namespace std; + +#define STATUS_ERROR_CHECK(call){vx_status status = call; if(status!= VX_SUCCESS) return status;} +#define PARAM_ERROR_CHECK(call){vx_status status = call; if(status!= VX_SUCCESS) goto exit;} +#define MAX_KERNELS 100 + +int VX_to_CV_Image(Mat**, vx_image); +int VX_to_CV_MATRIX(Mat**, vx_matrix); + +int CV_to_VX_Pyramid(vx_pyramid, vector); +int CV_to_VX_Image(vx_image, Mat*); + +int CV_to_VX_keypoints(vector, vx_array); +int CVPoints2f_to_VX_keypoints(vector, vx_array); +int CV_DESP_to_VX_DESP(Mat, vx_array, int); + +int match_vx_image_parameters(vx_image, vx_image); + +class Kernellist +{ +public: + struct node{ public: std::function func; node* next; }; + int count; + Kernellist(int max){ top = nullptr; maxnum = max; count = 0;} + + vx_status ADD(std::function element) + { + vx_status status = VX_SUCCESS; + if (count == maxnum) return VX_ERROR_NO_RESOURCES; + else + { + node *newTop = new node; + if (top == nullptr){ newTop->func = element; newTop->next = nullptr; top = newTop; count++; } + else{ newTop->func = element; newTop->next = top; top = newTop; count++; } + } + return status; + } + + vx_status REMOVE() + { + vx_status status = VX_SUCCESS; + if (top == nullptr) return VX_ERROR_NO_RESOURCES; + else{ node * old = top; top = top->next; count--; delete(old); } + return status; + } + + vx_status PUBLISH(vx_context context) + { + vx_status status = VX_SUCCESS; + + if (top == nullptr) { vxAddLogEntry((vx_reference)context, VX_ERROR_NO_RESOURCES, "PUBLISH Fail, Kernel list is empty"); return VX_ERROR_NO_RESOURCES; } + + else + { + node * Kernel = top; + for (int i = 0; i < count; i++){ STATUS_ERROR_CHECK(Kernel->func(context)); Kernel = Kernel->next;} + } + return status; + } + +private: + node *top; int maxnum; +}; + +static Kernellist *Kernel_List; + +#endif \ No newline at end of file diff --git a/vx_ext_cv/OpenCV_VX_Functions.h b/vx_ext_cv/OpenCV_VX_Functions.h new file mode 100644 index 0000000..e41d238 --- /dev/null +++ b/vx_ext_cv/OpenCV_VX_Functions.h @@ -0,0 +1,735 @@ +/* +Copyright (c) 2015 Advanced Micro Devices, Inc. All rights reserved. + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. +*/ + + +#include"publishkernels.h" + +// a very useful macro +#ifndef dimof +#define dimof(x) (sizeof(x)/sizeof(x[0])) +#endif + +vx_node vxCreateNodeByStructure(vx_graph graph, vx_enum kernelenum, vx_reference params[], vx_uint32 num); + +#ifdef __cplusplus +extern "C" { +#endif + + /*!*********************************************************************************************************** + OpenCV VX_API_ENTRY NODE C Functions + *************************************************************************************************************/ + + /*! \brief [Graph] Creates a OpenCV blur function node. + * \param [in] graph The reference to the graph. + * \param [in] input The input image in \ref VX_DF_IMAGE_U8 or \ref VX_DF_IMAGE_S16 or \ref VX_DF_IMAGE_U16 format. + * \param [out] output The output image is as same size and type of input. + * \param [in] kwidth The input \ref VX_TYPE_UINT32 scalar to set normalized box filter width. + * \param [in] kheight The input \ref VX_TYPE_UINT32 scalar to set normalized box filter height. + * \param [in] Anchor_X The input \ref VX_TYPE_UINT32 scalar to set anchor point x. + * \param [in] Anchor_Y The input \ref VX_TYPE_UINT32 scalar to set anchor point y. + * \param [in] Border_Type The input \ref VX_TYPE_UINT32 scalar to set borderType. + * \return \ref vx_node. + * \retval vx_node A node reference. Any possible errors preventing a successful creation should be checked using \ref vxGetStatus*/ + VX_API_ENTRY vx_node VX_API_CALL vxExtCvNode_blur(vx_graph graph, vx_image input, vx_image output, vx_uint32 kwidth, vx_uint32 kheight, vx_int32 Anchor_X, vx_int32 Anchor_Y, vx_int32 Bordertype); + + /*! \brief [Graph] Creates a OpenCV boxFilter function node. + * \param [in] graph The reference to the graph. + * \param [in] input The input image in \ref VX_DF_IMAGE_U8 or \ref VX_DF_IMAGE_S16 or \ref VX_DF_IMAGE_U16 format. + * \param [out] output The output image is as same size and type of input. + * \param [in] ddepth The input \ref VX_TYPE_INT32 scalar to set output image depth. + * \param [in] kwidth The input \ref VX_TYPE_UINT32 scalar to set box filter width. + * \param [in] kheight The input \ref VX_TYPE_UINT32 scalar to set box filter height. + * \return \ref vx_node. + * \retval vx_node A node reference. Any possible errors preventing a successful creation should be checked using \ref vxGetStatus*/ + VX_API_ENTRY vx_node VX_API_CALL vxExtCvNode_boxFilter(vx_graph graph, vx_image input, vx_image output, vx_int32 ddepth, vx_uint32 kwidth, vx_uint32 kheight, vx_int32 Anchor_X, vx_int32 Anchor_Y, vx_bool Normalized, vx_int32 Bordertype); + + /*! \brief [Graph] Creates a OpenCV GaussianBlur function node. + * \param [in] graph The reference to the graph. + * \param [in] input The input image in \ref VX_DF_IMAGE_U8 or \ref VX_DF_IMAGE_S16 or \ref VX_DF_IMAGE_U16 format. + * \param [out] output The output image is as same size and type of input. + * \param [in] kwidth The input \ref VX_TYPE_UINT32 scalar to set gaussian filter width. + * \param [in] kheight The input \ref VX_TYPE_UINT32 scalar to set gaussian filter height. + * \param [in] sigmaX The input \ref VX_TYPE_FLOAT32 scalar to set gaussian filter standard deviation in x-direction. + * \param [in] sigmaY The input \ref VX_TYPE_FLOAT32 scalar to set gaussian filter standard deviation in y-direction. + * \param [in] border_mode The input \ref VX_TYPE_ENUM scalar to set border mode. + * \return \ref vx_node. + * \retval vx_node A node reference. Any possible errors preventing a successful creation should be checked using \ref vxGetStatus*/ + VX_API_ENTRY vx_node VX_API_CALL vxExtCvNode_GaussianBlur(vx_graph graph, vx_image input, vx_image output, vx_uint32 kwidth, vx_uint32 kheight, vx_float32 sigmaX, vx_float32 sigmaY, vx_int32 border_mode); + + /*! \brief [Graph] Creates a OpenCV medianBlur function node. + * \param [in] graph The reference to the graph. + * \param [in] input The input image in \ref VX_DF_IMAGE_U8 or \ref VX_DF_IMAGE_U16 format. + * \param [out] output The output image is as same size and type of input. + * \param [in] ksize The input \ref VX_TYPE_UINT32 scalar to set the aperture linear size. + * \return \ref vx_node. + * \retval vx_node A node reference. Any possible errors preventing a successful creation should be checked using \ref vxGetStatus*/ + VX_API_ENTRY vx_node VX_API_CALL vxExtCvNode_medianBlur(vx_graph graph, vx_image input, vx_image output, vx_uint32 ksize); + + /*! \brief [Graph] Creates a OpenCV filter2D function node. + * \param [in] graph The reference to the graph. + * \param [in] input The input image in \ref VX_DF_IMAGE_U8 format. + * \param [out] output The output image is as same size and type of input. + * \param [in] ddepth The input \ref VX_TYPE_INT32 scalar to set ddepth. + * \param [in] Kernel The input \ref vx_matrix scalar to set Kernel. + * \param [in] Anchor_X The input \ref VX_TYPE_INT32 scalar to set Anchor_X. + * \param [in] Anchor_Y The input \ref VX_TYPE_INT32 scalar to set Anchor_Y. + * \param [in] delta The input \ref VX_TYPE_FLOAT32 scalar to set delta. + * \param [in] border The input \ref VX_TYPE_INT32 scalar to set border. + * \return \ref vx_node. + * \retval vx_node A node reference. Any possible errors preventing a successful creation should be checked using \ref vxGetStatus*/ + VX_API_ENTRY vx_node VX_API_CALL vxExtCvNode_filter2D(vx_graph graph, vx_image input, vx_image output, vx_int32 ddepth, vx_matrix Kernel, vx_int32 Anchor_X, vx_int32 Anchor_Y, vx_float32 delta, vx_int32 border); + + /*! \brief [Graph] Creates a OpenCV sepFilter2D function node. + * \param [in] graph The reference to the graph. + * \param [in] input The input image in \ref VX_DF_IMAGE_U8 format. + * \param [out] output The output image is as same size and type of input. + * \param [in] ddepth The input \ref VX_TYPE_INT32 scalar to set ddepth. + * \param [in] KernelX The input \ref vx_matrix matrix to set KernelX. + * \param [in] KernelY The input \ref vx_matrix matrix to set KernelY. + * \param [in] Anchor_X The input \ref VX_TYPE_INT32 scalar to set Anchor_X. + * \param [in] Anchor_Y The input \ref VX_TYPE_INT32 scalar to set Anchor_Y. + * \param [in] delta The input \ref VX_TYPE_FLOAT32 scalar to set delta. + * \param [in] border The input \ref VX_TYPE_INT32 scalar to set border. + * \return \ref vx_node. + * \retval vx_node A node reference. Any possible errors preventing a successful creation should be checked using \ref vxGetStatus*/ + VX_API_ENTRY vx_node VX_API_CALL vxExtCvNode_sepFilter2D(vx_graph graph, vx_image input, vx_image output, vx_int32 ddepth, vx_matrix KernelX, vx_matrix KernelY, vx_int32 Anchor_X, vx_int32 Anchor_Y, vx_float32 delta, vx_int32 border); + + /*! \brief [Graph] Creates a OpenCV BilateralFilter function node. + * \param [in] graph The reference to the graph. + * \param [in] input The input image in \ref VX_DF_IMAGE_U8 format. + * \param [out] output The output image is as same size and type of input. + * \param [in] kwidth The input \ref VX_TYPE_UINT32 scalar to set K width. + * \param [in] kheight The input \ref VX_TYPE_UINT32 scalar to set K height. + * \param [in] sigmaX The input \ref VX_TYPE_FLOAT32 scalar to set sigmaX. + * \param [in] sigmaY The input \ref VX_TYPE_FLOAT32 scalar to set sigmaY. + * \param [in] Border mode The input \ref VX_TYPE_UINT32 scalar to set border mode. + * \return \ref vx_node. + * \retval vx_node A node reference. Any possible errors preventing a successful creation should be checked using \ref vxGetStatus*/ + VX_API_ENTRY vx_node VX_API_CALL vxExtCvNode_bilateralFilter(vx_graph graph, vx_image input, vx_image output, vx_uint32 kwidth, vx_uint32 kheight, vx_float32 sigmaX, vx_float32 sigmaY, vx_int32 border_mode); + + /*! \brief [Graph] Creates a OpenCV BRISK compute node to detect keypoints and optionally compute descriptors. + * \param [in] graph The reference to the graph. + * \param [in] input The input image in \ref VX_DF_IMAGE_U8 format. + * \param [in] mask The mask image in \ref VX_DF_IMAGE_U8 format (optional). + * \param [out] output_kp The output keypoints \ref vx_array of \ref VX_TYPE_KEYPOINT. + * \param [out] output_des The output descriptors \ref vx_array of user defined data type with 64/128 byte element size depending upon extended argument (optional). + * \param [in] thresh The input \ref VX_TYPE_INT32 scalar for thresh argument. + * \param [in] octaves The input \ref VX_TYPE_INT32 scalar for octaves argument. + * \param [in] patternScale The input \ref VX_TYPE_FLOAT32 scalar for patternScale argument. + * \return \ref vx_node. + * \retval vx_node A node reference. Any possible errors preventing a successful creation should be checked using \ref vxGetStatus*/ + VX_API_ENTRY vx_node VX_API_CALL vxExtCvNode_BRISKcompute(vx_graph graph, vx_image input, vx_image mask, vx_array output_kp, vx_array output_des, vx_int32 thresh, vx_int32 octaves, vx_float32 patternScale); + + /*! \brief [Graph] Creates a OpenCV BRISK detector node to detect keypoints and optionally compute descriptors. + * \param [in] graph The reference to the graph. + * \param [in] input The input image in \ref VX_DF_IMAGE_U8 format. + * \param [in] mask The mask image in \ref VX_DF_IMAGE_U8 format (optional). + * \param [out] output_kp The output keypoints \ref vx_array of \ref VX_TYPE_KEYPOINT. + * \param [in] thresh The input \ref VX_TYPE_INT32 scalar for thresh argument. + * \param [in] octaves The input \ref VX_TYPE_INT32 scalar for octaves argument. + * \param [in] patternScale The input \ref VX_TYPE_FLOAT32 scalar for patternScale argument. + * \return \ref vx_node. + * \retval vx_node A node reference. Any possible errors preventing a successful creation should be checked using \ref vxGetStatus*/ + VX_API_ENTRY vx_node VX_API_CALL vxExtCvNode_BRISKdetect(vx_graph graph, vx_image input, vx_image mask, vx_array output_kp, vx_int32 thresh, vx_int32 octaves, vx_float32 patternScale); + + /*! \brief [Graph] Creates a OpenCV FAST feature detector node. + * \param [in] graph The reference to the graph. + * \param [in] input The input image in \ref VX_DF_IMAGE_U8 format. + * \param [out] output_kp The output keypoints \ref vx_array of \ref VX_TYPE_KEYPOINT. + * \param [in] threshold The input \ref VX_TYPE_INT32 scalar for threshold argument. + * \param [in] nonmaxSuppression The input \ref VX_TYPE_BOOL scalar for nonmaxSuppression argument. + * \return \ref vx_node. + * \retval vx_node A node reference. Any possible errors preventing a successful creation should be checked using \ref vxGetStatus*/ + VX_API_ENTRY vx_node VX_API_CALL vxExtCvNode_FAST(vx_graph graph, vx_image input, vx_array output_kp, vx_int32 threshold, vx_bool nonmaxSuppression); + + /*! \brief [Graph] Creates a OpenCV GoodFeaturesToTrack detector node. + * \param [in] graph The reference to the graph. + * \param [in] input The input image in \ref VX_DF_IMAGE_U8 format. + * \param [out] output_kp The output keypoints \ref vx_array of \ref VX_TYPE_KEYPOINT. + * \param [in] maxCorners The input \ref VX_TYPE_INT32 scalar for maxCorners argument. + * \param [in] qualityLevel The input \ref VX_TYPE_FLOAT32 scalar for qualityLevel argument. + * \param [in] minDistance The input \ref VX_TYPE_FLOAT32 scalar for minDistance argument. + * \param [in] mask The mask image in \ref VX_DF_IMAGE_U8 format (optional). + * \param [in] blockSize The input \ref VX_TYPE_INT32 scalar for blockSize argument. + * \param [in] useHarrisDetector The input \ref VX_TYPE_BOOL scalar for useHarrisDetector argument. + * \param [in] k The input \ref VX_TYPE_FLOAT32 scalar for k argument. + * \return \ref vx_node. + * \retval vx_node A node reference. Any possible errors preventing a successful creation should be checked using \ref vxGetStatus*/ + VX_API_ENTRY vx_node VX_API_CALL vxExtCvNode_goodFeaturesToTrack(vx_graph graph, vx_image input, vx_array output_kp, vx_int32 maxCorners, vx_float32 qualityLevel, vx_float32 minDistance, vx_image mask, vx_int32 blockSize, vx_bool useHarrisDetector, vx_float32 k); + + /*! \brief [Graph] Creates a OpenCV MSER feature detector node. + * \param [in] graph The reference to the graph. + * \param [in] input The input image in \ref VX_DF_IMAGE_U8 or \ref VX_DF_IMAGE_RGB format. + * \param [out] output_kp The output keypoints \ref vx_array of \ref VX_TYPE_KEYPOINT. + * \param [in] mask The mask image in \ref VX_DF_IMAGE_U8 format (optional). + * \param [in] delta The input \ref VX_TYPE_INT32 scalar for delta argument. + * \param [in] min_area The input \ref VX_TYPE_INT32 scalar for min_area argument. + * \param [in] max_area The input \ref VX_TYPE_INT32 scalar for max_area argument. + * \param [in] max_variation The input \ref VX_TYPE_FLOAT32 scalar for max_variation argument. + * \param [in] min_diversity The input \ref VX_TYPE_FLOAT32 scalar for min_diversity argument. + * \param [in] max_evolution The input \ref VX_TYPE_INT32 scalar for max_evolution argument. + * \param [in] area_threshold The input \ref VX_TYPE_FLOAT32 scalar for area_threshold argument. + * \param [in] min_margin The input \ref VX_TYPE_FLOAT32 scalar for min_margin argument. + * \param [in] edge_blur_size The input \ref VX_TYPE_INT32 scalar for max_area argument. + * \return \ref vx_node. + * \retval vx_node A node reference. Any possible errors preventing a successful creation should be checked using \ref vxGetStatus*/ + VX_API_ENTRY vx_node VX_API_CALL vxExtCvNode_MSERdetect(vx_graph graph, vx_image input, vx_array output_kp, vx_image mask, vx_int32 delta, vx_int32 min_area, vx_int32 max_area, vx_float32 max_variation, vx_float32 min_diversity, vx_int32 max_evolution, vx_float32 area_threshold, vx_float32 min_margin, vx_int32 edge_blur_size); + + /*! \brief [Graph] Creates a OpenCV ORB Compute node to detect keypoints and optionally compute descriptors. + * \param [in] graph The reference to the graph. + * \param [in] input The input image in \ref VX_DF_IMAGE_U8 format. + * \param [in] input_kp The output keypoints \ref vx_array of \ref VX_TYPE_KEYPOINT. + * \param [out] output_des The output descriptors \ref vx_array of user defined data type with 64/128 byte element size depending upon extended argument. + * \param [in] scaleFactor The input \ref VX_TYPE_FLOAT32 scalar for scaleFactor argument. + * \param [in] nlevels The input \ref VX_TYPE_INT32 scalar for nlevels argument. + * \param [in] edgeThreshold The input \ref VX_TYPE_INT32 scalar for edgeThreshold argument. + * \param [in] firstLevel The input \ref VX_TYPE_INT32 scalar for firstLevel argument. + * \param [in] WTA_K The input \ref VX_TYPE_INT32 scalar for WTA_K argument. + * \param [in] patchSize The input \ref VX_TYPE_INT32 scalar for patchSize argument. + * \return \ref vx_node. + * \retval vx_node A node reference. Any possible errors preventing a successful creation should be checked using \ref vxGetStatus*/ + VX_API_ENTRY vx_node VX_API_CALL vxExtCvNode_ORBcompute(vx_graph graph, vx_image input, vx_image mask, vx_array output_kp, vx_array output_des, vx_int32 nfeatures, vx_float32 scaleFactor, vx_int32 nlevels, vx_int32 edgeThreshold, vx_int32 firstLevel, vx_int32 WTA_K, vx_int32 scoreType, vx_int32 patchSize); + + /*! \brief [Graph] Creates a OpenCV ORB detector node to detect keypoints and optionally compute descriptors. + * \param [in] graph The reference to the graph. + * \param [in] input The input image in \ref VX_DF_IMAGE_U8 format. + * \param [in] mask The mask image in \ref VX_DF_IMAGE_U8 format (optional). + * \param [out] output_kp The output keypoints \ref vx_array of \ref VX_TYPE_KEYPOINT. + * \param [out] output_des The output descriptors \ref vx_array of user defined data type with 64/128 byte element size depending upon extended argument (optional). + * \param [in] nfeatures The input \ref VX_TYPE_INT32 scalar for nfeatures argument. + * \param [in] scaleFactor The input \ref VX_TYPE_FLOAT32 scalar for scaleFactor argument. + * \param [in] nlevels The input \ref VX_TYPE_INT32 scalar for nlevels argument. + * \param [in] edgeThreshold The input \ref VX_TYPE_INT32 scalar for edgeThreshold argument. + * \param [in] firstLevel The input \ref VX_TYPE_INT32 scalar for firstLevel argument. + * \param [in] WTA_K The input \ref VX_TYPE_INT32 scalar for WTA_K argument. + * \param [in] scoreType The input \ref VX_TYPE_INT32 scalar for scoreType argument. + * \param [in] patchSize The input \ref VX_TYPE_INT32 scalar for patchSize argument. + * \return \ref vx_node. + * \retval vx_node A node reference. Any possible errors preventing a successful creation should be checked using \ref vxGetStatus*/ + VX_API_ENTRY vx_node VX_API_CALL vxExtCvNode_ORBdetect(vx_graph graph, vx_image input, vx_image mask, vx_array output_kp, vx_int32 nfeatures, vx_float32 scaleFactor, vx_int32 nlevels, vx_int32 edgeThreshold, vx_int32 firstLevel, vx_int32 WTA_K, vx_int32 scoreType, vx_int32 patchSize); + + /*! \brief [Graph] Creates a OpenCV SIFT Compute node to compute descriptor from specified keypoints. + * \param [in] graph The reference to the graph. + * \param [in] input The input image in \ref VX_DF_IMAGE_U8 format. + * \param [in] input_kp The input keypoints \ref vx_array of \ref VX_TYPE_KEYPOINT. + * \param [out] output_des The output descriptors \ref vx_array of user defined data type with 128 byte element size. + * \param [in] nOctaveLayers The input \ref VX_TYPE_INT32 scalar for nOctaveLayers argument. + * \param [in] sigma The input \ref VX_TYPE_FLOAT32 scalar for sigma argument. + * \return \ref vx_node. + * \retval vx_node A node reference. Any possible errors preventing a successful creation should be checked using \ref vxGetStatus*/ + VX_API_ENTRY vx_node VX_API_CALL vxExtCvNode_SIFTcompute(vx_graph graph, vx_image input, vx_image mask, vx_array output_kp, vx_array output_des, vx_int32 nfeatures, vx_int32 nOctaveLayers, vx_float32 contrastThreshold, vx_float32 edgeThreshold, vx_float32 sigma); + + /*! \brief [Graph] Creates a OpenCV SIFT detector node to detect keypoints and optionally compute descriptors. + * \param [in] graph The reference to the graph. + * \param [in] input The input image in \ref VX_DF_IMAGE_U8 format. + * \param [in] mask The mask image in \ref VX_DF_IMAGE_U8 format (optional). + * \param [out] output_kp The output keypoints \ref vx_array of \ref VX_TYPE_KEYPOINT. + * \param [out] output_des The output descriptors \ref vx_array of user defined data type with 128 byte element size (optional). + * \param [in] nfeatures The input \ref VX_TYPE_INT32 scalar for nfeatures argument. Set this to capacity of output_kp to retain best keypoints. + * \param [in] nOctaveLayers The input \ref VX_TYPE_INT32 scalar for nOctaveLayers argument. + * \param [in] contrastThreshold The input \ref VX_TYPE_FLOAT32 scalar for contrastThreshold argument. + * \param [in] edgeThreshold The input \ref VX_TYPE_FLOAT32 scalar for edgeThreshold argument. + * \param [in] sigma The input \ref VX_TYPE_FLOAT32 scalar for sigma argument. + * \return \ref vx_node. + * \retval vx_node A node reference. Any possible errors preventing a successful creation should be checked using \ref vxGetStatus*/ + VX_API_ENTRY vx_node VX_API_CALL vxExtCvNode_SIFTdetect(vx_graph graph, vx_image input, vx_image mask, vx_array output_kp, vx_int32 nfeatures, vx_int32 nOctaveLayers, vx_float32 contrastThreshold, vx_float32 edgeThreshold, vx_float32 sigma); + + /*! \brief [Graph] Creates a OpenCV Simple Blob detector node. + * \param [in] graph The reference to the graph. + * \param [in] input The input image in \ref VX_DF_IMAGE_U8 or \ref VX_DF_IMAGE_RGB format. + * \param [out] output_kp The output keypoints \ref vx_array of \ref VX_TYPE_KEYPOINT. + * \param [in] mask The mask image in \ref VX_DF_IMAGE_U8 format (optional). + * \return \ref vx_node. + * \retval vx_node A node reference. Any possible errors preventing a successful creation should be checked using \ref vxGetStatus*/ + VX_API_ENTRY vx_node VX_API_CALL vxExtCvNode_SimpleBlobDetector(vx_graph graph, vx_image input, vx_array output_kp, vx_image mask); + + /*! \brief [Graph] Creates a OpenCV Star feature detector node. + * \param [in] graph The reference to the graph. + * \param [in] input The input image in \ref VX_DF_IMAGE_U8 or \ref VX_DF_IMAGE_RGB format. + * \param [out] output_kp The output keypoints \ref vx_array of \ref VX_TYPE_KEYPOINT. + * \param [in] mask The mask image in \ref VX_DF_IMAGE_U8 format (optional). + * \param [in] maxSize The input \ref VX_TYPE_INT32 scalar for maxSize argument. + * \param [in] responseThreshold The input \ref VX_TYPE_INT32 scalar for responseThreshold argument. + * \param [in] lineThresholdProjected The input \ref VX_TYPE_INT32 scalar for lineThresholdProjected argument. + * \param [in] lineThresholdBinarized The input \ref VX_TYPE_INT32 scalar for lineThresholdBinarized argument. + * \param [in] suppressNonmaxSize The input \ref VX_TYPE_INT32 scalar for suppressNonmaxSize argument. + * \return \ref vx_node. + * \retval vx_node A node reference. Any possible errors preventing a successful creation should be checked using \ref vxGetStatus*/ + VX_API_ENTRY vx_node VX_API_CALL vxExtCvNode_StarFeatureDetector(vx_graph graph, vx_image input, vx_array output_kp, vx_image mask, vx_int32 maxSize, vx_int32 responseThreshold, vx_int32 lineThresholdProjected, vx_int32 lineThresholdBinarized, vx_int32 suppressNonmaxSize); + + /*! \brief [Graph] Creates a OpenCV SURF Compute node to compute descriptor from specified keypoints. + * \param [in] graph The reference to the graph. + * \param [in] input The input image in \ref VX_DF_IMAGE_U8 format. + * \param [in] input_kp The input keypoints \ref vx_array of \ref VX_TYPE_KEYPOINT. + * \param [out] output_des The output descriptors \ref vx_array of user defined data type with 64/128 byte element size depending upon extended argument. + * \param [in] extended The input \ref VX_TYPE_BOOL scalar for extended argument. + * \param [in] upright The input \ref VX_TYPE_BOOL scalar for upright argument. + * \return \ref vx_node. + * \retval vx_node A node reference. Any possible errors preventing a successful creation should be checked using \ref vxGetStatus*/ + VX_API_ENTRY vx_node VX_API_CALL vxExtCvNode_SURFcompute(vx_graph graph, vx_image input, vx_image mask, vx_array output_kp, vx_array output_des, vx_float32 hessianThreshold, vx_int32 nOctaves, vx_int32 nOctaveLayers, vx_bool extended, vx_bool upright); + + /*! \brief [Graph] Creates a OpenCV SURF detector node to detect keypoints and optionally compute descriptors. + * \param [in] graph The reference to the graph. + * \param [in] input The input image in \ref VX_DF_IMAGE_U8 format. + * \param [in] mask The mask image in \ref VX_DF_IMAGE_U8 format (optional). + * \param [out] output_kp The output keypoints \ref vx_array of \ref VX_TYPE_KEYPOINT. + * \param [out] output_des The output descriptors \ref vx_array of user defined data type with 64/128 byte element size depending upon extended argument (optional). + * \param [in] hessianThreshold The input \ref VX_TYPE_FLOAT32 scalar for hessianThreshold argument. + * \param [in] nOctaves The input \ref VX_TYPE_INT32 scalar for nOctaves argument. + * \param [in] nOctaveLayers The input \ref VX_TYPE_INT32 scalar for nOctaveLayers argument. + * \param [in] extended The input \ref VX_TYPE_BOOL scalar for extended argument. + * \param [in] upright The input \ref VX_TYPE_BOOL scalar for upright argument. + * \return \ref vx_node. + * \retval vx_node A node reference. Any possible errors preventing a successful creation should be checked using \ref vxGetStatus*/ + VX_API_ENTRY vx_node VX_API_CALL vxExtCvNode_SURFdetect(vx_graph graph, vx_image input, vx_image mask, vx_array output_kp, vx_array output_des, vx_float32 hessianThreshold, vx_int32 nOctaves, vx_int32 nOctaveLayers); + + /*! \brief [Graph] Creates a OpenCV Flip function node. + * \param [in] graph The reference to the graph. + * \param [in] input The input image in \ref VX_DF_IMAGE_U8 or \ref VX_DF_IMAGE_S16 format. + * \param [out] output The output image is as same size and type of input. + * \param [in] FlipCode The input \ref VX_TYPE_INT32 scalar to set FlipCode. + * \return \ref vx_node. + * \retval vx_node A node reference. Any possible errors preventing a successful creation should be checked using \ref vxGetStatus*/ + VX_API_ENTRY vx_node VX_API_CALL vxExtCvNode_flip(vx_graph graph, vx_image input, vx_image output, vx_int32 FlipCode); + + /*! \brief [Graph] Creates a OpenCV transpose function node. + * \param [in] graph The reference to the graph. + * \param [in] input The input image in \ref VX_DF_IMAGE_U8 or \ref VX_DF_IMAGE_S16 or \ref VX_DF_IMAGE_U16 format. + * \param [out] output The output image is as same size and type of input. + * \return \ref vx_node. + * \retval vx_node A node reference. Any possible errors preventing a successful creation should be checked using \ref vxGetStatus*/ + VX_API_ENTRY vx_node VX_API_CALL vxExtCvNode_transpose(vx_graph graph, vx_image input, vx_image output); + + /*! \brief [Graph] Creates a OpenCV integral function node. + * \param [in] graph The reference to the graph. + * \param [in] input The input image in \ref VX_DF_IMAGE_U8 format. + * \param [out] output The output image in \ref VX_DF_IMAGE_U32 or \ref VX_DF_IMAGE_S32 format. + * \param [in] sdepth The input \ref VX_TYPE_INT32 scalar to set sdepth. + * \return \ref vx_node. + * \retval vx_node A node reference. Any possible errors preventing a successful creation should be checked using \ref vxGetStatus*/ + VX_API_ENTRY vx_node VX_API_CALL vxExtCvNode_integral(vx_graph graph, vx_image input, vx_image output, vx_int32 sdepth); + + /*! \brief [Graph] Creates a OpenCV norm function node. + * \param [in] graph The reference to the graph. + * \param [in] input The input image in \ref VX_DF_IMAGE_U8 format. + * \param [out] norm_value The output \ref VX_TYPE_FLOAT32 scalar norm_value. + * \param [in] sdepth The input \ref VX_TYPE_INT32 scalar to set sdepth. + * \return \ref vx_node. + * \retval vx_node A node reference. Any possible errors preventing a successful creation should be checked using \ref vxGetStatus*/ + VX_API_ENTRY vx_node VX_API_CALL vxExtCvNode_norm(vx_graph graph, vx_image input, vx_float32 norm_value, vx_int32 norm_type); + + /*! \brief [Graph] Creates a OpenCV countNonZero function node. + * \param [in] graph The reference to the graph. + * \param [in] input The input image in \ref VX_DF_IMAGE_U8 format. + * \param [out] non_zero The output \ref VX_TYPE_INT32 scalar non_zero. + * \return \ref vx_node. + * \retval vx_node A node reference. Any possible errors preventing a successful creation should be checked using \ref vxGetStatus*/ + VX_API_ENTRY vx_node VX_API_CALL vxExtCvNode_countNonZero(vx_graph graph, vx_image input, vx_int32 non_zero); + + /*! \brief [Graph] Creates a OpenCV Multiply function node. + * \param [in] graph The reference to the graph. + * \param [in] input_1 The input image in \ref VX_DF_IMAGE_U8 or \ref VX_DF_IMAGE_S16 format. + * \param [in] input_2 The input image in \ref VX_DF_IMAGE_U8 or \ref VX_DF_IMAGE_S16 format. + * \param [out] output The output image is as same size and type of input. + * \param [in] scale The input \ref VX_TYPE_FLOAT32 scalar to set scale. + * \param [in] dtype The input \ref VX_TYPE_INT32 scalar to set dtype. + * \return \ref vx_node. + * \retval vx_node A node reference. Any possible errors preventing a successful creation should be checked using \ref vxGetStatus*/ + VX_API_ENTRY vx_node VX_API_CALL vxExtCvNode_multiply(vx_graph graph, vx_image input_1, vx_image input_2, vx_image output, vx_float32 scale, vx_int32 dtype); + + /*! \brief [Graph] Creates a OpenCV Divide function node. + * \param [in] graph The reference to the graph. + * \param [in] input_1 The input image in \ref VX_DF_IMAGE_U8 or \ref VX_DF_IMAGE_S16 format. + * \param [in] input_2 The input image in \ref VX_DF_IMAGE_U8 or \ref VX_DF_IMAGE_S16 format. + * \param [out] output The output image is as same size and type of input. + * \param [in] scale The input \ref VX_TYPE_FLOAT32 scalar to set scale. + * \param [in] dtype The input \ref VX_TYPE_INT32 scalar to set dtype. + * \return \ref vx_node. + * \retval vx_node A node reference. Any possible errors preventing a successful creation should be checked using \ref vxGetStatus*/ + VX_API_ENTRY vx_node VX_API_CALL vxExtCvNode_divide(vx_graph graph, vx_image input_1, vx_image input_2, vx_image output, vx_float32 scale, vx_int32 dtype); + + /*! \brief [Graph] Creates a OpenCV ADD function node. + * \param [in] graph The reference to the graph. + * \param [in] input_1 The input image in \ref VX_DF_IMAGE_U8 or \ref VX_DF_IMAGE_S16 format. + * \param [in] input_2 The input image in \ref VX_DF_IMAGE_U8 or \ref VX_DF_IMAGE_S16 format. + * \param [out] output The output image is as same size and type of input. + * \return \ref vx_node. + * \retval vx_node A node reference. Any possible errors preventing a successful creation should be checked using \ref vxGetStatus*/ + VX_API_ENTRY vx_node VX_API_CALL vxExtCvNode_add(vx_graph graph, vx_image input_1, vx_image input_2, vx_image output); + + /*! \brief [Graph] Creates a OpenCV Subtract function node. + * \param [in] graph The reference to the graph. + * \param [in] input_1 The input image in \ref VX_DF_IMAGE_U8 or \ref VX_DF_IMAGE_S16 format. + * \param [in] input_2 The input image in \ref VX_DF_IMAGE_U8 or \ref VX_DF_IMAGE_S16 format. + * \param [out] output The output image is as same size and type of input. + * \return \ref vx_node. + * \retval vx_node A node reference. Any possible errors preventing a successful creation should be checked using \ref vxGetStatus*/ + VX_API_ENTRY vx_node VX_API_CALL vxExtCvNode_subtract(vx_graph graph, vx_image input_1, vx_image input_2, vx_image output); + + /*! \brief [Graph] Creates a OpenCV absdiff function node. + * \param [in] graph The reference to the graph. + * \param [in] input_1 The input image in \ref VX_DF_IMAGE_U8 or \ref VX_DF_IMAGE_S16 format. + * \param [in] input_2 The input image in \ref VX_DF_IMAGE_U8 or \ref VX_DF_IMAGE_S16 format. + * \param [out] output The output image is as same size and type of input. + * \return \ref vx_node. + * \retval vx_node A node reference. Any possible errors preventing a successful creation should be checked using \ref vxGetStatus*/ + VX_API_ENTRY vx_node VX_API_CALL vxExtCvNode_absdiff(vx_graph graph, vx_image input_1, vx_image input_2, vx_image output); + + /*! \brief [Graph] Creates a OpenCV addWeighted function node. + * \param [in] graph The reference to the graph. + * \param [in] input_1 The input image in \ref VX_DF_IMAGE_U8 or \ref VX_DF_IMAGE_S16 format. + * \param [in] aplha The input \ref VX_TYPE_FLOAT32 scalar to set aplha. + * \param [in] input_2 The input image in \ref VX_DF_IMAGE_U8 or \ref VX_DF_IMAGE_S16 format. + * \param [in] beta The input \ref VX_TYPE_FLOAT32 scalar to set beta. + * \param [in] gamma The input \ref VX_TYPE_FLOAT32 scalar to set gamma. + * \param [out] output The output image is as same size and type of input. + * \param [in] dtype The input \ref VX_TYPE_INT32 scalar to set dtype. + * \return \ref vx_node. + * \retval vx_node A node reference. Any possible errors preventing a successful creation should be checked using \ref vxGetStatus*/ + VX_API_ENTRY vx_node VX_API_CALL vxExtCvNode_addWeighted(vx_graph graph, vx_image imput_1, vx_float32 aplha, vx_image input_2, vx_float32 beta, vx_float32 gamma, vx_image output, vx_int32 dtype); + + /*! \brief [Graph] Creates a OpenCV adaptiveThreshold function node. + * \param [in] graph The reference to the graph. + * \param [in] input The input image in \ref VX_DF_IMAGE_U8 format. + * \param [out] output The output image is as same size and type of input. + * \param [in] maxValue The input \ref VX_TYPE_FLOAT32 scalar to set maxValue. + * \param [in] adaptiveMethod The input \ref VX_TYPE_INT32 scalar to set adaptiveMethod. + * \param [in] thresholdType The input \ref VX_TYPE_INT32 scalar to set thresholdType. + * \param [in] blockSize The input \ref VX_TYPE_INT32 scalar to set blockSize. + * \param [in] c The input \ref VX_TYPE_FLOAT32 scalar to set c. + * \return \ref vx_node. + * \retval vx_node A node reference. Any possible errors preventing a successful creation should be checked using \ref vxGetStatus*/ + VX_API_ENTRY vx_node VX_API_CALL vxExtCvNode_adaptiveThreshold(vx_graph graph, vx_image input, vx_image output, vx_float32 maxValue, vx_int32 adaptiveMethod, vx_int32 thresholdType, vx_int32 blockSize, vx_float32 c); + + /*! \brief [Graph] Creates a OpenCV threshold function node. + * \param [in] graph The reference to the graph. + * \param [in] input The input image in \ref VX_DF_IMAGE_U8 format. + * \param [out] output The output image is as same size and type of input. + * \param [in] thresh The input \ref VX_TYPE_FLOAT32 scalar to set thresh. + * \param [in] maxVal The input \ref VX_TYPE_FLOAT32 scalar to set maxVal. + * \param [in] type The input \ref VX_TYPE_UINT32 scalar to set type. + * \return \ref vx_node. + * \retval vx_node A node reference. Any possible errors preventing a successful creation should be checked using \ref vxGetStatus*/ + VX_API_ENTRY vx_node VX_API_CALL vxExtCvNode_threshold(vx_graph graph, vx_image input, vx_image output, vx_float32 thresh, vx_float32 maxVal, vx_int32 type); + + /*! \brief [Graph] Creates a OpenCV distanceTransform function node. + * \param [in] graph The reference to the graph. + * \param [in] input The input image in \ref VX_DF_IMAGE_U8 format. + * \param [out] output The output image is as same size and type of input. + * \return \ref vx_node. + * \retval vx_node A node reference. Any possible errors preventing a successful creation should be checked using \ref vxGetStatus*/ + VX_API_ENTRY vx_node VX_API_CALL vxExtCvNode_distanceTransform(vx_graph graph, vx_image input, vx_image output); + + /*! \brief [Graph] Creates a OpenCV cvtColor function node. + * \param [in] graph The reference to the graph. + * \param [in] input The input image in \ref VX_DF_IMAGE_U8 or \ref VX_DF_IMAGE_S16 format. + * \param [out] output The output image is as same size and type of input. + * \param [in] CODE The input \ref VX_TYPE_UINT32 scalar to set FlipCode. + * \return \ref vx_node. + * \retval vx_node A node reference. Any possible errors preventing a successful creation should be checked using \ref vxGetStatus*/ + VX_API_ENTRY vx_node VX_API_CALL vxExtCvNode_cvtColor(vx_graph graph, vx_image input, vx_image output, vx_uint32 CODE); + + /*! \brief [Graph] Creates a OpenCV fastNlMeansDenoising function node. + * \param [in] graph The reference to the graph. + * \param [in] input The input image in \ref VX_DF_IMAGE_U8 format. + * \param [out] output The output image is as same size and type of input. + * \param [in] h The input \ref VX_TYPE_FLOAT32 scalar to set h. + * \param [in] template_ws The input \ref VX_TYPE_INT32 scalar to set template_ws. + * \param [in] search_ws The input \ref VX_TYPE_UINT32 scalar to set search_ws. + * \return \ref vx_node. + * \retval vx_node A node reference. Any possible errors preventing a successful creation should be checked using \ref vxGetStatus*/ + VX_API_ENTRY vx_node VX_API_CALL vxExtCvNode_fastNlMeansDenoising(vx_graph graph, vx_image input, vx_image output, vx_float32 h, vx_int32 template_ws, vx_int32 search_ws); + + /*! \brief [Graph] Creates a OpenCV fastNlMeansDenoisingColored function node. + * \param [in] graph The reference to the graph. + * \param [in] input The input image in \ref VX_DF_IMAGE_RGB format. + * \param [out] output The output image is as same size and type of input. + * \param [in] h The input \ref VX_TYPE_FLOAT32 scalar to set h. + * \param [in] h_color The input \ref VX_TYPE_FLOAT32 scalar to set h_color. + * \param [in] template_ws The input \ref VX_TYPE_INT32 scalar to set template_ws. + * \param [in] search_ws The input \ref VX_TYPE_UINT32 scalar to set search_ws. + * \return \ref vx_node. + * \retval vx_node A node reference. Any possible errors preventing a successful creation should be checked using \ref vxGetStatus*/ + VX_API_ENTRY vx_node VX_API_CALL vxExtCvNode_fastNlMeansDenoisingColored(vx_graph graph, vx_image input, vx_image output, vx_float32 h, vx_float32 h_color, vx_int32 template_ws, vx_int32 search_ws); + + /*! \brief [Graph] Creates a OpenCV Resize function node. + * \param [in] graph The reference to the graph. + * \param [in] input The input image in \ref VX_DF_IMAGE_U8 format. + * \param [out] output The output image is as same size and type of input. + * \param [in] Size_X The input \ref VX_TYPE_INT32 scalar to set Size_X. + * \param [in] Size_Y The input \ref VX_TYPE_INT32 scalar to set Size_Y. + * \param [in] FX The input \ref VX_TYPE_FLOAT32 scalar to set FX. + * \param [in] FY The input \ref VX_TYPE_FLOAT32 scalar to set FY. + * \param [in] interpolation The input \ref VX_TYPE_INT32 scalar to set interpolation. + * \return \ref vx_node. + * \retval vx_node A node reference. Any possible errors preventing a successful creation should be checked using \ref vxGetStatus*/ + VX_API_ENTRY vx_node VX_API_CALL vxExtCvNode_Resize(vx_graph graph, vx_image input, vx_image output, vx_int32 Size_X, vx_int32 Size_Y, vx_float32 FX, vx_float32 FY, vx_int32 interpolation); + + /*! \brief [Graph] Creates a OpenCV pyrup function node. + * \param [in] graph The reference to the graph. + * \param [in] input The input image in \ref VX_DF_IMAGE_U8 format. + * \param [out] output The output image is as same size and type of input. + * \param [in] Swidth The input \ref VX_TYPE_UINT32 scalar to set Swidth. + * \param [in] Sheight The input \ref VX_TYPE_UINT32 scalar to set Sheight. + * \param [in] bordertype The input \ref VX_TYPE_INT32 scalar to set bordertype. + * \return \ref vx_node. + * \retval vx_node A node reference. Any possible errors preventing a successful creation should be checked using \ref vxGetStatus*/ + VX_API_ENTRY vx_node VX_API_CALL vxExtCvNode_pyrup(vx_graph graph, vx_image input, vx_image output, vx_uint32 Swidth, vx_uint32 Sheight, vx_int32 bordertype); + + /*! \brief [Graph] Creates a OpenCV pyrdown function node. + * \param [in] graph The reference to the graph. + * \param [in] input The input image in \ref VX_DF_IMAGE_U8 format. + * \param [out] output The output image is as same size and type of input. + * \param [in] Swidth The input \ref VX_TYPE_UINT32 scalar to set Swidth. + * \param [in] Sheight The input \ref VX_TYPE_UINT32 scalar to set Sheight. + * \param [in] bordertype The input \ref VX_TYPE_INT32 scalar to set bordertype. + * \return \ref vx_node. + * \retval vx_node A node reference. Any possible errors preventing a successful creation should be checked using \ref vxGetStatus*/ + VX_API_ENTRY vx_node VX_API_CALL vxExtCvNode_pyrdown(vx_graph graph, vx_image input, vx_image output, vx_uint32 Swidth, vx_uint32 Sheight, vx_int32 bordertype); + + /*! \brief [Graph] Creates a OpenCV buildPyramid function node. + * \param [in] graph The reference to the graph. + * \param [in] input The input image in \ref VX_DF_IMAGE_U8 format. + * \param [out] output The output Pyramid. + * \param [in] OP The input \ref VX_TYPE_INT32 scalar to set OP. + * \param [in] maxLevel The input \ref VX_TYPE_UINT32 scalar to set maxLevel. + * \param [in] border The input \ref VX_TYPE_UINT32 scalar to set border. + * \return \ref vx_node. + * \retval vx_node A node reference. Any possible errors preventing a successful creation should be checked using \ref vxGetStatus*/ + VX_API_ENTRY vx_node VX_API_CALL vxExtCvNode_buildPyramid(vx_graph graph, vx_image input, vx_pyramid output, vx_uint32 maxLevel, vx_uint32 border); + + /*! \brief [Graph] Creates a OpenCV buildOpticalFlowPyramid function node. + * \param [in] graph The reference to the graph. + * \param [in] input The input image in \ref VX_DF_IMAGE_U8 format. + * \param [out] output The output Pyramid. + * \param [in] WIN_Size_Width The input \ref VX_TYPE_INT32 scalar to set WIN_Size_Width. + * \param [in] WIN_Size_Height The input \ref VX_TYPE_INT32 scalar to set WIN_Size_Height. + * \param [in] maxLevel The input \ref VX_TYPE_INT32 scalar to set maxLevel. + * \param [in] withDerivatives The input \ref VX_TYPE_BOOL scalar to set withDerivatives. + * \param [in] pyrBorder The input \ref VX_TYPE_INT32 scalar to set pyrBorder. + * \param [in] derivBorder The input \ref VX_TYPE_INT32 scalar to set derivBorder. + * \param [in] tryReuseInputImage The input \ref VX_TYPE_BOOL scalar to set tryReuseInputImage. + * \return \ref vx_node. + * \retval vx_node A node reference. Any possible errors preventing a successful creation should be checked using \ref vxGetStatus*/ + VX_API_ENTRY vx_node VX_API_CALL vxExtCvNode_buildOpticalFlowPyramid(vx_graph graph, vx_image input, vx_pyramid output, vx_uint32 S_width, vx_uint32 S_height, vx_int32 WinSize, vx_bool WithDerivatives, vx_int32 Pyr_border, vx_int32 derviBorder, vx_bool tryReuse); + + /*! \brief [Graph] Creates a OpenCV Dilate function node. + * \param [in] graph The reference to the graph. + * \param [in] input The input image in \ref VX_DF_IMAGE_U8 format. + * \param [out] output The output image is as same size and type of input. + * \param [in] Kernel The input \ref vx_matrix matrix to set Kernel. + * \param [in] Anchor_X The input \ref VX_TYPE_INT32 scalar to set Anchor_X. + * \param [in] Anchor_Y The input \ref VX_TYPE_INT32 scalar to set Anchor_Y. + * \param [in] iterations The input \ref VX_TYPE_INT32 scalar to set iterations. + * \param [in] border The input \ref VX_TYPE_INT32 scalar to set border. + * \return \ref vx_node. + * \retval vx_node A node reference. Any possible errors preventing a successful creation should be checked using \ref vxGetStatus*/ + VX_API_ENTRY vx_node VX_API_CALL vxExtCvNode_Dilate(vx_graph graph, vx_image input, vx_image output, vx_matrix Kernel, vx_int32 Anchor_X, vx_int32 Anchor_Y, vx_int32 iterations, vx_int32 border); + + /*! \brief [Graph] Creates a OpenCV Erode function node. + * \param [in] graph The reference to the graph. + * \param [in] input The input image in \ref VX_DF_IMAGE_U8 format. + * \param [out] output The output image is as same size and type of input. + * \param [in] Kernel The input \ref vx_matrix matrix to set Kernel. + * \param [in] Anchor_X The input \ref VX_TYPE_INT32 scalar to set Anchor_X. + * \param [in] Anchor_Y The input \ref VX_TYPE_INT32 scalar to set Anchor_Y. + * \param [in] iterations The input \ref VX_TYPE_INT32 scalar to set iterations. + * \param [in] border The input \ref VX_TYPE_INT32 scalar to set border. + * \return \ref vx_node. + * \retval vx_node A node reference. Any possible errors preventing a successful creation should be checked using \ref vxGetStatus*/ + VX_API_ENTRY vx_node VX_API_CALL vxExtCvNode_Erode(vx_graph graph, vx_image input, vx_image output, vx_matrix Kernel, vx_int32 Anchor_X, vx_int32 Anchor_Y, vx_int32 iterations, vx_int32 border); + + /*! \brief [Graph] Creates a OpenCV warpAffine function node. + * \param [in] graph The reference to the graph. + * \param [in] input The input image in \ref VX_DF_IMAGE_U8 format. + * \param [out] output The output image is as same size and type of input. + * \param [in] M The input \ref vx_matrix matrix to set M. + * \param [in] Size_X The input \ref VX_TYPE_INT32 scalar to set Size_X. + * \param [in] Size_Y The input \ref VX_TYPE_INT32 scalar to set Size_Y. + * \param [in] flags The input \ref VX_TYPE_INT32 scalar to set flags. + * \param [in] border The input \ref VX_TYPE_INT32 scalar to set border. + * \return \ref vx_node. + * \retval vx_node A node reference. Any possible errors preventing a successful creation should be checked using \ref vxGetStatus*/ + VX_API_ENTRY vx_node VX_API_CALL vxExtCvNode_warpAffine(vx_graph graph, vx_image input, vx_image output, vx_matrix M, vx_int32 Size_X, vx_int32 Size_Y, vx_int32 flags, vx_int32 border); + + /*! \brief [Graph] Creates a OpenCV warpPerspective function node. + * \param [in] graph The reference to the graph. + * \param [in] input The input image in \ref VX_DF_IMAGE_U8 format. + * \param [out] output The output image is as same size and type of input. + * \param [in] M The input \ref vx_matrix matrix to set M. + * \param [in] Size_X The input \ref VX_TYPE_INT32 scalar to set Size_X. + * \param [in] Size_Y The input \ref VX_TYPE_INT32 scalar to set Size_Y. + * \param [in] flags The input \ref VX_TYPE_INT32 scalar to set flags. + * \param [in] border The input \ref VX_TYPE_INT32 scalar to set border. + * \return \ref vx_node. + * \retval vx_node A node reference. Any possible errors preventing a successful creation should be checked using \ref vxGetStatus*/ + VX_API_ENTRY vx_node VX_API_CALL vxExtCvNode_warpPerspective(vx_graph graph, vx_image input, vx_image output, vx_matrix M, vx_int32 Size_X, vx_int32 Size_Y, vx_int32 flags, vx_int32 border); + + /*! \brief [Graph] Creates a OpenCV morphologyEX function node. + * \param [in] graph The reference to the graph. + * \param [in] input The input image in \ref VX_DF_IMAGE_U8 format. + * \param [out] output The output image is as same size and type of input. + * \param [in] OP The input \ref VX_TYPE_INT32 scalar to set OP. + * \param [in] Kernel The input \ref vx_matrix matrix to set Kernel. + * \param [in] Anchor_X The input \ref VX_TYPE_INT32 scalar to set Anchor_X. + * \param [in] Anchor_Y The input \ref VX_TYPE_INT32 scalar to set Anchor_Y. + * \param [in] iterations The input \ref VX_TYPE_INT32 scalar to set iterations. + * \param [in] border The input \ref VX_TYPE_INT32 scalar to set border. + * \return \ref vx_node. + * \retval vx_node A node reference. Any possible errors preventing a successful creation should be checked using \ref vxGetStatus*/ + VX_API_ENTRY vx_node VX_API_CALL vxExtCvNode_morphologyEX(vx_graph graph, vx_image input, vx_image output, vx_int32 OP, vx_matrix Kernel, vx_int32 Anchor_X, vx_int32 Anchor_Y, vx_int32 iterations, vx_int32 border); + + /*! \brief [Graph] Creates a OpenCV Bitwise And function node. + * \param [in] graph The reference to the graph. + * \param [in] input_1 The input image in \ref VX_DF_IMAGE_U8 or \ref VX_DF_IMAGE_S16 format. + * \param [in] input_2 The input image in \ref VX_DF_IMAGE_U8 or \ref VX_DF_IMAGE_S16 format. + * \param [out] output The output image is as same size and type of input. + * \return \ref vx_node. + * \retval vx_node A node reference. Any possible errors preventing a successful creation should be checked using \ref vxGetStatus*/ + VX_API_ENTRY vx_node VX_API_CALL vxExtCvNode_bitwise_and(vx_graph graph, vx_image input_1, vx_image input_2, vx_image output); + + /*! \brief [Graph] Creates a OpenCV Bitwise NOT function node. + * \param [in] graph The reference to the graph. + * \param [in] input The input image in \ref VX_DF_IMAGE_U8 or \ref VX_DF_IMAGE_S16 format. + * \param [out] output The output image is as same size and type of input. + * \return \ref vx_node. + * \retval vx_node A node reference. Any possible errors preventing a successful creation should be checked using \ref vxGetStatus*/ + VX_API_ENTRY vx_node VX_API_CALL vxExtCvNode_bitwise_not(vx_graph graph, vx_image input, vx_image output); + + /*! \brief [Graph] Creates a OpenCV Bitwise OR function node. + * \param [in] graph The reference to the graph. + * \param [in] input_1 The input image in \ref VX_DF_IMAGE_U8 or \ref VX_DF_IMAGE_S16 format. + * \param [in] input_2 The input image in \ref VX_DF_IMAGE_U8 or \ref VX_DF_IMAGE_S16 format. + * \param [out] output The output image is as same size and type of input. + * \return \ref vx_node. + * \retval vx_node A node reference. Any possible errors preventing a successful creation should be checked using \ref vxGetStatus*/ + VX_API_ENTRY vx_node VX_API_CALL vxExtCvNode_bitwise_or(vx_graph graph, vx_image input_1, vx_image input_2, vx_image output); + + /*! \brief [Graph] Creates a OpenCV Bitwise XOR function node. + * \param [in] graph The reference to the graph. + * \param [in] input_1 The input image in \ref VX_DF_IMAGE_U8 or \ref VX_DF_IMAGE_S16 format. + * \param [in] input_2 The input image in \ref VX_DF_IMAGE_U8 or \ref VX_DF_IMAGE_S16 format. + * \param [out] output The output image is as same size and type of input. + * \return \ref vx_node. + * \retval vx_node A node reference. Any possible errors preventing a successful creation should be checked using \ref vxGetStatus*/ + VX_API_ENTRY vx_node VX_API_CALL vxExtCvNode_bitwise_xor(vx_graph graph, vx_image input_1, vx_image input_2, vx_image output); + + /*! \brief [Graph] Creates a OpenCV Canny function node. + * \param [in] graph The reference to the graph. + * \param [in] input The input image in \ref VX_DF_IMAGE_U8 format. + * \param [out] output The output image is as same size and type of input. + * \param [in] threshold1 The input \ref VX_TYPE_FLOAT32 scalar to set threshold1. + * \param [in] threshold2 The input \ref VX_TYPE_FLOAT32 scalar to set threshold2. + * \param [in] aperture_size The input \ref VX_TYPE_INT32 scalar to set aperture_size. + * \param [in] L2_Gradient The input \ref VX_BOOL scalar to set L2_Gradient. + * \return \ref vx_node. + * \retval vx_node A node reference. Any possible errors preventing a successful creation should be checked using \ref vxGetStatus*/ + VX_API_ENTRY vx_node VX_API_CALL vxExtCvNode_Canny(vx_graph graph, vx_image input, vx_image output, vx_float32 threshold1, vx_float32 threshold2, vx_int32 aperture_size, vx_bool L2_Gradient); + + /*! \brief [Graph] Creates a OpenCV Compare function node. + * \param [in] graph The reference to the graph. + * \param [in] input_1 The input image in \ref VX_DF_IMAGE_U8 or \ref VX_DF_IMAGE_S16 format. + * \param [in] input_2 The input image in \ref VX_DF_IMAGE_U8 or \ref VX_DF_IMAGE_S16 format. + * \param [out] output The output image is as same size and type of input. + * \return \ref vx_node. + * \retval vx_node A node reference. Any possible errors preventing a successful creation should be checked using \ref vxGetStatus*/ + VX_API_ENTRY vx_node VX_API_CALL vxExtCvNode_compare(vx_graph graph, vx_image input_1, vx_image input_2, vx_image output); + + /*! \brief [Graph] Creates a OpenCV convertScaleAbs function node. + * \param [in] graph The reference to the graph. + * \param [in] input The input image in \ref VX_DF_IMAGE_U8 format. + * \param [out] output The output image is as same size and type of input. + * \param [in] alpha The input \ref VX_TYPE_FLOAT32 scalar to set alpha. + * \param [in] beta The input \ref VX_TYPE_FLOAT32 scalar to set beta. + * \return \ref vx_node. + * \retval vx_node A node reference. Any possible errors preventing a successful creation should be checked using \ref vxGetStatus*/ + VX_API_ENTRY vx_node VX_API_CALL vxExtCvNode_convertScaleAbs(vx_graph graph, vx_image image_in, vx_image image_out, vx_float32 alpha, vx_float32 beta); + + /*! \brief [Graph] Creates a OpenCV cornerHarris function node. + * \param [in] graph The reference to the graph. + * \param [in] input The input image in \ref VX_DF_IMAGE_U8 format. + * \param [out] output The output image is as same size and type of input. + * \param [in] blocksize The input \ref VX_TYPE_INT32 scalar to set blocksize. + * \param [in] ksize The input \ref VX_TYPE_INT32 scalar to set ksize. + * \param [in] K The input \ref VX_TYPE_FLOAT32 scalar to set K. + * \param [in] border The input \ref VX_TYPE_INT32 scalar to set border. + * \return \ref vx_node. + * \retval vx_node A node reference. Any possible errors preventing a successful creation should be checked using \ref vxGetStatus*/ + VX_API_ENTRY vx_node VX_API_CALL vxExtCvNode_cornerHarris(vx_graph graph, vx_image input, vx_image output, vx_int32 blocksize, vx_int32 ksize, vx_float32 k, vx_int32 border); + + /*! \brief [Graph] Creates a OpenCV cornerMinEigenVal function node. + * \param [in] graph The reference to the graph. + * \param [in] input The input image in \ref VX_DF_IMAGE_U8 format. + * \param [out] output The output image is as same size and type of input. + * \param [in] blocksize The input \ref VX_TYPE_UINT32 scalar to set blocksize. + * \param [in] ksize The input \ref VX_TYPE_UINT32 scalar to set ksize. + * \param [in] border The input \ref VX_TYPE_INT32 scalar to set border. + * \return \ref vx_node. + * \retval vx_node A node reference. Any possible errors preventing a successful creation should be checked using \ref vxGetStatus*/ + VX_API_ENTRY vx_node VX_API_CALL vxExtCvNode_cornerMinEigenVal(vx_graph graph, vx_image input, vx_image output, vx_uint32 blockSize, vx_uint32 ksize, vx_int32 border); + + /*! \brief [Graph] Creates a OpenCV Laplacian function node. + * \param [in] graph The reference to the graph. + * \param [in] input The input image in \ref VX_DF_IMAGE_U8 format. + * \param [out] output The output image is as same size and type of input. + * \param [in] ddepth The input \ref VX_TYPE_UINT32 scalar to set ddepth. + * \param [in] ksize The input \ref VX_TYPE_UINT32 scalar to set ksize. + * \param [in] scale The input \ref VX_TYPE_FLOAT32 scalar to set scale. + * \param [in] delta The input \ref VX_TYPE_FLOAT32 scalar to set delta. + * \param [in] border_mode The input \ref VX_TYPE_INT32 scalar to set border_mode. + * \return \ref vx_node. + * \retval vx_node A node reference. Any possible errors preventing a successful creation should be checked using \ref vxGetStatus*/ + VX_API_ENTRY vx_node VX_API_CALL vxExtCvNode_Laplacian(vx_graph graph, vx_image input, vx_image output, vx_uint32 ddepth, vx_uint32 ksize, vx_float32 scale, vx_float32 delta, vx_int32 border_mode); + + /*! \brief [Graph] Creates a OpenCV Scharr function node. + * \param [in] graph The reference to the graph. + * \param [in] input The input image in \ref VX_DF_IMAGE_U8 format. + * \param [out] output The output image is as same size and type of input. + * \param [in] ddepth The input \ref VX_TYPE_INT32 scalar to set ddepth. + * \param [in] dx The input \ref VX_TYPE_INT32 scalar to set dx. + * \param [in] dy The input \ref VX_TYPE_INT32 scalar to set dy. + * \param [in] scale The input \ref VX_TYPE_FLOAT32 scalar to set scale. + * \param [in] delta The input \ref VX_TYPE_FLOAT32 scalar to set delta. + * \param [in] bordertype The input \ref VX_TYPE_INT32 scalar to set bordertype. + * \return \ref vx_node. + * \retval vx_node A node reference. Any possible errors preventing a successful creation should be checked using \ref vxGetStatus*/ + VX_API_ENTRY vx_node VX_API_CALL vxExtCvNode_Scharr(vx_graph graph, vx_image input, vx_image output, vx_int32 ddepth, vx_int32 dx, vx_int32 dy, vx_float32 scale, vx_float32 delta, vx_int32 bordertype); + + /*! \brief [Graph] Creates a OpenCV Sobel function node. + * \param [in] graph The reference to the graph. + * \param [in] input The input image in \ref VX_DF_IMAGE_U8 format. + * \param [out] output The output image is as same size and type of input. + * \param [in] ddepth The input \ref VX_TYPE_INT32 scalar to set ddepth. + * \param [in] dx The input \ref VX_TYPE_INT32 scalar to set dx. + * \param [in] dy The input \ref VX_TYPE_INT32 scalar to set dy. + * \param [in] Ksize The input \ref VX_TYPE_INT32 scalar to set Ksize. + * \param [in] scale The input \ref VX_TYPE_FLOAT32 scalar to set scale. + * \param [in] delta The input \ref VX_TYPE_FLOAT32 scalar to set delta. + * \param [in] bordertype The input \ref VX_TYPE_INT32 scalar to set bordertype. + * \return \ref vx_node. + * \retval vx_node A node reference. Any possible errors preventing a successful creation should be checked using \ref vxGetStatus*/ + VX_API_ENTRY vx_node VX_API_CALL vxExtCvNode_Sobel(vx_graph graph, vx_image input, vx_image output, vx_int32 ddepth, vx_int32 dx, vx_int32 dy, vx_int32 Ksize, vx_float32 scale, vx_float32 delta, vx_int32 bordertype); + + +#ifdef __cplusplus +} +#endif diff --git a/vx_ext_cv/OpenCV_VX_Nodes.cpp b/vx_ext_cv/OpenCV_VX_Nodes.cpp new file mode 100644 index 0000000..b6c404a --- /dev/null +++ b/vx_ext_cv/OpenCV_VX_Nodes.cpp @@ -0,0 +1,1638 @@ +/* +Copyright (c) 2015 Advanced Micro Devices, Inc. All rights reserved. + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. +*/ + + +#include"publishkernels.h" +#include"OpenCV_VX_Functions.h" + +vx_node vxCreateNodeByStructure(vx_graph graph, + vx_enum kernelenum, + vx_reference params[], + vx_uint32 num) +{ + vx_status status = VX_SUCCESS; + vx_node node = 0; + vx_context context = vxGetContext((vx_reference)graph); + vx_kernel kernel = vxGetKernelByEnum(context, kernelenum); + if (kernel) + { + node = vxCreateGenericNode(graph, kernel); + if (node) + { + vx_uint32 p = 0; + for (p = 0; p < num; p++) + { + if (params[p]) + { + status = vxSetParameterByIndex(node, + p, + params[p]); + if (status != VX_SUCCESS) + { + vxAddLogEntry((vx_reference)graph, status, "Kernel %d Parameter %u is invalid.\n", kernelenum, p); + vxReleaseNode(&node); + node = 0; + break; + } + } + } + } + else + { + vxAddLogEntry((vx_reference)graph, VX_ERROR_INVALID_PARAMETERS, "Failed to create node with kernel enum %d\n", kernelenum); + status = VX_ERROR_NO_MEMORY; + } + vxReleaseKernel(&kernel); + } + else + { + vxAddLogEntry((vx_reference)graph, VX_ERROR_INVALID_PARAMETERS, "failed to retrieve kernel enum %d\n", kernelenum); + status = VX_ERROR_NOT_SUPPORTED; + } + return node; +} + +/************************************************************************************************************ +OpenCV Absdiff C Function +*************************************************************************************************************/ +VX_API_ENTRY vx_node VX_API_CALL vxExtCvNode_absdiff(vx_graph graph, vx_image input_1, vx_image input_2, vx_image output) +{ + + vx_reference params[] = { + (vx_reference)input_1, + (vx_reference)input_2, + (vx_reference)output, + }; + + return vxCreateNodeByStructure(graph, + VX_KERNEL_EXT_CV_ABSDIFF, + params, + dimof(params)); +} + +/************************************************************************************************************ +OpenCV Add C Function +*************************************************************************************************************/ +VX_API_ENTRY vx_node VX_API_CALL vxExtCvNode_add(vx_graph graph, vx_image input_1, vx_image input_2, vx_image output) +{ + + vx_reference params[] = { + (vx_reference)input_1, + (vx_reference)input_2, + (vx_reference)output, + }; + + return vxCreateNodeByStructure(graph, + VX_KERNEL_EXT_CV_ADD, + params, + dimof(params)); + +} + +/************************************************************************************************************ +OpenCV Subtract C Function +*************************************************************************************************************/ +VX_API_ENTRY vx_node VX_API_CALL vxExtCvNode_subtract(vx_graph graph, vx_image input_1, vx_image input_2, vx_image output) +{ + + vx_reference params[] = { + (vx_reference)input_1, + (vx_reference)input_2, + (vx_reference)output, + }; + + return vxCreateNodeByStructure(graph, + VX_KERNEL_EXT_CV_SUBTRACT, + params, + dimof(params)); + +} + +/************************************************************************************************************ +OpenCV Bitwise_AND C Function +*************************************************************************************************************/ +VX_API_ENTRY vx_node VX_API_CALL vxExtCvNode_bitwise_and(vx_graph graph, vx_image input_1, vx_image input_2, vx_image output) +{ + + vx_reference params[] = { + (vx_reference)input_1, + (vx_reference)input_2, + (vx_reference)output, + }; + + return vxCreateNodeByStructure(graph, + VX_KERNEL_EXT_CV_BITWISE_AND, + params, + dimof(params)); + +} + +/************************************************************************************************************ +OpenCV Bitwise_NOT C Function +*************************************************************************************************************/ +VX_API_ENTRY vx_node VX_API_CALL vxExtCvNode_bitwise_not(vx_graph graph, vx_image input_1, vx_image output) +{ + + vx_reference params[] = { + (vx_reference)input_1, + (vx_reference)output, + }; + + return vxCreateNodeByStructure(graph, + VX_KERNEL_EXT_CV_BITWISE_NOT, + params, + dimof(params)); + +} + +/************************************************************************************************************ +OpenCV Bitwise_OR C Function +*************************************************************************************************************/ +VX_API_ENTRY vx_node VX_API_CALL vxExtCvNode_bitwise_or(vx_graph graph, vx_image input_1, vx_image input_2, vx_image output) +{ + + vx_reference params[] = { + (vx_reference)input_1, + (vx_reference)input_2, + (vx_reference)output, + }; + + return vxCreateNodeByStructure(graph, + VX_KERNEL_EXT_CV_BITWISE_OR, + params, + dimof(params)); + +} + +/************************************************************************************************************ +OpenCV Bitwise_XOR C Function +*************************************************************************************************************/ +VX_API_ENTRY vx_node VX_API_CALL vxExtCvNode_bitwise_xor(vx_graph graph, vx_image input_1, vx_image input_2, vx_image output) +{ + + vx_reference params[] = { + (vx_reference)input_1, + (vx_reference)input_2, + (vx_reference)output, + }; + + return vxCreateNodeByStructure(graph, + VX_KERNEL_EXT_CV_BITWISE_XOR, + params, + dimof(params)); + +} + +/************************************************************************************************************ +OpenCV Transpose C Function +*************************************************************************************************************/ +VX_API_ENTRY vx_node VX_API_CALL vxExtCvNode_transpose(vx_graph graph, vx_image input, vx_image output) +{ + + vx_reference params[] = { + (vx_reference)input, + (vx_reference)output, + }; + + return vxCreateNodeByStructure(graph, + VX_KERNEL_EXT_CV_TRANSPOSE, + params, + dimof(params)); + +} + +/************************************************************************************************************ +OpenCV Compare C Function +*************************************************************************************************************/ +VX_API_ENTRY vx_node VX_API_CALL vxExtCvNode_compare(vx_graph graph, vx_image input_1, vx_image input_2, vx_image output, vx_int32 cmpop) +{ + + vx_scalar CMPOP = vxCreateScalar(vxGetContext((vx_reference)graph), VX_TYPE_INT32, &cmpop); + + vx_reference params[] = { + (vx_reference)input_1, + (vx_reference)input_2, + (vx_reference)output, + (vx_reference)CMPOP, + }; + + return vxCreateNodeByStructure(graph, + VX_KERNEL_EXT_CV_COMPARE, + params, + dimof(params)); + +} + +/************************************************************************************************************ +OpenCV integral C Function +*************************************************************************************************************/ +VX_API_ENTRY vx_node VX_API_CALL vxExtCvNode_integral(vx_graph graph, vx_image input, vx_image output, vx_int32 sdepth){ + + vx_scalar Sdepth = vxCreateScalar(vxGetContext((vx_reference)graph), VX_TYPE_INT32, &sdepth); + + vx_reference params[] = { + (vx_reference)input, + (vx_reference)output, + (vx_reference)Sdepth, + }; + + return vxCreateNodeByStructure(graph, + VX_KERNEL_EXT_CV_INTEGRAL, + params, + dimof(params)); + +} + +/************************************************************************************************************ +OpenCV NORM C Function +*************************************************************************************************************/ +VX_API_ENTRY vx_node VX_API_CALL vxExtCvNode_norm(vx_graph graph, vx_image input, vx_float32 norm_value, vx_int32 norm_type){ + + vx_scalar Norm_value = vxCreateScalar(vxGetContext((vx_reference)graph), VX_TYPE_FLOAT32, &norm_value); + vx_scalar Norm_type = vxCreateScalar(vxGetContext((vx_reference)graph), VX_TYPE_INT32, &norm_type); + + vx_reference params[] = { + (vx_reference)input, + (vx_reference)Norm_value, + (vx_reference)Norm_type, + }; + + return vxCreateNodeByStructure(graph, + VX_KERNEL_EXT_CV_NORM, + params, + dimof(params)); + +} + +/************************************************************************************************************ +OpenCV countNonZero C Function +*************************************************************************************************************/ +VX_API_ENTRY vx_node VX_API_CALL vxExtCvNode_countNonZero(vx_graph graph, vx_image input, vx_int32 non_zero){ + + vx_scalar Non_zero = vxCreateScalar(vxGetContext((vx_reference)graph), VX_TYPE_INT32, &non_zero); + + vx_reference params[] = { + (vx_reference)input, + (vx_reference)Non_zero, + }; + + return vxCreateNodeByStructure(graph, + VX_KERNEL_EXT_CV_COUNT_NON_ZERO, + params, + dimof(params)); +} + +/************************************************************************************************************ +OpenCV flip C Function +*************************************************************************************************************/ +VX_API_ENTRY vx_node VX_API_CALL vxExtCvNode_flip(vx_graph graph, vx_image input, vx_image output, vx_int32 FlipCode) +{ + + vx_scalar FLIPCODE = vxCreateScalar(vxGetContext((vx_reference)graph), VX_TYPE_INT32, &FlipCode); + + vx_reference params[] = { + (vx_reference)input, + (vx_reference)output, + (vx_reference)FLIPCODE, + }; + + return vxCreateNodeByStructure(graph, + VX_KERNEL_EXT_CV_FLIP, + params, + dimof(params)); + +} + +/************************************************************************************************************ +OpenCV MedianBlur C Function +*************************************************************************************************************/ +VX_API_ENTRY vx_node VX_API_CALL vxExtCvNode_medianBlur(vx_graph graph, vx_image input, vx_image output, vx_uint32 ksize) +{ + + vx_scalar KSIZE = vxCreateScalar(vxGetContext((vx_reference)graph), VX_TYPE_INT32, &ksize); + + vx_reference params[] = { + (vx_reference)input, + (vx_reference)output, + (vx_reference)KSIZE, + }; + + return vxCreateNodeByStructure(graph, + VX_KERNEL_EXT_CV_MEDIAN_BLUR, + params, + dimof(params)); + +} + +/************************************************************************************************************ +OpenCV Boxfilter C function. +*************************************************************************************************************/ +VX_API_ENTRY vx_node VX_API_CALL vxExtCvNode_boxFilter(vx_graph graph, vx_image input, vx_image output, vx_int32 ddepth, vx_uint32 kwidth, vx_uint32 kheight, vx_int32 Anchor_X, vx_int32 Anchor_Y, vx_bool Normalized, vx_int32 Bordertype) +{ + + vx_scalar DDEPTH = vxCreateScalar(vxGetContext((vx_reference)graph), VX_TYPE_INT32, &ddepth); + vx_scalar KWIDTH = vxCreateScalar(vxGetContext((vx_reference)graph), VX_TYPE_INT32, &kwidth); + vx_scalar KHEIGHT = vxCreateScalar(vxGetContext((vx_reference)graph), VX_TYPE_INT32, &kheight); + vx_scalar A_X = vxCreateScalar(vxGetContext((vx_reference)graph), VX_TYPE_INT32, &Anchor_X); + vx_scalar A_Y = vxCreateScalar(vxGetContext((vx_reference)graph), VX_TYPE_INT32, &Anchor_Y); + vx_scalar NORM = vxCreateScalar(vxGetContext((vx_reference)graph), VX_TYPE_BOOL, &Normalized); + vx_scalar BORDER = vxCreateScalar(vxGetContext((vx_reference)graph), VX_TYPE_INT32, &Bordertype); + + vx_reference params[] = { + (vx_reference)input, + (vx_reference)output, + (vx_reference)DDEPTH, + (vx_reference)KWIDTH, + (vx_reference)KHEIGHT, + (vx_reference)A_X, + (vx_reference)A_Y, + (vx_reference)NORM, + (vx_reference)BORDER, + }; + + return vxCreateNodeByStructure(graph, + VX_KERNEL_EXT_CV_BOXFILTER, + params, + dimof(params)); + +} + +/************************************************************************************************************ +OpenCV Gaussian C Function +*************************************************************************************************************/ +VX_API_ENTRY vx_node VX_API_CALL vxExtCvNode_GaussianBlur(vx_graph graph, vx_image input, vx_image output, vx_uint32 kwidth, vx_uint32 kheight, vx_float32 sigmaX, vx_float32 sigmaY, vx_int32 border_mode) +{ + + vx_scalar KWIDTH = vxCreateScalar(vxGetContext((vx_reference)graph), VX_TYPE_INT32, &kwidth); + vx_scalar KHEIGHT = vxCreateScalar(vxGetContext((vx_reference)graph), VX_TYPE_INT32, &kheight); + vx_scalar SIGMA_X = vxCreateScalar(vxGetContext((vx_reference)graph), VX_TYPE_FLOAT32, &sigmaX); + vx_scalar SIGMA_Y = vxCreateScalar(vxGetContext((vx_reference)graph), VX_TYPE_FLOAT32, &sigmaY); + vx_scalar BORDER = vxCreateScalar(vxGetContext((vx_reference)graph), VX_TYPE_INT32, &border_mode); + + vx_reference params[] = { + (vx_reference)input, + (vx_reference)output, + (vx_reference)KWIDTH, + (vx_reference)KHEIGHT, + (vx_reference)SIGMA_X, + (vx_reference)SIGMA_Y, + (vx_reference)BORDER, + }; + + return vxCreateNodeByStructure(graph, + VX_KERNEL_EXT_CV_GAUSSIAN_BLUR, + params, + dimof(params)); + +} + +/************************************************************************************************************ +OpenCV Blur C Function +*************************************************************************************************************/ +VX_API_ENTRY vx_node VX_API_CALL vxExtCvNode_blur(vx_graph graph, vx_image input, vx_image output, vx_uint32 kwidth, vx_uint32 kheight, vx_int32 Anchor_X, vx_int32 Anchor_Y, vx_int32 Bordertype) +{ + + vx_scalar KWIDTH = vxCreateScalar(vxGetContext((vx_reference)graph), VX_TYPE_INT32, &kwidth); + vx_scalar KHEIGHT = vxCreateScalar(vxGetContext((vx_reference)graph), VX_TYPE_INT32, &kheight); + vx_scalar A_X = vxCreateScalar(vxGetContext((vx_reference)graph), VX_TYPE_INT32, &Anchor_X); + vx_scalar A_Y = vxCreateScalar(vxGetContext((vx_reference)graph), VX_TYPE_INT32, &Anchor_Y); + vx_scalar BORDER = vxCreateScalar(vxGetContext((vx_reference)graph), VX_TYPE_INT32, &Bordertype); + + vx_reference params[] = { + (vx_reference)input, + (vx_reference)output, + (vx_reference)KWIDTH, + (vx_reference)KHEIGHT, + (vx_reference)A_X, + (vx_reference)A_Y, + (vx_reference)BORDER, + }; + + return vxCreateNodeByStructure(graph, + VX_KERNEL_EXT_CV_BLUR, + params, + dimof(params)); + +} + +/************************************************************************************************************ +OpenCV Bilateral Filter C Function +*************************************************************************************************************/ +VX_API_ENTRY vx_node VX_API_CALL vxExtCvNode_bilateralFilter(vx_graph graph, vx_image input, vx_image output, vx_uint32 d, vx_float32 Sigma_Color, vx_float32 Sigma_Space, vx_int32 border_mode) +{ + + vx_scalar D = vxCreateScalar(vxGetContext((vx_reference)graph), VX_TYPE_INT32, &d); + vx_scalar S_COLOR = vxCreateScalar(vxGetContext((vx_reference)graph), VX_TYPE_FLOAT32, &Sigma_Color); + vx_scalar S_SPACE = vxCreateScalar(vxGetContext((vx_reference)graph), VX_TYPE_FLOAT32, &Sigma_Space); + vx_scalar BORDER = vxCreateScalar(vxGetContext((vx_reference)graph), VX_TYPE_INT32, &border_mode); + + vx_reference params[] = { + (vx_reference)input, + (vx_reference)output, + (vx_reference)D, + (vx_reference)S_COLOR, + (vx_reference)S_SPACE, + (vx_reference)BORDER, + }; + + return vxCreateNodeByStructure(graph, + VX_KERNEL_EXT_CV_BILATERAL_FILTER, + params, + dimof(params)); + +} + +/************************************************************************************************************ +OpenCV Sobel C function. +*************************************************************************************************************/ +VX_API_ENTRY vx_node VX_API_CALL vxExtCvNode_Sobel(vx_graph graph, vx_image input, vx_image output, vx_int32 ddepth, vx_int32 dx, vx_int32 dy, vx_int32 Ksize, vx_float32 scale, vx_float32 delta, vx_int32 bordertype) +{ + + vx_scalar DDEPTH = vxCreateScalar(vxGetContext((vx_reference)graph), VX_TYPE_INT32, &ddepth); + vx_scalar DX = vxCreateScalar(vxGetContext((vx_reference)graph), VX_TYPE_INT32, &dx); + vx_scalar DY = vxCreateScalar(vxGetContext((vx_reference)graph), VX_TYPE_INT32, &dy); + vx_scalar KSIZE = vxCreateScalar(vxGetContext((vx_reference)graph), VX_TYPE_INT32, &Ksize); + vx_scalar SCALE = vxCreateScalar(vxGetContext((vx_reference)graph), VX_TYPE_FLOAT32, &scale); + vx_scalar DELTA = vxCreateScalar(vxGetContext((vx_reference)graph), VX_TYPE_FLOAT32, &delta); + vx_scalar BORDER = vxCreateScalar(vxGetContext((vx_reference)graph), VX_TYPE_INT32, &bordertype); + + vx_reference params[] = { + (vx_reference)input, + (vx_reference)output, + (vx_reference)DDEPTH, + (vx_reference)DX, + (vx_reference)DY, + (vx_reference)KSIZE, + (vx_reference)SCALE, + (vx_reference)DELTA, + (vx_reference)BORDER, + }; + + return vxCreateNodeByStructure(graph, + VX_KERNEL_EXT_CV_SOBEL, + params, + dimof(params)); + +} + +/************************************************************************************************************ + OpenCV convertScaleAbs C Function function. + *************************************************************************************************************/ + +VX_API_ENTRY vx_node VX_API_CALL vxExtCvNode_convertScaleAbs(vx_graph graph, vx_image image_in, vx_image image_out, vx_float32 alpha, vx_float32 beta) +{ + + vx_scalar ALPHA = vxCreateScalar(vxGetContext((vx_reference)graph), VX_TYPE_FLOAT32, &alpha); + vx_scalar BETA = vxCreateScalar(vxGetContext((vx_reference)graph), VX_TYPE_FLOAT32, &beta); + + vx_reference params[] = { + (vx_reference)image_in, + (vx_reference)image_out, + (vx_reference)ALPHA, + (vx_reference)BETA, + + }; + + return vxCreateNodeByStructure(graph, + VX_KERNEL_EXT_CV_CONVERTSCALEABS, + params, + dimof(params)); + +} + +/************************************************************************************************************ +AddWeighted Node function. +*************************************************************************************************************/ +VX_API_ENTRY vx_node VX_API_CALL vxExtCvNode_addWeighted(vx_graph graph, vx_image imput_1, vx_float32 aplha, vx_image input_2, vx_float32 beta, vx_float32 gamma, vx_image output, vx_int32 dtype) +{ + + vx_scalar ALPHA = vxCreateScalar(vxGetContext((vx_reference)graph), VX_TYPE_FLOAT32, &aplha); + vx_scalar BETA = vxCreateScalar(vxGetContext((vx_reference)graph), VX_TYPE_FLOAT32, &beta); + vx_scalar GAMMA = vxCreateScalar(vxGetContext((vx_reference)graph), VX_TYPE_FLOAT32, &gamma); + vx_scalar DTYPE = vxCreateScalar(vxGetContext((vx_reference)graph), VX_TYPE_INT32, &dtype); + + vx_reference params[] = { + (vx_reference)imput_1, + (vx_reference)ALPHA, + (vx_reference)input_2, + (vx_reference)BETA, + (vx_reference)GAMMA, + (vx_reference)output, + (vx_reference)DTYPE, + + }; + + return vxCreateNodeByStructure(graph, + VX_KERNEL_EXT_CV_ADDWEIGHTED, + params, + dimof(params)); + +} + +/************************************************************************************************************ +Canny C Function +*************************************************************************************************************/ +VX_API_ENTRY vx_node VX_API_CALL vxExtCvNode_Canny(vx_graph graph, vx_image input, vx_image output, vx_float32 threshold1, vx_float32 threshold2, vx_int32 aperture_size, vx_bool L2_Gradient) +{ + + vx_scalar THRESH1 = vxCreateScalar(vxGetContext((vx_reference)graph), VX_TYPE_FLOAT32, &threshold1); + vx_scalar THRESH2 = vxCreateScalar(vxGetContext((vx_reference)graph), VX_TYPE_FLOAT32, &threshold2); + vx_scalar A_SIZE = vxCreateScalar(vxGetContext((vx_reference)graph), VX_TYPE_INT32, &aperture_size); + vx_scalar L2_GRA = vxCreateScalar(vxGetContext((vx_reference)graph), VX_TYPE_BOOL, &L2_Gradient); + + vx_reference params[] = { + (vx_reference)input, + (vx_reference)output, + (vx_reference)THRESH1, + (vx_reference)THRESH2, + (vx_reference)A_SIZE, + (vx_reference)L2_GRA, + + }; + + return vxCreateNodeByStructure(graph, + VX_KERNEL_EXT_CV_CANNY, + params, + dimof(params)); + +} + +/************************************************************************************************************ +cornerMinEigenVal C Function +*************************************************************************************************************/ +VX_API_ENTRY vx_node VX_API_CALL vxExtCvNode_cornerMinEigenVal(vx_graph graph, vx_image input, vx_image output, vx_uint32 blockSize, vx_uint32 ksize, vx_int32 border){ + + vx_scalar BlockSize = vxCreateScalar(vxGetContext((vx_reference)graph), VX_TYPE_UINT32, &blockSize); + vx_scalar KSIZE = vxCreateScalar(vxGetContext((vx_reference)graph), VX_TYPE_UINT32, &ksize); + vx_scalar BORDER = vxCreateScalar(vxGetContext((vx_reference)graph), VX_TYPE_INT32, &border); + + vx_reference params[] = { + (vx_reference)input, + (vx_reference)output, + (vx_reference)BlockSize, + (vx_reference)KSIZE, + (vx_reference)BORDER, + }; + + return vxCreateNodeByStructure(graph, + VX_KERNEL_EXT_CV_CORNER_MIN_EIGEN_VAL, + params, + dimof(params)); + +} + +/************************************************************************************************************ +cornerHarris C Function +*************************************************************************************************************/ +VX_API_ENTRY vx_node VX_API_CALL vxExtCvNode_cornerHarris(vx_graph graph, vx_image input, vx_image output, vx_int32 blocksize, vx_int32 ksize, vx_float32 k, vx_int32 border){ + + vx_scalar Blocksize = vxCreateScalar(vxGetContext((vx_reference)graph), VX_TYPE_INT32, &blocksize); + vx_scalar KSIZE = vxCreateScalar(vxGetContext((vx_reference)graph), VX_TYPE_INT32, &ksize); + vx_scalar K = vxCreateScalar(vxGetContext((vx_reference)graph), VX_TYPE_FLOAT32, &k); + vx_scalar BORDER = vxCreateScalar(vxGetContext((vx_reference)graph), VX_TYPE_INT32, &border); + + vx_reference params[] = { + (vx_reference)input, + (vx_reference)output, + (vx_reference)Blocksize, + (vx_reference)KSIZE, + (vx_reference)K, + (vx_reference)BORDER, + }; + + return vxCreateNodeByStructure(graph, + VX_KERNEL_EXT_CV_CORNERHARRIS, + params, + dimof(params)); + +} + +/************************************************************************************************************ +Laplacian C Function +*************************************************************************************************************/ +VX_API_ENTRY vx_node VX_API_CALL vxExtCvNode_Laplacian(vx_graph graph, vx_image input, vx_image output, vx_uint32 ddepth, vx_uint32 ksize, vx_float32 scale, vx_float32 delta, vx_int32 border_mode) +{ + + vx_scalar DDEPTH = vxCreateScalar(vxGetContext((vx_reference)graph), VX_TYPE_INT32, &ddepth); + vx_scalar KSIZE = vxCreateScalar(vxGetContext((vx_reference)graph), VX_TYPE_INT32, &ksize); + vx_scalar SCALE = vxCreateScalar(vxGetContext((vx_reference)graph), VX_TYPE_FLOAT32, &scale); + vx_scalar DELTA = vxCreateScalar(vxGetContext((vx_reference)graph), VX_TYPE_FLOAT32, &delta); + vx_scalar BORDER = vxCreateScalar(vxGetContext((vx_reference)graph), VX_TYPE_INT32, &border_mode); + + vx_reference params[] = { + (vx_reference)input, + (vx_reference)output, + (vx_reference)DDEPTH, + (vx_reference)KSIZE, + (vx_reference)SCALE, + (vx_reference)DELTA, + (vx_reference)BORDER, + }; + + return vxCreateNodeByStructure(graph, + VX_KERNEL_EXT_CV_LAPLACIAN, + params, + dimof(params)); + +} + +/************************************************************************************************************ +Scharr C function. +*************************************************************************************************************/ +VX_API_ENTRY vx_node VX_API_CALL vxExtCvNode_Scharr(vx_graph graph, vx_image input, vx_image output, vx_int32 ddepth, vx_int32 dx, vx_int32 dy, vx_float32 scale, vx_float32 delta, vx_int32 bordertype) +{ + + vx_scalar DDEPTH = vxCreateScalar(vxGetContext((vx_reference)graph), VX_TYPE_INT32, &ddepth); + vx_scalar DX = vxCreateScalar(vxGetContext((vx_reference)graph), VX_TYPE_INT32, &dx); + vx_scalar DY = vxCreateScalar(vxGetContext((vx_reference)graph), VX_TYPE_INT32, &dy); + vx_scalar SCALE = vxCreateScalar(vxGetContext((vx_reference)graph), VX_TYPE_FLOAT32, &scale); + vx_scalar DELTA = vxCreateScalar(vxGetContext((vx_reference)graph), VX_TYPE_FLOAT32, &delta); + vx_scalar BORDER = vxCreateScalar(vxGetContext((vx_reference)graph), VX_TYPE_INT32, &bordertype); + + vx_reference params[] = { + (vx_reference)input, + (vx_reference)output, + (vx_reference)DDEPTH, + (vx_reference)DX, + (vx_reference)DY, + (vx_reference)SCALE, + (vx_reference)DELTA, + (vx_reference)BORDER, + }; + + return vxCreateNodeByStructure(graph, + VX_KERNEL_EXT_CV_SCHARR, + params, + dimof(params)); + +} + +/*!*********************************************************************************************************** +SIFT Detector C function Call. +*************************************************************************************************************/ +VX_API_ENTRY vx_node VX_API_CALL vxExtCvNode_SIFTdetect(vx_graph graph, vx_image input, vx_image mask, vx_array output_kp, + vx_int32 nfeatures, vx_int32 nOctaveLayers, vx_float32 contrastThreshold, vx_float32 edgeThreshold, vx_float32 sigma) +{ + + vx_scalar NFEATURES = vxCreateScalar(vxGetContext((vx_reference)graph), VX_TYPE_INT32, &nfeatures); + vx_scalar N_O_LAYERS = vxCreateScalar(vxGetContext((vx_reference)graph), VX_TYPE_INT32, &nOctaveLayers); + vx_scalar C_THRESHOLD = vxCreateScalar(vxGetContext((vx_reference)graph), VX_TYPE_FLOAT32, &contrastThreshold); + vx_scalar EDGETHRESHOLD = vxCreateScalar(vxGetContext((vx_reference)graph), VX_TYPE_FLOAT32, &edgeThreshold); + vx_scalar SIGMA = vxCreateScalar(vxGetContext((vx_reference)graph), VX_TYPE_FLOAT32, &sigma); + + vx_reference params[] = { + (vx_reference)input, + (vx_reference)mask, + (vx_reference)output_kp, + (vx_reference)NFEATURES, + (vx_reference)N_O_LAYERS, + (vx_reference)C_THRESHOLD, + (vx_reference)EDGETHRESHOLD, + (vx_reference)SIGMA, + + }; + + return vxCreateNodeByStructure(graph, + VX_KERNEL_EXT_CV_SIFT_DETECT, + params, + dimof(params)); + +} + +/*!*********************************************************************************************************** +SURF function C call inside a graph +*************************************************************************************************************/ +VX_API_ENTRY vx_node VX_API_CALL vxExtCvNode_SURFdetect(vx_graph graph, vx_image input, vx_image mask, vx_array output_kp, vx_array output_des, + vx_float32 hessianThreshold, vx_int32 nOctaves, vx_int32 nOctaveLayers) +{ + + vx_scalar H_THRESHOLD = vxCreateScalar(vxGetContext((vx_reference)graph), VX_TYPE_FLOAT32, &hessianThreshold); + vx_scalar NFEATURES = vxCreateScalar(vxGetContext((vx_reference)graph), VX_TYPE_INT32, &nOctaves); + vx_scalar N_O_LAYERS = vxCreateScalar(vxGetContext((vx_reference)graph), VX_TYPE_INT32, &nOctaveLayers); + + vx_reference params[] = { + (vx_reference)input, + (vx_reference)mask, + (vx_reference)output_kp, + (vx_reference)H_THRESHOLD, + (vx_reference)NFEATURES, + (vx_reference)N_O_LAYERS, + + }; + + return vxCreateNodeByStructure(graph, + VX_KERNEL_EXT_CV_SURF_DETECT, + params, + dimof(params)); + +} + +/*!*********************************************************************************************************** +SIFT_Compute C call inside a graph +*************************************************************************************************************/ +VX_API_ENTRY vx_node VX_API_CALL vxExtCvNode_SIFTcompute(vx_graph graph, vx_image input, vx_image mask, vx_array output_kp, vx_array output_des, + vx_int32 nfeatures, vx_int32 nOctaveLayers, vx_float32 contrastThreshold, vx_float32 edgeThreshold, vx_float32 sigma) +{ + + vx_scalar NFEATURES = vxCreateScalar(vxGetContext((vx_reference)graph), VX_TYPE_INT32, &nfeatures); + vx_scalar N_O_LAYERS = vxCreateScalar(vxGetContext((vx_reference)graph), VX_TYPE_INT32, &nOctaveLayers); + vx_scalar C_THRESHOLD = vxCreateScalar(vxGetContext((vx_reference)graph), VX_TYPE_FLOAT32, &contrastThreshold); + vx_scalar EDGETHRESHOLD = vxCreateScalar(vxGetContext((vx_reference)graph), VX_TYPE_FLOAT32, &edgeThreshold); + vx_scalar SIGMA = vxCreateScalar(vxGetContext((vx_reference)graph), VX_TYPE_FLOAT32, &sigma); + + vx_reference params[] = { + (vx_reference)input, + (vx_reference)mask, + (vx_reference)output_kp, + (vx_reference)output_des, + (vx_reference)NFEATURES, + (vx_reference)N_O_LAYERS, + (vx_reference)C_THRESHOLD, + (vx_reference)EDGETHRESHOLD, + (vx_reference)SIGMA, + + }; + + return vxCreateNodeByStructure(graph, + VX_KERNEL_EXT_CV_SIFT_COMPUTE, + params, + dimof(params)); + +} + +/*!*********************************************************************************************************** +SURF_Compute function C call inside a graph +*************************************************************************************************************/ +VX_API_ENTRY vx_node VX_API_CALL vxExtCvNode_SURFcompute(vx_graph graph, vx_image input, vx_image mask, vx_array output_kp, vx_array output_des, + vx_float32 hessianThreshold, vx_int32 nOctaves, vx_int32 nOctaveLayers, vx_bool extended, vx_bool upright) +{ + + vx_scalar H_THRESHOLD = vxCreateScalar(vxGetContext((vx_reference)graph), VX_TYPE_FLOAT32, &hessianThreshold); + vx_scalar NFEATURES = vxCreateScalar(vxGetContext((vx_reference)graph), VX_TYPE_INT32, &nOctaves); + vx_scalar N_O_LAYERS = vxCreateScalar(vxGetContext((vx_reference)graph), VX_TYPE_INT32, &nOctaveLayers); + vx_scalar EXTENDED = vxCreateScalar(vxGetContext((vx_reference)graph), VX_TYPE_BOOL, &extended); + vx_scalar UPRIGHT = vxCreateScalar(vxGetContext((vx_reference)graph), VX_TYPE_BOOL, &upright); + + vx_reference params[] = { + (vx_reference)input, + (vx_reference)mask, + (vx_reference)output_kp, + (vx_reference)output_des, + (vx_reference)H_THRESHOLD, + (vx_reference)NFEATURES, + (vx_reference)N_O_LAYERS, + (vx_reference)EXTENDED, + (vx_reference)UPRIGHT, + + }; + + return vxCreateNodeByStructure(graph, + VX_KERNEL_EXT_CV_SURF_COMPUTE, + params, + dimof(params)); + +} + +/*!*********************************************************************************************************** +FAST Feature Detector OpenVX C function Call +*************************************************************************************************************/ +VX_API_ENTRY vx_node VX_API_CALL vxExtCvNode_FAST(vx_graph graph, vx_image input, vx_array output_kp, vx_int32 threshold, vx_bool nonmaxSuppression) +{ + + vx_scalar THRESHOLD = vxCreateScalar(vxGetContext((vx_reference)graph), VX_TYPE_FLOAT32, &threshold); + vx_scalar NONMAX = vxCreateScalar(vxGetContext((vx_reference)graph), VX_TYPE_BOOL, &nonmaxSuppression); + + vx_reference params[] = { + (vx_reference)input, + (vx_reference)output_kp, + (vx_reference)THRESHOLD, + (vx_reference)NONMAX, + + }; + + return vxCreateNodeByStructure(graph, + VX_KERNEL_EXT_CV_FAST, + params, + dimof(params)); + +} + +/*!*********************************************************************************************************** +Good Features To Track C function Call +*************************************************************************************************************/ +VX_API_ENTRY vx_node VX_API_CALL vxExtCvNode_goodFeaturesToTrack(vx_graph graph, vx_image input, vx_array output_kp, + vx_int32 maxCorners, vx_float32 qualityLevel, vx_float32 minDistance, vx_image mask, vx_int32 blockSize, vx_bool useHarrisDetector, vx_float32 k) +{ + + vx_scalar MAXCORNERS = vxCreateScalar(vxGetContext((vx_reference)graph), VX_TYPE_INT32, &maxCorners); + vx_scalar QUALITY_LEVEL = vxCreateScalar(vxGetContext((vx_reference)graph), VX_TYPE_FLOAT32, &qualityLevel); + vx_scalar MIN_DIS = vxCreateScalar(vxGetContext((vx_reference)graph), VX_TYPE_FLOAT32, &minDistance); + vx_scalar BLOCK_SIZE = vxCreateScalar(vxGetContext((vx_reference)graph), VX_TYPE_INT32, &blockSize); + vx_scalar HARRIS = vxCreateScalar(vxGetContext((vx_reference)graph), VX_TYPE_BOOL, &useHarrisDetector); + vx_scalar K = vxCreateScalar(vxGetContext((vx_reference)graph), VX_TYPE_FLOAT32, &k); + + vx_reference params[] = { + (vx_reference)input, + (vx_reference)output_kp, + (vx_reference)MAXCORNERS, + (vx_reference)QUALITY_LEVEL, + (vx_reference)MIN_DIS, + (vx_reference)mask, + (vx_reference)BLOCK_SIZE, + (vx_reference)HARRIS, + (vx_reference)K, + + }; + + return vxCreateNodeByStructure(graph, + VX_KERNEL_EXT_CV_GOOD_FEATURE_TO_TRACK, + params, + dimof(params)); + +} + +/*!*********************************************************************************************************** +Brisk Detector C function call. +**************************************************************************************************************/ +VX_API_ENTRY vx_node VX_API_CALL vxExtCvNode_BRISKdetect(vx_graph graph, vx_image input, vx_image mask, vx_array output_kp, + vx_int32 thresh, vx_int32 octaves, vx_float32 patternScale) +{ + + vx_scalar THRESH = vxCreateScalar(vxGetContext((vx_reference)graph), VX_TYPE_INT32, &thresh); + vx_scalar OCTAVES = vxCreateScalar(vxGetContext((vx_reference)graph), VX_TYPE_INT32, &octaves); + vx_scalar PATTERNSCALE = vxCreateScalar(vxGetContext((vx_reference)graph), VX_TYPE_FLOAT32, &patternScale); + + vx_reference params[] = { + + (vx_reference)input, + (vx_reference)mask, + (vx_reference)output_kp, + (vx_reference)THRESH, + (vx_reference)OCTAVES, + (vx_reference)PATTERNSCALE, + + }; + + return vxCreateNodeByStructure(graph, + VX_KERNEL_EXT_CV_BRISK_DETECT, + params, + dimof(params)); + +} + +/*!*********************************************************************************************************** +MSER feature detector C function call +*************************************************************************************************************/ +VX_API_ENTRY vx_node VX_API_CALL vxExtCvNode_MSERdetect(vx_graph graph, vx_image input, vx_array output_kp, vx_image mask, + vx_int32 delta, vx_int32 min_area, vx_int32 max_area, vx_float32 max_variation, vx_float32 min_diversity, vx_int32 max_evolution, vx_float32 area_threshold, vx_float32 min_margin, vx_int32 edge_blur_size) +{ + + vx_scalar DELTA = vxCreateScalar(vxGetContext((vx_reference)graph), VX_TYPE_INT32, &delta); + vx_scalar MIN_AERA = vxCreateScalar(vxGetContext((vx_reference)graph), VX_TYPE_INT32, &min_area); + vx_scalar MAX_AREA = vxCreateScalar(vxGetContext((vx_reference)graph), VX_TYPE_INT32, &max_area); + vx_scalar MAX_EVO = vxCreateScalar(vxGetContext((vx_reference)graph), VX_TYPE_INT32, &max_evolution); + vx_scalar EDGE_BLUR = vxCreateScalar(vxGetContext((vx_reference)graph), VX_TYPE_INT32, &edge_blur_size); + + vx_scalar MAX_VAR = vxCreateScalar(vxGetContext((vx_reference)graph), VX_TYPE_FLOAT32, &max_variation); + vx_scalar MIN_DIV = vxCreateScalar(vxGetContext((vx_reference)graph), VX_TYPE_FLOAT32, &min_diversity); + vx_scalar AREA_THRESH = vxCreateScalar(vxGetContext((vx_reference)graph), VX_TYPE_FLOAT32, &area_threshold); + vx_scalar MIN_MAR = vxCreateScalar(vxGetContext((vx_reference)graph), VX_TYPE_FLOAT32, &min_margin); + + vx_reference params[] = { + (vx_reference)input, + (vx_reference)output_kp, + (vx_reference)mask, + (vx_reference)DELTA, + (vx_reference)MIN_AERA, + (vx_reference)MAX_AREA, + (vx_reference)MAX_VAR, + (vx_reference)MIN_DIV, + (vx_reference)MAX_EVO, + (vx_reference)AREA_THRESH, + (vx_reference)MIN_MAR, + (vx_reference)EDGE_BLUR, + }; + + return vxCreateNodeByStructure(graph, + VX_KERNEL_EXT_CV_MSER_DETECT, + params, + dimof(params)); + +} + +/*!*********************************************************************************************************** +ORB function C call inside a graph +*************************************************************************************************************/ +VX_API_ENTRY vx_node VX_API_CALL vxExtCvNode_ORBdetect(vx_graph graph, vx_image input, vx_image mask, vx_array output_kp, + vx_int32 nfeatures, vx_float32 scaleFactor, vx_int32 nlevels, vx_int32 edgeThreshold, vx_int32 firstLevel, vx_int32 WTA_K, vx_int32 scoreType, vx_int32 patchSize) +{ + + vx_scalar Nfeatures = vxCreateScalar(vxGetContext((vx_reference)graph), VX_TYPE_INT32, &nfeatures); + vx_scalar SCALE_FAC = vxCreateScalar(vxGetContext((vx_reference)graph), VX_TYPE_FLOAT32, &scaleFactor); + vx_scalar NLEVELS = vxCreateScalar(vxGetContext((vx_reference)graph), VX_TYPE_INT32, &nlevels); + vx_scalar EDGE_THRE = vxCreateScalar(vxGetContext((vx_reference)graph), VX_TYPE_INT32, &edgeThreshold); + vx_scalar FIRST_LEVEL = vxCreateScalar(vxGetContext((vx_reference)graph), VX_TYPE_INT32, &firstLevel); + vx_scalar WTA = vxCreateScalar(vxGetContext((vx_reference)graph), VX_TYPE_INT32, &WTA_K); + vx_scalar SCORE_TYPE = vxCreateScalar(vxGetContext((vx_reference)graph), VX_TYPE_INT32, &scoreType); + vx_scalar PATCH_SIZE = vxCreateScalar(vxGetContext((vx_reference)graph), VX_TYPE_INT32, &patchSize); + + vx_reference params[] = { + (vx_reference)input, + (vx_reference)mask, + (vx_reference)output_kp, + (vx_reference)Nfeatures, + (vx_reference)SCALE_FAC, + (vx_reference)NLEVELS, + (vx_reference)EDGE_THRE, + (vx_reference)FIRST_LEVEL, + (vx_reference)WTA, + (vx_reference)SCORE_TYPE, + (vx_reference)PATCH_SIZE, + + }; + + return vxCreateNodeByStructure(graph, + VX_KERNEL_EXT_CV_ORB_DETECT, + params, + dimof(params)); + +} + + + +/*!*********************************************************************************************************** +Star feature detector C function call +*************************************************************************************************************/ +VX_API_ENTRY vx_node VX_API_CALL vxExtCvNode_StarFeatureDetector(vx_graph graph, vx_image input, vx_array output_kp, vx_image mask, vx_int32 maxSize, vx_int32 responseThreshold, vx_int32 lineThresholdProjected, vx_int32 lineThresholdBinarized, vx_int32 suppressNonmaxSize){ + + vx_scalar MaxSize = vxCreateScalar(vxGetContext((vx_reference)graph), VX_TYPE_INT32, &maxSize); + vx_scalar ResponseThreshold = vxCreateScalar(vxGetContext((vx_reference)graph), VX_TYPE_INT32, &responseThreshold); + vx_scalar LineThresholdProjected = vxCreateScalar(vxGetContext((vx_reference)graph), VX_TYPE_INT32, &lineThresholdProjected); + vx_scalar LineThresholdBinarized = vxCreateScalar(vxGetContext((vx_reference)graph), VX_TYPE_INT32, &lineThresholdBinarized); + vx_scalar SuppressNonmaxSize = vxCreateScalar(vxGetContext((vx_reference)graph), VX_TYPE_INT32, &suppressNonmaxSize); + + + vx_reference params[] = { + (vx_reference)input, + (vx_reference)output_kp, + (vx_reference)mask, + (vx_reference)MaxSize, + (vx_reference)ResponseThreshold, + (vx_reference)LineThresholdProjected, + (vx_reference)LineThresholdBinarized, + (vx_reference)SuppressNonmaxSize, + }; + + return vxCreateNodeByStructure(graph, + VX_KERNEL_EXT_CV_STAR_FEATURE_DETECT, + params, + dimof(params)); +} + +/*!*********************************************************************************************************** +SIMPLE BLOB feature detector C function call +*************************************************************************************************************/ +VX_API_ENTRY vx_node VX_API_CALL vxExtCvNode_SimpleBlobDetector(vx_graph graph, vx_image input, vx_array output_kp, vx_image mask) +{ + + vx_reference params[] = { + (vx_reference)input, + (vx_reference)output_kp, + (vx_reference)mask, + + }; + + return vxCreateNodeByStructure(graph, + VX_KERNEL_EXT_CV_SIMPLE_BLOB_DETECT, + params, + dimof(params)); + +} + +/*!*********************************************************************************************************** +Brisk Compute C function call. +*************************************************************************************************************/ +VX_API_ENTRY vx_node VX_API_CALL vxExtCvNode_BRISKcompute(vx_graph graph, vx_image input, vx_image mask, vx_array output_kp, vx_array output_des, + vx_int32 thresh, vx_int32 octaves, vx_float32 patternScale) +{ + + vx_scalar THRESH = vxCreateScalar(vxGetContext((vx_reference)graph), VX_TYPE_INT32, &thresh); + vx_scalar OCTAVES = vxCreateScalar(vxGetContext((vx_reference)graph), VX_TYPE_FLOAT32, &octaves); + vx_scalar PATTERN_SCALE = vxCreateScalar(vxGetContext((vx_reference)graph), VX_TYPE_FLOAT32, &patternScale); + + vx_reference params[] = { + (vx_reference)input, + (vx_reference)mask, + + (vx_reference)output_kp, + (vx_reference)output_des, + + (vx_reference)THRESH, + (vx_reference)OCTAVES, + (vx_reference)PATTERN_SCALE, + + }; + + return vxCreateNodeByStructure(graph, + VX_KERNEL_EXT_CV_BRISK_COMPUTE, + params, + dimof(params)); + +} + +/*!*********************************************************************************************************** +ORB function C call inside a graph +*************************************************************************************************************/ +VX_API_ENTRY vx_node VX_API_CALL vxExtCvNode_ORBcompute(vx_graph graph, vx_image input, vx_image mask, vx_array output_kp, vx_array output_des, + vx_int32 nfeatures, vx_float32 scaleFactor, vx_int32 nlevels, vx_int32 edgeThreshold, vx_int32 firstLevel, vx_int32 WTA_K, vx_int32 scoreType, vx_int32 patchSize) +{ + + vx_scalar Nfeatures = vxCreateScalar(vxGetContext((vx_reference)graph), VX_TYPE_INT32, &nfeatures); + vx_scalar SCALE_FAC = vxCreateScalar(vxGetContext((vx_reference)graph), VX_TYPE_FLOAT32, &scaleFactor); + vx_scalar NLEVELS = vxCreateScalar(vxGetContext((vx_reference)graph), VX_TYPE_INT32, &nlevels); + vx_scalar EDGE_THRE = vxCreateScalar(vxGetContext((vx_reference)graph), VX_TYPE_INT32, &edgeThreshold); + vx_scalar FIRST_LEVEL = vxCreateScalar(vxGetContext((vx_reference)graph), VX_TYPE_INT32, &firstLevel); + vx_scalar WTA = vxCreateScalar(vxGetContext((vx_reference)graph), VX_TYPE_INT32, &WTA_K); + vx_scalar SCORE_TYPE = vxCreateScalar(vxGetContext((vx_reference)graph), VX_TYPE_INT32, &scoreType); + vx_scalar PATCH_SIZE = vxCreateScalar(vxGetContext((vx_reference)graph), VX_TYPE_INT32, &patchSize); + + vx_reference params[] = { + (vx_reference)input, + (vx_reference)mask, + (vx_reference)output_kp, + (vx_reference)output_des, + + (vx_reference)Nfeatures, + (vx_reference)SCALE_FAC, + (vx_reference)NLEVELS, + (vx_reference)EDGE_THRE, + (vx_reference)FIRST_LEVEL, + (vx_reference)WTA, + (vx_reference)SCORE_TYPE, + (vx_reference)PATCH_SIZE, + + }; + + return vxCreateNodeByStructure(graph, + VX_KERNEL_EXT_CV_ORB_COMPUTE, + params, + dimof(params)); + +} + + +/************************************************************************************************************ +multiply C Function +*************************************************************************************************************/ +VX_API_ENTRY vx_node VX_API_CALL vxExtCvNode_multiply(vx_graph graph, vx_image input_1, vx_image input_2, vx_image output, vx_float32 scale, vx_int32 dtype) +{ + + vx_scalar SCALE = vxCreateScalar(vxGetContext((vx_reference)graph), VX_TYPE_FLOAT32, &scale); + vx_scalar DTYPE = vxCreateScalar(vxGetContext((vx_reference)graph), VX_TYPE_INT32, &dtype); + + vx_reference params[] = { + (vx_reference)input_1, + (vx_reference)input_2, + (vx_reference)output, + (vx_reference)SCALE, + (vx_reference)DTYPE, + + }; + + return vxCreateNodeByStructure(graph, + VX_KERNEL_EXT_CV_MULTIPLY, + params, + dimof(params)); + +} + +/************************************************************************************************************ +Divide C Function +*************************************************************************************************************/ +VX_API_ENTRY vx_node VX_API_CALL vxExtCvNode_divide(vx_graph graph, vx_image input_1, vx_image input_2, vx_image output, vx_float32 scale, vx_int32 dtype) +{ + + vx_scalar SCALE = vxCreateScalar(vxGetContext((vx_reference)graph), VX_TYPE_FLOAT32, &scale); + vx_scalar DTYPE = vxCreateScalar(vxGetContext((vx_reference)graph), VX_TYPE_INT32, &dtype); + + vx_reference params[] = { + (vx_reference)input_1, + (vx_reference)input_2, + (vx_reference)output, + (vx_reference)SCALE, + (vx_reference)DTYPE, + + }; + + return vxCreateNodeByStructure(graph, + VX_KERNEL_EXT_CV_DIVIDE, + params, + dimof(params)); + +} + +/************************************************************************************************************ +adaptiveThreshold C function. +************************************************************************************************************/ +VX_API_ENTRY vx_node VX_API_CALL vxExtCvNode_adaptiveThreshold(vx_graph graph, vx_image input, vx_image output, vx_float32 maxValue, vx_int32 adaptiveMethod, vx_int32 thresholdType, vx_int32 blockSize, vx_float32 c) +{ + + vx_scalar MAXVALUE = vxCreateScalar(vxGetContext((vx_reference)graph), VX_TYPE_FLOAT32, &maxValue); + vx_scalar A_Method = vxCreateScalar(vxGetContext((vx_reference)graph), VX_TYPE_INT32, &adaptiveMethod); + vx_scalar Thresh_type = vxCreateScalar(vxGetContext((vx_reference)graph), VX_TYPE_INT32, &thresholdType); + vx_scalar BLOCK = vxCreateScalar(vxGetContext((vx_reference)graph), VX_TYPE_INT32, &blockSize); + vx_scalar C = vxCreateScalar(vxGetContext((vx_reference)graph), VX_TYPE_FLOAT32, &c); + + vx_reference params[] = { + (vx_reference)input, + (vx_reference)output, + (vx_reference)MAXVALUE, + (vx_reference)A_Method, + (vx_reference)Thresh_type, + (vx_reference)BLOCK, + (vx_reference)C, + + }; + + return vxCreateNodeByStructure(graph, + VX_KERNEL_EXT_CV_ADAPTIVETHRESHOLD, + params, + dimof(params)); + +} + +/************************************************************************************************************ +distanceTransform C Function +************************************************************************************************************/ +VX_API_ENTRY vx_node VX_API_CALL vxExtCvNode_distanceTransform(vx_graph graph, vx_image input, vx_image output) +{ + + vx_reference params[] = { + + (vx_reference)input, + (vx_reference)output, + + }; + + return vxCreateNodeByStructure(graph, + VX_KERNEL_EXT_CV_DISTANCETRANSFORM, + params, + dimof(params)); + +} + +/************************************************************************************************************ +cvtColor C Function +************************************************************************************************************/ +VX_API_ENTRY vx_node VX_API_CALL vxExtCvNode_cvtColor(vx_graph graph, vx_image input, vx_image output, vx_uint32 CODE) +{ + + vx_scalar code = vxCreateScalar(vxGetContext((vx_reference)graph), VX_TYPE_INT32, &CODE); + + vx_reference params[] = { + (vx_reference)input, + (vx_reference)output, + (vx_reference)code, + + }; + + return vxCreateNodeByStructure(graph, + VX_KERNEL_EXT_CV_CVTCOLOR, + params, + dimof(params)); +} + +/************************************************************************************************************ +threshold C Function +************************************************************************************************************/ +VX_API_ENTRY vx_node VX_API_CALL vxExtCvNode_threshold(vx_graph graph, vx_image input, vx_image output, vx_float32 thresh, vx_float32 maxVal, vx_int32 type) +{ + + vx_scalar Thresh = vxCreateScalar(vxGetContext((vx_reference)graph), VX_TYPE_FLOAT32, &thresh); + vx_scalar MAXVAL = vxCreateScalar(vxGetContext((vx_reference)graph), VX_TYPE_FLOAT32, &maxVal); + vx_scalar TYPE = vxCreateScalar(vxGetContext((vx_reference)graph), VX_TYPE_INT32, &type); + + vx_reference params[] = { + (vx_reference)input, + (vx_reference)output, + (vx_reference)Thresh, + (vx_reference)MAXVAL, + (vx_reference)TYPE, + }; + + return vxCreateNodeByStructure(graph, + VX_KERNEL_EXT_CV_THRESHOLD, + params, + dimof(params)); + +} + +/************************************************************************************************************ +fastNlMeansDenoising C Function +*************************************************************************************************************/ +VX_API_ENTRY vx_node VX_API_CALL vxExtCvNode_fastNlMeansDenoising(vx_graph graph, vx_image input, vx_image output, vx_float32 h, vx_int32 template_ws, vx_int32 search_ws) +{ + + vx_scalar H = vxCreateScalar(vxGetContext((vx_reference)graph), VX_TYPE_FLOAT32, &h); + vx_scalar T = vxCreateScalar(vxGetContext((vx_reference)graph), VX_TYPE_FLOAT32, &template_ws); + vx_scalar S = vxCreateScalar(vxGetContext((vx_reference)graph), VX_TYPE_INT32, &search_ws); + + vx_reference params[] = { + (vx_reference)input, + (vx_reference)output, + (vx_reference)H, + (vx_reference)T, + (vx_reference)S, + }; + + return vxCreateNodeByStructure(graph, + VX_KERNEL_EXT_CV_FAST_NL_MEANS_DENOISING, + params, + dimof(params)); + +} + +/************************************************************************************************************ +fastNlMeansDenoisingColored C Function +*************************************************************************************************************/ +VX_API_ENTRY vx_node VX_API_CALL vxExtCvNode_fastNlMeansDenoisingColored(vx_graph graph, vx_image input, vx_image output, vx_float32 h, vx_float32 h_color, vx_int32 template_ws, vx_int32 search_ws) +{ + + vx_scalar H = vxCreateScalar(vxGetContext((vx_reference)graph), VX_TYPE_FLOAT32, &h); + vx_scalar H_C = vxCreateScalar(vxGetContext((vx_reference)graph), VX_TYPE_FLOAT32, &h_color); + vx_scalar T = vxCreateScalar(vxGetContext((vx_reference)graph), VX_TYPE_FLOAT32, &template_ws); + vx_scalar S = vxCreateScalar(vxGetContext((vx_reference)graph), VX_TYPE_INT32, &search_ws); + + vx_reference params[] = { + (vx_reference)input, + (vx_reference)output, + (vx_reference)H, + (vx_reference)H_C, + (vx_reference)T, + (vx_reference)S, + }; + + return vxCreateNodeByStructure(graph, + VX_KERNEL_EXT_CV_FAST_NL_MEANS_DENOISING_COLORED, + params, + dimof(params)); + +} + +/************************************************************************************************************ +pyrup C Function +*************************************************************************************************************/ +VX_API_ENTRY vx_node VX_API_CALL vxExtCvNode_pyrup(vx_graph graph, vx_image input, vx_image output, vx_uint32 Swidth, vx_uint32 Sheight, vx_int32 bordertype) +{ + + vx_scalar W = vxCreateScalar(vxGetContext((vx_reference)graph), VX_TYPE_INT32, &Swidth); + vx_scalar H = vxCreateScalar(vxGetContext((vx_reference)graph), VX_TYPE_INT32, &Sheight); + vx_scalar B = vxCreateScalar(vxGetContext((vx_reference)graph), VX_TYPE_INT32, &bordertype); + + vx_reference params[] = { + (vx_reference)input, + (vx_reference)output, + (vx_reference)W, + (vx_reference)H, + (vx_reference)B, + }; + + return vxCreateNodeByStructure(graph, + VX_KERNEL_EXT_CV_PYRUP, + params, + dimof(params)); + +} + +/************************************************************************************************************ +pyrdown C Function +************************************************************************************************************/ +VX_API_ENTRY vx_node VX_API_CALL vxExtCvNode_pyrdown(vx_graph graph, vx_image input, vx_image output, vx_uint32 Swidth, vx_uint32 Sheight, vx_int32 bordertype) +{ + + vx_scalar W = vxCreateScalar(vxGetContext((vx_reference)graph), VX_TYPE_INT32, &Swidth); + vx_scalar H = vxCreateScalar(vxGetContext((vx_reference)graph), VX_TYPE_INT32, &Sheight); + vx_scalar B = vxCreateScalar(vxGetContext((vx_reference)graph), VX_TYPE_INT32, &bordertype); + + vx_reference params[] = { + (vx_reference)input, + (vx_reference)output, + (vx_reference)W, + (vx_reference)H, + (vx_reference)B, + }; + + return vxCreateNodeByStructure(graph, + VX_KERNEL_EXT_CV_PYRDOWN, + params, + dimof(params)); + +} + +/************************************************************************************************************ +filter2D C function. +************************************************************************************************************/ +VX_API_ENTRY vx_node VX_API_CALL vxExtCvNode_filter2D(vx_graph graph, vx_image input, vx_image output, vx_int32 ddepth, vx_matrix Kernel, vx_int32 Anchor_X, vx_int32 Anchor_Y, vx_float32 delta, vx_int32 border) +{ + + vx_scalar D = vxCreateScalar(vxGetContext((vx_reference)graph), VX_TYPE_INT32, &ddepth); + vx_scalar X = vxCreateScalar(vxGetContext((vx_reference)graph), VX_TYPE_INT32, &Anchor_X); + vx_scalar Y = vxCreateScalar(vxGetContext((vx_reference)graph), VX_TYPE_INT32, &Anchor_Y); + vx_scalar DELTA = vxCreateScalar(vxGetContext((vx_reference)graph), VX_TYPE_FLOAT32, &delta); + vx_scalar B = vxCreateScalar(vxGetContext((vx_reference)graph), VX_TYPE_INT32, &border); + + vx_reference params[] = { + (vx_reference)input, + (vx_reference)output, + (vx_reference)D, + (vx_reference)Kernel, + (vx_reference)X, + (vx_reference)Y, + (vx_reference)DELTA, + (vx_reference)B, + }; + + return vxCreateNodeByStructure(graph, + VX_KERNEL_EXT_CV_FILTER_2D, + params, + dimof(params)); + +} + +/************************************************************************************************************ +sepFilter2D C function. +************************************************************************************************************/ +VX_API_ENTRY vx_node VX_API_CALL vxExtCvNode_sepFilter2D(vx_graph graph, vx_image input, vx_image output, vx_int32 ddepth, vx_matrix KernelX, vx_matrix KernelY, vx_int32 Anchor_X, vx_int32 Anchor_Y, vx_float32 delta, vx_int32 border) +{ + + vx_scalar D = vxCreateScalar(vxGetContext((vx_reference)graph), VX_TYPE_INT32, &ddepth); + vx_scalar X = vxCreateScalar(vxGetContext((vx_reference)graph), VX_TYPE_INT32, &Anchor_X); + vx_scalar Y = vxCreateScalar(vxGetContext((vx_reference)graph), VX_TYPE_INT32, &Anchor_Y); + vx_scalar DELTA = vxCreateScalar(vxGetContext((vx_reference)graph), VX_TYPE_FLOAT32, &delta); + vx_scalar B = vxCreateScalar(vxGetContext((vx_reference)graph), VX_TYPE_INT32, &border); + + vx_reference params[] = { + (vx_reference)input, + (vx_reference)output, + (vx_reference)D, + (vx_reference)KernelX, + (vx_reference)KernelY, + (vx_reference)X, + (vx_reference)Y, + (vx_reference)DELTA, + (vx_reference)B, + }; + + return vxCreateNodeByStructure(graph, + VX_KERNEL_EXT_CV_SEPFILTER_2D, + params, + dimof(params)); + +} + +/************************************************************************************************************ +Dilate C function. +************************************************************************************************************/ +VX_API_ENTRY vx_node VX_API_CALL vxExtCvNode_Dilate(vx_graph graph, vx_image input, vx_image output, vx_matrix Kernel, vx_int32 Anchor_X, vx_int32 Anchor_Y, vx_int32 iterations, vx_int32 border) +{ + + vx_scalar X = vxCreateScalar(vxGetContext((vx_reference)graph), VX_TYPE_INT32, &Anchor_X); + vx_scalar Y = vxCreateScalar(vxGetContext((vx_reference)graph), VX_TYPE_INT32, &Anchor_Y); + vx_scalar I = vxCreateScalar(vxGetContext((vx_reference)graph), VX_TYPE_INT32, &iterations); + vx_scalar B = vxCreateScalar(vxGetContext((vx_reference)graph), VX_TYPE_INT32, &border); + + vx_reference params[] = { + (vx_reference)input, + (vx_reference)output, + (vx_reference)Kernel, + (vx_reference)X, + (vx_reference)Y, + (vx_reference)I, + (vx_reference)B, + }; + + return vxCreateNodeByStructure(graph, + VX_KERNEL_EXT_CV_DILATE, + params, + dimof(params)); + +} + +/************************************************************************************************************ +Erode C function. +************************************************************************************************************/ +VX_API_ENTRY vx_node VX_API_CALL vxExtCvNode_Erode(vx_graph graph, vx_image input, vx_image output, vx_matrix Kernel, vx_int32 Anchor_X, vx_int32 Anchor_Y, vx_int32 iterations, vx_int32 border) +{ + + vx_scalar X = vxCreateScalar(vxGetContext((vx_reference)graph), VX_TYPE_INT32, &Anchor_X); + vx_scalar Y = vxCreateScalar(vxGetContext((vx_reference)graph), VX_TYPE_INT32, &Anchor_Y); + vx_scalar I = vxCreateScalar(vxGetContext((vx_reference)graph), VX_TYPE_INT32, &iterations); + vx_scalar B = vxCreateScalar(vxGetContext((vx_reference)graph), VX_TYPE_INT32, &border); + + vx_reference params[] = { + (vx_reference)input, + (vx_reference)output, + (vx_reference)Kernel, + (vx_reference)X, + (vx_reference)Y, + (vx_reference)I, + (vx_reference)B, + }; + + return vxCreateNodeByStructure(graph, + VX_KERNEL_EXT_CV_ERODE, + params, + dimof(params)); + +} + +/************************************************************************************************************ +WarpAffine C function. +************************************************************************************************************/ +VX_API_ENTRY vx_node VX_API_CALL vxExtCvNode_warpAffine(vx_graph graph, vx_image input, vx_image output, vx_matrix M, vx_int32 Size_X, vx_int32 Size_Y, vx_int32 flags, vx_int32 border) +{ + + vx_scalar X = vxCreateScalar(vxGetContext((vx_reference)graph), VX_TYPE_INT32, &Size_X); + vx_scalar Y = vxCreateScalar(vxGetContext((vx_reference)graph), VX_TYPE_INT32, &Size_Y); + vx_scalar F = vxCreateScalar(vxGetContext((vx_reference)graph), VX_TYPE_INT32, &flags); + vx_scalar B = vxCreateScalar(vxGetContext((vx_reference)graph), VX_TYPE_INT32, &border); + + vx_reference params[] = { + (vx_reference)input, + (vx_reference)output, + (vx_reference)M, + (vx_reference)X, + (vx_reference)Y, + (vx_reference)F, + (vx_reference)B, + }; + + return vxCreateNodeByStructure(graph, + VX_KERNEL_EXT_CV_WARP_AFFINE, + params, + dimof(params)); + +} + +/************************************************************************************************************ +WarpPerspective C function. +************************************************************************************************************/ +VX_API_ENTRY vx_node VX_API_CALL vxExtCvNode_warpPerspective(vx_graph graph, vx_image input, vx_image output, vx_matrix M, vx_int32 Size_X, vx_int32 Size_Y, vx_int32 flags, vx_int32 border) +{ + + vx_scalar X = vxCreateScalar(vxGetContext((vx_reference)graph), VX_TYPE_INT32, &Size_X); + vx_scalar Y = vxCreateScalar(vxGetContext((vx_reference)graph), VX_TYPE_INT32, &Size_Y); + vx_scalar F = vxCreateScalar(vxGetContext((vx_reference)graph), VX_TYPE_INT32, &flags); + vx_scalar B = vxCreateScalar(vxGetContext((vx_reference)graph), VX_TYPE_INT32, &border); + + vx_reference params[] = { + (vx_reference)input, + (vx_reference)output, + (vx_reference)M, + (vx_reference)X, + (vx_reference)Y, + (vx_reference)F, + (vx_reference)B, + }; + + return vxCreateNodeByStructure(graph, + VX_KERNEL_EXT_CV_WARP_PERSPECTIVE, + params, + dimof(params)); + +} + +/************************************************************************************************************ +Resize C function. +************************************************************************************************************/ +VX_API_ENTRY vx_node VX_API_CALL vxExtCvNode_Resize(vx_graph graph, vx_image input, vx_image output, vx_int32 Size_X, vx_int32 Size_Y, vx_float32 FX, vx_float32 FY, vx_int32 interpolation) +{ + + vx_scalar X = vxCreateScalar(vxGetContext((vx_reference)graph), VX_TYPE_INT32, &Size_X); + vx_scalar Y = vxCreateScalar(vxGetContext((vx_reference)graph), VX_TYPE_INT32, &Size_Y); + vx_scalar Fx = vxCreateScalar(vxGetContext((vx_reference)graph), VX_TYPE_FLOAT32, &FX); + vx_scalar Fy = vxCreateScalar(vxGetContext((vx_reference)graph), VX_TYPE_FLOAT32, &FY); + vx_scalar I = vxCreateScalar(vxGetContext((vx_reference)graph), VX_TYPE_INT32, &interpolation); + + vx_reference params[] = { + (vx_reference)input, + (vx_reference)output, + (vx_reference)X, + (vx_reference)Y, + (vx_reference)Fx, + (vx_reference)Fy, + (vx_reference)I, + }; + + return vxCreateNodeByStructure(graph, + VX_KERNEL_EXT_CV_RESIZE, + params, + dimof(params)); + +} + +/************************************************************************************************************ +morphologyEX C function. +************************************************************************************************************/ +VX_API_ENTRY vx_node VX_API_CALL vxExtCvNode_morphologyEX(vx_graph graph, vx_image input, vx_image output, vx_int32 OP, vx_matrix Kernel, vx_int32 Anchor_X, vx_int32 Anchor_Y, vx_int32 iterations, vx_int32 border) +{ + + vx_scalar op = vxCreateScalar(vxGetContext((vx_reference)graph), VX_TYPE_INT32, &OP); + vx_scalar X = vxCreateScalar(vxGetContext((vx_reference)graph), VX_TYPE_INT32, &Anchor_X); + vx_scalar Y = vxCreateScalar(vxGetContext((vx_reference)graph), VX_TYPE_INT32, &Anchor_Y); + vx_scalar I = vxCreateScalar(vxGetContext((vx_reference)graph), VX_TYPE_INT32, &iterations); + vx_scalar B = vxCreateScalar(vxGetContext((vx_reference)graph), VX_TYPE_INT32, &border); + + vx_reference params[] = { + (vx_reference)input, + (vx_reference)output, + (vx_reference)op, + (vx_reference)Kernel, + (vx_reference)X, + (vx_reference)Y, + (vx_reference)I, + (vx_reference)B, + }; + + return vxCreateNodeByStructure(graph, + VX_KERNEL_EXT_CV_MORPHOLOGYEX, + params, + dimof(params)); + +} + +/************************************************************************************************************ +buildPyramid C Function +************************************************************************************************************/ +VX_API_ENTRY vx_node VX_API_CALL vxExtCvNode_buildPyramid(vx_graph graph, vx_image input, vx_pyramid output, vx_uint32 maxLevel, vx_uint32 border) +{ + + vx_scalar ML = vxCreateScalar(vxGetContext((vx_reference)graph), VX_TYPE_INT32, &maxLevel); + vx_scalar B = vxCreateScalar(vxGetContext((vx_reference)graph), VX_TYPE_INT32, &border); + + vx_reference params[] = { + (vx_reference)input, + (vx_reference)output, + (vx_reference)ML, + (vx_reference)B, + }; + + return vxCreateNodeByStructure(graph, + VX_KERNEL_EXT_CV_BUILD_PYRAMID, + params, + dimof(params)); + +} + +/************************************************************************************************************ +BuildOpticalFlow C Function +*************************************************************************************************************/ +VX_API_ENTRY vx_node VX_API_CALL vxExtCvNode_buildOpticalFlowPyramid(vx_graph graph, vx_image input, vx_pyramid output, vx_uint32 S_width, vx_uint32 S_height, vx_int32 WinSize, vx_bool WithDerivatives, vx_int32 Pyr_border, vx_int32 derviBorder, vx_bool tryReuse) +{ + + vx_scalar W = vxCreateScalar(vxGetContext((vx_reference)graph), VX_TYPE_INT32, &S_width); + vx_scalar H = vxCreateScalar(vxGetContext((vx_reference)graph), VX_TYPE_INT32, &S_height); + vx_scalar Win_Size = vxCreateScalar(vxGetContext((vx_reference)graph), VX_TYPE_INT32, &WinSize); + vx_scalar WITH_DERIVA = vxCreateScalar(vxGetContext((vx_reference)graph), VX_TYPE_BOOL, &WithDerivatives); + vx_scalar P_border = vxCreateScalar(vxGetContext((vx_reference)graph), VX_TYPE_INT32, &Pyr_border); + vx_scalar D_border = vxCreateScalar(vxGetContext((vx_reference)graph), VX_TYPE_INT32, &derviBorder); + vx_scalar Reuse = vxCreateScalar(vxGetContext((vx_reference)graph), VX_TYPE_BOOL, &tryReuse); + + vx_reference params[] = { + (vx_reference)input, + (vx_reference)output, + (vx_reference)W, + (vx_reference)H, + (vx_reference)Win_Size, + (vx_reference)WITH_DERIVA, + (vx_reference)P_border, + (vx_reference)D_border, + (vx_reference)Reuse, + + }; + + return vxCreateNodeByStructure(graph, + VX_KERNEL_EXT_CV_BUILD_OPTICAL_FLOW_PYRAMID, + params, + dimof(params)); + +} \ No newline at end of file diff --git a/vx_ext_cv/OpenCV_absdiff.cpp b/vx_ext_cv/OpenCV_absdiff.cpp new file mode 100644 index 0000000..fec29d8 --- /dev/null +++ b/vx_ext_cv/OpenCV_absdiff.cpp @@ -0,0 +1,160 @@ +/* +Copyright (c) 2015 Advanced Micro Devices, Inc. All rights reserved. + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. +*/ + + +#include"publishkernels.h" + +/************************************************************************************************************ +input parameter validator. +param [in] node The handle to the node. +param [in] index The index of the parameter to validate. +*************************************************************************************************************/ +static vx_status VX_CALLBACK CV_absdiff_InputValidator(vx_node node, vx_uint32 index) +{ + vx_status status = VX_SUCCESS; + vx_parameter param = vxGetParameterByIndex(node, index); + + if (index == 0) + { + vx_image image; + vx_df_image df_image = VX_DF_IMAGE_VIRT; + STATUS_ERROR_CHECK(vxQueryParameter(param, VX_PARAMETER_ATTRIBUTE_REF, &image, sizeof(vx_image))); + STATUS_ERROR_CHECK(vxQueryImage(image, VX_IMAGE_ATTRIBUTE_FORMAT, &df_image, sizeof(df_image))); + if (df_image != VX_DF_IMAGE_U8 && df_image != VX_DF_IMAGE_S16) + status = VX_ERROR_INVALID_VALUE; + vxReleaseImage(&image); + } + + if (index == 1) + { + vx_image image; + vx_df_image df_image = VX_DF_IMAGE_VIRT; + STATUS_ERROR_CHECK(vxQueryParameter(param, VX_PARAMETER_ATTRIBUTE_REF, &image, sizeof(vx_image))); + STATUS_ERROR_CHECK(vxQueryImage(image, VX_IMAGE_ATTRIBUTE_FORMAT, &df_image, sizeof(df_image))); + if (df_image != VX_DF_IMAGE_U8 && df_image != VX_DF_IMAGE_S16) + status = VX_ERROR_INVALID_VALUE; + vxReleaseImage(&image); + } + + else if (index == 2) + { + vx_image image; + vx_df_image df_image = 0; + STATUS_ERROR_CHECK(vxQueryParameter(param, VX_PARAMETER_ATTRIBUTE_REF, &image, sizeof(vx_image))); + STATUS_ERROR_CHECK(vxQueryImage(image, VX_IMAGE_ATTRIBUTE_FORMAT, &df_image, sizeof(df_image))); + if (df_image != VX_DF_IMAGE_U8 && df_image != VX_DF_IMAGE_S16) + status = VX_ERROR_INVALID_VALUE; + vxReleaseImage(&image); + } + + vxReleaseParameter(¶m); + return status; +} + +/************************************************************************************************************ +output parameter validator. +*************************************************************************************************************/ +static vx_status VX_CALLBACK CV_absdiff_OutputValidator(vx_node node, vx_uint32 index, vx_meta_format meta) +{ + vx_status status = VX_SUCCESS; + if (index == 2) + { + vx_parameter output_param = vxGetParameterByIndex(node, 2); + vx_image output; vx_uint32 width = 0, height = 0; vx_df_image format = VX_DF_IMAGE_VIRT; + + STATUS_ERROR_CHECK(vxQueryParameter(output_param, VX_PARAMETER_ATTRIBUTE_REF, &output, sizeof(vx_image))); + STATUS_ERROR_CHECK(vxQueryImage(output, VX_IMAGE_ATTRIBUTE_FORMAT, &format, sizeof(format))); + STATUS_ERROR_CHECK(vxQueryImage(output, VX_IMAGE_ATTRIBUTE_WIDTH, &width, sizeof(width))); + STATUS_ERROR_CHECK(vxQueryImage(output, VX_IMAGE_ATTRIBUTE_HEIGHT, &height, sizeof(height))); + + if (format != VX_DF_IMAGE_U8 && format != VX_DF_IMAGE_S16) + status = VX_ERROR_INVALID_VALUE; + + STATUS_ERROR_CHECK(vxSetMetaFormatAttribute(meta, VX_IMAGE_ATTRIBUTE_WIDTH, &width, sizeof(width))); + STATUS_ERROR_CHECK(vxSetMetaFormatAttribute(meta, VX_IMAGE_ATTRIBUTE_HEIGHT, &height, sizeof(height))); + STATUS_ERROR_CHECK(vxSetMetaFormatAttribute(meta, VX_IMAGE_ATTRIBUTE_FORMAT, &format, sizeof(format))); + + vxReleaseImage(&output); + vxReleaseParameter(&output_param); + } + return status; +} + +/************************************************************************************************************ +Execution Kernel +*************************************************************************************************************/ +static vx_status VX_CALLBACK CV_absdiff_Kernel(vx_node node, const vx_reference *parameters, vx_uint32 num) +{ + vx_status status = VX_SUCCESS; + + vx_image image_1 = (vx_image) parameters[0]; + vx_image image_2 = (vx_image) parameters[1]; + vx_image image_out = (vx_image) parameters[2]; + Mat *mat_1, *mat_2, bl; + + //Converting VX Images to OpenCV Mat + STATUS_ERROR_CHECK(match_vx_image_parameters(image_1, image_2)); + STATUS_ERROR_CHECK(match_vx_image_parameters(image_1, image_out)); + STATUS_ERROR_CHECK(VX_to_CV_Image(&mat_1, image_1)); + STATUS_ERROR_CHECK(VX_to_CV_Image(&mat_2, image_2)); + + //Compute using OpenCV + cv::absdiff(*mat_1, *mat_2, bl); + + //Converting OpenCV Mat into VX Image + STATUS_ERROR_CHECK(CV_to_VX_Image(image_out, &bl)); + + return status; +} + + +/************************************************************************************************************ +Function to Register the Kernel for Publish +*************************************************************************************************************/ +vx_status CV_absdiff_Register(vx_context context) +{ + vx_status status = VX_SUCCESS; + vx_kernel kernel = vxAddKernel(context, + "org.opencv.absdiff", + VX_KERNEL_EXT_CV_ABSDIFF, + CV_absdiff_Kernel, + 3, + CV_absdiff_InputValidator, + CV_absdiff_OutputValidator, + nullptr, + nullptr); + + if (kernel) + { + PARAM_ERROR_CHECK(vxAddParameterToKernel(kernel, 0, VX_INPUT, VX_TYPE_IMAGE, VX_PARAMETER_STATE_REQUIRED)); + PARAM_ERROR_CHECK(vxAddParameterToKernel(kernel, 1, VX_INPUT, VX_TYPE_IMAGE, VX_PARAMETER_STATE_REQUIRED)); + PARAM_ERROR_CHECK(vxAddParameterToKernel(kernel, 2, VX_OUTPUT, VX_TYPE_IMAGE, VX_PARAMETER_STATE_REQUIRED)); + PARAM_ERROR_CHECK(vxFinalizeKernel(kernel)); + } + + if (status != VX_SUCCESS) + { + exit: vxRemoveKernel(kernel); return VX_FAILURE; + } + + return status; +} \ No newline at end of file diff --git a/vx_ext_cv/OpenCV_adaptiveThreshold.cpp b/vx_ext_cv/OpenCV_adaptiveThreshold.cpp new file mode 100644 index 0000000..3a2e19e --- /dev/null +++ b/vx_ext_cv/OpenCV_adaptiveThreshold.cpp @@ -0,0 +1,219 @@ +/* +Copyright (c) 2015 Advanced Micro Devices, Inc. All rights reserved. + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. +*/ + + +#include"publishkernels.h" + +/************************************************************************************************************ +input parameter validator. +param [in] node The handle to the node. +param [in] index The index of the parameter to validate. +*************************************************************************************************************/ +vx_status VX_CALLBACK CV_adaptiveThreshold_InputValidator(vx_node node, vx_uint32 index) +{ + vx_status status = VX_SUCCESS; + vx_parameter param = vxGetParameterByIndex(node, index); + + if (index == 0) + { + vx_image image; vx_df_image df_image = VX_DF_IMAGE_VIRT; + STATUS_ERROR_CHECK(vxQueryParameter(param, VX_PARAMETER_ATTRIBUTE_REF, &image, sizeof(vx_image))); + STATUS_ERROR_CHECK(vxQueryImage(image, VX_IMAGE_ATTRIBUTE_FORMAT, &df_image, sizeof(df_image))); + if (df_image != VX_DF_IMAGE_U8) + status = VX_ERROR_INVALID_VALUE; + vxReleaseImage(&image); + } + + else if (index == 1) + { + vx_image image; vx_df_image df_image = VX_DF_IMAGE_VIRT; + STATUS_ERROR_CHECK(vxQueryParameter(param, VX_PARAMETER_ATTRIBUTE_REF, &image, sizeof(vx_image))); + STATUS_ERROR_CHECK(vxQueryImage(image, VX_IMAGE_ATTRIBUTE_FORMAT, &df_image, sizeof(df_image))); + if (df_image != VX_DF_IMAGE_U8) + status = VX_ERROR_INVALID_VALUE; + vxReleaseImage(&image); + } + + else if (index == 2) + { + vx_scalar scalar = 0; vx_enum type = 0; vx_float32 value = 0; + STATUS_ERROR_CHECK(vxQueryParameter(param, VX_PARAMETER_ATTRIBUTE_REF, &scalar, sizeof(scalar))); + STATUS_ERROR_CHECK(vxQueryScalar(scalar, VX_SCALAR_ATTRIBUTE_TYPE, &type, sizeof(type))); + STATUS_ERROR_CHECK(vxReadScalarValue(scalar, &value)); + if (value < 0 || type != VX_TYPE_FLOAT32) + status = VX_ERROR_INVALID_VALUE; + vxReleaseScalar(&scalar); + } + + else if (index == 3) + { + vx_scalar scalar = 0; vx_enum type = 0; vx_int32 value = 0; + STATUS_ERROR_CHECK(vxQueryParameter(param, VX_PARAMETER_ATTRIBUTE_REF, &scalar, sizeof(scalar))); + STATUS_ERROR_CHECK(vxQueryScalar(scalar, VX_SCALAR_ATTRIBUTE_TYPE, &type, sizeof(type))); + STATUS_ERROR_CHECK(vxReadScalarValue(scalar, &value)); + if (value < 0 || type != VX_TYPE_INT32) + status = VX_ERROR_INVALID_VALUE; + vxReleaseScalar(&scalar); + } + + else if (index == 4) + { + vx_scalar scalar = 0; vx_enum type = 0; vx_int32 value = 0; + STATUS_ERROR_CHECK(vxQueryParameter(param, VX_PARAMETER_ATTRIBUTE_REF, &scalar, sizeof(scalar))); + STATUS_ERROR_CHECK(vxQueryScalar(scalar, VX_SCALAR_ATTRIBUTE_TYPE, &type, sizeof(type))); + STATUS_ERROR_CHECK(vxReadScalarValue(scalar, &value)); + if (value < 0 || type != VX_TYPE_INT32) + status = VX_ERROR_INVALID_VALUE; + vxReleaseScalar(&scalar); + } + + else if (index == 5) + { + vx_scalar scalar = 0; vx_enum type = 0; vx_int32 value = 0; + STATUS_ERROR_CHECK(vxQueryParameter(param, VX_PARAMETER_ATTRIBUTE_REF, &scalar, sizeof(scalar))); + STATUS_ERROR_CHECK(vxQueryScalar(scalar, VX_SCALAR_ATTRIBUTE_TYPE, &type, sizeof(type))); + STATUS_ERROR_CHECK(vxReadScalarValue(scalar, &value)); + if (value < 3 || (value % 2 == 0) || type != VX_TYPE_INT32) + status = VX_ERROR_INVALID_VALUE; + vxReleaseScalar(&scalar); + } + + else if (index == 6) + { + vx_scalar scalar = 0; vx_enum type = 0; vx_float32 value = 0; + STATUS_ERROR_CHECK(vxQueryParameter(param, VX_PARAMETER_ATTRIBUTE_REF, &scalar, sizeof(scalar))); + STATUS_ERROR_CHECK(vxQueryScalar(scalar, VX_SCALAR_ATTRIBUTE_TYPE, &type, sizeof(type))); + STATUS_ERROR_CHECK(vxReadScalarValue(scalar, &value)); + if (type != VX_TYPE_FLOAT32) + status = VX_ERROR_INVALID_VALUE; + vxReleaseScalar(&scalar); + } + + vxReleaseParameter(¶m); + return status; +} + +/************************************************************************************************************ +output parameter validator. +*************************************************************************************************************/ +vx_status VX_CALLBACK CV_adaptiveThreshold_OutputValidator(vx_node node, vx_uint32 index, vx_meta_format meta) +{ + vx_status status = VX_SUCCESS; + if (index == 1) + { + vx_parameter output_param = vxGetParameterByIndex(node, 1); + vx_image output; vx_uint32 width = 0, height = 0; vx_df_image format = VX_DF_IMAGE_VIRT; + + STATUS_ERROR_CHECK(vxQueryParameter(output_param, VX_PARAMETER_ATTRIBUTE_REF, &output, sizeof(vx_image))); + STATUS_ERROR_CHECK(vxQueryImage(output, VX_IMAGE_ATTRIBUTE_FORMAT, &format, sizeof(format))); + STATUS_ERROR_CHECK(vxQueryImage(output, VX_IMAGE_ATTRIBUTE_WIDTH, &width, sizeof(width))); + STATUS_ERROR_CHECK(vxQueryImage(output, VX_IMAGE_ATTRIBUTE_HEIGHT, &height, sizeof(height))); + + if (format != VX_DF_IMAGE_U8) + status = VX_ERROR_INVALID_VALUE; + + STATUS_ERROR_CHECK(vxSetMetaFormatAttribute(meta, VX_IMAGE_ATTRIBUTE_WIDTH, &width, sizeof(width))); + STATUS_ERROR_CHECK(vxSetMetaFormatAttribute(meta, VX_IMAGE_ATTRIBUTE_HEIGHT, &height, sizeof(height))); + STATUS_ERROR_CHECK(vxSetMetaFormatAttribute(meta, VX_IMAGE_ATTRIBUTE_FORMAT, &format, sizeof(format))); + vxReleaseImage(&output); + vxReleaseParameter(&output_param); + } + return status; +} + +/************************************************************************************************************ +Execution Kernel +*************************************************************************************************************/ +vx_status VX_CALLBACK CV_adaptiveThreshold_Kernel(vx_node node, const vx_reference *parameters, vx_uint32 num) +{ + vx_status status = VX_SUCCESS; + + vx_image image_in = (vx_image)parameters[0]; + vx_image image_out = (vx_image)parameters[1]; + vx_scalar scalar = (vx_scalar)parameters[2]; + vx_scalar ADAPTIVE_METHOD = (vx_scalar)parameters[3]; + vx_scalar THRESHOLD_TYPE = (vx_scalar)parameters[4]; + vx_scalar BLOCKSIZE = (vx_scalar)parameters[5]; + vx_scalar C = (vx_scalar)parameters[6]; + + Mat *mat, bl; + + int adaptiveMethod, thresholdType, blockSize; + float maxValue, c; + vx_int32 value = 0; + vx_float32 value_f = 0; + + //Extracting Values from the Scalar + STATUS_ERROR_CHECK(vxReadScalarValue(scalar, &value_f)); maxValue = value_f; + STATUS_ERROR_CHECK(vxReadScalarValue(ADAPTIVE_METHOD, &value)); adaptiveMethod = value; + STATUS_ERROR_CHECK(vxReadScalarValue(THRESHOLD_TYPE, &value)); thresholdType = value; + STATUS_ERROR_CHECK(vxReadScalarValue(BLOCKSIZE, &value)); blockSize = value; + STATUS_ERROR_CHECK(vxReadScalarValue(C, &value_f)); c = value_f; + + //Converting VX Image to OpenCV Mat + STATUS_ERROR_CHECK(match_vx_image_parameters(image_in, image_out)); + STATUS_ERROR_CHECK(VX_to_CV_Image(&mat, image_in)); + + //Compute using OpenCV + cv::adaptiveThreshold(*mat, bl, maxValue, adaptiveMethod, thresholdType, blockSize, c); + + //Converting OpenCV Mat into VX Image + STATUS_ERROR_CHECK(CV_to_VX_Image(image_out, &bl)); + + return status; +} + +/************************************************************************************************************ +Function to Register the Kernel for Publish +*************************************************************************************************************/ +vx_status CV_adaptiveThreshold_Register(vx_context context) +{ + vx_status status = VX_SUCCESS; + vx_kernel kernel = vxAddKernel(context, + "org.opencv.adaptivethreshold", + VX_KERNEL_EXT_CV_ADAPTIVETHRESHOLD, + CV_adaptiveThreshold_Kernel, + 7, + CV_adaptiveThreshold_InputValidator, + CV_adaptiveThreshold_OutputValidator, + nullptr, + nullptr); + + if (kernel) + { + PARAM_ERROR_CHECK(vxAddParameterToKernel(kernel, 0, VX_INPUT, VX_TYPE_IMAGE, VX_PARAMETER_STATE_REQUIRED)); + PARAM_ERROR_CHECK(vxAddParameterToKernel(kernel, 1, VX_OUTPUT, VX_TYPE_IMAGE, VX_PARAMETER_STATE_REQUIRED)); + PARAM_ERROR_CHECK(vxAddParameterToKernel(kernel, 2, VX_INPUT, VX_TYPE_SCALAR, VX_PARAMETER_STATE_REQUIRED)); + PARAM_ERROR_CHECK(vxAddParameterToKernel(kernel, 3, VX_INPUT, VX_TYPE_SCALAR, VX_PARAMETER_STATE_REQUIRED)); + PARAM_ERROR_CHECK(vxAddParameterToKernel(kernel, 4, VX_INPUT, VX_TYPE_SCALAR, VX_PARAMETER_STATE_REQUIRED)); + PARAM_ERROR_CHECK(vxAddParameterToKernel(kernel, 5, VX_INPUT, VX_TYPE_SCALAR, VX_PARAMETER_STATE_REQUIRED)); + PARAM_ERROR_CHECK(vxAddParameterToKernel(kernel, 6, VX_INPUT, VX_TYPE_SCALAR, VX_PARAMETER_STATE_REQUIRED)); + PARAM_ERROR_CHECK(vxFinalizeKernel(kernel)); + } + + if (status != VX_SUCCESS) + { + exit: vxRemoveKernel(kernel); return VX_FAILURE; + } + + return status; +} \ No newline at end of file diff --git a/vx_ext_cv/OpenCV_add.cpp b/vx_ext_cv/OpenCV_add.cpp new file mode 100644 index 0000000..e5f8cd2 --- /dev/null +++ b/vx_ext_cv/OpenCV_add.cpp @@ -0,0 +1,160 @@ +/* +Copyright (c) 2015 Advanced Micro Devices, Inc. All rights reserved. + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. +*/ + + +#include"publishkernels.h" + +/************************************************************************************************************ +input parameter validator. +param [in] node The handle to the node. +param [in] index The index of the parameter to validate. +*************************************************************************************************************/ +vx_status VX_CALLBACK CV_add_InputValidator(vx_node node, vx_uint32 index) +{ + vx_status status = VX_SUCCESS ; + vx_parameter param = vxGetParameterByIndex(node, index); + + if (index == 0) + { + vx_image image; + vx_df_image df_image = VX_DF_IMAGE_VIRT; + STATUS_ERROR_CHECK(vxQueryParameter(param, VX_PARAMETER_ATTRIBUTE_REF, &image, sizeof(vx_image))); + STATUS_ERROR_CHECK(vxQueryImage(image, VX_IMAGE_ATTRIBUTE_FORMAT, &df_image, sizeof(df_image))); + if (df_image != VX_DF_IMAGE_U8 && df_image != VX_DF_IMAGE_S16) + status = VX_ERROR_INVALID_VALUE; + vxReleaseImage(&image); + } + if (index == 1) + { + vx_image image; + vx_df_image df_image = VX_DF_IMAGE_VIRT; + STATUS_ERROR_CHECK(vxQueryParameter(param, VX_PARAMETER_ATTRIBUTE_REF, &image, sizeof(vx_image))); + STATUS_ERROR_CHECK(vxQueryImage(image, VX_IMAGE_ATTRIBUTE_FORMAT, &df_image, sizeof(df_image))); + if (df_image != VX_DF_IMAGE_U8 && df_image != VX_DF_IMAGE_S16) + status = VX_ERROR_INVALID_VALUE; + vxReleaseImage(&image); + } + else if (index == 2) + { + vx_image image; + vx_df_image df_image = VX_DF_IMAGE_VIRT; + STATUS_ERROR_CHECK(vxQueryParameter(param, VX_PARAMETER_ATTRIBUTE_REF, &image, sizeof(vx_image))); + STATUS_ERROR_CHECK(vxQueryImage(image, VX_IMAGE_ATTRIBUTE_FORMAT, &df_image, sizeof(df_image))); + if (df_image != VX_DF_IMAGE_U8 && df_image != VX_DF_IMAGE_S16) + status = VX_ERROR_INVALID_VALUE; + vxReleaseImage(&image); + } + + vxReleaseParameter(¶m); + return status; +} + +/************************************************************************************************************ +output parameter validator. +*************************************************************************************************************/ +vx_status VX_CALLBACK CV_add_OutputValidator(vx_node node, vx_uint32 index, vx_meta_format meta) +{ + vx_status status = VX_SUCCESS ; + if (index == 2) + { + vx_parameter output_param = vxGetParameterByIndex(node, 2); + vx_image output; vx_uint32 width = 0, height = 0; vx_df_image format = VX_DF_IMAGE_VIRT; + + STATUS_ERROR_CHECK(vxQueryParameter(output_param, VX_PARAMETER_ATTRIBUTE_REF, &output, sizeof(vx_image))); + STATUS_ERROR_CHECK(vxQueryImage(output, VX_IMAGE_ATTRIBUTE_FORMAT, &format, sizeof(format))); + STATUS_ERROR_CHECK(vxQueryImage(output, VX_IMAGE_ATTRIBUTE_WIDTH, &width, sizeof(width))); + STATUS_ERROR_CHECK(vxQueryImage(output, VX_IMAGE_ATTRIBUTE_HEIGHT, &height, sizeof(height))); + + if (format != VX_DF_IMAGE_U8 && format != VX_DF_IMAGE_S16) + status = VX_ERROR_INVALID_VALUE; + + STATUS_ERROR_CHECK(vxSetMetaFormatAttribute(meta, VX_IMAGE_ATTRIBUTE_WIDTH, &width, sizeof(width))); + STATUS_ERROR_CHECK(vxSetMetaFormatAttribute(meta, VX_IMAGE_ATTRIBUTE_HEIGHT, &height, sizeof(height))); + STATUS_ERROR_CHECK(vxSetMetaFormatAttribute(meta, VX_IMAGE_ATTRIBUTE_FORMAT, &format, sizeof(format))); + + vxReleaseImage(&output); + vxReleaseParameter(&output_param); + } + return status; +} + +/************************************************************************************************************ +Execution Kernel +*************************************************************************************************************/ +vx_status VX_CALLBACK CV_add_Kernel(vx_node node, const vx_reference *parameters, vx_uint32 num) +{ + vx_status status = VX_SUCCESS; + + vx_image image_1 = (vx_image) parameters[0]; + vx_image image_2 = (vx_image) parameters[1]; + vx_image image_out = (vx_image) parameters[2]; + + Mat *mat_1, *mat_2, bl; + vx_int32 value = 0; + + //Converting VX Image to OpenCV Mat 1 + STATUS_ERROR_CHECK(match_vx_image_parameters(image_1, image_2)); + STATUS_ERROR_CHECK(match_vx_image_parameters(image_1, image_out)); + STATUS_ERROR_CHECK(VX_to_CV_Image(&mat_1, image_1)); + STATUS_ERROR_CHECK(VX_to_CV_Image(&mat_2, image_2)); + + //Compute using OpenCV + cv::add(*mat_1, *mat_2, bl); + + //Converting OpenCV Mat into VX Image + STATUS_ERROR_CHECK(CV_to_VX_Image(image_out, &bl)); + + return status; +} + + +/************************************************************************************************************ +Function to Register the Kernel for Publish +*************************************************************************************************************/ +vx_status CV_add_Register(vx_context context) +{ + vx_status status = VX_SUCCESS; + vx_kernel kernel = vxAddKernel(context, + "org.opencv.add", + VX_KERNEL_EXT_CV_ADD, + CV_add_Kernel, + 3, + CV_add_InputValidator, + CV_add_OutputValidator, + nullptr, + nullptr); + + if (kernel) + { + PARAM_ERROR_CHECK(vxAddParameterToKernel(kernel, 0, VX_INPUT, VX_TYPE_IMAGE, VX_PARAMETER_STATE_REQUIRED)); + PARAM_ERROR_CHECK(vxAddParameterToKernel(kernel, 1, VX_INPUT, VX_TYPE_IMAGE, VX_PARAMETER_STATE_REQUIRED)); + PARAM_ERROR_CHECK(vxAddParameterToKernel(kernel, 2, VX_OUTPUT, VX_TYPE_IMAGE, VX_PARAMETER_STATE_REQUIRED)); + PARAM_ERROR_CHECK(vxFinalizeKernel(kernel)); + } + + if (status != VX_SUCCESS) + { + exit: vxRemoveKernel(kernel); return VX_FAILURE; + } + + return status; +} \ No newline at end of file diff --git a/vx_ext_cv/OpenCV_bilateralFilter.cpp b/vx_ext_cv/OpenCV_bilateralFilter.cpp new file mode 100644 index 0000000..1143fd0 --- /dev/null +++ b/vx_ext_cv/OpenCV_bilateralFilter.cpp @@ -0,0 +1,207 @@ +/* +Copyright (c) 2015 Advanced Micro Devices, Inc. All rights reserved. + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. +*/ + + +#include"publishkernels.h" + +/************************************************************************************************************ +input parameter validator. +param [in] node The handle to the node. +param [in] index The index of the parameter to validate. +*************************************************************************************************************/ +vx_status VX_CALLBACK CV_bilateralFilter_InputValidator(vx_node node, vx_uint32 index) +{ + vx_status status = VX_SUCCESS; + vx_parameter param = vxGetParameterByIndex(node, index); + + if (index == 0) + { + vx_image image; + vx_df_image df_image = VX_DF_IMAGE_VIRT; + STATUS_ERROR_CHECK(vxQueryParameter(param, VX_PARAMETER_ATTRIBUTE_REF, &image, sizeof(vx_image))); + STATUS_ERROR_CHECK(vxQueryImage(image, VX_IMAGE_ATTRIBUTE_FORMAT, &df_image, sizeof(df_image))); + if (df_image != VX_DF_IMAGE_U8) + status = VX_ERROR_INVALID_VALUE; + vxReleaseImage(&image); + } + + else if (index == 1) + { + vx_image image; + vx_df_image df_image = VX_DF_IMAGE_VIRT; + STATUS_ERROR_CHECK(vxQueryParameter(param, VX_PARAMETER_ATTRIBUTE_REF, &image, sizeof(vx_image))); + STATUS_ERROR_CHECK(vxQueryImage(image, VX_IMAGE_ATTRIBUTE_FORMAT, &df_image, sizeof(df_image))); + if (df_image != VX_DF_IMAGE_U8) + status = VX_ERROR_INVALID_VALUE; + vxReleaseImage(&image); + } + else if (index == 2) + { + vx_scalar scalar = 0; vx_enum type = 0; vx_int32 value = 0; + STATUS_ERROR_CHECK(vxQueryParameter(param, VX_PARAMETER_ATTRIBUTE_REF, &scalar, sizeof(scalar))); + STATUS_ERROR_CHECK(vxQueryScalar(scalar, VX_SCALAR_ATTRIBUTE_TYPE, &type, sizeof(type))); + STATUS_ERROR_CHECK(vxReadScalarValue(scalar, &value)); + if (value < 0 || (value % 2 == 0) || type != VX_TYPE_INT32) + status = VX_ERROR_INVALID_VALUE; + vxReleaseScalar(&scalar); + } + + else if (index == 3) + { + vx_scalar scalar = 0; vx_enum type = 0; vx_float32 value = 0; + STATUS_ERROR_CHECK(vxQueryParameter(param, VX_PARAMETER_ATTRIBUTE_REF, &scalar, sizeof(scalar))); + STATUS_ERROR_CHECK(vxQueryScalar(scalar, VX_SCALAR_ATTRIBUTE_TYPE, &type, sizeof(type))); + STATUS_ERROR_CHECK(vxReadScalarValue(scalar, &value)); + if (value < 0 || type != VX_TYPE_FLOAT32) + status = VX_ERROR_INVALID_VALUE; + vxReleaseScalar(&scalar); + } + + else if (index == 4) + { + vx_scalar scalar = 0; vx_enum type = 0; vx_float32 value = 0; + STATUS_ERROR_CHECK(vxQueryParameter(param, VX_PARAMETER_ATTRIBUTE_REF, &scalar, sizeof(scalar))); + STATUS_ERROR_CHECK(vxQueryScalar(scalar, VX_SCALAR_ATTRIBUTE_TYPE, &type, sizeof(type))); + STATUS_ERROR_CHECK(vxReadScalarValue(scalar, &value)); + if (value < 0 || type != VX_TYPE_FLOAT32) + status = VX_ERROR_INVALID_VALUE; + vxReleaseScalar(&scalar); + } + + else if (index == 5) + { + vx_scalar scalar = 0; vx_enum type = 0; vx_int32 value = 0; + STATUS_ERROR_CHECK(vxQueryParameter(param, VX_PARAMETER_ATTRIBUTE_REF, &scalar, sizeof(scalar))); + STATUS_ERROR_CHECK(vxQueryScalar(scalar, VX_SCALAR_ATTRIBUTE_TYPE, &type, sizeof(type))); + STATUS_ERROR_CHECK(vxReadScalarValue(scalar, &value)); + if (value < 0 || type != VX_TYPE_INT32) + status = VX_ERROR_INVALID_VALUE; + vxReleaseScalar(&scalar); + } + + vxReleaseParameter(¶m); + return status; +} + +/************************************************************************************************************ +output parameter validator. +*************************************************************************************************************/ +vx_status VX_CALLBACK CV_bilateralFilter_OutputValidator(vx_node node, vx_uint32 index, vx_meta_format meta) +{ + vx_status status = VX_SUCCESS; + if (index == 1) + { + vx_parameter output_param = vxGetParameterByIndex(node, 1); + vx_image output; vx_uint32 width = 0, height = 0; vx_df_image format = VX_DF_IMAGE_VIRT; + + STATUS_ERROR_CHECK(vxQueryParameter(output_param, VX_PARAMETER_ATTRIBUTE_REF, &output, sizeof(vx_image))); + STATUS_ERROR_CHECK(vxQueryImage(output, VX_IMAGE_ATTRIBUTE_FORMAT, &format, sizeof(format))); + STATUS_ERROR_CHECK(vxQueryImage(output, VX_IMAGE_ATTRIBUTE_WIDTH, &width, sizeof(width))); + STATUS_ERROR_CHECK(vxQueryImage(output, VX_IMAGE_ATTRIBUTE_HEIGHT, &height, sizeof(height))); + + if (format != VX_DF_IMAGE_U8) + status = VX_ERROR_INVALID_VALUE; + + STATUS_ERROR_CHECK(vxSetMetaFormatAttribute(meta, VX_IMAGE_ATTRIBUTE_WIDTH, &width, sizeof(width))); + STATUS_ERROR_CHECK(vxSetMetaFormatAttribute(meta, VX_IMAGE_ATTRIBUTE_HEIGHT, &height, sizeof(height))); + STATUS_ERROR_CHECK(vxSetMetaFormatAttribute(meta, VX_IMAGE_ATTRIBUTE_FORMAT, &format, sizeof(format))); + + vxReleaseImage(&output); + vxReleaseParameter(&output_param); + } + return status; +} + +/************************************************************************************************************ +Execution Kernel +*************************************************************************************************************/ +vx_status VX_CALLBACK CV_bilateralFilter_Kernel(vx_node node, const vx_reference *parameters, vx_uint32 num) +{ + vx_status status = VX_SUCCESS; + + vx_image image_in = (vx_image) parameters[0]; + vx_image image_out = (vx_image) parameters[1]; + vx_scalar D = (vx_scalar) parameters[2]; + vx_scalar SIGMA_C = (vx_scalar) parameters[3]; + vx_scalar SIGMA_S = (vx_scalar) parameters[4]; + vx_scalar BORDER = (vx_scalar) parameters[5]; + + Mat *mat, bl; + int d, Border; + float Sigma_Color, Sigma_Space; + + vx_int32 value = 0; + vx_float32 value_f = 0; + + //Extracting Values from the Scalar into Ksize and Ddepth + STATUS_ERROR_CHECK(vxReadScalarValue(D, &value)); d = value; + STATUS_ERROR_CHECK(vxReadScalarValue(SIGMA_C, &value_f)); Sigma_Color = value_f; + STATUS_ERROR_CHECK(vxReadScalarValue(SIGMA_S, &value_f)); Sigma_Space = value_f; + STATUS_ERROR_CHECK(vxReadScalarValue(BORDER, &value)); Border = value; + + //Converting VX Image to OpenCV Mat + STATUS_ERROR_CHECK(match_vx_image_parameters(image_in, image_out)); + STATUS_ERROR_CHECK(VX_to_CV_Image(&mat, image_in)); + + //Compute using OpenCV + cv::bilateralFilter(*mat, bl, d, Sigma_Color, Sigma_Space, Border); + + //Converting OpenCV Mat into VX Image + STATUS_ERROR_CHECK(CV_to_VX_Image(image_out, &bl)); + + return status; +} + +/************************************************************************************************************ +Function to Register the Kernel for Publish +*************************************************************************************************************/ +vx_status CV_bilateralFilter_Register(vx_context context) +{ + vx_status status = VX_SUCCESS; + vx_kernel kernel = vxAddKernel(context, + "org.opencv.bilateralfilter", + VX_KERNEL_EXT_CV_BILATERAL_FILTER, + CV_bilateralFilter_Kernel, + 6, + CV_bilateralFilter_InputValidator, + CV_bilateralFilter_OutputValidator, + nullptr, + nullptr); + + if (kernel) + { + PARAM_ERROR_CHECK(vxAddParameterToKernel(kernel, 0, VX_INPUT, VX_TYPE_IMAGE, VX_PARAMETER_STATE_REQUIRED)); + PARAM_ERROR_CHECK(vxAddParameterToKernel(kernel, 1, VX_OUTPUT, VX_TYPE_IMAGE, VX_PARAMETER_STATE_REQUIRED)); + PARAM_ERROR_CHECK(vxAddParameterToKernel(kernel, 2, VX_INPUT, VX_TYPE_SCALAR, VX_PARAMETER_STATE_REQUIRED)); + PARAM_ERROR_CHECK(vxAddParameterToKernel(kernel, 3, VX_INPUT, VX_TYPE_SCALAR, VX_PARAMETER_STATE_REQUIRED)); + PARAM_ERROR_CHECK(vxAddParameterToKernel(kernel, 4, VX_INPUT, VX_TYPE_SCALAR, VX_PARAMETER_STATE_REQUIRED)); + PARAM_ERROR_CHECK(vxAddParameterToKernel(kernel, 5, VX_INPUT, VX_TYPE_SCALAR, VX_PARAMETER_STATE_REQUIRED)); + PARAM_ERROR_CHECK(vxFinalizeKernel(kernel)); + } + + if (status != VX_SUCCESS) + { + exit: vxRemoveKernel(kernel); return VX_FAILURE; + } + + return status; +} \ No newline at end of file diff --git a/vx_ext_cv/OpenCV_bitwise_and.cpp b/vx_ext_cv/OpenCV_bitwise_and.cpp new file mode 100644 index 0000000..f395322 --- /dev/null +++ b/vx_ext_cv/OpenCV_bitwise_and.cpp @@ -0,0 +1,159 @@ +/* +Copyright (c) 2015 Advanced Micro Devices, Inc. All rights reserved. + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. +*/ + + +#include"publishkernels.h" + +/************************************************************************************************************ +input parameter validator. +param [in] node The handle to the node. +param [in] index The index of the parameter to validate. +*************************************************************************************************************/ +vx_status VX_CALLBACK CV_bitwise_and_InputValidator(vx_node node, vx_uint32 index) +{ + vx_status status = VX_SUCCESS; + vx_parameter param = vxGetParameterByIndex(node, index); + + if (index == 0) + { + vx_image image; + vx_df_image df_image = VX_DF_IMAGE_VIRT; + STATUS_ERROR_CHECK(vxQueryParameter(param, VX_PARAMETER_ATTRIBUTE_REF, &image, sizeof(vx_image))); + STATUS_ERROR_CHECK(vxQueryImage(image, VX_IMAGE_ATTRIBUTE_FORMAT, &df_image, sizeof(df_image))); + if (df_image != VX_DF_IMAGE_U8 && df_image != VX_DF_IMAGE_S16) + status = VX_ERROR_INVALID_VALUE; + vxReleaseImage(&image); + } + + if (index == 1) + { + vx_image image; + vx_df_image df_image = VX_DF_IMAGE_VIRT; + STATUS_ERROR_CHECK(vxQueryParameter(param, VX_PARAMETER_ATTRIBUTE_REF, &image, sizeof(vx_image))); + STATUS_ERROR_CHECK(vxQueryImage(image, VX_IMAGE_ATTRIBUTE_FORMAT, &df_image, sizeof(df_image))); + if (df_image != VX_DF_IMAGE_U8 && df_image != VX_DF_IMAGE_S16) + status = VX_ERROR_INVALID_VALUE; + vxReleaseImage(&image); + } + + else if (index == 2) + { + vx_image image; + vx_df_image df_image = VX_DF_IMAGE_VIRT; + STATUS_ERROR_CHECK(vxQueryParameter(param, VX_PARAMETER_ATTRIBUTE_REF, &image, sizeof(vx_image))); + STATUS_ERROR_CHECK(vxQueryImage(image, VX_IMAGE_ATTRIBUTE_FORMAT, &df_image, sizeof(df_image))); + if (df_image != VX_DF_IMAGE_U8 && df_image != VX_DF_IMAGE_S16) + status = VX_ERROR_INVALID_VALUE; + vxReleaseImage(&image); + } + + vxReleaseParameter(¶m); + return status; +} + +/************************************************************************************************************ +output parameter validator. +*************************************************************************************************************/ +vx_status VX_CALLBACK CV_bitwise_and_OutputValidator(vx_node node, vx_uint32 index, vx_meta_format meta) +{ + vx_status status = VX_SUCCESS; + if (index == 2) + { + vx_parameter output_param = vxGetParameterByIndex(node, 2); + vx_image output; vx_uint32 width = 0, height = 0; vx_df_image format = VX_DF_IMAGE_VIRT; + + STATUS_ERROR_CHECK(vxQueryParameter(output_param, VX_PARAMETER_ATTRIBUTE_REF, &output, sizeof(vx_image))); + STATUS_ERROR_CHECK(vxQueryImage(output, VX_IMAGE_ATTRIBUTE_FORMAT, &format, sizeof(format))); + STATUS_ERROR_CHECK(vxQueryImage(output, VX_IMAGE_ATTRIBUTE_WIDTH, &width, sizeof(width))); + STATUS_ERROR_CHECK(vxQueryImage(output, VX_IMAGE_ATTRIBUTE_HEIGHT, &height, sizeof(height))); + + if (format != VX_DF_IMAGE_U8 && format != VX_DF_IMAGE_S16) + status = VX_ERROR_INVALID_VALUE; + + STATUS_ERROR_CHECK(vxSetMetaFormatAttribute(meta, VX_IMAGE_ATTRIBUTE_WIDTH, &width, sizeof(width))); + STATUS_ERROR_CHECK(vxSetMetaFormatAttribute(meta, VX_IMAGE_ATTRIBUTE_HEIGHT, &height, sizeof(height))); + STATUS_ERROR_CHECK(vxSetMetaFormatAttribute(meta, VX_IMAGE_ATTRIBUTE_FORMAT, &format, sizeof(format))); + + vxReleaseImage(&output); + vxReleaseParameter(&output_param); + } + return status; +} + +/************************************************************************************************************ +Execution Kernel +*************************************************************************************************************/ +vx_status VX_CALLBACK CV_bitwise_and_Kernel(vx_node node, const vx_reference *parameters, vx_uint32 num) +{ + vx_status status = VX_SUCCESS; + vx_image image_1 = (vx_image)parameters[0]; + vx_image image_2 = (vx_image)parameters[1]; + vx_image image_out = (vx_image)parameters[2]; + + Mat *mat_1, *mat_2, bl; + + //Converting VX Image to OpenCV Mat 1 + STATUS_ERROR_CHECK(match_vx_image_parameters(image_1, image_2)); + STATUS_ERROR_CHECK(match_vx_image_parameters(image_1, image_out)); + STATUS_ERROR_CHECK(VX_to_CV_Image(&mat_1, image_1)); + STATUS_ERROR_CHECK(VX_to_CV_Image(&mat_2, image_2)); + + //Compute using OpenCV + cv::bitwise_and(*mat_1, *mat_2, bl); + + //Converting OpenCV Mat into VX Image + STATUS_ERROR_CHECK(CV_to_VX_Image(image_out, &bl)); + + return status; +} + +/************************************************************************************************************ +Function to Register the Kernel for Publish +*************************************************************************************************************/ +vx_status CV_bitwise_and_Register(vx_context context) +{ + vx_status status = VX_SUCCESS; + vx_kernel kernel = vxAddKernel(context, + "org.opencv.bitwise_and", + VX_KERNEL_EXT_CV_BITWISE_AND, + CV_bitwise_and_Kernel, + 3, + CV_bitwise_and_InputValidator, + CV_bitwise_and_OutputValidator, + nullptr, + nullptr); + + if (kernel) + { + PARAM_ERROR_CHECK(vxAddParameterToKernel(kernel, 0, VX_INPUT, VX_TYPE_IMAGE, VX_PARAMETER_STATE_REQUIRED)); + PARAM_ERROR_CHECK(vxAddParameterToKernel(kernel, 1, VX_INPUT, VX_TYPE_IMAGE, VX_PARAMETER_STATE_REQUIRED)); + PARAM_ERROR_CHECK(vxAddParameterToKernel(kernel, 2, VX_OUTPUT, VX_TYPE_IMAGE, VX_PARAMETER_STATE_REQUIRED)); + PARAM_ERROR_CHECK(vxFinalizeKernel(kernel)); + } + + if (status != VX_SUCCESS) + { + exit: vxRemoveKernel(kernel); return VX_FAILURE; + } + + return status; +} \ No newline at end of file diff --git a/vx_ext_cv/OpenCV_bitwise_not.cpp b/vx_ext_cv/OpenCV_bitwise_not.cpp new file mode 100644 index 0000000..66c7c69 --- /dev/null +++ b/vx_ext_cv/OpenCV_bitwise_not.cpp @@ -0,0 +1,144 @@ +/* +Copyright (c) 2015 Advanced Micro Devices, Inc. All rights reserved. + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. +*/ + + +#include"publishkernels.h" + +/************************************************************************************************************ +input parameter validator. +param [in] node The handle to the node. +param [in] index The index of the parameter to validate. +*************************************************************************************************************/ +vx_status VX_CALLBACK CV_bitwise_not_InputValidator(vx_node node, vx_uint32 index) +{ + vx_status status = VX_SUCCESS; + vx_parameter param = vxGetParameterByIndex(node, index); + + if (index == 0) + { + vx_image image; + vx_df_image df_image = VX_DF_IMAGE_VIRT; + STATUS_ERROR_CHECK(vxQueryParameter(param, VX_PARAMETER_ATTRIBUTE_REF, &image, sizeof(vx_image))); + STATUS_ERROR_CHECK(vxQueryImage(image, VX_IMAGE_ATTRIBUTE_FORMAT, &df_image, sizeof(df_image))); + if (df_image != VX_DF_IMAGE_U8 && df_image != VX_DF_IMAGE_S16) + status = VX_ERROR_INVALID_VALUE; + vxReleaseImage(&image); + } + + else if (index == 1) + { + vx_image image; + vx_df_image df_image = VX_DF_IMAGE_VIRT; + STATUS_ERROR_CHECK(vxQueryParameter(param, VX_PARAMETER_ATTRIBUTE_REF, &image, sizeof(vx_image))); + STATUS_ERROR_CHECK(vxQueryImage(image, VX_IMAGE_ATTRIBUTE_FORMAT, &df_image, sizeof(df_image))); + if (df_image != VX_DF_IMAGE_U8 && df_image != VX_DF_IMAGE_S16) + status = VX_ERROR_INVALID_VALUE; + vxReleaseImage(&image); + } + + vxReleaseParameter(¶m); + return status; +} + +/************************************************************************************************************ +output parameter validator. +*************************************************************************************************************/ +vx_status VX_CALLBACK CV_bitwise_not_OutputValidator(vx_node node, vx_uint32 index, vx_meta_format meta) +{ + vx_status status = VX_SUCCESS; + if (index == 1) + { + vx_parameter output_param = vxGetParameterByIndex(node, 1); + vx_image output; vx_uint32 width = 0, height = 0; vx_df_image format = VX_DF_IMAGE_VIRT; + + STATUS_ERROR_CHECK(vxQueryParameter(output_param, VX_PARAMETER_ATTRIBUTE_REF, &output, sizeof(vx_image))); + STATUS_ERROR_CHECK(vxQueryImage(output, VX_IMAGE_ATTRIBUTE_FORMAT, &format, sizeof(format))); + STATUS_ERROR_CHECK(vxQueryImage(output, VX_IMAGE_ATTRIBUTE_WIDTH, &width, sizeof(width))); + STATUS_ERROR_CHECK(vxQueryImage(output, VX_IMAGE_ATTRIBUTE_HEIGHT, &height, sizeof(height))); + + if (format != VX_DF_IMAGE_U8 && format != VX_DF_IMAGE_S16) + status = VX_ERROR_INVALID_VALUE; + + STATUS_ERROR_CHECK(vxSetMetaFormatAttribute(meta, VX_IMAGE_ATTRIBUTE_WIDTH, &width, sizeof(width))); + STATUS_ERROR_CHECK(vxSetMetaFormatAttribute(meta, VX_IMAGE_ATTRIBUTE_HEIGHT, &height, sizeof(height))); + STATUS_ERROR_CHECK(vxSetMetaFormatAttribute(meta, VX_IMAGE_ATTRIBUTE_FORMAT, &format, sizeof(format))); + + vxReleaseImage(&output); + vxReleaseParameter(&output_param); + } + return status; +} + +/************************************************************************************************************ +Execution Kernel +*************************************************************************************************************/ +vx_status VX_CALLBACK CV_bitwise_not_Kernel(vx_node node, const vx_reference *parameters, vx_uint32 num) +{ + vx_status status = VX_SUCCESS; + vx_image image_in = (vx_image) parameters[0]; + vx_image image_out = (vx_image) parameters[1]; + + Mat *mat, bl; + + //Converting VX Image to OpenCV Mat 1 + STATUS_ERROR_CHECK(match_vx_image_parameters(image_in, image_out)); + STATUS_ERROR_CHECK(VX_to_CV_Image(&mat, image_in)); + + //Compute using OpenCV + cv::bitwise_not(*mat, bl); + + //Converting OpenCV Mat into VX Image + STATUS_ERROR_CHECK(CV_to_VX_Image(image_out, &bl)); + + return status; +} + +/************************************************************************************************************ +Function to Register the Kernel for Publish +*************************************************************************************************************/ +vx_status CV_bitwise_not_Register(vx_context context) +{ + vx_status status = VX_SUCCESS; + vx_kernel kernel = vxAddKernel(context, + "org.opencv.bitwise_not", + VX_KERNEL_EXT_CV_BITWISE_NOT, + CV_bitwise_not_Kernel, + 2, + CV_bitwise_not_InputValidator, + CV_bitwise_not_OutputValidator, + nullptr, + nullptr); + + if (kernel) + { + PARAM_ERROR_CHECK(vxAddParameterToKernel(kernel, 0, VX_INPUT, VX_TYPE_IMAGE, VX_PARAMETER_STATE_REQUIRED)); + PARAM_ERROR_CHECK(vxAddParameterToKernel(kernel, 1, VX_OUTPUT, VX_TYPE_IMAGE, VX_PARAMETER_STATE_REQUIRED)); + PARAM_ERROR_CHECK(vxFinalizeKernel(kernel)); + } + + if (status != VX_SUCCESS) + { + exit: vxRemoveKernel(kernel); return VX_FAILURE; + } + + return status; +} \ No newline at end of file diff --git a/vx_ext_cv/OpenCV_bitwise_or.cpp b/vx_ext_cv/OpenCV_bitwise_or.cpp new file mode 100644 index 0000000..d8aa694 --- /dev/null +++ b/vx_ext_cv/OpenCV_bitwise_or.cpp @@ -0,0 +1,159 @@ +/* +Copyright (c) 2015 Advanced Micro Devices, Inc. All rights reserved. + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. +*/ + + +#include"publishkernels.h" + +/************************************************************************************************************ +input parameter validator. +param [in] node The handle to the node. +param [in] index The index of the parameter to validate. +*************************************************************************************************************/ +vx_status VX_CALLBACK CV_bitwise_or_InputValidator(vx_node node, vx_uint32 index) +{ + vx_status status = VX_SUCCESS; + vx_parameter param = vxGetParameterByIndex(node, index); + + if (index == 0) + { + vx_image image; + vx_df_image df_image = VX_DF_IMAGE_VIRT; + STATUS_ERROR_CHECK(vxQueryParameter(param, VX_PARAMETER_ATTRIBUTE_REF, &image, sizeof(vx_image))); + STATUS_ERROR_CHECK(vxQueryImage(image, VX_IMAGE_ATTRIBUTE_FORMAT, &df_image, sizeof(df_image))); + if (df_image != VX_DF_IMAGE_U8 && df_image != VX_DF_IMAGE_S16) + status = VX_ERROR_INVALID_VALUE; + vxReleaseImage(&image); + } + + if (index == 1) + { + vx_image image; + vx_df_image df_image = VX_DF_IMAGE_VIRT; + STATUS_ERROR_CHECK(vxQueryParameter(param, VX_PARAMETER_ATTRIBUTE_REF, &image, sizeof(vx_image))); + STATUS_ERROR_CHECK(vxQueryImage(image, VX_IMAGE_ATTRIBUTE_FORMAT, &df_image, sizeof(df_image))); + if (df_image != VX_DF_IMAGE_U8 && df_image != VX_DF_IMAGE_S16) + status = VX_ERROR_INVALID_VALUE; + vxReleaseImage(&image); + } + + else if (index == 2) + { + vx_image image; + vx_df_image df_image = VX_DF_IMAGE_VIRT; + STATUS_ERROR_CHECK(vxQueryParameter(param, VX_PARAMETER_ATTRIBUTE_REF, &image, sizeof(vx_image))); + STATUS_ERROR_CHECK(vxQueryImage(image, VX_IMAGE_ATTRIBUTE_FORMAT, &df_image, sizeof(df_image))); + if (df_image != VX_DF_IMAGE_U8 && df_image != VX_DF_IMAGE_S16) + status = VX_ERROR_INVALID_VALUE; + vxReleaseImage(&image); + } + + vxReleaseParameter(¶m); + return status; +} + +/************************************************************************************************************ +output parameter validator. +*************************************************************************************************************/ +vx_status VX_CALLBACK CV_bitwise_or_OutputValidator(vx_node node, vx_uint32 index, vx_meta_format meta) +{ + vx_status status = VX_SUCCESS; + if (index == 2) + { + vx_parameter output_param = vxGetParameterByIndex(node, 2); + vx_image output; vx_uint32 width = 0, height = 0; vx_df_image format = VX_DF_IMAGE_VIRT; + + STATUS_ERROR_CHECK(vxQueryParameter(output_param, VX_PARAMETER_ATTRIBUTE_REF, &output, sizeof(vx_image))); + STATUS_ERROR_CHECK(vxQueryImage(output, VX_IMAGE_ATTRIBUTE_FORMAT, &format, sizeof(format))); + STATUS_ERROR_CHECK(vxQueryImage(output, VX_IMAGE_ATTRIBUTE_WIDTH, &width, sizeof(width))); + STATUS_ERROR_CHECK(vxQueryImage(output, VX_IMAGE_ATTRIBUTE_HEIGHT, &height, sizeof(height))); + + if (format != VX_DF_IMAGE_U8 && format != VX_DF_IMAGE_S16) + status = VX_ERROR_INVALID_VALUE; + + STATUS_ERROR_CHECK(vxSetMetaFormatAttribute(meta, VX_IMAGE_ATTRIBUTE_WIDTH, &width, sizeof(width))); + STATUS_ERROR_CHECK(vxSetMetaFormatAttribute(meta, VX_IMAGE_ATTRIBUTE_HEIGHT, &height, sizeof(height))); + STATUS_ERROR_CHECK(vxSetMetaFormatAttribute(meta, VX_IMAGE_ATTRIBUTE_FORMAT, &format, sizeof(format))); + + vxReleaseImage(&output); + vxReleaseParameter(&output_param); + } + return status; +} + +/************************************************************************************************************ +Execution Kernel +*************************************************************************************************************/ +vx_status VX_CALLBACK CV_bitwise_or_Kernel(vx_node node, const vx_reference *parameters, vx_uint32 num) +{ + vx_status status = VX_SUCCESS; + + vx_image image_1 = (vx_image) parameters[0]; + vx_image image_2 = (vx_image) parameters[1]; + vx_image image_out = (vx_image) parameters[2]; + Mat *mat_1, *mat_2, bl; + + //Converting VX Image to OpenCV Mat 1 + STATUS_ERROR_CHECK(match_vx_image_parameters(image_1, image_2)); + STATUS_ERROR_CHECK(match_vx_image_parameters(image_1, image_out)); + STATUS_ERROR_CHECK(VX_to_CV_Image(&mat_1, image_1)); + STATUS_ERROR_CHECK(VX_to_CV_Image(&mat_2, image_2)); + + //Compute using OpenCV + cv::bitwise_or(*mat_1, *mat_2, bl); + + //Converting OpenCV Mat into VX Image + STATUS_ERROR_CHECK(CV_to_VX_Image(image_out, &bl)); + + return status; +} + +/************************************************************************************************************ +Function to Register the Kernel for Publish +*************************************************************************************************************/ +vx_status CV_bitwise_or_Register(vx_context context) +{ + vx_status status = VX_SUCCESS; + vx_kernel kernel = vxAddKernel(context, + "org.opencv.bitwise_or", + VX_KERNEL_EXT_CV_BITWISE_OR, + CV_bitwise_or_Kernel, + 3, + CV_bitwise_or_InputValidator, + CV_bitwise_or_OutputValidator, + nullptr, + nullptr); + + if (kernel) + { + PARAM_ERROR_CHECK(vxAddParameterToKernel(kernel, 0, VX_INPUT, VX_TYPE_IMAGE, VX_PARAMETER_STATE_REQUIRED)); + PARAM_ERROR_CHECK(vxAddParameterToKernel(kernel, 1, VX_INPUT, VX_TYPE_IMAGE, VX_PARAMETER_STATE_REQUIRED)); + PARAM_ERROR_CHECK(vxAddParameterToKernel(kernel, 2, VX_OUTPUT, VX_TYPE_IMAGE, VX_PARAMETER_STATE_REQUIRED)); + PARAM_ERROR_CHECK(vxFinalizeKernel(kernel)); + } + + if (status != VX_SUCCESS) + { + exit: vxRemoveKernel(kernel); return VX_FAILURE; + } + + return status; +} \ No newline at end of file diff --git a/vx_ext_cv/OpenCV_bitwise_xor.cpp b/vx_ext_cv/OpenCV_bitwise_xor.cpp new file mode 100644 index 0000000..481e070 --- /dev/null +++ b/vx_ext_cv/OpenCV_bitwise_xor.cpp @@ -0,0 +1,160 @@ +/* +Copyright (c) 2015 Advanced Micro Devices, Inc. All rights reserved. + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. +*/ + + +#include"publishkernels.h" + +/************************************************************************************************************ +input parameter validator. +param [in] node The handle to the node. +param [in] index The index of the parameter to validate. +*************************************************************************************************************/ +vx_status VX_CALLBACK CV_bitwise_xor_InputValidator(vx_node node, vx_uint32 index) +{ + vx_status status = VX_SUCCESS; + vx_parameter param = vxGetParameterByIndex(node, index); + + if (index == 0) + { + vx_image image; + vx_df_image df_image = VX_DF_IMAGE_VIRT; + STATUS_ERROR_CHECK(vxQueryParameter(param, VX_PARAMETER_ATTRIBUTE_REF, &image, sizeof(vx_image))); + STATUS_ERROR_CHECK(vxQueryImage(image, VX_IMAGE_ATTRIBUTE_FORMAT, &df_image, sizeof(df_image))); + if (df_image != VX_DF_IMAGE_U8 && df_image != VX_DF_IMAGE_S16) + status = VX_ERROR_INVALID_VALUE; + vxReleaseImage(&image); + } + + if (index == 1) + { + vx_image image; + vx_df_image df_image = VX_DF_IMAGE_VIRT; + STATUS_ERROR_CHECK(vxQueryParameter(param, VX_PARAMETER_ATTRIBUTE_REF, &image, sizeof(vx_image))); + STATUS_ERROR_CHECK(vxQueryImage(image, VX_IMAGE_ATTRIBUTE_FORMAT, &df_image, sizeof(df_image))); + if (df_image != VX_DF_IMAGE_U8 && df_image != VX_DF_IMAGE_S16) + status = VX_ERROR_INVALID_VALUE; + vxReleaseImage(&image); + } + + else if (index == 2) + { + vx_image image; + vx_df_image df_image = VX_DF_IMAGE_VIRT; + STATUS_ERROR_CHECK(vxQueryParameter(param, VX_PARAMETER_ATTRIBUTE_REF, &image, sizeof(vx_image))); + STATUS_ERROR_CHECK(vxQueryImage(image, VX_IMAGE_ATTRIBUTE_FORMAT, &df_image, sizeof(df_image))); + if (df_image != VX_DF_IMAGE_U8 && df_image != VX_DF_IMAGE_S16) + status = VX_ERROR_INVALID_VALUE; + vxReleaseImage(&image); + } + + vxReleaseParameter(¶m); + return status; +} + +/************************************************************************************************************ +output parameter validator. +*************************************************************************************************************/ +vx_status VX_CALLBACK CV_bitwise_xor_OutputValidator(vx_node node, vx_uint32 index, vx_meta_format meta) +{ + vx_status status = VX_SUCCESS; + if (index == 2) + { + vx_parameter output_param = vxGetParameterByIndex(node, 2); + vx_image output; vx_uint32 width = 0, height = 0; vx_df_image format = VX_DF_IMAGE_VIRT; + + STATUS_ERROR_CHECK(vxQueryParameter(output_param, VX_PARAMETER_ATTRIBUTE_REF, &output, sizeof(vx_image))); + STATUS_ERROR_CHECK(vxQueryImage(output, VX_IMAGE_ATTRIBUTE_FORMAT, &format, sizeof(format))); + STATUS_ERROR_CHECK(vxQueryImage(output, VX_IMAGE_ATTRIBUTE_WIDTH, &width, sizeof(width))); + STATUS_ERROR_CHECK(vxQueryImage(output, VX_IMAGE_ATTRIBUTE_HEIGHT, &height, sizeof(height))); + + if (format != VX_DF_IMAGE_U8 && format != VX_DF_IMAGE_S16) + status = VX_ERROR_INVALID_VALUE; + + STATUS_ERROR_CHECK(vxSetMetaFormatAttribute(meta, VX_IMAGE_ATTRIBUTE_WIDTH, &width, sizeof(width))); + STATUS_ERROR_CHECK(vxSetMetaFormatAttribute(meta, VX_IMAGE_ATTRIBUTE_HEIGHT, &height, sizeof(height))); + STATUS_ERROR_CHECK(vxSetMetaFormatAttribute(meta, VX_IMAGE_ATTRIBUTE_FORMAT, &format, sizeof(format))); + + vxReleaseImage(&output); + vxReleaseParameter(&output_param); + } + return status; +} + +/************************************************************************************************************ +Execution Kernel +*************************************************************************************************************/ +vx_status VX_CALLBACK CV_bitwise_xor_Kernel(vx_node node, const vx_reference *parameters, vx_uint32 num) +{ + vx_status status = VX_SUCCESS; + + vx_image image_1 = (vx_image) parameters[0]; + vx_image image_2 = (vx_image) parameters[1]; + vx_image image_out = (vx_image) parameters[2]; + + Mat *mat_1, *mat_2, bl; + + //Converting VX Image to OpenCV Mat 1 + STATUS_ERROR_CHECK(match_vx_image_parameters(image_1, image_2)); + STATUS_ERROR_CHECK(match_vx_image_parameters(image_1, image_out)); + STATUS_ERROR_CHECK(VX_to_CV_Image(&mat_1, image_1)); + STATUS_ERROR_CHECK(VX_to_CV_Image(&mat_2, image_2)); + + //Compute using OpenCV + cv::bitwise_xor(*mat_1, *mat_2, bl); + + //Converting OpenCV Mat into VX Image + STATUS_ERROR_CHECK(CV_to_VX_Image(image_out, &bl)); + + return status; +} + +/************************************************************************************************************ +Function to Register the Kernel for Publish +*************************************************************************************************************/ +vx_status CV_bitwise_xor_Register(vx_context context) +{ + vx_status status = VX_SUCCESS; + vx_kernel kernel = vxAddKernel(context, + "org.opencv.bitwise_xor", + VX_KERNEL_EXT_CV_BITWISE_XOR, + CV_bitwise_xor_Kernel, + 3, + CV_bitwise_xor_InputValidator, + CV_bitwise_xor_OutputValidator, + nullptr, + nullptr); + + if (kernel) + { + PARAM_ERROR_CHECK(vxAddParameterToKernel(kernel, 0, VX_INPUT, VX_TYPE_IMAGE, VX_PARAMETER_STATE_REQUIRED)); + PARAM_ERROR_CHECK(vxAddParameterToKernel(kernel, 1, VX_INPUT, VX_TYPE_IMAGE, VX_PARAMETER_STATE_REQUIRED)); + PARAM_ERROR_CHECK(vxAddParameterToKernel(kernel, 2, VX_OUTPUT, VX_TYPE_IMAGE, VX_PARAMETER_STATE_REQUIRED)); + PARAM_ERROR_CHECK(vxFinalizeKernel(kernel)); + } + + if (status != VX_SUCCESS) + { + exit: vxRemoveKernel(kernel); return VX_FAILURE; + } + + return status; +} \ No newline at end of file diff --git a/vx_ext_cv/OpenCV_brisk_compute.cpp b/vx_ext_cv/OpenCV_brisk_compute.cpp new file mode 100644 index 0000000..1519cee --- /dev/null +++ b/vx_ext_cv/OpenCV_brisk_compute.cpp @@ -0,0 +1,213 @@ +/* +Copyright (c) 2015 Advanced Micro Devices, Inc. All rights reserved. + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. +*/ + + +#include"publishkernels.h" + +/*!*********************************************************************************************************** +input parameter validator. +param [in] node The handle to the node. +param [in] index The index of the parameter to validate. +*************************************************************************************************************/ +static vx_status VX_CALLBACK CV_brisk_compute_InputValidator(vx_node node, vx_uint32 index) +{ + vx_status status = VX_SUCCESS ; + vx_parameter param = vxGetParameterByIndex(node, index); + + if (index == 0) + { + vx_image image; + vx_df_image df_image = VX_DF_IMAGE_VIRT; + STATUS_ERROR_CHECK(vxQueryParameter(param, VX_PARAMETER_ATTRIBUTE_REF, &image, sizeof(vx_image))); + STATUS_ERROR_CHECK(vxQueryImage(image, VX_IMAGE_ATTRIBUTE_FORMAT, &df_image, sizeof(df_image))); + if (df_image != VX_DF_IMAGE_U8) + status = VX_ERROR_INVALID_VALUE; + vxReleaseImage(&image); + } + + if (index == 1) + { + vx_image image; + vx_df_image df_image = VX_DF_IMAGE_VIRT; + STATUS_ERROR_CHECK(vxQueryParameter(param, VX_PARAMETER_ATTRIBUTE_REF, &image, sizeof(vx_image))); + STATUS_ERROR_CHECK(vxQueryImage(image, VX_IMAGE_ATTRIBUTE_FORMAT, &df_image, sizeof(df_image))); + if (df_image != VX_DF_IMAGE_U8) + status = VX_ERROR_INVALID_VALUE; + vxReleaseImage(&image); + } + + else if (index == 2) + { + vx_array array; vx_size size = 0; + STATUS_ERROR_CHECK(vxQueryParameter(param, VX_PARAMETER_ATTRIBUTE_REF, &array, sizeof(array))); + STATUS_ERROR_CHECK(vxQueryArray(array, VX_ARRAY_ATTRIBUTE_CAPACITY, &size, sizeof(size))); + vxReleaseArray(&array); + } + + else if (index == 3) + { + vx_array array; vx_size size = 0; + STATUS_ERROR_CHECK(vxQueryParameter(param, VX_PARAMETER_ATTRIBUTE_REF, &array, sizeof(array))); + STATUS_ERROR_CHECK(vxQueryArray(array, VX_ARRAY_ATTRIBUTE_CAPACITY, &size, sizeof(size))); + vxReleaseArray(&array); + } + + else if (index == 4) + { + vx_scalar scalar = 0; vx_enum type = 0; vx_int32 value = 0; + STATUS_ERROR_CHECK(vxQueryParameter(param, VX_PARAMETER_ATTRIBUTE_REF, &scalar, sizeof(scalar))); + STATUS_ERROR_CHECK(vxQueryScalar(scalar, VX_SCALAR_ATTRIBUTE_TYPE, &type, sizeof(type))); + STATUS_ERROR_CHECK(vxReadScalarValue(scalar, &value)); + if (value < 0 || type != VX_TYPE_INT32) + status = VX_ERROR_INVALID_VALUE; + vxReleaseScalar(&scalar); + } + + else if (index == 5) + { + vx_scalar scalar = 0; vx_enum type = 0; vx_int32 value = 0; + STATUS_ERROR_CHECK(vxQueryParameter(param, VX_PARAMETER_ATTRIBUTE_REF, &scalar, sizeof(scalar))); + STATUS_ERROR_CHECK(vxQueryScalar(scalar, VX_SCALAR_ATTRIBUTE_TYPE, &type, sizeof(type))); + STATUS_ERROR_CHECK(vxReadScalarValue(scalar, &value)); + if (value < 0 || type != VX_TYPE_INT32) + status = VX_ERROR_INVALID_VALUE; + vxReleaseScalar(&scalar); + } + + else if (index == 6) + { + vx_scalar scalar = 0; vx_enum type = 0; vx_float32 value = 0; + STATUS_ERROR_CHECK(vxQueryParameter(param, VX_PARAMETER_ATTRIBUTE_REF, &scalar, sizeof(scalar))); + STATUS_ERROR_CHECK(vxQueryScalar(scalar, VX_SCALAR_ATTRIBUTE_TYPE, &type, sizeof(type))); + STATUS_ERROR_CHECK(vxReadScalarValue(scalar, &value)); + if (value < 0 || type != VX_TYPE_FLOAT32) + status = VX_ERROR_INVALID_VALUE; + vxReleaseScalar(&scalar); + } + + vxReleaseParameter(¶m); + return status; +} + +/*!*********************************************************************************************************** +output parameter validator. +*************************************************************************************************************/ +static vx_status VX_CALLBACK CV_brisk_compute_OutputValidator(vx_node node, vx_uint32 index, vx_meta_format meta) +{ + vx_status status = VX_SUCCESS ; + if (index == 2) + { + vx_parameter output_param = vxGetParameterByIndex(node, 2); + vx_array output; vx_size size = 0; + + STATUS_ERROR_CHECK(vxQueryParameter(output_param, VX_PARAMETER_ATTRIBUTE_REF, &output, sizeof(vx_array))); + STATUS_ERROR_CHECK(vxQueryArray(output, VX_ARRAY_ATTRIBUTE_CAPACITY, &size, sizeof(size))); + + if (size <= 0 ) + status = VX_ERROR_INVALID_VALUE; + + vxReleaseArray(&output); + vxReleaseParameter(&output_param); + } + + return status; +} + +/*!*********************************************************************************************************** +Execution Kernel +*************************************************************************************************************/ +static vx_status VX_CALLBACK CV_brisk_compute_Kernel(vx_node node, const vx_reference *parameters, vx_uint32 num) +{ + vx_status status = VX_SUCCESS; + + vx_image image_in = (vx_image) parameters[0]; + vx_image mask = (vx_image) parameters[1]; + vx_array array = (vx_array) parameters[2]; + vx_array DESP = (vx_array) parameters[3]; + vx_scalar THRESH = (vx_scalar) parameters[4]; + vx_scalar OCTAVES = (vx_scalar) parameters[5]; + vx_scalar SCALE = (vx_scalar) parameters[6]; + + Mat *mat, *mask_mat, Img; + int thresh, octaves; + float patternscale; + vx_float32 FloatValue = 0; + vx_int32 value = 0; + + //Extracting Values from the Scalar + STATUS_ERROR_CHECK(vxReadScalarValue(SCALE, &FloatValue));patternscale = FloatValue; + STATUS_ERROR_CHECK(vxReadScalarValue(THRESH, &value));thresh = value; + STATUS_ERROR_CHECK(vxReadScalarValue(OCTAVES, &value));octaves = value; + + //Converting VX Image to OpenCV Mat + STATUS_ERROR_CHECK(VX_to_CV_Image(&mat, image_in)); + STATUS_ERROR_CHECK(VX_to_CV_Image(&mask_mat, mask)); + + //Compute using OpenCV + vector key_points; + Mat desp; + Ptr brisk = BRISK::create(thresh, octaves, patternscale); + brisk->detectAndCompute(*mat, *mask_mat, key_points, desp); + + //Converting OpenCV Keypoints/Descriptors to OpenVX Keypoints/Descriptors + STATUS_ERROR_CHECK(CV_to_VX_keypoints(key_points, array)); + STATUS_ERROR_CHECK(CV_DESP_to_VX_DESP(desp, DESP, 64));//Supports 64 bit descriptor at this time + + return status; +} + +/************************************************************************************************************ +Function to Register the Kernel for Publish +*************************************************************************************************************/ +vx_status CV_brisk_compute_Register(vx_context context) +{ + vx_status status = VX_SUCCESS; + vx_kernel Kernel = vxAddKernel(context, + "org.opencv.brisk_compute", + VX_KERNEL_EXT_CV_BRISK_COMPUTE, + CV_brisk_compute_Kernel, + 7, + CV_brisk_compute_InputValidator, + CV_brisk_compute_OutputValidator, + nullptr, + nullptr); + + if (Kernel) + { + PARAM_ERROR_CHECK(vxAddParameterToKernel(Kernel, 0, VX_INPUT, VX_TYPE_IMAGE, VX_PARAMETER_STATE_REQUIRED)); + PARAM_ERROR_CHECK(vxAddParameterToKernel(Kernel, 1, VX_INPUT, VX_TYPE_IMAGE, VX_PARAMETER_STATE_REQUIRED)); + PARAM_ERROR_CHECK(vxAddParameterToKernel(Kernel, 2, VX_BIDIRECTIONAL, VX_TYPE_ARRAY, VX_PARAMETER_STATE_REQUIRED)); + PARAM_ERROR_CHECK(vxAddParameterToKernel(Kernel, 3, VX_BIDIRECTIONAL, VX_TYPE_ARRAY, VX_PARAMETER_STATE_REQUIRED)); + PARAM_ERROR_CHECK(vxAddParameterToKernel(Kernel, 4, VX_INPUT, VX_TYPE_SCALAR, VX_PARAMETER_STATE_REQUIRED)); + PARAM_ERROR_CHECK(vxAddParameterToKernel(Kernel, 5, VX_INPUT, VX_TYPE_SCALAR, VX_PARAMETER_STATE_REQUIRED)); + PARAM_ERROR_CHECK(vxAddParameterToKernel(Kernel, 6, VX_INPUT, VX_TYPE_SCALAR, VX_PARAMETER_STATE_REQUIRED)); + PARAM_ERROR_CHECK(vxFinalizeKernel(Kernel)); + } + + if (status != VX_SUCCESS) + { + exit: vxRemoveKernel(Kernel); return VX_FAILURE; + } + + return status; +} + diff --git a/vx_ext_cv/OpenCV_buildOpticalFlowPyramid.cpp b/vx_ext_cv/OpenCV_buildOpticalFlowPyramid.cpp new file mode 100644 index 0000000..3cf610e --- /dev/null +++ b/vx_ext_cv/OpenCV_buildOpticalFlowPyramid.cpp @@ -0,0 +1,267 @@ +/* +Copyright (c) 2015 Advanced Micro Devices, Inc. All rights reserved. + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. +*/ + + +#include"publishkernels.h" + +/************************************************************************************************************ +input parameter validator. +param [in] node The handle to the node. +param [in] index The index of the parameter to validate. + +*************************************************************************************************************/ +static vx_status VX_CALLBACK CV_buildOpticalFlowPyramid_InputValidator(vx_node node, vx_uint32 index) +{ + vx_status status = VX_SUCCESS; + vx_parameter param = vxGetParameterByIndex(node, index); + + if (index == 0) + { + vx_image image; + vx_df_image df_image = VX_DF_IMAGE_VIRT; + STATUS_ERROR_CHECK(vxQueryParameter(param, VX_PARAMETER_ATTRIBUTE_REF, &image, sizeof(vx_image))); + STATUS_ERROR_CHECK(vxQueryImage(image, VX_IMAGE_ATTRIBUTE_FORMAT, &df_image, sizeof(df_image))); + if (df_image != VX_DF_IMAGE_U8) + status = VX_ERROR_INVALID_VALUE; + vxReleaseImage(&image); + } + + else if (index == 1) + { + vx_pyramid image; + vx_df_image df_image = VX_DF_IMAGE_VIRT; + STATUS_ERROR_CHECK(vxQueryParameter(param, VX_PARAMETER_ATTRIBUTE_REF, &image, sizeof(vx_pyramid))); + STATUS_ERROR_CHECK(vxQueryPyramid(image, VX_PYRAMID_ATTRIBUTE_FORMAT, &df_image, sizeof(df_image))); + if (df_image != VX_DF_IMAGE_U8) + status = VX_ERROR_INVALID_VALUE; + vxReleasePyramid(&image); + } + + else if (index == 2) + { + vx_scalar scalar = 0; vx_enum type = 0; vx_int32 value = 0; + STATUS_ERROR_CHECK(vxQueryParameter(param, VX_PARAMETER_ATTRIBUTE_REF, &scalar, sizeof(scalar))); + STATUS_ERROR_CHECK(vxQueryScalar(scalar, VX_SCALAR_ATTRIBUTE_TYPE, &type, sizeof(type))); + STATUS_ERROR_CHECK(vxReadScalarValue(scalar, &value)); + if (value < 0 || (value % 2 == 0) || type != VX_TYPE_INT32) + status = VX_ERROR_INVALID_VALUE; + vxReleaseScalar(&scalar); + } + + else if (index == 3) + { + vx_scalar scalar = 0; vx_enum type = 0; vx_int32 value = 0; + STATUS_ERROR_CHECK(vxQueryParameter(param, VX_PARAMETER_ATTRIBUTE_REF, &scalar, sizeof(scalar))); + STATUS_ERROR_CHECK(vxQueryScalar(scalar, VX_SCALAR_ATTRIBUTE_TYPE, &type, sizeof(type))); + STATUS_ERROR_CHECK(vxReadScalarValue(scalar, &value)); + if (value < 0 || (value % 2 == 0) || type != VX_TYPE_INT32) + status = VX_ERROR_INVALID_VALUE; + vxReleaseScalar(&scalar); + } + + else if (index == 4) + { + vx_scalar scalar = 0; vx_enum type = 0; vx_int32 value = 0; + STATUS_ERROR_CHECK(vxQueryParameter(param, VX_PARAMETER_ATTRIBUTE_REF, &scalar, sizeof(scalar))); + STATUS_ERROR_CHECK(vxQueryScalar(scalar, VX_SCALAR_ATTRIBUTE_TYPE, &type, sizeof(type))); + STATUS_ERROR_CHECK(vxReadScalarValue(scalar, &value)); + if (value < 0 || type != VX_TYPE_INT32) + status = VX_ERROR_INVALID_VALUE; + vxReleaseScalar(&scalar); + } + + else if (index == 5) + { + vx_scalar scalar = 0; vx_enum type = 0; vx_bool value = vx_true_e; + STATUS_ERROR_CHECK(vxQueryParameter(param, VX_PARAMETER_ATTRIBUTE_REF, &scalar, sizeof(scalar))); + STATUS_ERROR_CHECK(vxQueryScalar(scalar, VX_SCALAR_ATTRIBUTE_TYPE, &type, sizeof(type))); + STATUS_ERROR_CHECK(vxReadScalarValue(scalar, &value)); + if ((value != vx_true_e && value != vx_false_e) || type != VX_TYPE_BOOL) + status = VX_ERROR_INVALID_VALUE; + vxReleaseScalar(&scalar); + } + + else if (index == 6) + { + vx_scalar scalar = 0; vx_enum type = 0; vx_int32 value = 0; + STATUS_ERROR_CHECK(vxQueryParameter(param, VX_PARAMETER_ATTRIBUTE_REF, &scalar, sizeof(scalar))); + STATUS_ERROR_CHECK(vxQueryScalar(scalar, VX_SCALAR_ATTRIBUTE_TYPE, &type, sizeof(type))); + STATUS_ERROR_CHECK(vxReadScalarValue(scalar, &value)); + if (value < 0 || type != VX_TYPE_INT32) + status = VX_ERROR_INVALID_VALUE; + vxReleaseScalar(&scalar); + } + + else if (index == 7) + { + vx_scalar scalar = 0; vx_enum type = 0; vx_int32 value = 0; + STATUS_ERROR_CHECK(vxQueryParameter(param, VX_PARAMETER_ATTRIBUTE_REF, &scalar, sizeof(scalar))); + STATUS_ERROR_CHECK(vxQueryScalar(scalar, VX_SCALAR_ATTRIBUTE_TYPE, &type, sizeof(type))); + STATUS_ERROR_CHECK(vxReadScalarValue(scalar, &value)); + if (value < 0 || type != VX_TYPE_INT32) + status = VX_ERROR_INVALID_VALUE; + vxReleaseScalar(&scalar); + } + + else if (index == 8) + { + vx_scalar scalar = 0; vx_enum type = 0; vx_bool value = vx_true_e; + STATUS_ERROR_CHECK(vxQueryParameter(param, VX_PARAMETER_ATTRIBUTE_REF, &scalar, sizeof(scalar))); + STATUS_ERROR_CHECK(vxQueryScalar(scalar, VX_SCALAR_ATTRIBUTE_TYPE, &type, sizeof(type))); + STATUS_ERROR_CHECK(vxReadScalarValue(scalar, &value)); + if ((value != vx_true_e && value != vx_false_e) || type != VX_TYPE_BOOL) + status = VX_ERROR_INVALID_VALUE; + vxReleaseScalar(&scalar); + } + + vxReleaseParameter(¶m); + return status; +} + +/************************************************************************************************************ +output parameter validator. +*************************************************************************************************************/ +static vx_status VX_CALLBACK CV_buildOpticalFlowPyramid_OutputValidator(vx_node node, vx_uint32 index, vx_meta_format meta) +{ + vx_status status = VX_SUCCESS; + if (index == 1) + { + vx_parameter output_param = vxGetParameterByIndex(node, 1); + vx_pyramid output; vx_uint32 width = 0, height = 0, level = 0; vx_float32 scale; + vx_df_image format = VX_DF_IMAGE_VIRT; + + STATUS_ERROR_CHECK(vxQueryParameter(output_param, VX_PARAMETER_ATTRIBUTE_REF, &output, sizeof(vx_image))); + STATUS_ERROR_CHECK(vxQueryPyramid(output, VX_PYRAMID_ATTRIBUTE_FORMAT, &format, sizeof(format))); + STATUS_ERROR_CHECK(vxQueryPyramid(output, VX_PYRAMID_ATTRIBUTE_WIDTH, &width, sizeof(width))); + STATUS_ERROR_CHECK(vxQueryPyramid(output, VX_PYRAMID_ATTRIBUTE_HEIGHT, &height, sizeof(height))); + STATUS_ERROR_CHECK(vxQueryPyramid(output, VX_PYRAMID_ATTRIBUTE_LEVELS, &level, sizeof(level))); + STATUS_ERROR_CHECK(vxQueryPyramid(output, VX_PYRAMID_ATTRIBUTE_SCALE, &scale, sizeof(scale))); + + if (format != VX_DF_IMAGE_U8) + status = VX_ERROR_INVALID_VALUE; + if (scale <= 0) + status = VX_ERROR_INVALID_VALUE; + if (level <= 0) + status = VX_ERROR_INVALID_VALUE; + if (width <= 0) + status = VX_ERROR_INVALID_VALUE; + if (height <= 0) + status = VX_ERROR_INVALID_VALUE; + + STATUS_ERROR_CHECK(vxSetMetaFormatAttribute(meta, VX_PYRAMID_ATTRIBUTE_WIDTH, &width, sizeof(width))); + STATUS_ERROR_CHECK(vxSetMetaFormatAttribute(meta, VX_PYRAMID_ATTRIBUTE_HEIGHT, &height, sizeof(height))); + STATUS_ERROR_CHECK(vxSetMetaFormatAttribute(meta, VX_PYRAMID_ATTRIBUTE_FORMAT, &format, sizeof(format))); + STATUS_ERROR_CHECK(vxSetMetaFormatAttribute(meta, VX_PYRAMID_ATTRIBUTE_LEVELS, &level, sizeof(level))); + STATUS_ERROR_CHECK(vxSetMetaFormatAttribute(meta, VX_PYRAMID_ATTRIBUTE_SCALE, &scale, sizeof(scale))); + + vxReleasePyramid(&output); + vxReleaseParameter(&output_param); + } + return status; +} + +/************************************************************************************************************ +Execution Kernel +*************************************************************************************************************/ +static vx_status VX_CALLBACK CV_buildOpticalFlowPyramid_Kernel(vx_node node, const vx_reference *parameters, vx_uint32 num) +{ + vx_status status = VX_SUCCESS; + + vx_image image_in = (vx_image) parameters[0]; + vx_pyramid pyramid_vx = (vx_pyramid) parameters[1]; + vx_scalar S_width = (vx_scalar) parameters[2]; + vx_scalar S_height = (vx_scalar) parameters[3]; + vx_scalar scalar = (vx_scalar) parameters[4]; + vx_scalar WITH_D = (vx_scalar) parameters[5]; + vx_scalar PYR_B = (vx_scalar) parameters[6]; + vx_scalar D_Border = (vx_scalar) parameters[7]; + vx_scalar TRY_Reuse = (vx_scalar) parameters[8]; + + Mat *mat, bl; + int W, H, WinSize, Pry_Border, derviBorder; + vx_bool WithDervi, try_reuse; + vx_int32 value = 0; + vx_bool value_b; + + //Extracting Values from the Scalar into Ksize and Ddepth + STATUS_ERROR_CHECK(vxReadScalarValue(S_width, &value)); W = value; + STATUS_ERROR_CHECK(vxReadScalarValue(S_height, &value)); H = value; + STATUS_ERROR_CHECK(vxReadScalarValue(scalar, &value)); WinSize = value; + STATUS_ERROR_CHECK(vxReadScalarValue(WITH_D, &value_b)); WithDervi = value_b; + STATUS_ERROR_CHECK(vxReadScalarValue(PYR_B, &value)); Pry_Border = value; + STATUS_ERROR_CHECK(vxReadScalarValue(D_Border, &value)); derviBorder = value; + STATUS_ERROR_CHECK(vxReadScalarValue(TRY_Reuse, &value_b)); try_reuse = value_b; + + //Converting VX Image to OpenCV Mat + STATUS_ERROR_CHECK(VX_to_CV_Image(&mat, image_in)); + + //Compute using OpenCV + vector pyramid_cv; + bool WithDervi_b, try_reuse_b; + if (WithDervi == 1) WithDervi_b = true; else WithDervi_b = false; + if (try_reuse == 1) try_reuse_b = true; else try_reuse_b = false; + cv::buildOpticalFlowPyramid(*mat, pyramid_cv, Size(W, H), WinSize, WithDervi_b, Pry_Border, derviBorder, try_reuse_b); + + //Converting OpenCV Mat into VX Image + STATUS_ERROR_CHECK(CV_to_VX_Pyramid(pyramid_vx, pyramid_cv)); + + return status; +} + +/************************************************************************************************************ +Function to Register the Kernel for Publish +*************************************************************************************************************/ +vx_status CV_buildOpticalFlowPyramid_Register(vx_context context) +{ + vx_status status = VX_SUCCESS; + vx_kernel kernel = vxAddKernel(context, + "org.opencv.buildopticalflowpyramid", + VX_KERNEL_EXT_CV_BUILD_OPTICAL_FLOW_PYRAMID, + CV_buildOpticalFlowPyramid_Kernel, + 9, + CV_buildOpticalFlowPyramid_InputValidator, + CV_buildOpticalFlowPyramid_OutputValidator, + nullptr, + nullptr); + + if (kernel) + { + PARAM_ERROR_CHECK(vxAddParameterToKernel(kernel, 0, VX_INPUT, VX_TYPE_IMAGE, VX_PARAMETER_STATE_REQUIRED)); + PARAM_ERROR_CHECK(vxAddParameterToKernel(kernel, 1, VX_BIDIRECTIONAL, VX_TYPE_PYRAMID, VX_PARAMETER_STATE_REQUIRED)); + PARAM_ERROR_CHECK(vxAddParameterToKernel(kernel, 2, VX_INPUT, VX_TYPE_SCALAR, VX_PARAMETER_STATE_REQUIRED)); + PARAM_ERROR_CHECK(vxAddParameterToKernel(kernel, 3, VX_INPUT, VX_TYPE_SCALAR, VX_PARAMETER_STATE_REQUIRED)); + PARAM_ERROR_CHECK(vxAddParameterToKernel(kernel, 4, VX_INPUT, VX_TYPE_SCALAR, VX_PARAMETER_STATE_REQUIRED)); + PARAM_ERROR_CHECK(vxAddParameterToKernel(kernel, 5, VX_INPUT, VX_TYPE_SCALAR, VX_PARAMETER_STATE_REQUIRED)); + PARAM_ERROR_CHECK(vxAddParameterToKernel(kernel, 6, VX_INPUT, VX_TYPE_SCALAR, VX_PARAMETER_STATE_REQUIRED)); + PARAM_ERROR_CHECK(vxAddParameterToKernel(kernel, 7, VX_INPUT, VX_TYPE_SCALAR, VX_PARAMETER_STATE_REQUIRED)); + PARAM_ERROR_CHECK(vxAddParameterToKernel(kernel, 8, VX_INPUT, VX_TYPE_SCALAR, VX_PARAMETER_STATE_REQUIRED)); + PARAM_ERROR_CHECK(vxFinalizeKernel(kernel)); + + } + + if (status != VX_SUCCESS) + { + exit: vxRemoveKernel(kernel); return VX_FAILURE; + } + + return status; +} diff --git a/vx_ext_cv/OpenCV_buildPyramid.cpp b/vx_ext_cv/OpenCV_buildPyramid.cpp new file mode 100644 index 0000000..8418687 --- /dev/null +++ b/vx_ext_cv/OpenCV_buildPyramid.cpp @@ -0,0 +1,190 @@ +/* +Copyright (c) 2015 Advanced Micro Devices, Inc. All rights reserved. + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. +*/ + + +#include"publishkernels.h" + +/************************************************************************************************************ +input parameter validator. +param [in] node The handle to the node. +param [in] index The index of the parameter to validate. +*************************************************************************************************************/ +static vx_status VX_CALLBACK CV_buildPyramid_InputValidator(vx_node node, vx_uint32 index) +{ + vx_status status = VX_SUCCESS; + vx_parameter param = vxGetParameterByIndex(node, index); + + if (index == 0) + { + vx_image image; + vx_df_image df_image = VX_DF_IMAGE_VIRT; + STATUS_ERROR_CHECK(vxQueryParameter(param, VX_PARAMETER_ATTRIBUTE_REF, &image, sizeof(vx_image))); + STATUS_ERROR_CHECK(vxQueryImage(image, VX_IMAGE_ATTRIBUTE_FORMAT, &df_image, sizeof(df_image))); + if (df_image != VX_DF_IMAGE_U8) + status = VX_ERROR_INVALID_VALUE; + vxReleaseImage(&image); + } + + else if (index == 1) + { + vx_pyramid image; + vx_df_image df_image = VX_DF_IMAGE_VIRT; + STATUS_ERROR_CHECK(vxQueryParameter(param, VX_PARAMETER_ATTRIBUTE_REF, &image, sizeof(vx_pyramid))); + STATUS_ERROR_CHECK(vxQueryPyramid(image, VX_PYRAMID_ATTRIBUTE_FORMAT, &df_image, sizeof(df_image))); + if (df_image != VX_DF_IMAGE_U8) + status = VX_ERROR_INVALID_VALUE; + vxReleasePyramid(&image); + } + + else if (index == 2) + { + vx_scalar scalar = 0; vx_enum type = 0; vx_int32 value = 0; + STATUS_ERROR_CHECK(vxQueryParameter(param, VX_PARAMETER_ATTRIBUTE_REF, &scalar, sizeof(scalar))); + STATUS_ERROR_CHECK(vxQueryScalar(scalar, VX_SCALAR_ATTRIBUTE_TYPE, &type, sizeof(type))); + STATUS_ERROR_CHECK(vxReadScalarValue(scalar, &value)); + if (value < 0 || type != VX_TYPE_INT32) + status = VX_ERROR_INVALID_VALUE; + vxReleaseScalar(&scalar); + } + + else if (index == 3) + { + vx_scalar scalar = 0; vx_enum type = 0; vx_int32 value = 0; + STATUS_ERROR_CHECK(vxQueryParameter(param, VX_PARAMETER_ATTRIBUTE_REF, &scalar, sizeof(scalar))); + STATUS_ERROR_CHECK(vxQueryScalar(scalar, VX_SCALAR_ATTRIBUTE_TYPE, &type, sizeof(type))); + STATUS_ERROR_CHECK(vxReadScalarValue(scalar, &value)); + if (value < 0 || type != VX_TYPE_INT32) + status = VX_ERROR_INVALID_VALUE; + vxReleaseScalar(&scalar); + } + + vxReleaseParameter(¶m); + return status; +} + +/************************************************************************************************************ +output parameter validator. +*************************************************************************************************************/ +static vx_status VX_CALLBACK CV_buildPyramid_OutputValidator(vx_node node, vx_uint32 index, vx_meta_format meta) +{ + vx_status status = VX_SUCCESS; + if (index == 1) + { + vx_parameter output_param = vxGetParameterByIndex(node, 1); + vx_pyramid output; vx_uint32 width = 0, height = 0, level = 0; vx_float32 scale; + vx_df_image format = VX_DF_IMAGE_VIRT; + + STATUS_ERROR_CHECK(vxQueryParameter(output_param, VX_PARAMETER_ATTRIBUTE_REF, &output, sizeof(vx_image))); + STATUS_ERROR_CHECK(vxQueryPyramid(output, VX_PYRAMID_ATTRIBUTE_FORMAT, &format, sizeof(format))); + STATUS_ERROR_CHECK(vxQueryPyramid(output, VX_PYRAMID_ATTRIBUTE_WIDTH, &width, sizeof(width))); + STATUS_ERROR_CHECK(vxQueryPyramid(output, VX_PYRAMID_ATTRIBUTE_HEIGHT, &height, sizeof(height))); + STATUS_ERROR_CHECK(vxQueryPyramid(output, VX_PYRAMID_ATTRIBUTE_LEVELS, &level, sizeof(level))); + STATUS_ERROR_CHECK(vxQueryPyramid(output, VX_PYRAMID_ATTRIBUTE_SCALE, &scale, sizeof(scale))); + + if (format != VX_DF_IMAGE_U8) + status = VX_ERROR_INVALID_VALUE; + if (scale <= 0) + status = VX_ERROR_INVALID_VALUE; + if (level <= 0) + status = VX_ERROR_INVALID_VALUE; + if (width <= 0) + status = VX_ERROR_INVALID_VALUE; + if (height <= 0) + status = VX_ERROR_INVALID_VALUE; + + STATUS_ERROR_CHECK(vxSetMetaFormatAttribute(meta, VX_PYRAMID_ATTRIBUTE_WIDTH, &width, sizeof(width))); + STATUS_ERROR_CHECK(vxSetMetaFormatAttribute(meta, VX_PYRAMID_ATTRIBUTE_HEIGHT, &height, sizeof(height))); + STATUS_ERROR_CHECK(vxSetMetaFormatAttribute(meta, VX_PYRAMID_ATTRIBUTE_FORMAT, &format, sizeof(format))); + STATUS_ERROR_CHECK(vxSetMetaFormatAttribute(meta, VX_PYRAMID_ATTRIBUTE_LEVELS, &level, sizeof(level))); + STATUS_ERROR_CHECK(vxSetMetaFormatAttribute(meta, VX_PYRAMID_ATTRIBUTE_SCALE, &scale, sizeof(scale))); + + vxReleasePyramid(&output); + vxReleaseParameter(&output_param); + } + return status; +} + +/************************************************************************************************************ +Execution Kernel +*************************************************************************************************************/ +static vx_status VX_CALLBACK CV_buildPyramid_Kernel(vx_node node, const vx_reference *parameters, vx_uint32 num) +{ + vx_status status = VX_SUCCESS; + vx_image image_in = (vx_image) parameters[0]; + vx_pyramid pyramid = (vx_pyramid) parameters[1]; + vx_scalar scalar = (vx_scalar) parameters[2]; + vx_scalar scalar1 = (vx_scalar) parameters[3]; + + Mat *mat, bl; + int maxLevel, border; + + vx_int32 value = 0; + + //Extracting Values from the Scalar into maxLevel and Ddepth + STATUS_ERROR_CHECK(vxReadScalarValue(scalar, &value));maxLevel = value; + STATUS_ERROR_CHECK(vxReadScalarValue(scalar1, &value));border = value; + + //Converting VX Image to OpenCV Mat + STATUS_ERROR_CHECK(VX_to_CV_Image(&mat, image_in)); + + //Compute using OpenCV + vector pyramid_cv; + cv::buildPyramid(*mat, pyramid_cv, maxLevel, border); + + //Converting OpenCV Vector Mat into VX Image + STATUS_ERROR_CHECK(CV_to_VX_Pyramid(pyramid, pyramid_cv)); + + return status; +} + +/************************************************************************************************************ +Function to Register the Kernel for Publish +*************************************************************************************************************/ +vx_status CV_buildPyramid_Register(vx_context context) +{ + vx_status status = VX_SUCCESS; + vx_kernel kernel = vxAddKernel(context, + "org.opencv.buildpyramid", + VX_KERNEL_EXT_CV_BUILD_PYRAMID, + CV_buildPyramid_Kernel, + 4, + CV_buildPyramid_InputValidator, + CV_buildPyramid_OutputValidator, + nullptr, + nullptr); + + if (kernel) + { + PARAM_ERROR_CHECK(vxAddParameterToKernel(kernel, 0, VX_INPUT, VX_TYPE_IMAGE, VX_PARAMETER_STATE_REQUIRED)); + PARAM_ERROR_CHECK(vxAddParameterToKernel(kernel, 1, VX_BIDIRECTIONAL, VX_TYPE_PYRAMID, VX_PARAMETER_STATE_REQUIRED)); + PARAM_ERROR_CHECK(vxAddParameterToKernel(kernel, 2, VX_INPUT, VX_TYPE_SCALAR, VX_PARAMETER_STATE_REQUIRED)); + PARAM_ERROR_CHECK(vxAddParameterToKernel(kernel, 3, VX_INPUT, VX_TYPE_SCALAR, VX_PARAMETER_STATE_REQUIRED)); + PARAM_ERROR_CHECK(vxFinalizeKernel(kernel)); + } + + if (status != VX_SUCCESS) + { + exit: vxRemoveKernel(kernel); return VX_FAILURE; + } + + return status; +} \ No newline at end of file diff --git a/vx_ext_cv/OpenCV_compare.cpp b/vx_ext_cv/OpenCV_compare.cpp new file mode 100644 index 0000000..ac3d9b7 --- /dev/null +++ b/vx_ext_cv/OpenCV_compare.cpp @@ -0,0 +1,177 @@ +/* +Copyright (c) 2015 Advanced Micro Devices, Inc. All rights reserved. + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. +*/ + + +#include"publishkernels.h" + +/************************************************************************************************************ +input parameter validator. +param [in] node The handle to the node. +param [in] index The index of the parameter to validate. +*************************************************************************************************************/ +static vx_status VX_CALLBACK CV_compare_InputValidator(vx_node node, vx_uint32 index) +{ + vx_status status = VX_SUCCESS; + vx_parameter param = vxGetParameterByIndex(node, index); + + if (index == 0) + { + vx_image image; + vx_df_image df_image = VX_DF_IMAGE_VIRT; + STATUS_ERROR_CHECK(vxQueryParameter(param, VX_PARAMETER_ATTRIBUTE_REF, &image, sizeof(vx_image))); + STATUS_ERROR_CHECK(vxQueryImage(image, VX_IMAGE_ATTRIBUTE_FORMAT, &df_image, sizeof(df_image))); + if (df_image != VX_DF_IMAGE_U8 && df_image != VX_DF_IMAGE_S16) + status = VX_ERROR_INVALID_VALUE; + vxReleaseImage(&image); + } + + if (index == 1) + { + vx_image image; + vx_df_image df_image = VX_DF_IMAGE_VIRT; + STATUS_ERROR_CHECK(vxQueryParameter(param, VX_PARAMETER_ATTRIBUTE_REF, &image, sizeof(vx_image))); + STATUS_ERROR_CHECK(vxQueryImage(image, VX_IMAGE_ATTRIBUTE_FORMAT, &df_image, sizeof(df_image))); + if (df_image != VX_DF_IMAGE_U8 && df_image != VX_DF_IMAGE_S16) + status = VX_ERROR_INVALID_VALUE; + vxReleaseImage(&image); + } + + else if (index == 2) + { + vx_image image; + vx_df_image df_image = VX_DF_IMAGE_VIRT; + STATUS_ERROR_CHECK(vxQueryParameter(param, VX_PARAMETER_ATTRIBUTE_REF, &image, sizeof(vx_image))); + STATUS_ERROR_CHECK(vxQueryImage(image, VX_IMAGE_ATTRIBUTE_FORMAT, &df_image, sizeof(df_image))); + if (df_image != VX_DF_IMAGE_U8 && df_image != VX_DF_IMAGE_S16) + status = VX_ERROR_INVALID_VALUE; + vxReleaseImage(&image); + } + + else if (index == 3) + { + vx_scalar scalar = 0; vx_enum type = 0; vx_int32 value = 0; + STATUS_ERROR_CHECK(vxQueryParameter(param, VX_PARAMETER_ATTRIBUTE_REF, &scalar, sizeof(scalar))); + STATUS_ERROR_CHECK(vxQueryScalar(scalar, VX_SCALAR_ATTRIBUTE_TYPE, &type, sizeof(type))); + STATUS_ERROR_CHECK(vxReadScalarValue(scalar, &value)); + if (value < 0 || type != VX_TYPE_INT32) + status = VX_ERROR_INVALID_VALUE; + vxReleaseScalar(&scalar); + } + + vxReleaseParameter(¶m); + return status; +} + +/************************************************************************************************************ +output parameter validator. +*************************************************************************************************************/ +static vx_status VX_CALLBACK CV_compare_OutputValidator(vx_node node, vx_uint32 index, vx_meta_format meta) +{ + vx_status status = VX_SUCCESS; + if (index == 2) + { + vx_parameter output_param = vxGetParameterByIndex(node, 2); + vx_image output; vx_uint32 width = 0, height = 0; vx_df_image format = VX_DF_IMAGE_VIRT; + + STATUS_ERROR_CHECK(vxQueryParameter(output_param, VX_PARAMETER_ATTRIBUTE_REF, &output, sizeof(vx_image))); + STATUS_ERROR_CHECK(vxQueryImage(output, VX_IMAGE_ATTRIBUTE_FORMAT, &format, sizeof(format))); + STATUS_ERROR_CHECK(vxQueryImage(output, VX_IMAGE_ATTRIBUTE_WIDTH, &width, sizeof(width))); + STATUS_ERROR_CHECK(vxQueryImage(output, VX_IMAGE_ATTRIBUTE_HEIGHT, &height, sizeof(height))); + + if (format != VX_DF_IMAGE_U8 && format != VX_DF_IMAGE_S16) + status = VX_ERROR_INVALID_VALUE; + + STATUS_ERROR_CHECK(vxSetMetaFormatAttribute(meta, VX_IMAGE_ATTRIBUTE_WIDTH, &width, sizeof(width))); + STATUS_ERROR_CHECK(vxSetMetaFormatAttribute(meta, VX_IMAGE_ATTRIBUTE_HEIGHT, &height, sizeof(height))); + STATUS_ERROR_CHECK(vxSetMetaFormatAttribute(meta, VX_IMAGE_ATTRIBUTE_FORMAT, &format, sizeof(format))); + + vxReleaseImage(&output); + vxReleaseParameter(&output_param); + } + return status; +} + +/************************************************************************************************************ +Execution Kernel +*************************************************************************************************************/ +static vx_status VX_CALLBACK CV_compare_Kernel(vx_node node, const vx_reference *parameters, vx_uint32 num) +{ + vx_status status = VX_SUCCESS; + vx_image image_1 = (vx_image) parameters[0]; + vx_image image_2 = (vx_image) parameters[1]; + vx_image image_out = (vx_image) parameters[2]; + vx_scalar CMPOP = (vx_scalar) parameters[3]; + + Mat *mat_1, *mat_2, bl; + vx_int32 value = 0; + int cmpop; + + //Extracting Values from the Scalar into Ksize and Ddepth + STATUS_ERROR_CHECK(vxReadScalarValue(CMPOP, &value)); cmpop = value; + + //Converting VX Image to OpenCV Mat + STATUS_ERROR_CHECK(match_vx_image_parameters(image_1, image_2)); + STATUS_ERROR_CHECK(match_vx_image_parameters(image_1, image_out)); + STATUS_ERROR_CHECK(VX_to_CV_Image(&mat_1, image_1)); + STATUS_ERROR_CHECK(VX_to_CV_Image(&mat_2, image_2)); + + //Compute using OpenCV + cv::compare(*mat_1, *mat_2, bl, cmpop); + + //Converting OpenCV Mat into VX Image + STATUS_ERROR_CHECK(CV_to_VX_Image(image_out, &bl)); + + return status; +} + +/************************************************************************************************************ +Function to Register the Kernel for Publish +*************************************************************************************************************/ +vx_status CV_compare_Register(vx_context context) +{ + vx_status status = VX_SUCCESS; + vx_kernel kernel = vxAddKernel(context, + "org.opencv.compare", + VX_KERNEL_EXT_CV_COMPARE, + CV_compare_Kernel, + 4, + CV_compare_InputValidator, + CV_compare_OutputValidator, + nullptr, + nullptr); + + if (kernel) + { + PARAM_ERROR_CHECK(vxAddParameterToKernel(kernel, 0, VX_INPUT, VX_TYPE_IMAGE, VX_PARAMETER_STATE_REQUIRED)); + PARAM_ERROR_CHECK(vxAddParameterToKernel(kernel, 1, VX_INPUT, VX_TYPE_IMAGE, VX_PARAMETER_STATE_REQUIRED)); + PARAM_ERROR_CHECK(vxAddParameterToKernel(kernel, 2, VX_OUTPUT, VX_TYPE_IMAGE, VX_PARAMETER_STATE_REQUIRED)); + PARAM_ERROR_CHECK(vxAddParameterToKernel(kernel, 3, VX_INPUT, VX_TYPE_SCALAR, VX_PARAMETER_STATE_REQUIRED)); + PARAM_ERROR_CHECK(vxFinalizeKernel(kernel)); + } + + if (status != VX_SUCCESS) + { + exit: vxRemoveKernel(kernel); return VX_FAILURE; + } + + return status; +} \ No newline at end of file diff --git a/vx_ext_cv/OpenCV_convertScaleAbs.cpp b/vx_ext_cv/OpenCV_convertScaleAbs.cpp new file mode 100644 index 0000000..5f42f45 --- /dev/null +++ b/vx_ext_cv/OpenCV_convertScaleAbs.cpp @@ -0,0 +1,176 @@ +/* +Copyright (c) 2015 Advanced Micro Devices, Inc. All rights reserved. + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. +*/ + + +#include"publishkernels.h" + +/************************************************************************************************************ +input parameter validator. +param [in] node The handle to the node. +param [in] index The index of the parameter to validate. +*************************************************************************************************************/ +static vx_status VX_CALLBACK CV_convertScaleAbs_InputValidator(vx_node node, vx_uint32 index) +{ + vx_status status = VX_SUCCESS; + vx_parameter param = vxGetParameterByIndex(node, index); + + if (index == 0) + { + vx_image image; + vx_df_image df_image = VX_DF_IMAGE_VIRT; + STATUS_ERROR_CHECK(vxQueryParameter(param, VX_PARAMETER_ATTRIBUTE_REF, &image, sizeof(vx_image))); + STATUS_ERROR_CHECK(vxQueryImage(image, VX_IMAGE_ATTRIBUTE_FORMAT, &df_image, sizeof(df_image))); + if (df_image != VX_DF_IMAGE_U8 && df_image != VX_DF_IMAGE_U16 && df_image != VX_DF_IMAGE_S16) + status = VX_ERROR_INVALID_VALUE; + vxReleaseImage(&image); + } + + else if (index == 1) + { + vx_image image; + vx_df_image df_image = VX_DF_IMAGE_VIRT; + STATUS_ERROR_CHECK(vxQueryParameter(param, VX_PARAMETER_ATTRIBUTE_REF, &image, sizeof(vx_image))); + STATUS_ERROR_CHECK(vxQueryImage(image, VX_IMAGE_ATTRIBUTE_FORMAT, &df_image, sizeof(df_image))); + if (df_image != VX_DF_IMAGE_U8) + status = VX_ERROR_INVALID_VALUE; + vxReleaseImage(&image); + } + + else if (index == 2) + { + vx_scalar scalar = 0; vx_enum type = 0; vx_float32 value = 0; + STATUS_ERROR_CHECK(vxQueryParameter(param, VX_PARAMETER_ATTRIBUTE_REF, &scalar, sizeof(scalar))); + STATUS_ERROR_CHECK(vxQueryScalar(scalar, VX_SCALAR_ATTRIBUTE_TYPE, &type, sizeof(type))); + STATUS_ERROR_CHECK(vxReadScalarValue(scalar, &value)); + if (value < 0 || type != VX_TYPE_FLOAT32) + status = VX_ERROR_INVALID_VALUE; + vxReleaseScalar(&scalar); + } + + else if (index == 3) + { + vx_scalar scalar = 0; vx_enum type = 0; vx_float32 value = 0; + STATUS_ERROR_CHECK(vxQueryParameter(param, VX_PARAMETER_ATTRIBUTE_REF, &scalar, sizeof(scalar))); + STATUS_ERROR_CHECK(vxQueryScalar(scalar, VX_SCALAR_ATTRIBUTE_TYPE, &type, sizeof(type))); + STATUS_ERROR_CHECK(vxReadScalarValue(scalar, &value)); + if (value < 0 || type != VX_TYPE_FLOAT32) + status = VX_ERROR_INVALID_VALUE; + vxReleaseScalar(&scalar); + } + + vxReleaseParameter(¶m); + return status; +} + +/************************************************************************************************************ +output parameter validator. +*************************************************************************************************************/ +static vx_status VX_CALLBACK CV_convertScaleAbs_OutputValidator(vx_node node, vx_uint32 index, vx_meta_format meta) +{ + vx_status status = VX_SUCCESS; + if (index == 1) + { + vx_parameter output_param = vxGetParameterByIndex(node, 1); + vx_image output; vx_uint32 width = 0, height = 0; vx_df_image format = VX_DF_IMAGE_VIRT; + + STATUS_ERROR_CHECK(vxQueryParameter(output_param, VX_PARAMETER_ATTRIBUTE_REF, &output, sizeof(vx_image))); + STATUS_ERROR_CHECK(vxQueryImage(output, VX_IMAGE_ATTRIBUTE_FORMAT, &format, sizeof(format))); + STATUS_ERROR_CHECK(vxQueryImage(output, VX_IMAGE_ATTRIBUTE_WIDTH, &width, sizeof(width))); + STATUS_ERROR_CHECK(vxQueryImage(output, VX_IMAGE_ATTRIBUTE_HEIGHT, &height, sizeof(height))); + + if (format != VX_DF_IMAGE_U8) + status = VX_ERROR_INVALID_VALUE; + + STATUS_ERROR_CHECK(vxSetMetaFormatAttribute(meta, VX_IMAGE_ATTRIBUTE_WIDTH, &width, sizeof(width))); + STATUS_ERROR_CHECK(vxSetMetaFormatAttribute(meta, VX_IMAGE_ATTRIBUTE_HEIGHT, &height, sizeof(height))); + STATUS_ERROR_CHECK(vxSetMetaFormatAttribute(meta, VX_IMAGE_ATTRIBUTE_FORMAT, &format, sizeof(format))); + + vxReleaseImage(&output); + vxReleaseParameter(&output_param); + } + return status; +} + +/************************************************************************************************************ +Execution Kernel +*************************************************************************************************************/ +static vx_status VX_CALLBACK CV_convertScaleAbs_Kernel(vx_node node, const vx_reference *parameters, vx_uint32 num) +{ + vx_status status = VX_SUCCESS; + + vx_image image_in = (vx_image)parameters[0]; + vx_image image_out = (vx_image)parameters[1]; + vx_scalar ALPHA = (vx_scalar)parameters[2]; + vx_scalar BETA = (vx_scalar)parameters[3]; + Mat *mat, bl; + double alpha, beta; + vx_float32 value = 0; + + //Extracting Values from the Scalar into Ksize and Ddepth + STATUS_ERROR_CHECK(vxReadScalarValue(ALPHA, &value)); alpha = value; + STATUS_ERROR_CHECK(vxReadScalarValue(BETA, &value)); beta = value; + + //Converting VX Image to OpenCV Mat + STATUS_ERROR_CHECK(match_vx_image_parameters(image_in, image_out)); + STATUS_ERROR_CHECK(VX_to_CV_Image(&mat, image_in)); + + //Compute using OpenCV + convertScaleAbs(*mat, bl, alpha, beta); + + //Converting OpenCV Mat into VX Image + STATUS_ERROR_CHECK(CV_to_VX_Image(image_out, &bl)); + + return status; +} + +/************************************************************************************************************ +Function to Register the Kernel for Publish +*************************************************************************************************************/ +vx_status CV_convertScaleAbs_Register(vx_context context) +{ + vx_status status = VX_SUCCESS; + vx_kernel Kernel = vxAddKernel(context, + "org.opencv.convertscaleabs", + VX_KERNEL_EXT_CV_CONVERTSCALEABS, + CV_convertScaleAbs_Kernel, + 4, + CV_convertScaleAbs_InputValidator, + CV_convertScaleAbs_OutputValidator, + nullptr, + nullptr); + + if (Kernel) + { + PARAM_ERROR_CHECK(vxAddParameterToKernel(Kernel, 0, VX_INPUT, VX_TYPE_IMAGE, VX_PARAMETER_STATE_REQUIRED)); + PARAM_ERROR_CHECK(vxAddParameterToKernel(Kernel, 1, VX_OUTPUT, VX_TYPE_IMAGE, VX_PARAMETER_STATE_REQUIRED)); + PARAM_ERROR_CHECK(vxAddParameterToKernel(Kernel, 2, VX_INPUT, VX_TYPE_SCALAR, VX_PARAMETER_STATE_REQUIRED)); + PARAM_ERROR_CHECK(vxAddParameterToKernel(Kernel, 3, VX_INPUT, VX_TYPE_SCALAR, VX_PARAMETER_STATE_REQUIRED)); + PARAM_ERROR_CHECK(vxFinalizeKernel(Kernel)); + } + + if (status != VX_SUCCESS) + { + exit: vxRemoveKernel(Kernel); return VX_FAILURE; + } + + return status; +} \ No newline at end of file diff --git a/vx_ext_cv/OpenCV_cornerHarris.cpp b/vx_ext_cv/OpenCV_cornerHarris.cpp new file mode 100644 index 0000000..291eaea --- /dev/null +++ b/vx_ext_cv/OpenCV_cornerHarris.cpp @@ -0,0 +1,207 @@ +/* +Copyright (c) 2015 Advanced Micro Devices, Inc. All rights reserved. + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. +*/ + + +#include"publishkernels.h" + +/************************************************************************************************************ +input parameter validator. +param [in] node The handle to the node. +param [in] index The index of the parameter to validate. +*************************************************************************************************************/ +static vx_status VX_CALLBACK CV_cornerHarris_InputValidator(vx_node node, vx_uint32 index) +{ + vx_status status = VX_SUCCESS ; + vx_parameter param = vxGetParameterByIndex(node, index); + + if (index == 0) + { + vx_image image; + vx_df_image df_image = VX_DF_IMAGE_VIRT; + STATUS_ERROR_CHECK(vxQueryParameter(param, VX_PARAMETER_ATTRIBUTE_REF, &image, sizeof(vx_image))); + STATUS_ERROR_CHECK(vxQueryImage(image, VX_IMAGE_ATTRIBUTE_FORMAT, &df_image, sizeof(df_image))); + if (df_image != VX_DF_IMAGE_U8) + status = VX_ERROR_INVALID_VALUE; + vxReleaseImage(&image); + } + + else if (index == 1) + { + vx_image image; + vx_df_image df_image = VX_DF_IMAGE_VIRT; + STATUS_ERROR_CHECK(vxQueryParameter(param, VX_PARAMETER_ATTRIBUTE_REF, &image, sizeof(vx_image))); + STATUS_ERROR_CHECK(vxQueryImage(image, VX_IMAGE_ATTRIBUTE_FORMAT, &df_image, sizeof(df_image))); + if (df_image != VX_DF_IMAGE_U8) + status = VX_ERROR_INVALID_VALUE; + vxReleaseImage(&image); + } + + else if (index == 2) + { + vx_scalar scalar = 0; vx_enum type = 0; vx_int32 value = 0; + STATUS_ERROR_CHECK(vxQueryParameter(param, VX_PARAMETER_ATTRIBUTE_REF, &scalar, sizeof(scalar))); + STATUS_ERROR_CHECK(vxQueryScalar(scalar, VX_SCALAR_ATTRIBUTE_TYPE, &type, sizeof(type))); + STATUS_ERROR_CHECK(vxReadScalarValue(scalar, &value)); + if (value < 0 || type != VX_TYPE_INT32) + status = VX_ERROR_INVALID_VALUE; + vxReleaseScalar(&scalar); + } + + else if (index == 3) + { + vx_scalar scalar = 0; vx_enum type = 0; vx_int32 value = 0; + STATUS_ERROR_CHECK(vxQueryParameter(param, VX_PARAMETER_ATTRIBUTE_REF, &scalar, sizeof(scalar))); + STATUS_ERROR_CHECK(vxQueryScalar(scalar, VX_SCALAR_ATTRIBUTE_TYPE, &type, sizeof(type))); + STATUS_ERROR_CHECK(vxReadScalarValue(scalar, &value)); + if (value < 0 || type != VX_TYPE_INT32) + status = VX_ERROR_INVALID_VALUE; + vxReleaseScalar(&scalar); + } + + else if (index == 4) + { + + vx_scalar scalar = 0; vx_enum type = 0; vx_float32 value = 0; + STATUS_ERROR_CHECK(vxQueryParameter(param, VX_PARAMETER_ATTRIBUTE_REF, &scalar, sizeof(scalar))); + STATUS_ERROR_CHECK(vxQueryScalar(scalar, VX_SCALAR_ATTRIBUTE_TYPE, &type, sizeof(type))); + STATUS_ERROR_CHECK(vxReadScalarValue(scalar, &value)); + if (value < 0 || type != VX_TYPE_FLOAT32) + status = VX_ERROR_INVALID_VALUE; + vxReleaseScalar(&scalar); + } + + else if (index == 5) + { + vx_scalar scalar = 0; vx_enum type = 0; vx_int32 value = 0; + STATUS_ERROR_CHECK(vxQueryParameter(param, VX_PARAMETER_ATTRIBUTE_REF, &scalar, sizeof(scalar))); + STATUS_ERROR_CHECK(vxQueryScalar(scalar, VX_SCALAR_ATTRIBUTE_TYPE, &type, sizeof(type))); + STATUS_ERROR_CHECK(vxReadScalarValue(scalar, &value)); + if (value < 0 || type != VX_TYPE_INT32) + status = VX_ERROR_INVALID_VALUE; + vxReleaseScalar(&scalar); + } + + vxReleaseParameter(¶m); + return status; +} + +/************************************************************************************************************ +output parameter validator. +*************************************************************************************************************/ +static vx_status VX_CALLBACK CV_cornerHarris_OutputValidator(vx_node node, vx_uint32 index, vx_meta_format meta) +{ + vx_status status = VX_SUCCESS ; + if (index == 1) + { + vx_parameter output_param = vxGetParameterByIndex(node, 1); + vx_image output; vx_uint32 width = 0, height = 0; vx_df_image format = VX_DF_IMAGE_VIRT; + + STATUS_ERROR_CHECK(vxQueryParameter(output_param, VX_PARAMETER_ATTRIBUTE_REF, &output, sizeof(vx_image))); + STATUS_ERROR_CHECK(vxQueryImage(output, VX_IMAGE_ATTRIBUTE_FORMAT, &format, sizeof(format))); + STATUS_ERROR_CHECK(vxQueryImage(output, VX_IMAGE_ATTRIBUTE_WIDTH, &width, sizeof(width))); + STATUS_ERROR_CHECK(vxQueryImage(output, VX_IMAGE_ATTRIBUTE_HEIGHT, &height, sizeof(height))); + + if (format != VX_DF_IMAGE_U8 && format != VX_DF_IMAGE_S16) + status = VX_ERROR_INVALID_VALUE; + + STATUS_ERROR_CHECK(vxSetMetaFormatAttribute(meta, VX_IMAGE_ATTRIBUTE_WIDTH, &width, sizeof(width))); + STATUS_ERROR_CHECK(vxSetMetaFormatAttribute(meta, VX_IMAGE_ATTRIBUTE_HEIGHT, &height, sizeof(height))); + STATUS_ERROR_CHECK(vxSetMetaFormatAttribute(meta, VX_IMAGE_ATTRIBUTE_FORMAT, &format, sizeof(format))); + + vxReleaseImage(&output); + vxReleaseParameter(&output_param); + } + return status; +} + +/************************************************************************************************************ +Execution Kernel +*************************************************************************************************************/ +static vx_status VX_CALLBACK CV_cornerHarris_Kernel(vx_node node, const vx_reference *parameters, vx_uint32 num) +{ + vx_status status = VX_SUCCESS; + + vx_image image_in = (vx_image) parameters[0]; + vx_image image_out = (vx_image) parameters[1]; + vx_scalar BLOCK_SIZE = (vx_scalar) parameters[2]; + vx_scalar KSIZE = (vx_scalar) parameters[3]; + vx_scalar K = (vx_scalar) parameters[4]; + vx_scalar BORDER = (vx_scalar) parameters[5]; + Mat *mat, bl; + int blocksize, ksize, border; + float k; + vx_int32 value = 0; + vx_float32 value_f = 0; + + //Extracting Values from the Scalar into Ksize and Ddepth + STATUS_ERROR_CHECK(vxReadScalarValue(BLOCK_SIZE, &value));blocksize = value; + STATUS_ERROR_CHECK(vxReadScalarValue(KSIZE, &value));ksize = value; + STATUS_ERROR_CHECK(vxReadScalarValue(K, &value_f));k = value_f; + STATUS_ERROR_CHECK(vxReadScalarValue(BORDER, &value));border = value; + + //Converting VX Image to OpenCV Mat + STATUS_ERROR_CHECK(match_vx_image_parameters(image_in, image_out)); + STATUS_ERROR_CHECK(VX_to_CV_Image(&mat, image_in)); + + //Compute using OpenCV + cv::cornerHarris(*mat, bl, blocksize, ksize, k, border); + + //Converting OpenCV Mat into VX Image + STATUS_ERROR_CHECK(CV_to_VX_Image(image_out, &bl)); + + return status; +} + +/************************************************************************************************************ +Function to Register the Kernel for Publish +*************************************************************************************************************/ +vx_status CV_cornerHarris_Register(vx_context context) +{ + vx_status status = VX_SUCCESS; + vx_kernel Kernel = vxAddKernel(context, + "org.opencv.cornerharris", + VX_KERNEL_EXT_CV_CORNERHARRIS, + CV_cornerHarris_Kernel, + 6, + CV_cornerHarris_InputValidator, + CV_cornerHarris_OutputValidator, + nullptr, + nullptr); + + if (Kernel) + { + PARAM_ERROR_CHECK(vxAddParameterToKernel(Kernel, 0, VX_INPUT, VX_TYPE_IMAGE, VX_PARAMETER_STATE_REQUIRED)); + PARAM_ERROR_CHECK(vxAddParameterToKernel(Kernel, 1, VX_OUTPUT, VX_TYPE_IMAGE, VX_PARAMETER_STATE_REQUIRED)); + PARAM_ERROR_CHECK(vxAddParameterToKernel(Kernel, 2, VX_INPUT, VX_TYPE_SCALAR, VX_PARAMETER_STATE_REQUIRED)); + PARAM_ERROR_CHECK(vxAddParameterToKernel(Kernel, 3, VX_INPUT, VX_TYPE_SCALAR, VX_PARAMETER_STATE_REQUIRED)); + PARAM_ERROR_CHECK(vxAddParameterToKernel(Kernel, 4, VX_INPUT, VX_TYPE_SCALAR, VX_PARAMETER_STATE_REQUIRED)); + PARAM_ERROR_CHECK(vxAddParameterToKernel(Kernel, 5, VX_INPUT, VX_TYPE_SCALAR, VX_PARAMETER_STATE_REQUIRED)); + PARAM_ERROR_CHECK(vxFinalizeKernel(Kernel)); + } + + if (status != VX_SUCCESS) + { + exit: vxRemoveKernel(Kernel); return VX_FAILURE; + } + + return status; +} \ No newline at end of file diff --git a/vx_ext_cv/OpenCV_cornerMinEigenVal.cpp b/vx_ext_cv/OpenCV_cornerMinEigenVal.cpp new file mode 100644 index 0000000..bfca587 --- /dev/null +++ b/vx_ext_cv/OpenCV_cornerMinEigenVal.cpp @@ -0,0 +1,190 @@ +/* +Copyright (c) 2015 Advanced Micro Devices, Inc. All rights reserved. + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. +*/ + + +#include"publishkernels.h" + +/************************************************************************************************************ +input parameter validator. +param [in] node The handle to the node. +param [in] index The index of the parameter to validate. +*************************************************************************************************************/ +static vx_status VX_CALLBACK CV_cornerMinEigenVal_InputValidator(vx_node node, vx_uint32 index) +{ + vx_status status = VX_SUCCESS ; + vx_parameter param = vxGetParameterByIndex(node, index); + + if (index == 0) + { + vx_image image; + vx_df_image df_image = VX_DF_IMAGE_VIRT; + STATUS_ERROR_CHECK(vxQueryParameter(param, VX_PARAMETER_ATTRIBUTE_REF, &image, sizeof(vx_image))); + STATUS_ERROR_CHECK(vxQueryImage(image, VX_IMAGE_ATTRIBUTE_FORMAT, &df_image, sizeof(df_image))); + if (df_image != VX_DF_IMAGE_U8) + status = VX_ERROR_INVALID_VALUE; + vxReleaseImage(&image); + } + + else if (index == 1) + { + vx_image image; + vx_df_image df_image = VX_DF_IMAGE_VIRT; + STATUS_ERROR_CHECK(vxQueryParameter(param, VX_PARAMETER_ATTRIBUTE_REF, &image, sizeof(vx_image))); + STATUS_ERROR_CHECK(vxQueryImage(image, VX_IMAGE_ATTRIBUTE_FORMAT, &df_image, sizeof(df_image))); + if (df_image != VX_DF_IMAGE_U8) + status = VX_ERROR_INVALID_VALUE; + vxReleaseImage(&image); + } + + else if (index == 2) + { + vx_scalar scalar = 0; vx_enum type = 0; vx_int32 value = 0; + STATUS_ERROR_CHECK(vxQueryParameter(param, VX_PARAMETER_ATTRIBUTE_REF, &scalar, sizeof(scalar))); + STATUS_ERROR_CHECK(vxQueryScalar(scalar, VX_SCALAR_ATTRIBUTE_TYPE, &type, sizeof(type))); + STATUS_ERROR_CHECK(vxReadScalarValue(scalar, &value)); + if (value < 0 || type != VX_TYPE_INT32) + status = VX_ERROR_INVALID_VALUE; + vxReleaseScalar(&scalar); + } + + else if (index == 3) + { + vx_scalar scalar = 0; vx_enum type = 0; vx_int32 value = 0; + STATUS_ERROR_CHECK(vxQueryParameter(param, VX_PARAMETER_ATTRIBUTE_REF, &scalar, sizeof(scalar))); + STATUS_ERROR_CHECK(vxQueryScalar(scalar, VX_SCALAR_ATTRIBUTE_TYPE, &type, sizeof(type))); + STATUS_ERROR_CHECK(vxReadScalarValue(scalar, &value)); + if (value < 0 || type != VX_TYPE_INT32) + status = VX_ERROR_INVALID_VALUE; + vxReleaseScalar(&scalar); + } + + else if (index == 4) + { + vx_scalar scalar = 0; vx_enum type = 0; vx_int32 value = 0; + STATUS_ERROR_CHECK(vxQueryParameter(param, VX_PARAMETER_ATTRIBUTE_REF, &scalar, sizeof(scalar))); + STATUS_ERROR_CHECK(vxQueryScalar(scalar, VX_SCALAR_ATTRIBUTE_TYPE, &type, sizeof(type))); + STATUS_ERROR_CHECK(vxReadScalarValue(scalar, &value)); + if (value < 0 || type != VX_TYPE_INT32) + status = VX_ERROR_INVALID_VALUE; + vxReleaseScalar(&scalar); + } + + vxReleaseParameter(¶m); + return status; +} + +/************************************************************************************************************ +output parameter validator. +*************************************************************************************************************/ +static vx_status VX_CALLBACK CV_cornerMinEigenVal_OutputValidator(vx_node node, vx_uint32 index, vx_meta_format meta) +{ + vx_status status = VX_SUCCESS ; + if (index == 1) + { + vx_parameter output_param = vxGetParameterByIndex(node, 1); + vx_image output; vx_uint32 width = 0, height = 0; vx_df_image format = VX_DF_IMAGE_VIRT; + + STATUS_ERROR_CHECK(vxQueryParameter(output_param, VX_PARAMETER_ATTRIBUTE_REF, &output, sizeof(vx_image))); + STATUS_ERROR_CHECK(vxQueryImage(output, VX_IMAGE_ATTRIBUTE_FORMAT, &format, sizeof(format))); + STATUS_ERROR_CHECK(vxQueryImage(output, VX_IMAGE_ATTRIBUTE_WIDTH, &width, sizeof(width))); + STATUS_ERROR_CHECK(vxQueryImage(output, VX_IMAGE_ATTRIBUTE_HEIGHT, &height, sizeof(height))); + + if (format != VX_DF_IMAGE_U8) + status = VX_ERROR_INVALID_VALUE; + + STATUS_ERROR_CHECK(vxSetMetaFormatAttribute(meta, VX_IMAGE_ATTRIBUTE_WIDTH, &width, sizeof(width))); + STATUS_ERROR_CHECK(vxSetMetaFormatAttribute(meta, VX_IMAGE_ATTRIBUTE_HEIGHT, &height, sizeof(height))); + STATUS_ERROR_CHECK(vxSetMetaFormatAttribute(meta, VX_IMAGE_ATTRIBUTE_FORMAT, &format, sizeof(format))); + + vxReleaseImage(&output); + vxReleaseParameter(&output_param); + } + return status; +} + +/************************************************************************************************************ +Execution Kernel +*************************************************************************************************************/ +static vx_status VX_CALLBACK CV_cornerMinEigenVal_Kernel(vx_node node, const vx_reference *parameters, vx_uint32 num) +{ + vx_status status = VX_SUCCESS; + vx_image image_in = (vx_image) parameters[0]; + vx_image image_out = (vx_image) parameters[1]; + vx_scalar BLOCKSIZE = (vx_scalar) parameters[2]; + vx_scalar KSIZE = (vx_scalar) parameters[3]; + vx_scalar BORDER = (vx_scalar) parameters[4]; + + Mat *mat, bl; + int blockSize, ksize, border; + vx_int32 value = 0; + + //Extracting Values from the Scalar into Ksize and Ddepth + STATUS_ERROR_CHECK(vxReadScalarValue(BLOCKSIZE, &value));blockSize = value; + STATUS_ERROR_CHECK(vxReadScalarValue(KSIZE, &value));ksize = value; + STATUS_ERROR_CHECK(vxReadScalarValue(BORDER, &value));border = value; + + //Converting VX Image to OpenCV Mat + STATUS_ERROR_CHECK(match_vx_image_parameters(image_in, image_out)); + STATUS_ERROR_CHECK(VX_to_CV_Image(&mat, image_in)); + + //Compute using OpenCV + cv::cornerMinEigenVal(*mat, bl, blockSize, ksize, border); + + //Converting OpenCV Mat into VX Image + STATUS_ERROR_CHECK(CV_to_VX_Image(image_out, &bl)); + + return status; +} + +/************************************************************************************************************ +Function to Register the Kernel for Publish +*************************************************************************************************************/ +vx_status CV_cornerMinEigenVal_Register(vx_context context) +{ + vx_status status = VX_SUCCESS; + vx_kernel Kernel = vxAddKernel(context, + "org.opencv.cornermineigenval", + VX_KERNEL_EXT_CV_CORNER_MIN_EIGEN_VAL, + CV_cornerMinEigenVal_Kernel, + 5, + CV_cornerMinEigenVal_InputValidator, + CV_cornerMinEigenVal_OutputValidator, + nullptr, + nullptr); + + if (Kernel) + { + PARAM_ERROR_CHECK(vxAddParameterToKernel(Kernel, 0, VX_INPUT, VX_TYPE_IMAGE, VX_PARAMETER_STATE_REQUIRED)); + PARAM_ERROR_CHECK(vxAddParameterToKernel(Kernel, 1, VX_OUTPUT, VX_TYPE_IMAGE, VX_PARAMETER_STATE_REQUIRED)); + PARAM_ERROR_CHECK(vxAddParameterToKernel(Kernel, 2, VX_INPUT, VX_TYPE_SCALAR, VX_PARAMETER_STATE_REQUIRED)); + PARAM_ERROR_CHECK(vxAddParameterToKernel(Kernel, 3, VX_INPUT, VX_TYPE_SCALAR, VX_PARAMETER_STATE_REQUIRED)); + PARAM_ERROR_CHECK(vxAddParameterToKernel(Kernel, 4, VX_INPUT, VX_TYPE_SCALAR, VX_PARAMETER_STATE_REQUIRED)); + PARAM_ERROR_CHECK(vxFinalizeKernel(Kernel)); + } + + if (status != VX_SUCCESS) + { + exit: vxRemoveKernel(Kernel); return VX_FAILURE; + } + + return status; +} \ No newline at end of file diff --git a/vx_ext_cv/OpenCV_countNonZero.cpp b/vx_ext_cv/OpenCV_countNonZero.cpp new file mode 100644 index 0000000..b7354ff --- /dev/null +++ b/vx_ext_cv/OpenCV_countNonZero.cpp @@ -0,0 +1,134 @@ +/* +Copyright (c) 2015 Advanced Micro Devices, Inc. All rights reserved. + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. +*/ + + +#include"publishkernels.h" + +/************************************************************************************************************ +input parameter validator. +param [in] node The handle to the node. +param [in] index The index of the parameter to validate. +*************************************************************************************************************/ +static vx_status VX_CALLBACK CV_countNonZero_InputValidator(vx_node node, vx_uint32 index) +{ + vx_status status = VX_SUCCESS; + vx_parameter param = vxGetParameterByIndex(node, index); + + if (index == 0) + { + vx_image image; + vx_df_image df_image = VX_DF_IMAGE_VIRT; + STATUS_ERROR_CHECK(vxQueryParameter(param, VX_PARAMETER_ATTRIBUTE_REF, &image, sizeof(vx_image))); + STATUS_ERROR_CHECK(vxQueryImage(image, VX_IMAGE_ATTRIBUTE_FORMAT, &df_image, sizeof(df_image))); + if (df_image != VX_DF_IMAGE_U8 && df_image != VX_DF_IMAGE_S16) + status = VX_ERROR_INVALID_VALUE; + vxReleaseImage(&image); + } + + else if (index == 1) + { + vx_scalar scalar = 0; vx_enum type = 0; vx_int32 value = 0; + STATUS_ERROR_CHECK(vxQueryParameter(param, VX_PARAMETER_ATTRIBUTE_REF, &scalar, sizeof(scalar))); + STATUS_ERROR_CHECK(vxQueryScalar(scalar, VX_SCALAR_ATTRIBUTE_TYPE, &type, sizeof(type))); + STATUS_ERROR_CHECK(vxReadScalarValue(scalar, &value)); + if (value < 0 || type != VX_TYPE_INT32) + status = VX_ERROR_INVALID_VALUE; + vxReleaseScalar(&scalar); + } + + vxReleaseParameter(¶m); + return status; +} + +/************************************************************************************************************ +output parameter validator. +*************************************************************************************************************/ +static vx_status VX_CALLBACK CV_countNonZero_OutputValidator(vx_node node, vx_uint32 index, vx_meta_format meta) +{ + vx_status status = VX_SUCCESS; + if (index == 1) + { + vx_parameter output_param = vxGetParameterByIndex(node, 1); + vx_scalar output; vx_scalar scalar = 0; vx_enum type = 0; vx_int32 value = 0; + + STATUS_ERROR_CHECK(vxQueryParameter(output_param, VX_PARAMETER_ATTRIBUTE_REF, &scalar, sizeof(scalar))); + STATUS_ERROR_CHECK(vxReadScalarValue(scalar, &value)); + + vxReleaseScalar(&output); + vxReleaseParameter(&output_param); + } + return status; +} + +/************************************************************************************************************ +Execution Kernel +*************************************************************************************************************/ +static vx_status VX_CALLBACK CV_countNonZero_Kernel(vx_node node, const vx_reference *parameters, vx_uint32 num) +{ + vx_status status = VX_SUCCESS; + vx_image image_in = (vx_image) parameters[0]; + vx_scalar scalar = (vx_scalar) parameters[1]; + Mat *mat; + int NonZero; + + //Converting VX Image to OpenCV Mat + STATUS_ERROR_CHECK(VX_to_CV_Image(&mat, image_in)); + + //Compute using OpenCV + NonZero = cv::countNonZero(*mat); + + //Converting int to Scalar + STATUS_ERROR_CHECK(vxWriteScalarValue(scalar, &NonZero)); + + return status; +} + +/************************************************************************************************************ +Function to Register the Kernel for Publish +*************************************************************************************************************/ +vx_status CV_countNonZero_Register(vx_context context) +{ + vx_status status = VX_SUCCESS; + vx_kernel kernel = vxAddKernel(context, + "org.opencv.countnonzero", + VX_KERNEL_EXT_CV_COUNT_NON_ZERO, + CV_countNonZero_Kernel, + 2, + CV_countNonZero_InputValidator, + CV_countNonZero_OutputValidator, + nullptr, + nullptr); + + if (kernel) + { + PARAM_ERROR_CHECK(vxAddParameterToKernel(kernel, 0, VX_INPUT, VX_TYPE_IMAGE, VX_PARAMETER_STATE_REQUIRED)); + PARAM_ERROR_CHECK(vxAddParameterToKernel(kernel, 1, VX_BIDIRECTIONAL, VX_TYPE_SCALAR, VX_PARAMETER_STATE_REQUIRED)); + PARAM_ERROR_CHECK(vxFinalizeKernel(kernel)); + } + + if (status != VX_SUCCESS) + { + exit: vxRemoveKernel(kernel); return VX_FAILURE; + } + + return status; +} diff --git a/vx_ext_cv/OpenCV_cvtColor.cpp b/vx_ext_cv/OpenCV_cvtColor.cpp new file mode 100644 index 0000000..112ca19 --- /dev/null +++ b/vx_ext_cv/OpenCV_cvtColor.cpp @@ -0,0 +1,164 @@ +/* +Copyright (c) 2015 Advanced Micro Devices, Inc. All rights reserved. + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. +*/ + + +#include"publishkernels.h" + +/************************************************************************************************************ +input parameter validator. +param [in] node The handle to the node. +param [in] index The index of the parameter to validate. +*************************************************************************************************************/ +static vx_status VX_CALLBACK CV_cvtColor_InputValidator(vx_node node, vx_uint32 index) +{ + vx_status status = VX_SUCCESS; + vx_parameter param = vxGetParameterByIndex(node, index); + + if (index == 0) + { // expects input images of type U008 or S016 + vx_image image; + vx_df_image df_image = 0; + STATUS_ERROR_CHECK(vxQueryParameter(param, VX_PARAMETER_ATTRIBUTE_REF, &image, sizeof(vx_image))); + STATUS_ERROR_CHECK(vxQueryImage(image, VX_IMAGE_ATTRIBUTE_FORMAT, &df_image, sizeof(df_image))); + if (df_image != VX_DF_IMAGE_U8 && df_image != VX_DF_IMAGE_S16 && df_image != VX_DF_IMAGE_RGB) + status = VX_ERROR_INVALID_VALUE; + } + + else if (index == 1) + { + vx_image image; + vx_df_image df_image = 0; + STATUS_ERROR_CHECK(vxQueryParameter(param, VX_PARAMETER_ATTRIBUTE_REF, &image, sizeof(vx_image))); + STATUS_ERROR_CHECK(vxQueryImage(image, VX_IMAGE_ATTRIBUTE_FORMAT, &df_image, sizeof(df_image))); + if (df_image != VX_DF_IMAGE_U8 && df_image != VX_DF_IMAGE_S16 && df_image != VX_DF_IMAGE_RGB) + status = VX_ERROR_INVALID_VALUE; + } + + else if (index == 2) + { + vx_scalar scalar = 0; vx_enum type = 0; vx_int32 value = 0; + STATUS_ERROR_CHECK(vxQueryParameter(param, VX_PARAMETER_ATTRIBUTE_REF, &scalar, sizeof(scalar))); + STATUS_ERROR_CHECK(vxQueryScalar(scalar, VX_SCALAR_ATTRIBUTE_TYPE, &type, sizeof(type))); + STATUS_ERROR_CHECK(vxReadScalarValue(scalar, &value)); + if ((value < 0 || value > 254) || type != VX_TYPE_INT32) + status = VX_ERROR_INVALID_VALUE; + vxReleaseScalar(&scalar); + } + + vxReleaseParameter(¶m); + return status; +} + +/************************************************************************************************************ +output parameter validator. +*************************************************************************************************************/ +static vx_status VX_CALLBACK CV_cvtColor_OutputValidator(vx_node node, vx_uint32 index, vx_meta_format meta) +{ + vx_status status = VX_SUCCESS; + if (index == 1) + { + vx_parameter output_param = vxGetParameterByIndex(node, 1); + vx_image output; vx_uint32 width = 0, height = 0; vx_df_image format = VX_DF_IMAGE_VIRT; + + STATUS_ERROR_CHECK(vxQueryParameter(output_param, VX_PARAMETER_ATTRIBUTE_REF, &output, sizeof(vx_image))); + STATUS_ERROR_CHECK(vxQueryImage(output, VX_IMAGE_ATTRIBUTE_FORMAT, &format, sizeof(format))); + STATUS_ERROR_CHECK(vxQueryImage(output, VX_IMAGE_ATTRIBUTE_WIDTH, &width, sizeof(width))); + STATUS_ERROR_CHECK(vxQueryImage(output, VX_IMAGE_ATTRIBUTE_HEIGHT, &height, sizeof(height))); + + if (format != VX_DF_IMAGE_U8 && format != VX_DF_IMAGE_S16 && format != VX_DF_IMAGE_RGB) + status = VX_ERROR_INVALID_VALUE; + + STATUS_ERROR_CHECK(vxSetMetaFormatAttribute(meta, VX_IMAGE_ATTRIBUTE_WIDTH, &width, sizeof(width))); + STATUS_ERROR_CHECK(vxSetMetaFormatAttribute(meta, VX_IMAGE_ATTRIBUTE_HEIGHT, &height, sizeof(height))); + STATUS_ERROR_CHECK(vxSetMetaFormatAttribute(meta, VX_IMAGE_ATTRIBUTE_FORMAT, &format, sizeof(format))); + + vxReleaseImage(&output); + vxReleaseParameter(&output_param); + } + return status; +} + +/************************************************************************************************************ +Execution Kernel +*************************************************************************************************************/ +static vx_status VX_CALLBACK CV_cvtColor_Kernel(vx_node node, const vx_reference *parameters, vx_uint32 num) +{ + vx_status status = VX_SUCCESS; + + vx_image image_in = (vx_image) parameters[0]; + vx_image image_out = (vx_image) parameters[1]; + vx_scalar scalar = (vx_scalar) parameters[2]; + Mat *mat, bl; + int CODE; + vx_int32 value = 0; + + //Extracting Values from the Scalar into CODE + STATUS_ERROR_CHECK(vxReadScalarValue(scalar, &value));CODE = value; + + //Converting VX Image to OpenCV Mat + STATUS_ERROR_CHECK(match_vx_image_parameters(image_in, image_out)); + STATUS_ERROR_CHECK(VX_to_CV_Image(&mat, image_in)); + + //Compute using OpenCV + cv::cvtColor(*mat, bl, CODE);// CODE have to be checked with OpenCV, the frame work will not check for invalid code + + //Converting OpenCV Mat into VX Image + STATUS_ERROR_CHECK(CV_to_VX_Image(image_out, &bl)); + + return status; +} + +/************************************************************************************************************ +Function to Register the Kernel for Publish +*************************************************************************************************************/ +vx_status CV_cvtColor_Register(vx_context context) +{ + //OpenCV cvtColor Node + vx_status status = VX_SUCCESS; + vx_kernel kernel = vxAddKernel(context, + "org.opencv.cvtcolor", + VX_KERNEL_EXT_CV_CVTCOLOR, + CV_cvtColor_Kernel, + 3, + CV_cvtColor_InputValidator, + CV_cvtColor_OutputValidator, + nullptr, + nullptr); + + if (kernel) + { + PARAM_ERROR_CHECK(vxAddParameterToKernel(kernel, 0, VX_INPUT, VX_TYPE_IMAGE, VX_PARAMETER_STATE_REQUIRED)); + PARAM_ERROR_CHECK(vxAddParameterToKernel(kernel, 1, VX_OUTPUT, VX_TYPE_IMAGE, VX_PARAMETER_STATE_REQUIRED)); + PARAM_ERROR_CHECK(vxAddParameterToKernel(kernel, 2, VX_INPUT, VX_TYPE_SCALAR, VX_PARAMETER_STATE_REQUIRED)); + PARAM_ERROR_CHECK(vxFinalizeKernel(kernel)); + } + + if (status != VX_SUCCESS) + { + exit: vxRemoveKernel(kernel); return VX_FAILURE; + } + + return status; +} + + + diff --git a/vx_ext_cv/OpenCV_data_translator.cpp b/vx_ext_cv/OpenCV_data_translator.cpp new file mode 100644 index 0000000..0a69d68 --- /dev/null +++ b/vx_ext_cv/OpenCV_data_translator.cpp @@ -0,0 +1,298 @@ +/* +Copyright (c) 2015 Advanced Micro Devices, Inc. All rights reserved. + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. +*/ + + +#include"OpenCV_Tunnel.h" + +/************************************************************************************************************ +Converting CV Pyramid into an OpenVX Pyramid +*************************************************************************************************************/ +int CV_to_VX_Pyramid(vx_pyramid pyramid_vx, vector pyramid_cv) +{ + vx_status status = VX_SUCCESS; + vx_size Level_vx = 0; vx_uint32 width = 0; vx_uint32 height = 0; vx_int32 i; + + STATUS_ERROR_CHECK(vxQueryPyramid(pyramid_vx, VX_PYRAMID_ATTRIBUTE_LEVELS, &Level_vx, sizeof(Level_vx))); + for (i = 0; i < (int)Level_vx; i++) + { + vx_image this_level = vxGetPyramidLevel(pyramid_vx, i); + STATUS_ERROR_CHECK(vxQueryImage(this_level, VX_IMAGE_ATTRIBUTE_WIDTH, &width, sizeof(width))); + STATUS_ERROR_CHECK(vxQueryImage(this_level, VX_IMAGE_ATTRIBUTE_HEIGHT, &height, sizeof(height))); + if (width != pyramid_cv[i].cols && height != pyramid_cv[i].rows) + { + vxAddLogEntry((vx_reference)pyramid_vx, VX_ERROR_INVALID_DIMENSION, "CV_to_VX_Pyramid ERROR: Pyramid Image Mismatch\n"); return VX_ERROR_INVALID_DIMENSION; + } + Mat* pyr_level; + pyr_level = &pyramid_cv[i]; + CV_to_VX_Image(this_level, pyr_level); + } + return 0; +} + +/************************************************************************************************************ +Converting VX matrix into an OpenCV Mat +*************************************************************************************************************/ +int VX_to_CV_MATRIX(Mat** mat, vx_matrix matrix_vx) +{ + vx_status status = VX_SUCCESS; + vx_size numRows = 0; vx_size numCols = 0; vx_enum type; int Type_CV = 0; + + STATUS_ERROR_CHECK(vxQueryMatrix(matrix_vx, VX_MATRIX_ATTRIBUTE_ROWS, &numRows, sizeof(numRows))); + STATUS_ERROR_CHECK(vxQueryMatrix(matrix_vx, VX_MATRIX_ATTRIBUTE_COLUMNS, &numCols, sizeof(numCols))); + STATUS_ERROR_CHECK(vxQueryMatrix(matrix_vx, VX_MATRIX_ATTRIBUTE_TYPE, &type, sizeof(type))); + + if (type == VX_TYPE_INT32)Type_CV = CV_32S; + if (type == VX_TYPE_FLOAT32)Type_CV = CV_32F; + + if (type != VX_TYPE_FLOAT32 && type != VX_TYPE_INT32) + { + vxAddLogEntry((vx_reference)matrix_vx, VX_ERROR_INVALID_FORMAT, "VX_to_CV_MATRIX ERROR: Matrix type not Supported in this RELEASE\n"); return VX_ERROR_INVALID_FORMAT; + } + + Mat * m_cv; m_cv = new Mat((int)numRows, (int)numCols, Type_CV); vx_size mat_size = numRows * numCols; + float *dyn_matrix = new float[mat_size]; int z = 0; + + STATUS_ERROR_CHECK(vxReadMatrix(matrix_vx, (void *)dyn_matrix)); + for (int i = 0; i < (int)numRows; i++) + for (int j = 0; j < (int)numCols; j++) + { + m_cv->at(i, j) = dyn_matrix[z]; z++; + } + + *mat = m_cv; + return status; +} + +/************************************************************************************************************ +Converting VX Image into an OpenCV Mat +*************************************************************************************************************/ +int VX_to_CV_Image(Mat** mat, vx_image image) +{ + vx_status status = VX_SUCCESS; + vx_uint32 width = 0; vx_uint32 height = 0; vx_df_image format = VX_DF_IMAGE_VIRT; int CV_format = 0; vx_size planes = 0; + + STATUS_ERROR_CHECK(vxQueryImage(image, VX_IMAGE_ATTRIBUTE_WIDTH, &width, sizeof(width))); + STATUS_ERROR_CHECK(vxQueryImage(image, VX_IMAGE_ATTRIBUTE_HEIGHT, &height, sizeof(height))); + STATUS_ERROR_CHECK(vxQueryImage(image, VX_IMAGE_ATTRIBUTE_FORMAT, &format, sizeof(format))); + STATUS_ERROR_CHECK(vxQueryImage(image, VX_IMAGE_ATTRIBUTE_PLANES, &planes, sizeof(planes))); + + if (format == VX_DF_IMAGE_U8)CV_format = CV_8U; + if (format == VX_DF_IMAGE_S16)CV_format = CV_16S; + if (format == VX_DF_IMAGE_RGB)CV_format = CV_8UC3; + + if (format != VX_DF_IMAGE_U8 && format != VX_DF_IMAGE_S16 && format != VX_DF_IMAGE_RGB) + { + vxAddLogEntry((vx_reference)image, VX_ERROR_INVALID_FORMAT, "VX_to_CV_Image ERROR: Image type not Supported in this RELEASE\n"); return VX_ERROR_INVALID_FORMAT; + } + + Mat * m_cv; m_cv = new Mat(height, width, CV_format); Mat *pMat = (Mat *)m_cv; + vx_rectangle_t rect; rect.start_x = 0; rect.start_y = 0; rect.end_x = width; rect.end_y = height; + + vx_uint8 *src[4] = { NULL, NULL, NULL, NULL }; vx_uint32 p; void *ptr = NULL; + vx_imagepatch_addressing_t addr[4] = { 0, 0, 0, 0 }; vx_uint32 y = 0u; + + for (p = 0u; (p < (int)planes); p++) + { + STATUS_ERROR_CHECK(vxAccessImagePatch(image, &rect, p, &addr[p], (void **)&src[p], VX_READ_ONLY)); + size_t len = addr[p].stride_x * (addr[p].dim_x * addr[p].scale_x) / VX_SCALE_UNITY; + for (y = 0; y < height; y += addr[p].step_y) + { + ptr = vxFormatImagePatchAddress2d(src[p], 0, y - rect.start_y, &addr[p]); + memcpy(pMat->data + y * pMat->step, ptr, len); + } + } + + for (p = 0u; p < (int)planes; p++) + STATUS_ERROR_CHECK(vxCommitImagePatch(image, &rect, p, &addr[p], src[p])); + + *mat = pMat; + + return status; +} + +/************************************************************************************************************ +Converting CV Image into an OpenVX Image +*************************************************************************************************************/ +int CV_to_VX_Image(vx_image image, Mat* mat) +{ + vx_status status = VX_SUCCESS; vx_uint32 width = 0; vx_uint32 height = 0; vx_size planes = 0; + + STATUS_ERROR_CHECK(vxQueryImage(image, VX_IMAGE_ATTRIBUTE_WIDTH, &width, sizeof(width))); + STATUS_ERROR_CHECK(vxQueryImage(image, VX_IMAGE_ATTRIBUTE_HEIGHT, &height, sizeof(height))); + STATUS_ERROR_CHECK(vxQueryImage(image, VX_IMAGE_ATTRIBUTE_PLANES, &planes, sizeof(planes))); + + Mat *pMat = mat; vx_rectangle_t rect; rect.start_x = 0; rect.start_y = 0; rect.end_x = width; rect.end_y = height; + + vx_uint8 *src[4] = { NULL, NULL, NULL, NULL }; vx_uint32 p; void *ptr = NULL; + vx_imagepatch_addressing_t addr[4] = { 0, 0, 0, 0 }; vx_uint32 y = 0u; + + for (p = 0u; (p <(int)planes); p++) + { + STATUS_ERROR_CHECK(vxAccessImagePatch(image, &rect, p, &addr[p], (void **)&src[p], VX_READ_ONLY)); + size_t len = addr[p].stride_x * (addr[p].dim_x * addr[p].scale_x) / VX_SCALE_UNITY; + for (y = 0; y < height; y += addr[p].step_y) + { + ptr = vxFormatImagePatchAddress2d(src[p], 0, y - rect.start_y, &addr[p]); + memcpy(ptr, pMat->data + y * pMat->step, len); + } + } + + for (p = 0u; p < (int)planes; p++) + STATUS_ERROR_CHECK(vxCommitImagePatch(image, &rect, p, &addr[p], src[p])); + + return status; +} + +/************************************************************************************************************ +sort function. +*************************************************************************************************************/ +bool sortbysize_CV(const KeyPoint &lhs, const KeyPoint &rhs) +{ + return lhs.size < rhs.size; +} + +/************************************************************************************************************ +OpenCV Keypoints to OpenVX Keypoints +*************************************************************************************************************/ +int CV_to_VX_keypoints(vector key_points, vx_array array) +{ + + vx_status status = VX_SUCCESS; + vector Keypoint_VX; + + float X, Y, K_Size, K_Angle, K_Response; int x, y, j = 0; + void *ptr = NULL; vx_size size = 0; + + STATUS_ERROR_CHECK(vxQueryArray(array, VX_ARRAY_ATTRIBUTE_CAPACITY, &size, sizeof(size))); + + size_t S = key_points.size(); Keypoint_VX.resize(S); + //sort(key_points.begin(), key_points.end(), sortbysize_CV); + vx_size stride = 0; void *base = NULL; vx_size L = 0; + + for (vector::const_iterator i = key_points.begin(); i != key_points.end(); ++i) + { + X = key_points[j].pt.x; Y = key_points[j].pt.y; + K_Size = key_points[j].size; K_Angle = key_points[j].angle; K_Response = key_points[j].response; + + if (fmod(X, 1) >= 0.5)x = (int)ceil(X); else x = (int)floor(X); + if (fmod(Y, 1) >= 0.5)y = (int)ceil(Y); else y = (int)floor(Y); + + Keypoint_VX[j].x = x; Keypoint_VX[j].y = y; + Keypoint_VX[j].strength = K_Size; Keypoint_VX[j].orientation = K_Angle; Keypoint_VX[j].scale = K_Response; + j++; + } + + vx_keypoint_t * keypoint_ptr = &Keypoint_VX[0]; size = min(size, S); + + status = vxTruncateArray(array, 0); + if (status){ vxAddLogEntry((vx_reference)array, status, "CV_to_VX_keypoints ERROR: vxTruncateArray failed\n"); return status; } + + status = vxAddArrayItems(array, size, keypoint_ptr, sizeof(vx_keypoint_t)); + if (status){ vxAddLogEntry((vx_reference)array, status, "CV_to_VX_keypoints ERROR: vxAddArrayItems failed\n"); return status; } + + return status; +} + +/************************************************************************************************************ +OpenCV Points to OpenVX Keypoints +*************************************************************************************************************/ +int CVPoints2f_to_VX_keypoints(vector key_points, vx_array array) +{ + vx_status status = VX_SUCCESS; + vector Keypoint_VX; float X, Y; int x, y, j = 0; + void *ptr = NULL; vx_size size = 0; + + STATUS_ERROR_CHECK(vxQueryArray(array, VX_ARRAY_ATTRIBUTE_CAPACITY, &size, sizeof(size))); + + size_t S = key_points.size(); Keypoint_VX.resize(S); + //sort(key_points.begin(), key_points.end(), sortbysize_CV); + vx_size stride = 0; void *base = NULL; vx_size L = 0; + + for (int i = 0; i < (int)key_points.size(); ++i) + { + X = key_points[j].x; Y = key_points[j].y; + + if (fmod(X, 1) >= 0.5)x = (int)ceil(X); else x = (int)floor(X); + if (fmod(Y, 1) >= 0.5)y = (int)ceil(Y); else y = (int)floor(Y); + + Keypoint_VX[j].x = x; Keypoint_VX[j].y = y; + Keypoint_VX[j].strength = 0; Keypoint_VX[j].orientation = 0; Keypoint_VX[j].scale = 0; + + j++; + } + + vx_keypoint_t * keypoint_ptr = &Keypoint_VX[0]; size = min(size, S); + + status = vxTruncateArray(array, 0); + if (status){ vxAddLogEntry((vx_reference)array, status, "CVPoints2f_to_VX_keypoints ERROR: vxTruncateArray failed\n"); return status; } + + status = vxAddArrayItems(array, size, keypoint_ptr, sizeof(vx_keypoint_t)); + if (status){ vxAddLogEntry((vx_reference)array, status, "CVPoints2f_to_VX_keypoints ERROR: vxAddArrayItems failed\n"); return status; } + + return status; + +} + +/************************************************************************************************************ +OpenCV Descriptors to OpenVX Descriptors +*************************************************************************************************************/ +int CV_DESP_to_VX_DESP(Mat mat, vx_array array, int stride) +{ + vx_status status = VX_SUCCESS; vx_size size = 0; + + STATUS_ERROR_CHECK(vxQueryArray(array, VX_ARRAY_ATTRIBUTE_CAPACITY, &size, sizeof(size))); + + uchar *p = mat.data; + + status = vxTruncateArray(array, 0); + if (status){ vxAddLogEntry((vx_reference)array, status, "CV_DESP_to_VX_DESP ERROR: vxTruncateArray failed\n"); return status; } + + status = vxAddArrayItems(array, size, p, stride); + if (status){ vxAddLogEntry((vx_reference)array, status, "CV_DESP_to_VX_DESP ERROR: vxAddArrayItems failed\n"); return status; } + + return status; +} + +/************************************************************************************************************ +Match VX in and out image size +*************************************************************************************************************/ +int match_vx_image_parameters(vx_image image1, vx_image image2) +{ + vx_status status = VX_SUCCESS; + vx_uint32 W1 = 0; vx_uint32 H1 = 0; + STATUS_ERROR_CHECK(vxQueryImage(image1, VX_IMAGE_ATTRIBUTE_WIDTH, &W1, sizeof(W1))); + STATUS_ERROR_CHECK(vxQueryImage(image1, VX_IMAGE_ATTRIBUTE_HEIGHT, &H1, sizeof(H1))); + + vx_uint32 W2 = 0; vx_uint32 H2 = 0; + STATUS_ERROR_CHECK(vxQueryImage(image2, VX_IMAGE_ATTRIBUTE_WIDTH, &W2, sizeof(W2))); + STATUS_ERROR_CHECK(vxQueryImage(image2, VX_IMAGE_ATTRIBUTE_HEIGHT, &H2, sizeof(H2))); + + //Input and Output image size match check + if (W1 != W2 || H1 != H2) + { + status = VX_ERROR_INVALID_DIMENSION; + vxAddLogEntry((vx_reference)image1, status, "match_vx_image_parameters ERROR: Image1 Height or Width Not Equal to Image2\n"); + return status; + } + + return status; +} \ No newline at end of file diff --git a/vx_ext_cv/OpenCV_dilate.cpp b/vx_ext_cv/OpenCV_dilate.cpp new file mode 100644 index 0000000..394f211 --- /dev/null +++ b/vx_ext_cv/OpenCV_dilate.cpp @@ -0,0 +1,218 @@ +/* +Copyright (c) 2015 Advanced Micro Devices, Inc. All rights reserved. + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. +*/ + + +#include"publishkernels.h" + +/************************************************************************************************************ +input parameter validator. +param [in] node The handle to the node. +param [in] index The index of the parameter to validate. +*************************************************************************************************************/ +static vx_status VX_CALLBACK CV_dilate_InputValidator(vx_node node, vx_uint32 index) +{ + vx_status status = VX_SUCCESS; + vx_parameter param = vxGetParameterByIndex(node, index); + + if (index == 0) + { + vx_image image; + vx_df_image df_image = VX_DF_IMAGE_VIRT; + STATUS_ERROR_CHECK(vxQueryParameter(param, VX_PARAMETER_ATTRIBUTE_REF, &image, sizeof(vx_image))); + STATUS_ERROR_CHECK(vxQueryImage(image, VX_IMAGE_ATTRIBUTE_FORMAT, &df_image, sizeof(df_image))); + if (df_image != VX_DF_IMAGE_U8 && df_image != VX_DF_IMAGE_U16 && df_image != VX_DF_IMAGE_S16) + status = VX_ERROR_INVALID_VALUE; + vxReleaseImage(&image); + } + + else if (index == 1) + { + vx_image image; + vx_df_image df_image = VX_DF_IMAGE_VIRT; + STATUS_ERROR_CHECK(vxQueryParameter(param, VX_PARAMETER_ATTRIBUTE_REF, &image, sizeof(vx_image))); + STATUS_ERROR_CHECK(vxQueryImage(image, VX_IMAGE_ATTRIBUTE_FORMAT, &df_image, sizeof(df_image))); + if (df_image != VX_DF_IMAGE_U8) + status = VX_ERROR_INVALID_VALUE; + vxReleaseImage(&image); + } + + else if (index == 2) + { + vx_matrix mat; + STATUS_ERROR_CHECK(vxQueryParameter(param, VX_PARAMETER_ATTRIBUTE_REF, &mat, sizeof(vx_matrix))); + vxReleaseMatrix(&mat); + } + + else if (index == 3) + { + vx_scalar scalar = 0; vx_enum type = 0; vx_int32 value = 0; + STATUS_ERROR_CHECK(vxQueryParameter(param, VX_PARAMETER_ATTRIBUTE_REF, &scalar, sizeof(scalar))); + STATUS_ERROR_CHECK(vxQueryScalar(scalar, VX_SCALAR_ATTRIBUTE_TYPE, &type, sizeof(type))); + STATUS_ERROR_CHECK(vxReadScalarValue(scalar, &value)); + if (value < -1 || type != VX_TYPE_INT32) + status = VX_ERROR_INVALID_VALUE; + vxReleaseScalar(&scalar); + } + + else if (index == 4) + { + vx_scalar scalar = 0; vx_enum type = 0; vx_int32 value = 0; + STATUS_ERROR_CHECK(vxQueryParameter(param, VX_PARAMETER_ATTRIBUTE_REF, &scalar, sizeof(scalar))); + STATUS_ERROR_CHECK(vxQueryScalar(scalar, VX_SCALAR_ATTRIBUTE_TYPE, &type, sizeof(type))); + STATUS_ERROR_CHECK(vxReadScalarValue(scalar, &value)); + if (value < -1 || type != VX_TYPE_INT32) + status = VX_ERROR_INVALID_VALUE; + vxReleaseScalar(&scalar); + } + + else if (index == 5) + { + vx_scalar scalar = 0; vx_enum type = 0; vx_int32 value = 0; + STATUS_ERROR_CHECK(vxQueryParameter(param, VX_PARAMETER_ATTRIBUTE_REF, &scalar, sizeof(scalar))); + STATUS_ERROR_CHECK(vxQueryScalar(scalar, VX_SCALAR_ATTRIBUTE_TYPE, &type, sizeof(type))); + STATUS_ERROR_CHECK(vxReadScalarValue(scalar, &value)); + if (value < 0 || type != VX_TYPE_INT32) + status = VX_ERROR_INVALID_VALUE; + vxReleaseScalar(&scalar); + } + + else if (index == 6) + { + vx_scalar scalar = 0; vx_enum type = 0; vx_int32 value = 0; + STATUS_ERROR_CHECK(vxQueryParameter(param, VX_PARAMETER_ATTRIBUTE_REF, &scalar, sizeof(scalar))); + STATUS_ERROR_CHECK(vxQueryScalar(scalar, VX_SCALAR_ATTRIBUTE_TYPE, &type, sizeof(type))); + STATUS_ERROR_CHECK(vxReadScalarValue(scalar, &value)); + if (value < 0 || type != VX_TYPE_INT32) + status = VX_ERROR_INVALID_VALUE; + vxReleaseScalar(&scalar); + } + + vxReleaseParameter(¶m); + return status; +} + +/************************************************************************************************************ +output parameter validator. +*************************************************************************************************************/ +static vx_status VX_CALLBACK CV_dilate_OutputValidator(vx_node node, vx_uint32 index, vx_meta_format meta) +{ + vx_status status = VX_SUCCESS; + if (index == 1) + { + vx_parameter output_param = vxGetParameterByIndex(node, 1); + vx_image output; vx_uint32 width = 0, height = 0; vx_df_image format = VX_DF_IMAGE_VIRT; + + STATUS_ERROR_CHECK(vxQueryParameter(output_param, VX_PARAMETER_ATTRIBUTE_REF, &output, sizeof(vx_image))); + STATUS_ERROR_CHECK(vxQueryImage(output, VX_IMAGE_ATTRIBUTE_FORMAT, &format, sizeof(format))); + STATUS_ERROR_CHECK(vxQueryImage(output, VX_IMAGE_ATTRIBUTE_WIDTH, &width, sizeof(width))); + STATUS_ERROR_CHECK(vxQueryImage(output, VX_IMAGE_ATTRIBUTE_HEIGHT, &height, sizeof(height))); + + if (format != VX_DF_IMAGE_U8) + status = VX_ERROR_INVALID_VALUE; + + STATUS_ERROR_CHECK(vxSetMetaFormatAttribute(meta, VX_IMAGE_ATTRIBUTE_WIDTH, &width, sizeof(width))); + STATUS_ERROR_CHECK(vxSetMetaFormatAttribute(meta, VX_IMAGE_ATTRIBUTE_HEIGHT, &height, sizeof(height))); + STATUS_ERROR_CHECK(vxSetMetaFormatAttribute(meta, VX_IMAGE_ATTRIBUTE_FORMAT, &format, sizeof(format))); + + vxReleaseImage(&output); + vxReleaseParameter(&output_param); + } + return status; +} + +/************************************************************************************************************ +Execution Kernel +*************************************************************************************************************/ +static vx_status VX_CALLBACK CV_dilate_Kernel(vx_node node, const vx_reference *parameters, vx_uint32 num) +{ + vx_status status = VX_SUCCESS; + + vx_image image_in = (vx_image) parameters[0]; + vx_image image_out = (vx_image) parameters[1]; + vx_matrix KERNEL = (vx_matrix) parameters[2]; + vx_scalar A_X = (vx_scalar) parameters[3]; + vx_scalar A_Y = (vx_scalar) parameters[4]; + vx_scalar ITERATION = (vx_scalar) parameters[5]; + vx_scalar BORDER = (vx_scalar) parameters[6]; + + Mat *mat, bl; + int iteration; + int a_x = -1, a_y = -1, border = 4; + vx_int32 value = 0; + + //Extracting Values from the Scalar into Ksize and Ddepth + STATUS_ERROR_CHECK(vxReadScalarValue(ITERATION, &value));iteration = value; + STATUS_ERROR_CHECK(vxReadScalarValue(A_X, &value));a_x = value; + STATUS_ERROR_CHECK(vxReadScalarValue(A_Y, &value));a_y = value; + STATUS_ERROR_CHECK(vxReadScalarValue(BORDER, &value));border = value; + + //Converting VX Image to OpenCV Mat + STATUS_ERROR_CHECK(match_vx_image_parameters(image_in, image_out)); + STATUS_ERROR_CHECK(VX_to_CV_Image(&mat, image_in)); + + //Compute using OpenCV + Mat *kernel; + STATUS_ERROR_CHECK(VX_to_CV_MATRIX(&kernel, KERNEL)); + cv::dilate(*mat, bl, *kernel, Point(a_x, a_y), iteration, border); + + //Converting OpenCV Mat into VX Image + STATUS_ERROR_CHECK(CV_to_VX_Image(image_out, &bl)); + + return status; +} + + +/************************************************************************************************************ +Function to Register the Kernel for Publish +*************************************************************************************************************/ +vx_status CV_dilate_Register(vx_context context) +{ + vx_status status = VX_SUCCESS; + vx_kernel Kernel = vxAddKernel(context, + "org.opencv.dilate", + VX_KERNEL_EXT_CV_DILATE, + CV_dilate_Kernel, + 7, + CV_dilate_InputValidator, + CV_dilate_OutputValidator, + nullptr, + nullptr); + + if (Kernel) + { + PARAM_ERROR_CHECK(vxAddParameterToKernel(Kernel, 0, VX_INPUT, VX_TYPE_IMAGE, VX_PARAMETER_STATE_REQUIRED)); + PARAM_ERROR_CHECK(vxAddParameterToKernel(Kernel, 1, VX_OUTPUT, VX_TYPE_IMAGE, VX_PARAMETER_STATE_REQUIRED)); + PARAM_ERROR_CHECK(vxAddParameterToKernel(Kernel, 2, VX_INPUT, VX_TYPE_MATRIX, VX_PARAMETER_STATE_REQUIRED)); + PARAM_ERROR_CHECK(vxAddParameterToKernel(Kernel, 3, VX_INPUT, VX_TYPE_SCALAR, VX_PARAMETER_STATE_REQUIRED)); + PARAM_ERROR_CHECK(vxAddParameterToKernel(Kernel, 4, VX_INPUT, VX_TYPE_SCALAR, VX_PARAMETER_STATE_REQUIRED)); + PARAM_ERROR_CHECK(vxAddParameterToKernel(Kernel, 5, VX_INPUT, VX_TYPE_SCALAR, VX_PARAMETER_STATE_REQUIRED)); + PARAM_ERROR_CHECK(vxAddParameterToKernel(Kernel, 6, VX_INPUT, VX_TYPE_SCALAR, VX_PARAMETER_STATE_REQUIRED)); + PARAM_ERROR_CHECK(vxFinalizeKernel(Kernel)); + } + + if (status != VX_SUCCESS) + { + exit: vxRemoveKernel(Kernel); return VX_FAILURE; + } + + return status; +} diff --git a/vx_ext_cv/OpenCV_distanceTransform.cpp b/vx_ext_cv/OpenCV_distanceTransform.cpp new file mode 100644 index 0000000..fec65a8 --- /dev/null +++ b/vx_ext_cv/OpenCV_distanceTransform.cpp @@ -0,0 +1,144 @@ +/* +Copyright (c) 2015 Advanced Micro Devices, Inc. All rights reserved. + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. +*/ + + +#include"publishkernels.h" + +/************************************************************************************************************ +input parameter validator. +param [in] node The handle to the node. +param [in] index The index of the parameter to validate. +*************************************************************************************************************/ +static vx_status VX_CALLBACK CV_distanceTransform_InputValidator(vx_node node, vx_uint32 index) +{ + vx_status status = VX_SUCCESS ; + vx_parameter param = vxGetParameterByIndex(node, index); + + if (index == 0) + { + vx_image image; + vx_df_image df_image = VX_DF_IMAGE_VIRT; + STATUS_ERROR_CHECK(vxQueryParameter(param, VX_PARAMETER_ATTRIBUTE_REF, &image, sizeof(vx_image))); + STATUS_ERROR_CHECK(vxQueryImage(image, VX_IMAGE_ATTRIBUTE_FORMAT, &df_image, sizeof(df_image))); + if (df_image != VX_DF_IMAGE_U8) + status = VX_ERROR_INVALID_VALUE; + vxReleaseImage(&image); + } + + else if (index == 1) + { + vx_image image; + vx_df_image df_image = VX_DF_IMAGE_VIRT; + STATUS_ERROR_CHECK(vxQueryParameter(param, VX_PARAMETER_ATTRIBUTE_REF, &image, sizeof(vx_image))); + STATUS_ERROR_CHECK(vxQueryImage(image, VX_IMAGE_ATTRIBUTE_FORMAT, &df_image, sizeof(df_image))); + if (df_image != VX_DF_IMAGE_U8) + status = VX_ERROR_INVALID_VALUE; + vxReleaseImage(&image); + } + + vxReleaseParameter(¶m); + return status; +} + +/************************************************************************************************************ +output parameter validator. +*************************************************************************************************************/ +static vx_status VX_CALLBACK CV_distanceTransform_OutputValidator(vx_node node, vx_uint32 index, vx_meta_format meta) +{ + vx_status status = VX_SUCCESS ; + if (index == 1) + { + vx_parameter output_param = vxGetParameterByIndex(node, 1); + vx_image output; vx_uint32 width = 0, height = 0; vx_df_image format = VX_DF_IMAGE_VIRT; + + STATUS_ERROR_CHECK(vxQueryParameter(output_param, VX_PARAMETER_ATTRIBUTE_REF, &output, sizeof(vx_image))); + STATUS_ERROR_CHECK(vxQueryImage(output, VX_IMAGE_ATTRIBUTE_FORMAT, &format, sizeof(format))); + STATUS_ERROR_CHECK(vxQueryImage(output, VX_IMAGE_ATTRIBUTE_WIDTH, &width, sizeof(width))); + STATUS_ERROR_CHECK(vxQueryImage(output, VX_IMAGE_ATTRIBUTE_HEIGHT, &height, sizeof(height))); + + if (format != VX_DF_IMAGE_U8 && format != VX_DF_IMAGE_S16) + status = VX_ERROR_INVALID_VALUE; + + STATUS_ERROR_CHECK(vxSetMetaFormatAttribute(meta, VX_IMAGE_ATTRIBUTE_WIDTH, &width, sizeof(width))); + STATUS_ERROR_CHECK(vxSetMetaFormatAttribute(meta, VX_IMAGE_ATTRIBUTE_HEIGHT, &height, sizeof(height))); + STATUS_ERROR_CHECK(vxSetMetaFormatAttribute(meta, VX_IMAGE_ATTRIBUTE_FORMAT, &format, sizeof(format))); + + vxReleaseImage(&output); + vxReleaseParameter(&output_param); + } + return status; +} + +/************************************************************************************************************ +Execution Kernel +*************************************************************************************************************/ +static vx_status VX_CALLBACK CV_distanceTransform_Kernel(vx_node node, const vx_reference *parameters, vx_uint32 num) +{ + vx_status status = VX_SUCCESS; + + vx_image image_in = (vx_image) parameters[0]; + vx_image image_out = (vx_image) parameters[1]; + Mat *mat, bl; + + //Converting VX Image to OpenCV Mat 1 + STATUS_ERROR_CHECK(match_vx_image_parameters(image_in, image_out)); + STATUS_ERROR_CHECK(VX_to_CV_Image(&mat, image_in)); + + //Compute using OpenCV + cv::distanceTransform(*mat, bl, CV_DIST_L1, 3, CV_8U); //only CV_DIST_L1 & CV_8U supported in this release + + //Converting OpenCV Mat into VX Image + STATUS_ERROR_CHECK(CV_to_VX_Image(image_out, &bl)); + + return status; +} + +/************************************************************************************************************ +Function to Register the Kernel for Publish +*************************************************************************************************************/ +vx_status CV_distanceTransform_Register(vx_context context) +{ + vx_status status = VX_SUCCESS; + vx_kernel Kernel = vxAddKernel(context, + "org.opencv.distancetransform", + VX_KERNEL_EXT_CV_DISTANCETRANSFORM, + CV_distanceTransform_Kernel, + 2, + CV_distanceTransform_InputValidator, + CV_distanceTransform_OutputValidator, + nullptr, + nullptr); + + if (Kernel) + { + PARAM_ERROR_CHECK(vxAddParameterToKernel(Kernel, 0, VX_INPUT, VX_TYPE_IMAGE, VX_PARAMETER_STATE_REQUIRED)); + PARAM_ERROR_CHECK(vxAddParameterToKernel(Kernel, 1, VX_OUTPUT, VX_TYPE_IMAGE, VX_PARAMETER_STATE_REQUIRED)); + PARAM_ERROR_CHECK(vxFinalizeKernel(Kernel)); + } + + if (status != VX_SUCCESS) + { + exit: vxRemoveKernel(Kernel); return VX_FAILURE; + } + + return status; +} diff --git a/vx_ext_cv/OpenCV_divide.cpp b/vx_ext_cv/OpenCV_divide.cpp new file mode 100644 index 0000000..54418c1 --- /dev/null +++ b/vx_ext_cv/OpenCV_divide.cpp @@ -0,0 +1,194 @@ +/* +Copyright (c) 2015 Advanced Micro Devices, Inc. All rights reserved. + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. +*/ + + +#include"publishkernels.h" + +/************************************************************************************************************ +input parameter validator. +param [in] node The handle to the node. +param [in] index The index of the parameter to validate. +*************************************************************************************************************/ +static vx_status VX_CALLBACK CV_divide_InputValidator(vx_node node, vx_uint32 index) +{ + vx_status status = VX_SUCCESS; + vx_parameter param = vxGetParameterByIndex(node, index); + + if (index == 0) + { + vx_image image; + vx_df_image df_image = VX_DF_IMAGE_VIRT; + STATUS_ERROR_CHECK(vxQueryParameter(param, VX_PARAMETER_ATTRIBUTE_REF, &image, sizeof(vx_image))); + STATUS_ERROR_CHECK(vxQueryImage(image, VX_IMAGE_ATTRIBUTE_FORMAT, &df_image, sizeof(df_image))); + if (df_image != VX_DF_IMAGE_U8 && df_image != VX_DF_IMAGE_S16) + status = VX_ERROR_INVALID_VALUE; + vxReleaseImage(&image); + } + + if (index == 1) + { + vx_image image; + vx_df_image df_image = VX_DF_IMAGE_VIRT; + STATUS_ERROR_CHECK(vxQueryParameter(param, VX_PARAMETER_ATTRIBUTE_REF, &image, sizeof(vx_image))); + STATUS_ERROR_CHECK(vxQueryImage(image, VX_IMAGE_ATTRIBUTE_FORMAT, &df_image, sizeof(df_image))); + if (df_image != VX_DF_IMAGE_U8 && df_image != VX_DF_IMAGE_S16) + status = VX_ERROR_INVALID_VALUE; + vxReleaseImage(&image); + } + + else if (index == 2) + { + vx_image image; + vx_df_image df_image = VX_DF_IMAGE_VIRT; + STATUS_ERROR_CHECK(vxQueryParameter(param, VX_PARAMETER_ATTRIBUTE_REF, &image, sizeof(vx_image))); + STATUS_ERROR_CHECK(vxQueryImage(image, VX_IMAGE_ATTRIBUTE_FORMAT, &df_image, sizeof(df_image))); + if (df_image != VX_DF_IMAGE_U8 && df_image != VX_DF_IMAGE_S16) + status = VX_ERROR_INVALID_VALUE; + vxReleaseImage(&image); + } + + else if (index == 3) + { + vx_scalar scalar = 0; vx_enum type = 0; vx_float32 value = 0; + STATUS_ERROR_CHECK(vxQueryParameter(param, VX_PARAMETER_ATTRIBUTE_REF, &scalar, sizeof(scalar))); + STATUS_ERROR_CHECK(vxQueryScalar(scalar, VX_SCALAR_ATTRIBUTE_TYPE, &type, sizeof(type))); + STATUS_ERROR_CHECK(vxReadScalarValue(scalar, &value)); + if (value < 0 || type != VX_TYPE_FLOAT32) + status = VX_ERROR_INVALID_VALUE; + vxReleaseScalar(&scalar); + } + + else if (index == 4) + { + vx_scalar scalar = 0; vx_enum type = 0; vx_int32 value = 0; + STATUS_ERROR_CHECK(vxQueryParameter(param, VX_PARAMETER_ATTRIBUTE_REF, &scalar, sizeof(scalar))); + STATUS_ERROR_CHECK(vxQueryScalar(scalar, VX_SCALAR_ATTRIBUTE_TYPE, &type, sizeof(type))); + STATUS_ERROR_CHECK(vxReadScalarValue(scalar, &value)); + if (value < -1 || type != VX_TYPE_INT32) + status = VX_ERROR_INVALID_VALUE; + vxReleaseScalar(&scalar); + } + + vxReleaseParameter(¶m); + return status; +} + +/************************************************************************************************************ +output parameter validator. +*************************************************************************************************************/ +static vx_status VX_CALLBACK CV_divide_OutputValidator(vx_node node, vx_uint32 index, vx_meta_format meta) +{ + vx_status status = VX_SUCCESS; + if (index == 2) + { + vx_parameter output_param = vxGetParameterByIndex(node, 2); + vx_image output; vx_uint32 width = 0, height = 0; vx_df_image format = VX_DF_IMAGE_VIRT; + + STATUS_ERROR_CHECK(vxQueryParameter(output_param, VX_PARAMETER_ATTRIBUTE_REF, &output, sizeof(vx_image))); + STATUS_ERROR_CHECK(vxQueryImage(output, VX_IMAGE_ATTRIBUTE_FORMAT, &format, sizeof(format))); + STATUS_ERROR_CHECK(vxQueryImage(output, VX_IMAGE_ATTRIBUTE_WIDTH, &width, sizeof(width))); + STATUS_ERROR_CHECK(vxQueryImage(output, VX_IMAGE_ATTRIBUTE_HEIGHT, &height, sizeof(height))); + + if (format != VX_DF_IMAGE_U8 && format != VX_DF_IMAGE_S16) + status = VX_ERROR_INVALID_VALUE; + + STATUS_ERROR_CHECK(vxSetMetaFormatAttribute(meta, VX_IMAGE_ATTRIBUTE_WIDTH, &width, sizeof(width))); + STATUS_ERROR_CHECK(vxSetMetaFormatAttribute(meta, VX_IMAGE_ATTRIBUTE_HEIGHT, &height, sizeof(height))); + STATUS_ERROR_CHECK(vxSetMetaFormatAttribute(meta, VX_IMAGE_ATTRIBUTE_FORMAT, &format, sizeof(format))); + + vxReleaseImage(&output); + vxReleaseParameter(&output_param); + } + return status; +} + +/************************************************************************************************************ +Execution Kernel +*************************************************************************************************************/ +static vx_status VX_CALLBACK CV_divide_Kernel(vx_node node, const vx_reference *parameters, vx_uint32 num) +{ + vx_status status = VX_SUCCESS; + + vx_image image_1 = (vx_image) parameters[0]; + vx_image image_2 = (vx_image) parameters[1]; + vx_image image_out = (vx_image) parameters[2]; + vx_scalar SCALE = (vx_scalar) parameters[3]; + vx_scalar DTYPE = (vx_scalar) parameters[4]; + Mat *mat_1, *mat_2, bl; + + vx_int32 value = 0; + int dtype; + vx_float32 value_f = 0; + float scale; + + //Extracting Values from the Scalar + STATUS_ERROR_CHECK(vxReadScalarValue(SCALE, &value_f)); scale = value_f; + STATUS_ERROR_CHECK(vxReadScalarValue(DTYPE, &value)); dtype = value; + + //Converting VX Image to OpenCV Mat + STATUS_ERROR_CHECK(match_vx_image_parameters(image_1, image_2)); + STATUS_ERROR_CHECK(match_vx_image_parameters(image_1, image_out)); + STATUS_ERROR_CHECK(VX_to_CV_Image(&mat_1, image_1)); + STATUS_ERROR_CHECK(VX_to_CV_Image(&mat_2, image_2)); + + //Compute using OpenCV + cv::divide(*mat_1, *mat_2, bl, scale, dtype); + + //Converting OpenCV Mat into VX Image + STATUS_ERROR_CHECK(CV_to_VX_Image(image_out, &bl)); + + return status; +} + +/************************************************************************************************************ +Function to Register the Kernel for Publish +*************************************************************************************************************/ +vx_status CV_divide_Register(vx_context context) +{ + vx_status status = VX_SUCCESS; + vx_kernel kernel = vxAddKernel(context, + "org.opencv.divide", + VX_KERNEL_EXT_CV_DIVIDE, + CV_divide_Kernel, + 5, + CV_divide_InputValidator, + CV_divide_OutputValidator, + nullptr, + nullptr); + + if (kernel) + { + PARAM_ERROR_CHECK(vxAddParameterToKernel(kernel, 0, VX_INPUT, VX_TYPE_IMAGE, VX_PARAMETER_STATE_REQUIRED)); + PARAM_ERROR_CHECK(vxAddParameterToKernel(kernel, 1, VX_INPUT, VX_TYPE_IMAGE, VX_PARAMETER_STATE_REQUIRED)); + PARAM_ERROR_CHECK(vxAddParameterToKernel(kernel, 2, VX_OUTPUT, VX_TYPE_IMAGE, VX_PARAMETER_STATE_REQUIRED)); + PARAM_ERROR_CHECK(vxAddParameterToKernel(kernel, 3, VX_INPUT, VX_TYPE_SCALAR, VX_PARAMETER_STATE_REQUIRED)); + PARAM_ERROR_CHECK(vxAddParameterToKernel(kernel, 4, VX_INPUT, VX_TYPE_SCALAR, VX_PARAMETER_STATE_REQUIRED)); + PARAM_ERROR_CHECK(vxFinalizeKernel(kernel)); + } + if (status != VX_SUCCESS) + { + exit: vxRemoveKernel(kernel); return VX_FAILURE; + } + + return status; +} + diff --git a/vx_ext_cv/OpenCV_erode.cpp b/vx_ext_cv/OpenCV_erode.cpp new file mode 100644 index 0000000..ee5d701 --- /dev/null +++ b/vx_ext_cv/OpenCV_erode.cpp @@ -0,0 +1,217 @@ +/* +Copyright (c) 2015 Advanced Micro Devices, Inc. All rights reserved. + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. +*/ + + +#include"publishkernels.h" + +/************************************************************************************************************ +input parameter validator. +param [in] node The handle to the node. +param [in] index The index of the parameter to validate. +*************************************************************************************************************/ +static vx_status VX_CALLBACK CV_erode_InputValidator(vx_node node, vx_uint32 index) +{ + vx_status status = VX_SUCCESS; + vx_parameter param = vxGetParameterByIndex(node, index); + + if (index == 0) + { + vx_image image; + vx_df_image df_image = VX_DF_IMAGE_VIRT; + STATUS_ERROR_CHECK(vxQueryParameter(param, VX_PARAMETER_ATTRIBUTE_REF, &image, sizeof(vx_image))); + STATUS_ERROR_CHECK(vxQueryImage(image, VX_IMAGE_ATTRIBUTE_FORMAT, &df_image, sizeof(df_image))); + if (df_image != VX_DF_IMAGE_U8 && df_image != VX_DF_IMAGE_U16 && df_image != VX_DF_IMAGE_S16) + status = VX_ERROR_INVALID_VALUE; + vxReleaseImage(&image); + } + + else if (index == 1) + { + vx_image image; + vx_df_image df_image = VX_DF_IMAGE_VIRT; + STATUS_ERROR_CHECK(vxQueryParameter(param, VX_PARAMETER_ATTRIBUTE_REF, &image, sizeof(vx_image))); + STATUS_ERROR_CHECK(vxQueryImage(image, VX_IMAGE_ATTRIBUTE_FORMAT, &df_image, sizeof(df_image))); + if (df_image != VX_DF_IMAGE_U8) + status = VX_ERROR_INVALID_VALUE; + vxReleaseImage(&image); + } + + else if (index == 2) + { + vx_matrix mat; + STATUS_ERROR_CHECK(vxQueryParameter(param, VX_PARAMETER_ATTRIBUTE_REF, &mat, sizeof(vx_matrix))); + vxReleaseMatrix(&mat); + } + + else if (index == 3) + { + vx_scalar scalar = 0; vx_enum type = 0; vx_int32 value = 0; + STATUS_ERROR_CHECK(vxQueryParameter(param, VX_PARAMETER_ATTRIBUTE_REF, &scalar, sizeof(scalar))); + STATUS_ERROR_CHECK(vxQueryScalar(scalar, VX_SCALAR_ATTRIBUTE_TYPE, &type, sizeof(type))); + STATUS_ERROR_CHECK(vxReadScalarValue(scalar, &value)); + if (value < -1 || type != VX_TYPE_INT32) + status = VX_ERROR_INVALID_VALUE; + vxReleaseScalar(&scalar); + } + + else if (index == 4) + { + vx_scalar scalar = 0; vx_enum type = 0; vx_int32 value = 0; + STATUS_ERROR_CHECK(vxQueryParameter(param, VX_PARAMETER_ATTRIBUTE_REF, &scalar, sizeof(scalar))); + STATUS_ERROR_CHECK(vxQueryScalar(scalar, VX_SCALAR_ATTRIBUTE_TYPE, &type, sizeof(type))); + STATUS_ERROR_CHECK(vxReadScalarValue(scalar, &value)); + if (value < -1 || type != VX_TYPE_INT32) + status = VX_ERROR_INVALID_VALUE; + vxReleaseScalar(&scalar); + } + + else if (index == 5) + { + vx_scalar scalar = 0; vx_enum type = 0; vx_int32 value = 0; + STATUS_ERROR_CHECK(vxQueryParameter(param, VX_PARAMETER_ATTRIBUTE_REF, &scalar, sizeof(scalar))); + STATUS_ERROR_CHECK(vxQueryScalar(scalar, VX_SCALAR_ATTRIBUTE_TYPE, &type, sizeof(type))); + STATUS_ERROR_CHECK(vxReadScalarValue(scalar, &value)); + if (value < 0 || type != VX_TYPE_INT32) + status = VX_ERROR_INVALID_VALUE; + vxReleaseScalar(&scalar); + } + + else if (index == 6) + { + vx_scalar scalar = 0; vx_enum type = 0; vx_int32 value = 0; + STATUS_ERROR_CHECK(vxQueryParameter(param, VX_PARAMETER_ATTRIBUTE_REF, &scalar, sizeof(scalar))); + STATUS_ERROR_CHECK(vxQueryScalar(scalar, VX_SCALAR_ATTRIBUTE_TYPE, &type, sizeof(type))); + STATUS_ERROR_CHECK(vxReadScalarValue(scalar, &value)); + if (value < 0 || type != VX_TYPE_INT32) + status = VX_ERROR_INVALID_VALUE; + vxReleaseScalar(&scalar); + } + + vxReleaseParameter(¶m); + return status; +} + +/************************************************************************************************************ +output parameter validator. +*************************************************************************************************************/ +static vx_status VX_CALLBACK CV_erode_OutputValidator(vx_node node, vx_uint32 index, vx_meta_format meta) +{ + vx_status status = VX_SUCCESS; + if (index == 1) + { + vx_parameter output_param = vxGetParameterByIndex(node, 1); + vx_image output; vx_uint32 width = 0, height = 0; vx_df_image format = VX_DF_IMAGE_VIRT; + + STATUS_ERROR_CHECK(vxQueryParameter(output_param, VX_PARAMETER_ATTRIBUTE_REF, &output, sizeof(vx_image))); + STATUS_ERROR_CHECK(vxQueryImage(output, VX_IMAGE_ATTRIBUTE_FORMAT, &format, sizeof(format))); + STATUS_ERROR_CHECK(vxQueryImage(output, VX_IMAGE_ATTRIBUTE_WIDTH, &width, sizeof(width))); + STATUS_ERROR_CHECK(vxQueryImage(output, VX_IMAGE_ATTRIBUTE_HEIGHT, &height, sizeof(height))); + + if (format != VX_DF_IMAGE_U8) + status = VX_ERROR_INVALID_VALUE; + + STATUS_ERROR_CHECK(vxSetMetaFormatAttribute(meta, VX_IMAGE_ATTRIBUTE_WIDTH, &width, sizeof(width))); + STATUS_ERROR_CHECK(vxSetMetaFormatAttribute(meta, VX_IMAGE_ATTRIBUTE_HEIGHT, &height, sizeof(height))); + STATUS_ERROR_CHECK(vxSetMetaFormatAttribute(meta, VX_IMAGE_ATTRIBUTE_FORMAT, &format, sizeof(format))); + + vxReleaseImage(&output); + vxReleaseParameter(&output_param); + } + return status; +} + +/************************************************************************************************************ +Execution Kernel +*************************************************************************************************************/ +static vx_status VX_CALLBACK CV_erode_Kernel(vx_node node, const vx_reference *parameters, vx_uint32 num) +{ + vx_status status = VX_SUCCESS; + + vx_image image_in = (vx_image) parameters[0]; + vx_image image_out = (vx_image) parameters[1]; + vx_matrix KERNEL = (vx_matrix) parameters[2]; + vx_scalar A_X = (vx_scalar) parameters[3]; + vx_scalar A_Y = (vx_scalar) parameters[4]; + vx_scalar ITERATION = (vx_scalar) parameters[5]; + vx_scalar BORDER = (vx_scalar) parameters[6]; + Mat *mat, bl; + int iteration; + int a_x = -1, a_y = -1, border = 4; + + vx_int32 value = 0; + + //Extracting Values from the Scalar into Ksize and Ddepth + STATUS_ERROR_CHECK(vxReadScalarValue(ITERATION, &value)); iteration = value; + STATUS_ERROR_CHECK(vxReadScalarValue(A_X, &value)); a_x = value; + STATUS_ERROR_CHECK(vxReadScalarValue(A_Y, &value)); a_y = value; + STATUS_ERROR_CHECK(vxReadScalarValue(BORDER, &value)); border = value; + + //Converting VX Image to OpenCV Mat + STATUS_ERROR_CHECK(match_vx_image_parameters(image_in, image_out)); + STATUS_ERROR_CHECK(VX_to_CV_Image(&mat, image_in)); + + //Compute using OpenCV + Mat *kernel; + STATUS_ERROR_CHECK(VX_to_CV_MATRIX(&kernel, KERNEL)); + cv::erode(*mat, bl, *kernel, Point(a_x, a_y), iteration, border); + + //Converting OpenCV Mat into VX Image + STATUS_ERROR_CHECK(CV_to_VX_Image(image_out, &bl)); + + return status; +} + +/************************************************************************************************************ +Function to Register the Kernel for Publish +*************************************************************************************************************/ +vx_status CV_erode_Register(vx_context context) +{ + vx_status status = VX_SUCCESS; + vx_kernel Kernel = vxAddKernel(context, + "org.opencv.erode", + VX_KERNEL_EXT_CV_ERODE, + CV_erode_Kernel, + 7, + CV_erode_InputValidator, + CV_erode_OutputValidator, + nullptr, + nullptr); + + if (Kernel) + { + PARAM_ERROR_CHECK(vxAddParameterToKernel(Kernel, 0, VX_INPUT, VX_TYPE_IMAGE, VX_PARAMETER_STATE_REQUIRED)); + PARAM_ERROR_CHECK(vxAddParameterToKernel(Kernel, 1, VX_OUTPUT, VX_TYPE_IMAGE, VX_PARAMETER_STATE_REQUIRED)); + PARAM_ERROR_CHECK(vxAddParameterToKernel(Kernel, 2, VX_INPUT, VX_TYPE_MATRIX, VX_PARAMETER_STATE_REQUIRED)); + PARAM_ERROR_CHECK(vxAddParameterToKernel(Kernel, 3, VX_INPUT, VX_TYPE_SCALAR, VX_PARAMETER_STATE_REQUIRED)); + PARAM_ERROR_CHECK(vxAddParameterToKernel(Kernel, 4, VX_INPUT, VX_TYPE_SCALAR, VX_PARAMETER_STATE_REQUIRED)); + PARAM_ERROR_CHECK(vxAddParameterToKernel(Kernel, 5, VX_INPUT, VX_TYPE_SCALAR, VX_PARAMETER_STATE_REQUIRED)); + PARAM_ERROR_CHECK(vxAddParameterToKernel(Kernel, 6, VX_INPUT, VX_TYPE_SCALAR, VX_PARAMETER_STATE_REQUIRED)); + PARAM_ERROR_CHECK(vxFinalizeKernel(Kernel)); + } + + if (status != VX_SUCCESS) + { + exit: vxRemoveKernel(Kernel); return VX_FAILURE; + } + + return status; +} diff --git a/vx_ext_cv/OpenCV_fastNlMeansDenoising.cpp b/vx_ext_cv/OpenCV_fastNlMeansDenoising.cpp new file mode 100644 index 0000000..99465b7 --- /dev/null +++ b/vx_ext_cv/OpenCV_fastNlMeansDenoising.cpp @@ -0,0 +1,193 @@ +/* +Copyright (c) 2015 Advanced Micro Devices, Inc. All rights reserved. + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. +*/ + + +#include"publishkernels.h" + +/************************************************************************************************************ +input parameter validator. +param [in] node The handle to the node. +param [in] index The index of the parameter to validate. +*************************************************************************************************************/ +static vx_status VX_CALLBACK CV_fastNlMeansDenoising_InputValidator(vx_node node, vx_uint32 index) +{ + vx_status status = VX_SUCCESS ; + vx_parameter param = vxGetParameterByIndex(node, index); + + if (index == 0) + { + vx_image image; + vx_df_image df_image = VX_DF_IMAGE_VIRT; + STATUS_ERROR_CHECK(vxQueryParameter(param, VX_PARAMETER_ATTRIBUTE_REF, &image, sizeof(vx_image))); + STATUS_ERROR_CHECK(vxQueryImage(image, VX_IMAGE_ATTRIBUTE_FORMAT, &df_image, sizeof(df_image))); + if (df_image != VX_DF_IMAGE_U8) + status = VX_ERROR_INVALID_VALUE; + vxReleaseImage(&image); + } + + else if (index == 1) + { + vx_image image; + vx_df_image df_image = VX_DF_IMAGE_VIRT; + STATUS_ERROR_CHECK(vxQueryParameter(param, VX_PARAMETER_ATTRIBUTE_REF, &image, sizeof(vx_image))); + STATUS_ERROR_CHECK(vxQueryImage(image, VX_IMAGE_ATTRIBUTE_FORMAT, &df_image, sizeof(df_image))); + if (df_image != VX_DF_IMAGE_U8) + status = VX_ERROR_INVALID_VALUE; + vxReleaseImage(&image); + } + + else if (index == 2) + { + vx_scalar scalar = 0; vx_enum type = 0; vx_float32 value = 0; + STATUS_ERROR_CHECK(vxQueryParameter(param, VX_PARAMETER_ATTRIBUTE_REF, &scalar, sizeof(scalar))); + STATUS_ERROR_CHECK(vxQueryScalar(scalar, VX_SCALAR_ATTRIBUTE_TYPE, &type, sizeof(type))); + STATUS_ERROR_CHECK(vxReadScalarValue(scalar, &value)); + if (value < 0 || type != VX_TYPE_FLOAT32) + status = VX_ERROR_INVALID_VALUE; + vxReleaseScalar(&scalar); + } + + else if (index == 3) + { + vx_scalar scalar = 0; vx_enum type = 0; vx_int32 value = 0; + STATUS_ERROR_CHECK(vxQueryParameter(param, VX_PARAMETER_ATTRIBUTE_REF, &scalar, sizeof(scalar))); + STATUS_ERROR_CHECK(vxQueryScalar(scalar, VX_SCALAR_ATTRIBUTE_TYPE, &type, sizeof(type))); + STATUS_ERROR_CHECK(vxReadScalarValue(scalar, &value)); + if (value < 0 || type != VX_TYPE_INT32) + status = VX_ERROR_INVALID_VALUE; + vxReleaseScalar(&scalar); + } + + else if (index == 4) + { + vx_scalar scalar = 0; vx_enum type = 0; vx_int32 value = 0; + STATUS_ERROR_CHECK(vxQueryParameter(param, VX_PARAMETER_ATTRIBUTE_REF, &scalar, sizeof(scalar))); + STATUS_ERROR_CHECK(vxQueryScalar(scalar, VX_SCALAR_ATTRIBUTE_TYPE, &type, sizeof(type))); + STATUS_ERROR_CHECK(vxReadScalarValue(scalar, &value)); + if (value < 0 || type != VX_TYPE_INT32) + status = VX_ERROR_INVALID_VALUE; + vxReleaseScalar(&scalar); + } + + vxReleaseParameter(¶m); + return status; +} + +/************************************************************************************************************ +output parameter validator. +*************************************************************************************************************/ +static vx_status VX_CALLBACK CV_fastNlMeansDenoising_OutputValidator(vx_node node, vx_uint32 index, vx_meta_format meta) +{ + vx_status status = VX_SUCCESS ; + if (index == 1) + { + vx_parameter output_param = vxGetParameterByIndex(node, 1); + vx_image output; vx_uint32 width = 0, height = 0; vx_df_image format = VX_DF_IMAGE_VIRT; + + STATUS_ERROR_CHECK(vxQueryParameter(output_param, VX_PARAMETER_ATTRIBUTE_REF, &output, sizeof(vx_image))); + STATUS_ERROR_CHECK(vxQueryImage(output, VX_IMAGE_ATTRIBUTE_FORMAT, &format, sizeof(format))); + STATUS_ERROR_CHECK(vxQueryImage(output, VX_IMAGE_ATTRIBUTE_WIDTH, &width, sizeof(width))); + STATUS_ERROR_CHECK(vxQueryImage(output, VX_IMAGE_ATTRIBUTE_HEIGHT, &height, sizeof(height))); + + if (format != VX_DF_IMAGE_U8) + status = VX_ERROR_INVALID_VALUE; + + STATUS_ERROR_CHECK(vxSetMetaFormatAttribute(meta, VX_IMAGE_ATTRIBUTE_WIDTH, &width, sizeof(width))); + STATUS_ERROR_CHECK(vxSetMetaFormatAttribute(meta, VX_IMAGE_ATTRIBUTE_HEIGHT, &height, sizeof(height))); + STATUS_ERROR_CHECK(vxSetMetaFormatAttribute(meta, VX_IMAGE_ATTRIBUTE_FORMAT, &format, sizeof(format))); + + vxReleaseImage(&output); + vxReleaseParameter(&output_param); + } + return status; +} + +/************************************************************************************************************ +Execution Kernel +*************************************************************************************************************/ +static vx_status VX_CALLBACK CV_fastNlMeansDenoising_Kernel(vx_node node, const vx_reference *parameters, vx_uint32 num) +{ + vx_status status = VX_SUCCESS; + + vx_image image_in = (vx_image) parameters[0]; + vx_image image_out = (vx_image) parameters[1]; + vx_scalar H = (vx_scalar) parameters[2]; + vx_scalar Template_WS = (vx_scalar) parameters[3]; + vx_scalar Search_WS = (vx_scalar) parameters[4]; + + Mat *mat, bl; + int search_ws, template_ws; + float h; + vx_float32 value_f = 0; + vx_int32 value = 0; + + //Extracting Values from the Scalar into Ksize and Ddepth + STATUS_ERROR_CHECK(vxReadScalarValue(H, &value_f));h = value_f; + STATUS_ERROR_CHECK(vxReadScalarValue(Template_WS, &value));template_ws = value; + STATUS_ERROR_CHECK(vxReadScalarValue(Search_WS, &value));search_ws = value; + + //Converting VX Image to OpenCV Mat + STATUS_ERROR_CHECK(match_vx_image_parameters(image_in, image_out)); + STATUS_ERROR_CHECK(VX_to_CV_Image(&mat, image_in)); + + //Compute using OpenCV + cv::fastNlMeansDenoising(*mat, bl, h, template_ws, search_ws); + + //Converting OpenCV Mat into VX Image + STATUS_ERROR_CHECK(CV_to_VX_Image(image_out, &bl)); + + return status; +} + +/************************************************************************************************************ +Function to Register the Kernel for Publish +*************************************************************************************************************/ +vx_status CV_fastNlMeansDenoising_Register(vx_context context) +{ + vx_status status = VX_SUCCESS; + vx_kernel Kernel = vxAddKernel(context, + "org.opencv.fastnlmeansdenoising", + VX_KERNEL_EXT_CV_FAST_NL_MEANS_DENOISING, + CV_fastNlMeansDenoising_Kernel, + 5, + CV_fastNlMeansDenoising_InputValidator, + CV_fastNlMeansDenoising_OutputValidator, + nullptr, + nullptr); + + if (Kernel) + { + PARAM_ERROR_CHECK(vxAddParameterToKernel(Kernel, 0, VX_INPUT, VX_TYPE_IMAGE, VX_PARAMETER_STATE_REQUIRED)); + PARAM_ERROR_CHECK(vxAddParameterToKernel(Kernel, 1, VX_OUTPUT, VX_TYPE_IMAGE, VX_PARAMETER_STATE_REQUIRED)); + PARAM_ERROR_CHECK(vxAddParameterToKernel(Kernel, 2, VX_INPUT, VX_TYPE_SCALAR, VX_PARAMETER_STATE_REQUIRED)); + PARAM_ERROR_CHECK(vxAddParameterToKernel(Kernel, 3, VX_INPUT, VX_TYPE_SCALAR, VX_PARAMETER_STATE_REQUIRED)); + PARAM_ERROR_CHECK(vxAddParameterToKernel(Kernel, 4, VX_INPUT, VX_TYPE_SCALAR, VX_PARAMETER_STATE_REQUIRED)); + PARAM_ERROR_CHECK(vxFinalizeKernel(Kernel)); + + } + if (status != VX_SUCCESS) + { + exit: vxRemoveKernel(Kernel); return VX_FAILURE; + } + + return status; +} diff --git a/vx_ext_cv/OpenCV_fastNlMeansDenoisingColored.cpp b/vx_ext_cv/OpenCV_fastNlMeansDenoisingColored.cpp new file mode 100644 index 0000000..dad9a54 --- /dev/null +++ b/vx_ext_cv/OpenCV_fastNlMeansDenoisingColored.cpp @@ -0,0 +1,208 @@ +/* +Copyright (c) 2015 Advanced Micro Devices, Inc. All rights reserved. + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. +*/ + + +#include"publishkernels.h" + +/************************************************************************************************************ +input parameter validator. +param [in] node The handle to the node. +param [in] index The index of the parameter to validate. +*************************************************************************************************************/ +static vx_status VX_CALLBACK CV_fastNlMeansDenoisingColored_InputValidator(vx_node node, vx_uint32 index) +{ + vx_status status = VX_SUCCESS; + vx_parameter param = vxGetParameterByIndex(node, index); + + if (index == 0) + { + vx_image image; + vx_df_image df_image = VX_DF_IMAGE_VIRT; + STATUS_ERROR_CHECK(vxQueryParameter(param, VX_PARAMETER_ATTRIBUTE_REF, &image, sizeof(vx_image))); + STATUS_ERROR_CHECK(vxQueryImage(image, VX_IMAGE_ATTRIBUTE_FORMAT, &df_image, sizeof(df_image))); + if (df_image != VX_DF_IMAGE_RGB) + status = VX_ERROR_INVALID_VALUE; + vxReleaseImage(&image); + } + + else if (index == 1) + { + vx_image image; + vx_df_image df_image = VX_DF_IMAGE_VIRT; + STATUS_ERROR_CHECK(vxQueryParameter(param, VX_PARAMETER_ATTRIBUTE_REF, &image, sizeof(vx_image))); + STATUS_ERROR_CHECK(vxQueryImage(image, VX_IMAGE_ATTRIBUTE_FORMAT, &df_image, sizeof(df_image))); + if (df_image != VX_DF_IMAGE_RGB) + status = VX_ERROR_INVALID_VALUE; + vxReleaseImage(&image); + } + + else if (index == 2) + { + vx_scalar scalar = 0; vx_enum type = 0; vx_float32 value = 0; + STATUS_ERROR_CHECK(vxQueryParameter(param, VX_PARAMETER_ATTRIBUTE_REF, &scalar, sizeof(scalar))); + STATUS_ERROR_CHECK(vxQueryScalar(scalar, VX_SCALAR_ATTRIBUTE_TYPE, &type, sizeof(type))); + STATUS_ERROR_CHECK(vxReadScalarValue(scalar, &value)); + if (value < 0 || type != VX_TYPE_FLOAT32) + status = VX_ERROR_INVALID_VALUE; + vxReleaseScalar(&scalar); + } + + else if (index == 3) + { + vx_scalar scalar = 0; vx_enum type = 0; vx_float32 value = 0; + STATUS_ERROR_CHECK(vxQueryParameter(param, VX_PARAMETER_ATTRIBUTE_REF, &scalar, sizeof(scalar))); + STATUS_ERROR_CHECK(vxQueryScalar(scalar, VX_SCALAR_ATTRIBUTE_TYPE, &type, sizeof(type))); + STATUS_ERROR_CHECK(vxReadScalarValue(scalar, &value)); + if (value < 0 || type != VX_TYPE_FLOAT32) + status = VX_ERROR_INVALID_VALUE; + vxReleaseScalar(&scalar); + } + + else if (index == 4) + { + vx_scalar scalar = 0; vx_enum type = 0; vx_int32 value = 0; + STATUS_ERROR_CHECK(vxQueryParameter(param, VX_PARAMETER_ATTRIBUTE_REF, &scalar, sizeof(scalar))); + STATUS_ERROR_CHECK(vxQueryScalar(scalar, VX_SCALAR_ATTRIBUTE_TYPE, &type, sizeof(type))); + STATUS_ERROR_CHECK(vxReadScalarValue(scalar, &value)); + if (value < 0 || type != VX_TYPE_INT32) + status = VX_ERROR_INVALID_VALUE; + vxReleaseScalar(&scalar); + } + + else if (index == 5) + { + vx_scalar scalar = 0; vx_enum type = 0; vx_int32 value = 0; + STATUS_ERROR_CHECK(vxQueryParameter(param, VX_PARAMETER_ATTRIBUTE_REF, &scalar, sizeof(scalar))); + STATUS_ERROR_CHECK(vxQueryScalar(scalar, VX_SCALAR_ATTRIBUTE_TYPE, &type, sizeof(type))); + STATUS_ERROR_CHECK(vxReadScalarValue(scalar, &value)); + if (value < 0 || type != VX_TYPE_INT32) + status = VX_ERROR_INVALID_VALUE; + vxReleaseScalar(&scalar); + } + + vxReleaseParameter(¶m); + return status; +} + +/************************************************************************************************************ +output parameter validator. +*************************************************************************************************************/ +static vx_status VX_CALLBACK CV_fastNlMeansDenoisingColored_OutputValidator(vx_node node, vx_uint32 index, vx_meta_format meta) +{ + vx_status status = VX_SUCCESS; + if (index == 1) + { + vx_parameter output_param = vxGetParameterByIndex(node, 1); + vx_image output; vx_uint32 width = 0, height = 0; vx_df_image format = VX_DF_IMAGE_VIRT; + + STATUS_ERROR_CHECK(vxQueryParameter(output_param, VX_PARAMETER_ATTRIBUTE_REF, &output, sizeof(vx_image))); + STATUS_ERROR_CHECK(vxQueryImage(output, VX_IMAGE_ATTRIBUTE_FORMAT, &format, sizeof(format))); + STATUS_ERROR_CHECK(vxQueryImage(output, VX_IMAGE_ATTRIBUTE_WIDTH, &width, sizeof(width))); + STATUS_ERROR_CHECK(vxQueryImage(output, VX_IMAGE_ATTRIBUTE_HEIGHT, &height, sizeof(height))); + + if (format != VX_DF_IMAGE_RGB) + status = VX_ERROR_INVALID_VALUE; + + STATUS_ERROR_CHECK(vxSetMetaFormatAttribute(meta, VX_IMAGE_ATTRIBUTE_WIDTH, &width, sizeof(width))); + STATUS_ERROR_CHECK(vxSetMetaFormatAttribute(meta, VX_IMAGE_ATTRIBUTE_HEIGHT, &height, sizeof(height))); + STATUS_ERROR_CHECK(vxSetMetaFormatAttribute(meta, VX_IMAGE_ATTRIBUTE_FORMAT, &format, sizeof(format))); + + vxReleaseImage(&output); + vxReleaseParameter(&output_param); + } + return status; +} + +/************************************************************************************************************ +Execution Kernel +*************************************************************************************************************/ +static vx_status VX_CALLBACK CV_fastNlMeansDenoisingColored_Kernel(vx_node node, const vx_reference *parameters, vx_uint32 num) +{ + vx_status status = VX_SUCCESS; + + + vx_image image_in = (vx_image) parameters[0]; + vx_image image_out = (vx_image) parameters[1]; + vx_scalar H = (vx_scalar) parameters[2]; + vx_scalar H_COLOR = (vx_scalar) parameters[3]; + vx_scalar Template_WS = (vx_scalar) parameters[4]; + vx_scalar Search_WS = (vx_scalar) parameters[5]; + Mat *mat, bl; + int search_ws, template_ws; + float h, h_color; + vx_float32 value_f = 0; + vx_int32 value = 0; + + //Extracting Values from the Scalar into Ksize and Ddepth + STATUS_ERROR_CHECK(vxReadScalarValue(H, &value_f));h = value_f; + STATUS_ERROR_CHECK(vxReadScalarValue(H_COLOR, &value_f));h_color = value_f; + STATUS_ERROR_CHECK(vxReadScalarValue(Template_WS, &value));template_ws = value; + STATUS_ERROR_CHECK(vxReadScalarValue(Search_WS, &value));search_ws = value; + + //Converting VX Image to OpenCV Mat + STATUS_ERROR_CHECK(match_vx_image_parameters(image_in, image_out)); + STATUS_ERROR_CHECK(VX_to_CV_Image(&mat, image_in)); + + //Compute using OpenCV + cv::fastNlMeansDenoisingColored(*mat, bl, h, h_color, template_ws, search_ws); + + //Converting OpenCV Mat into VX Image + STATUS_ERROR_CHECK(CV_to_VX_Image(image_out, &bl)); + + return status; +} + +/************************************************************************************************************ +Function to Register the Kernel for Publish +*************************************************************************************************************/ +vx_status CV_fastNlMeansDenoisingColored_Register(vx_context context) +{ + vx_status status = VX_SUCCESS; + vx_kernel Kernel = vxAddKernel(context, + "org.opencv.fastnlmeansdenoisingcolored", + VX_KERNEL_EXT_CV_FAST_NL_MEANS_DENOISING_COLORED, + CV_fastNlMeansDenoisingColored_Kernel, + 6, + CV_fastNlMeansDenoisingColored_InputValidator, + CV_fastNlMeansDenoisingColored_OutputValidator, + nullptr, + nullptr); + + if (Kernel) + { + PARAM_ERROR_CHECK(vxAddParameterToKernel(Kernel, 0, VX_INPUT, VX_TYPE_IMAGE, VX_PARAMETER_STATE_REQUIRED)); + PARAM_ERROR_CHECK(vxAddParameterToKernel(Kernel, 1, VX_OUTPUT, VX_TYPE_IMAGE, VX_PARAMETER_STATE_REQUIRED)); + PARAM_ERROR_CHECK(vxAddParameterToKernel(Kernel, 2, VX_INPUT, VX_TYPE_SCALAR, VX_PARAMETER_STATE_REQUIRED)); + PARAM_ERROR_CHECK(vxAddParameterToKernel(Kernel, 3, VX_INPUT, VX_TYPE_SCALAR, VX_PARAMETER_STATE_REQUIRED)); + PARAM_ERROR_CHECK(vxAddParameterToKernel(Kernel, 4, VX_INPUT, VX_TYPE_SCALAR, VX_PARAMETER_STATE_REQUIRED)); + PARAM_ERROR_CHECK(vxAddParameterToKernel(Kernel, 5, VX_INPUT, VX_TYPE_SCALAR, VX_PARAMETER_STATE_REQUIRED)); + PARAM_ERROR_CHECK(vxFinalizeKernel(Kernel)); + } + + if (status != VX_SUCCESS) + { + exit: vxRemoveKernel(Kernel); return VX_FAILURE; + } + + return status; +} + diff --git a/vx_ext_cv/OpenCV_filter2D.cpp b/vx_ext_cv/OpenCV_filter2D.cpp new file mode 100644 index 0000000..e31a5c3 --- /dev/null +++ b/vx_ext_cv/OpenCV_filter2D.cpp @@ -0,0 +1,237 @@ +/* +Copyright (c) 2015 Advanced Micro Devices, Inc. All rights reserved. + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. +*/ + + +#include"publishkernels.h" + +/************************************************************************************************************ +input parameter validator. +param [in] node The handle to the node. +param [in] index The index of the parameter to validate. +*************************************************************************************************************/ +static vx_status VX_CALLBACK CV_filter2D_InputValidator(vx_node node, vx_uint32 index) +{ + vx_status status = VX_SUCCESS; + vx_parameter param = vxGetParameterByIndex(node, index); + + if (index == 0) + { + vx_image image; + vx_df_image df_image = VX_DF_IMAGE_VIRT; + STATUS_ERROR_CHECK(vxQueryParameter(param, VX_PARAMETER_ATTRIBUTE_REF, &image, sizeof(vx_image))); + STATUS_ERROR_CHECK(vxQueryImage(image, VX_IMAGE_ATTRIBUTE_FORMAT, &df_image, sizeof(df_image))); + if (df_image != VX_DF_IMAGE_U8) + status = VX_ERROR_INVALID_VALUE; + vxReleaseImage(&image); + } + + else if (index == 1) + { + vx_image image; + vx_df_image df_image = VX_DF_IMAGE_VIRT; + STATUS_ERROR_CHECK(vxQueryParameter(param, VX_PARAMETER_ATTRIBUTE_REF, &image, sizeof(vx_image))); + STATUS_ERROR_CHECK(vxQueryImage(image, VX_IMAGE_ATTRIBUTE_FORMAT, &df_image, sizeof(df_image))); + if (df_image != VX_DF_IMAGE_U8) + status = VX_ERROR_INVALID_VALUE; + vxReleaseImage(&image); + } + + else if (index == 2) + { + vx_scalar scalar = 0; vx_enum type = 0; vx_int32 value = 0; + STATUS_ERROR_CHECK(vxQueryParameter(param, VX_PARAMETER_ATTRIBUTE_REF, &scalar, sizeof(scalar))); + STATUS_ERROR_CHECK(vxQueryScalar(scalar, VX_SCALAR_ATTRIBUTE_TYPE, &type, sizeof(type))); + STATUS_ERROR_CHECK(vxReadScalarValue(scalar, &value)); + if (value < -1 || type != VX_TYPE_INT32) + status = VX_ERROR_INVALID_VALUE; + vxReleaseScalar(&scalar); + } + + else if (index == 3) + { + vx_matrix mat; + STATUS_ERROR_CHECK(vxQueryParameter(param, VX_PARAMETER_ATTRIBUTE_REF, &mat, sizeof(vx_matrix))); + vxReleaseMatrix(&mat); + } + + else if (index == 4) + { + vx_scalar scalar = 0; vx_enum type = 0; vx_int32 value = 0; + STATUS_ERROR_CHECK(vxQueryParameter(param, VX_PARAMETER_ATTRIBUTE_REF, &scalar, sizeof(scalar))); + STATUS_ERROR_CHECK(vxQueryScalar(scalar, VX_SCALAR_ATTRIBUTE_TYPE, &type, sizeof(type))); + STATUS_ERROR_CHECK(vxReadScalarValue(scalar, &value)); + if (value < -1 || type != VX_TYPE_INT32) + status = VX_ERROR_INVALID_VALUE; + vxReleaseScalar(&scalar); + } + + else if (index == 5) + { + vx_scalar scalar = 0; vx_enum type = 0; vx_int32 value = 0; + STATUS_ERROR_CHECK(vxQueryParameter(param, VX_PARAMETER_ATTRIBUTE_REF, &scalar, sizeof(scalar))); + STATUS_ERROR_CHECK(vxQueryScalar(scalar, VX_SCALAR_ATTRIBUTE_TYPE, &type, sizeof(type))); + STATUS_ERROR_CHECK(vxReadScalarValue(scalar, &value)); + if (value < -1 || type != VX_TYPE_INT32) + status = VX_ERROR_INVALID_VALUE; + vxReleaseScalar(&scalar); + } + + else if (index == 6) + { + vx_scalar scalar = 0; vx_enum type = 0; vx_float32 value = 0; + STATUS_ERROR_CHECK(vxQueryParameter(param, VX_PARAMETER_ATTRIBUTE_REF, &scalar, sizeof(scalar))); + STATUS_ERROR_CHECK(vxQueryScalar(scalar, VX_SCALAR_ATTRIBUTE_TYPE, &type, sizeof(type))); + STATUS_ERROR_CHECK(vxReadScalarValue(scalar, &value)); + if (value < 0 || type != VX_TYPE_FLOAT32) + status = VX_ERROR_INVALID_VALUE; + vxReleaseScalar(&scalar); + } + + else if (index == 7) + { + vx_scalar scalar = 0; vx_enum type = 0; vx_int32 value = 0; + STATUS_ERROR_CHECK(vxQueryParameter(param, VX_PARAMETER_ATTRIBUTE_REF, &scalar, sizeof(scalar))); + STATUS_ERROR_CHECK(vxQueryScalar(scalar, VX_SCALAR_ATTRIBUTE_TYPE, &type, sizeof(type))); + STATUS_ERROR_CHECK(vxReadScalarValue(scalar, &value)); + if (value < 0 || type != VX_TYPE_INT32) + status = VX_ERROR_INVALID_VALUE; + vxReleaseScalar(&scalar); + } + + vxReleaseParameter(¶m); + return status; +} + +/************************************************************************************************************ +output parameter validator. +*************************************************************************************************************/ +static vx_status VX_CALLBACK CV_filter2D_OutputValidator(vx_node node, vx_uint32 index, vx_meta_format meta) +{ + vx_status status = VX_SUCCESS; + if (index == 1) + { + vx_parameter output_param = vxGetParameterByIndex(node, 1); + vx_image output; vx_uint32 width = 0, height = 0; vx_df_image format = VX_DF_IMAGE_VIRT; + + STATUS_ERROR_CHECK(vxQueryParameter(output_param, VX_PARAMETER_ATTRIBUTE_REF, &output, sizeof(vx_image))); + STATUS_ERROR_CHECK(vxQueryImage(output, VX_IMAGE_ATTRIBUTE_FORMAT, &format, sizeof(format))); + STATUS_ERROR_CHECK(vxQueryImage(output, VX_IMAGE_ATTRIBUTE_WIDTH, &width, sizeof(width))); + STATUS_ERROR_CHECK(vxQueryImage(output, VX_IMAGE_ATTRIBUTE_HEIGHT, &height, sizeof(height))); + + if (format != VX_DF_IMAGE_U8) + status = VX_ERROR_INVALID_VALUE; + + STATUS_ERROR_CHECK(vxSetMetaFormatAttribute(meta, VX_IMAGE_ATTRIBUTE_WIDTH, &width, sizeof(width))); + STATUS_ERROR_CHECK(vxSetMetaFormatAttribute(meta, VX_IMAGE_ATTRIBUTE_HEIGHT, &height, sizeof(height))); + STATUS_ERROR_CHECK(vxSetMetaFormatAttribute(meta, VX_IMAGE_ATTRIBUTE_FORMAT, &format, sizeof(format))); + + vxReleaseImage(&output); + vxReleaseParameter(&output_param); + } + return status; +} + +/************************************************************************************************************ +Execution Kernel +*************************************************************************************************************/ +static vx_status VX_CALLBACK CV_filter2D_Kernel(vx_node node, const vx_reference *parameters, vx_uint32 num) +{ + vx_status status = VX_SUCCESS; + + vx_image image_in = (vx_image) parameters[0]; + vx_image image_out = (vx_image) parameters[1]; + vx_scalar scalar = (vx_scalar) parameters[2]; + vx_matrix KERNEL = (vx_matrix) parameters[3]; + vx_scalar A_X = (vx_scalar) parameters[4]; + vx_scalar A_Y = (vx_scalar) parameters[5]; + vx_scalar DELTA = (vx_scalar) parameters[6]; + vx_scalar BORDER = (vx_scalar) parameters[7]; + + Mat *mat, bl; + int ddepth, a_x = -1, a_y = -1, border = 4; + float delta = 0; + vx_int32 value = 0; + vx_float32 value_f = 0; + + //Extracting Values from the Scalar into Ksize and Ddepth + STATUS_ERROR_CHECK(vxReadScalarValue(scalar, &value));ddepth = value; + STATUS_ERROR_CHECK(vxReadScalarValue(A_X, &value));a_x = value; + STATUS_ERROR_CHECK(vxReadScalarValue(A_Y, &value));a_y = value; + STATUS_ERROR_CHECK(vxReadScalarValue(DELTA, &value_f));delta = value_f; + STATUS_ERROR_CHECK(vxReadScalarValue(BORDER, &value));border = value; + + //Converting VX Image to OpenCV Mat + STATUS_ERROR_CHECK(match_vx_image_parameters(image_in, image_out)); + STATUS_ERROR_CHECK(VX_to_CV_Image(&mat, image_in)); + + //Compute using OpenCV + Point point; + point.x = a_x; + point.y = a_y; + Mat *kernel; + STATUS_ERROR_CHECK(VX_to_CV_MATRIX(&kernel, KERNEL)); + cv::filter2D(*mat, bl, ddepth, *kernel, point, delta, border); + + //Converting OpenCV Mat into VX Image + STATUS_ERROR_CHECK(CV_to_VX_Image(image_out, &bl)); + + return status; +} + +/************************************************************************************************************ +Function to Register the Kernel for Publish +*************************************************************************************************************/ +vx_status CV_filter2D_Register(vx_context context) +{ + vx_status status = VX_SUCCESS; + vx_kernel Kernel = vxAddKernel(context, + "org.opencv.filter2d", + VX_KERNEL_EXT_CV_FILTER_2D, + CV_filter2D_Kernel, + 8, + CV_filter2D_InputValidator, + CV_filter2D_OutputValidator, + nullptr, + nullptr); + + if (Kernel) + { + PARAM_ERROR_CHECK(vxAddParameterToKernel(Kernel, 0, VX_INPUT, VX_TYPE_IMAGE, VX_PARAMETER_STATE_REQUIRED)); + PARAM_ERROR_CHECK(vxAddParameterToKernel(Kernel, 1, VX_OUTPUT, VX_TYPE_IMAGE, VX_PARAMETER_STATE_REQUIRED)); + PARAM_ERROR_CHECK(vxAddParameterToKernel(Kernel, 2, VX_INPUT, VX_TYPE_SCALAR, VX_PARAMETER_STATE_REQUIRED)); + PARAM_ERROR_CHECK(vxAddParameterToKernel(Kernel, 3, VX_INPUT, VX_TYPE_MATRIX, VX_PARAMETER_STATE_REQUIRED)); + PARAM_ERROR_CHECK(vxAddParameterToKernel(Kernel, 4, VX_INPUT, VX_TYPE_SCALAR, VX_PARAMETER_STATE_REQUIRED)); + PARAM_ERROR_CHECK(vxAddParameterToKernel(Kernel, 5, VX_INPUT, VX_TYPE_SCALAR, VX_PARAMETER_STATE_REQUIRED)); + PARAM_ERROR_CHECK(vxAddParameterToKernel(Kernel, 6, VX_INPUT, VX_TYPE_SCALAR, VX_PARAMETER_STATE_REQUIRED)); + PARAM_ERROR_CHECK(vxAddParameterToKernel(Kernel, 7, VX_INPUT, VX_TYPE_SCALAR, VX_PARAMETER_STATE_REQUIRED)); + PARAM_ERROR_CHECK(vxFinalizeKernel(Kernel)); + + } + + if (status != VX_SUCCESS) + { + exit: vxRemoveKernel(Kernel); return VX_FAILURE; + } + + return status; +} + diff --git a/vx_ext_cv/OpenCV_flip.cpp b/vx_ext_cv/OpenCV_flip.cpp new file mode 100644 index 0000000..b84c1ac --- /dev/null +++ b/vx_ext_cv/OpenCV_flip.cpp @@ -0,0 +1,162 @@ +/* +Copyright (c) 2015 Advanced Micro Devices, Inc. All rights reserved. + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. +*/ + + +#include"publishkernels.h" + +/************************************************************************************************************ +input parameter validator. +param [in] node The handle to the node. +param [in] index The index of the parameter to validate. +*************************************************************************************************************/ +static vx_status VX_CALLBACK CV_flip_InputValidator(vx_node node, vx_uint32 index) +{ + vx_status status = VX_SUCCESS; + vx_parameter param = vxGetParameterByIndex(node, index); + + if (index == 0) + { + vx_image image; + vx_df_image df_image = VX_DF_IMAGE_VIRT; + STATUS_ERROR_CHECK(vxQueryParameter(param, VX_PARAMETER_ATTRIBUTE_REF, &image, sizeof(vx_image))); + STATUS_ERROR_CHECK(vxQueryImage(image, VX_IMAGE_ATTRIBUTE_FORMAT, &df_image, sizeof(df_image))); + if (df_image != VX_DF_IMAGE_U8) + status = VX_ERROR_INVALID_VALUE; + vxReleaseImage(&image); + } + + else if (index == 1) + { + vx_image image; + vx_df_image df_image = VX_DF_IMAGE_VIRT; + STATUS_ERROR_CHECK(vxQueryParameter(param, VX_PARAMETER_ATTRIBUTE_REF, &image, sizeof(vx_image))); + STATUS_ERROR_CHECK(vxQueryImage(image, VX_IMAGE_ATTRIBUTE_FORMAT, &df_image, sizeof(df_image))); + if (df_image != VX_DF_IMAGE_U8) + status = VX_ERROR_INVALID_VALUE; + vxReleaseImage(&image); + } + + else if (index == 2) + { + vx_scalar scalar = 0; vx_enum type = 0; vx_int32 value = 0; + STATUS_ERROR_CHECK(vxQueryParameter(param, VX_PARAMETER_ATTRIBUTE_REF, &scalar, sizeof(scalar))); + STATUS_ERROR_CHECK(vxQueryScalar(scalar, VX_SCALAR_ATTRIBUTE_TYPE, &type, sizeof(type))); + STATUS_ERROR_CHECK(vxReadScalarValue(scalar, &value)); + if (value < -1 || type != VX_TYPE_INT32) + status = VX_ERROR_INVALID_VALUE; + vxReleaseScalar(&scalar); + } + + vxReleaseParameter(¶m); + return status; +} + +/************************************************************************************************************ +output parameter validator. +*************************************************************************************************************/ +static vx_status VX_CALLBACK CV_flip_OutputValidator(vx_node node, vx_uint32 index, vx_meta_format meta) +{ + vx_status status = VX_SUCCESS; + if (index == 1) + { + vx_parameter output_param = vxGetParameterByIndex(node, 1); + vx_image output; vx_uint32 width = 0, height = 0; vx_df_image format = VX_DF_IMAGE_VIRT; + + STATUS_ERROR_CHECK(vxQueryParameter(output_param, VX_PARAMETER_ATTRIBUTE_REF, &output, sizeof(vx_image))); + STATUS_ERROR_CHECK(vxQueryImage(output, VX_IMAGE_ATTRIBUTE_FORMAT, &format, sizeof(format))); + STATUS_ERROR_CHECK(vxQueryImage(output, VX_IMAGE_ATTRIBUTE_WIDTH, &width, sizeof(width))); + STATUS_ERROR_CHECK(vxQueryImage(output, VX_IMAGE_ATTRIBUTE_HEIGHT, &height, sizeof(height))); + + if (format != VX_DF_IMAGE_U8) + status = VX_ERROR_INVALID_VALUE; + + STATUS_ERROR_CHECK(vxSetMetaFormatAttribute(meta, VX_IMAGE_ATTRIBUTE_WIDTH, &width, sizeof(width))); + STATUS_ERROR_CHECK(vxSetMetaFormatAttribute(meta, VX_IMAGE_ATTRIBUTE_HEIGHT, &height, sizeof(height))); + STATUS_ERROR_CHECK(vxSetMetaFormatAttribute(meta, VX_IMAGE_ATTRIBUTE_FORMAT, &format, sizeof(format))); + + vxReleaseImage(&output); + vxReleaseParameter(&output_param); + } + return status; +} + +/************************************************************************************************************ +Execution Kernel +*************************************************************************************************************/ +static vx_status VX_CALLBACK CV_flip_Kernel(vx_node node, const vx_reference *parameters, vx_uint32 num) +{ + vx_status status = VX_SUCCESS; + + vx_image image_in = (vx_image)parameters[0]; + vx_image image_out = (vx_image)parameters[1]; + vx_scalar scalar = (vx_scalar)parameters[2]; + Mat *mat, bl; + int FlipCode; + + vx_int32 value = 0; + + //Extracting Values from the Scalar into FlipCode + STATUS_ERROR_CHECK(vxReadScalarValue(scalar, &value)); FlipCode = value; + + //Converting VX Image to OpenCV Mat + STATUS_ERROR_CHECK(VX_to_CV_Image(&mat, image_in)); + + //Compute using OpenCV + cv::flip(*mat, bl, FlipCode); //output image size should correspond to the right flip code + + //Converting OpenCV Mat into VX Image + STATUS_ERROR_CHECK(CV_to_VX_Image(image_out, &bl)); + + return status; +} + +/************************************************************************************************************ +Function to Register the Kernel for Publish +*************************************************************************************************************/ +vx_status CV_flip_Register(vx_context context) +{ + vx_status status = VX_SUCCESS; + vx_kernel kernel = vxAddKernel(context, + "org.opencv.flip", + VX_KERNEL_EXT_CV_FLIP, + CV_flip_Kernel, + 3, + CV_flip_InputValidator, + CV_flip_OutputValidator, + nullptr, + nullptr); + + if (kernel) + { + PARAM_ERROR_CHECK(vxAddParameterToKernel(kernel, 0, VX_INPUT, VX_TYPE_IMAGE, VX_PARAMETER_STATE_REQUIRED)); + PARAM_ERROR_CHECK(vxAddParameterToKernel(kernel, 1, VX_OUTPUT, VX_TYPE_IMAGE, VX_PARAMETER_STATE_REQUIRED)); + PARAM_ERROR_CHECK(vxAddParameterToKernel(kernel, 2, VX_INPUT, VX_TYPE_SCALAR, VX_PARAMETER_STATE_REQUIRED)); + PARAM_ERROR_CHECK(vxFinalizeKernel(kernel)); + } + + if (status != VX_SUCCESS) + { + exit: vxRemoveKernel(kernel); return VX_FAILURE; + } + + return status; +} diff --git a/vx_ext_cv/OpenCV_integral.cpp b/vx_ext_cv/OpenCV_integral.cpp new file mode 100644 index 0000000..0fd89d8 --- /dev/null +++ b/vx_ext_cv/OpenCV_integral.cpp @@ -0,0 +1,164 @@ +/* +Copyright (c) 2015 Advanced Micro Devices, Inc. All rights reserved. + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. +*/ + + +#include"publishkernels.h" + +/************************************************************************************************************ +input parameter validator. +param [in] node The handle to the node. +param [in] index The index of the parameter to validate. +*************************************************************************************************************/ +static vx_status VX_CALLBACK CV_integral_InputValidator(vx_node node, vx_uint32 index) +{ + vx_status status = VX_SUCCESS; + vx_parameter param = vxGetParameterByIndex(node, index); + + if (index == 0) + { + vx_image image; + vx_df_image df_image = VX_DF_IMAGE_VIRT; + STATUS_ERROR_CHECK(vxQueryParameter(param, VX_PARAMETER_ATTRIBUTE_REF, &image, sizeof(vx_image))); + STATUS_ERROR_CHECK(vxQueryImage(image, VX_IMAGE_ATTRIBUTE_FORMAT, &df_image, sizeof(df_image))); + if (df_image != VX_DF_IMAGE_U8) + status = VX_ERROR_INVALID_VALUE; + vxReleaseImage(&image); + } + + else if (index == 1) + { + vx_image image; + vx_df_image df_image = VX_DF_IMAGE_VIRT; + STATUS_ERROR_CHECK(vxQueryParameter(param, VX_PARAMETER_ATTRIBUTE_REF, &image, sizeof(vx_image))); + STATUS_ERROR_CHECK(vxQueryImage(image, VX_IMAGE_ATTRIBUTE_FORMAT, &df_image, sizeof(df_image))); + if (df_image != VX_DF_IMAGE_U32 && df_image != VX_DF_IMAGE_S32) + status = VX_ERROR_INVALID_VALUE; + vxReleaseImage(&image); + } + + else if (index == 2) + { + vx_scalar scalar = 0; vx_enum type = 0; vx_int32 value = 0; + STATUS_ERROR_CHECK(vxQueryParameter(param, VX_PARAMETER_ATTRIBUTE_REF, &scalar, sizeof(scalar))); + STATUS_ERROR_CHECK(vxQueryScalar(scalar, VX_SCALAR_ATTRIBUTE_TYPE, &type, sizeof(type))); + STATUS_ERROR_CHECK(vxReadScalarValue(scalar, &value)); + if (value < -1 || type != VX_TYPE_INT32) + status = VX_ERROR_INVALID_VALUE; + vxReleaseScalar(&scalar); + } + + vxReleaseParameter(¶m); + return status; +} + +/************************************************************************************************************ +output parameter validator. +*************************************************************************************************************/ +static vx_status VX_CALLBACK CV_integral_OutputValidator(vx_node node, vx_uint32 index, vx_meta_format meta) +{ + vx_status status = VX_SUCCESS; + if (index == 1) + { + vx_parameter output_param = vxGetParameterByIndex(node, 1); + vx_image output; vx_uint32 width = 0, height = 0; vx_df_image format = VX_DF_IMAGE_VIRT; + + STATUS_ERROR_CHECK(vxQueryParameter(output_param, VX_PARAMETER_ATTRIBUTE_REF, &output, sizeof(vx_image))); + STATUS_ERROR_CHECK(vxQueryImage(output, VX_IMAGE_ATTRIBUTE_FORMAT, &format, sizeof(format))); + STATUS_ERROR_CHECK(vxQueryImage(output, VX_IMAGE_ATTRIBUTE_WIDTH, &width, sizeof(width))); + STATUS_ERROR_CHECK(vxQueryImage(output, VX_IMAGE_ATTRIBUTE_HEIGHT, &height, sizeof(height))); + + if (format != VX_DF_IMAGE_U32 && format != VX_DF_IMAGE_S32) + status = VX_ERROR_INVALID_VALUE; + + STATUS_ERROR_CHECK(vxSetMetaFormatAttribute(meta, VX_IMAGE_ATTRIBUTE_WIDTH, &width, sizeof(width))); + STATUS_ERROR_CHECK(vxSetMetaFormatAttribute(meta, VX_IMAGE_ATTRIBUTE_HEIGHT, &height, sizeof(height))); + STATUS_ERROR_CHECK(vxSetMetaFormatAttribute(meta, VX_IMAGE_ATTRIBUTE_FORMAT, &format, sizeof(format))); + + vxReleaseImage(&output); + vxReleaseParameter(&output_param); + } + return status; +} + +/************************************************************************************************************ +Execution Kernel +*************************************************************************************************************/ +static vx_status VX_CALLBACK CV_integral_Kernel(vx_node node, const vx_reference *parameters, vx_uint32 num) +{ + vx_status status = VX_SUCCESS; + + vx_image image_in = (vx_image) parameters[0]; + vx_image image_out = (vx_image) parameters[1]; + vx_scalar scalar = (vx_scalar) parameters[2]; + + Mat *mat, bl; + int sdepth; + vx_int32 value = 0; + + //Extracting Values from the Scalar into sdepth + STATUS_ERROR_CHECK(vxReadScalarValue(scalar, &value)); sdepth = value; + + //Converting VX Image to OpenCV Mat + STATUS_ERROR_CHECK(match_vx_image_parameters(image_in, image_out)); + STATUS_ERROR_CHECK(VX_to_CV_Image(&mat, image_in)); + + //Compute using OpenCV + cv::integral(*mat, bl, sdepth); + + //Converting OpenCV Mat into VX Image + STATUS_ERROR_CHECK(CV_to_VX_Image(image_out, &bl)); + + return status; +} + +/************************************************************************************************************ +Function to Register the Kernel for Publish +*************************************************************************************************************/ +vx_status CV_integral_Register(vx_context context) +{ + vx_status status = VX_SUCCESS; + vx_kernel kernel = vxAddKernel(context, + "org.opencv.integral", + VX_KERNEL_EXT_CV_INTEGRAL, + CV_integral_Kernel, + 3, + CV_integral_InputValidator, + CV_integral_OutputValidator, + nullptr, + nullptr); + + if (kernel) + { + PARAM_ERROR_CHECK(vxAddParameterToKernel(kernel, 0, VX_INPUT, VX_TYPE_IMAGE, VX_PARAMETER_STATE_REQUIRED)); + PARAM_ERROR_CHECK(vxAddParameterToKernel(kernel, 1, VX_OUTPUT, VX_TYPE_IMAGE, VX_PARAMETER_STATE_REQUIRED)); + PARAM_ERROR_CHECK(vxAddParameterToKernel(kernel, 2, VX_INPUT, VX_TYPE_SCALAR, VX_PARAMETER_STATE_REQUIRED)); + PARAM_ERROR_CHECK(vxFinalizeKernel(kernel)); + } + + if (status != VX_SUCCESS) + { + exit: vxRemoveKernel(kernel); return VX_FAILURE; + } + + return status; +} + diff --git a/vx_ext_cv/OpenCV_morphologyEx.cpp b/vx_ext_cv/OpenCV_morphologyEx.cpp new file mode 100644 index 0000000..cc18a0e --- /dev/null +++ b/vx_ext_cv/OpenCV_morphologyEx.cpp @@ -0,0 +1,232 @@ +/* +Copyright (c) 2015 Advanced Micro Devices, Inc. All rights reserved. + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. +*/ + + +#include"publishkernels.h" + +/************************************************************************************************************ +input parameter validator. +param [in] node The handle to the node. +param [in] index The index of the parameter to validate. +*************************************************************************************************************/ +static vx_status VX_CALLBACK CV_morphologyEx_InputValidator(vx_node node, vx_uint32 index) +{ + vx_status status = VX_SUCCESS; + vx_parameter param = vxGetParameterByIndex(node, index); + + if (index == 0) + { + vx_image image; + vx_df_image df_image = VX_DF_IMAGE_VIRT; + STATUS_ERROR_CHECK(vxQueryParameter(param, VX_PARAMETER_ATTRIBUTE_REF, &image, sizeof(vx_image))); + STATUS_ERROR_CHECK(vxQueryImage(image, VX_IMAGE_ATTRIBUTE_FORMAT, &df_image, sizeof(df_image))); + if (df_image != VX_DF_IMAGE_U8) + status = VX_ERROR_INVALID_VALUE; + vxReleaseImage(&image); + } + + else if (index == 1) + { + vx_image image; + vx_df_image df_image = VX_DF_IMAGE_VIRT; + STATUS_ERROR_CHECK(vxQueryParameter(param, VX_PARAMETER_ATTRIBUTE_REF, &image, sizeof(vx_image))); + STATUS_ERROR_CHECK(vxQueryImage(image, VX_IMAGE_ATTRIBUTE_FORMAT, &df_image, sizeof(df_image))); + if (df_image != VX_DF_IMAGE_U8) + status = VX_ERROR_INVALID_VALUE; + vxReleaseImage(&image); + } + + else if (index == 2) + { + vx_scalar scalar = 0; vx_enum type = 0; vx_int32 value = 0; + STATUS_ERROR_CHECK(vxQueryParameter(param, VX_PARAMETER_ATTRIBUTE_REF, &scalar, sizeof(scalar))); + STATUS_ERROR_CHECK(vxQueryScalar(scalar, VX_SCALAR_ATTRIBUTE_TYPE, &type, sizeof(type))); + STATUS_ERROR_CHECK(vxReadScalarValue(scalar, &value)); + if ((value < 0 || value >6) || type != VX_TYPE_INT32) + status = VX_ERROR_INVALID_VALUE; + vxReleaseScalar(&scalar); + } + + else if (index == 3) + { + vx_matrix mat; + STATUS_ERROR_CHECK(vxQueryParameter(param, VX_PARAMETER_ATTRIBUTE_REF, &mat, sizeof(vx_matrix))); + vxReleaseMatrix(&mat); + } + + else if (index == 4) + { + vx_scalar scalar = 0; vx_enum type = 0; vx_int32 value = 0; + STATUS_ERROR_CHECK(vxQueryParameter(param, VX_PARAMETER_ATTRIBUTE_REF, &scalar, sizeof(scalar))); + STATUS_ERROR_CHECK(vxQueryScalar(scalar, VX_SCALAR_ATTRIBUTE_TYPE, &type, sizeof(type))); + STATUS_ERROR_CHECK(vxReadScalarValue(scalar, &value)); + if (value < -1 || type != VX_TYPE_INT32) + status = VX_ERROR_INVALID_VALUE; + vxReleaseScalar(&scalar); + } + + else if (index == 5) + { + vx_scalar scalar = 0; vx_enum type = 0; vx_int32 value = 0; + STATUS_ERROR_CHECK(vxQueryParameter(param, VX_PARAMETER_ATTRIBUTE_REF, &scalar, sizeof(scalar))); + STATUS_ERROR_CHECK(vxQueryScalar(scalar, VX_SCALAR_ATTRIBUTE_TYPE, &type, sizeof(type))); + STATUS_ERROR_CHECK(vxReadScalarValue(scalar, &value)); + if (value < -1 || type != VX_TYPE_INT32) + status = VX_ERROR_INVALID_VALUE; + vxReleaseScalar(&scalar); + } + + else if (index == 6) + { + vx_scalar scalar = 0; vx_enum type = 0; vx_int32 value = 0; + STATUS_ERROR_CHECK(vxQueryParameter(param, VX_PARAMETER_ATTRIBUTE_REF, &scalar, sizeof(scalar))); + STATUS_ERROR_CHECK(vxQueryScalar(scalar, VX_SCALAR_ATTRIBUTE_TYPE, &type, sizeof(type))); + STATUS_ERROR_CHECK(vxReadScalarValue(scalar, &value)); + if (value < 0 || type != VX_TYPE_INT32) + status = VX_ERROR_INVALID_VALUE; + vxReleaseScalar(&scalar); + } + + else if (index == 7) + { + vx_scalar scalar = 0; vx_enum type = 0; vx_int32 value = 0; + STATUS_ERROR_CHECK(vxQueryParameter(param, VX_PARAMETER_ATTRIBUTE_REF, &scalar, sizeof(scalar))); + STATUS_ERROR_CHECK(vxQueryScalar(scalar, VX_SCALAR_ATTRIBUTE_TYPE, &type, sizeof(type))); + STATUS_ERROR_CHECK(vxReadScalarValue(scalar, &value)); + if (value < 0 || type != VX_TYPE_INT32) + status = VX_ERROR_INVALID_VALUE; + vxReleaseScalar(&scalar); + } + + vxReleaseParameter(¶m); + return status; +} + +/************************************************************************************************************ +output parameter validator. +*************************************************************************************************************/ +static vx_status VX_CALLBACK CV_morphologyEx_OutputValidator(vx_node node, vx_uint32 index, vx_meta_format meta) +{ + vx_status status = VX_SUCCESS; + if (index == 1) + { + vx_parameter output_param = vxGetParameterByIndex(node, 1); + vx_image output; vx_uint32 width = 0, height = 0; vx_df_image format = VX_DF_IMAGE_VIRT; + + STATUS_ERROR_CHECK(vxQueryParameter(output_param, VX_PARAMETER_ATTRIBUTE_REF, &output, sizeof(vx_image))); + STATUS_ERROR_CHECK(vxQueryImage(output, VX_IMAGE_ATTRIBUTE_FORMAT, &format, sizeof(format))); + STATUS_ERROR_CHECK(vxQueryImage(output, VX_IMAGE_ATTRIBUTE_WIDTH, &width, sizeof(width))); + STATUS_ERROR_CHECK(vxQueryImage(output, VX_IMAGE_ATTRIBUTE_HEIGHT, &height, sizeof(height))); + + if (format != VX_DF_IMAGE_U8) + status = VX_ERROR_INVALID_VALUE; + + STATUS_ERROR_CHECK(vxSetMetaFormatAttribute(meta, VX_IMAGE_ATTRIBUTE_WIDTH, &width, sizeof(width))); + STATUS_ERROR_CHECK(vxSetMetaFormatAttribute(meta, VX_IMAGE_ATTRIBUTE_HEIGHT, &height, sizeof(height))); + STATUS_ERROR_CHECK(vxSetMetaFormatAttribute(meta, VX_IMAGE_ATTRIBUTE_FORMAT, &format, sizeof(format))); + + vxReleaseImage(&output); + vxReleaseParameter(&output_param); + } + return status; +} + +/************************************************************************************************************ +Execution Kernel +*************************************************************************************************************/ +static vx_status VX_CALLBACK CV_morphologyEx_Kernel(vx_node node, const vx_reference *parameters, vx_uint32 num) +{ + vx_status status = VX_SUCCESS; + + vx_image image_in = (vx_image) parameters[0]; + vx_image image_out = (vx_image) parameters[1]; + vx_scalar OP = (vx_scalar) parameters[2]; + vx_matrix KERNEL = (vx_matrix) parameters[3]; + vx_scalar A_X = (vx_scalar) parameters[4]; + vx_scalar A_Y = (vx_scalar) parameters[5]; + vx_scalar ITERATION = (vx_scalar) parameters[6]; + vx_scalar BORDER = (vx_scalar) parameters[7]; + + Mat *mat, bl; + int op, iteration; + int a_x = -1, a_y = -1, border = 4; + vx_int32 value = 0; + + //Extracting Values from the Scalar into Ksize and Ddepth + STATUS_ERROR_CHECK(vxReadScalarValue(OP, &value)); op = value; + STATUS_ERROR_CHECK(vxReadScalarValue(ITERATION, &value)); iteration = value; + STATUS_ERROR_CHECK(vxReadScalarValue(A_X, &value)); a_x = value; + STATUS_ERROR_CHECK(vxReadScalarValue(A_Y, &value)); a_y = value; + STATUS_ERROR_CHECK(vxReadScalarValue(BORDER, &value)); border = value; + + //Converting VX Image to OpenCV Mat + STATUS_ERROR_CHECK(match_vx_image_parameters(image_in, image_out)); + STATUS_ERROR_CHECK(VX_to_CV_Image(&mat, image_in)); + + //Compute using OpenCV + Mat *kernel; + STATUS_ERROR_CHECK(VX_to_CV_MATRIX(&kernel, KERNEL)); + cv::morphologyEx(*mat, bl, op, *kernel, Point(a_x, a_y), iteration, border); + + //Converting OpenCV Mat into VX Image + STATUS_ERROR_CHECK(CV_to_VX_Image(image_out, &bl)); + + return status; +} + +/************************************************************************************************************ +Function to Register the Kernel for Publish +*************************************************************************************************************/ +vx_status CV_morphologyEx_Register(vx_context context) +{ + vx_status status = VX_SUCCESS; + vx_kernel Kernel = vxAddKernel(context, + "org.opencv.morphologyex", + VX_KERNEL_EXT_CV_MORPHOLOGYEX, + CV_morphologyEx_Kernel, + 8, + CV_morphologyEx_InputValidator, + CV_morphologyEx_OutputValidator, + nullptr, + nullptr); + + if (Kernel) + { + PARAM_ERROR_CHECK(vxAddParameterToKernel(Kernel, 0, VX_INPUT, VX_TYPE_IMAGE, VX_PARAMETER_STATE_REQUIRED)); + PARAM_ERROR_CHECK(vxAddParameterToKernel(Kernel, 1, VX_OUTPUT, VX_TYPE_IMAGE, VX_PARAMETER_STATE_REQUIRED)); + PARAM_ERROR_CHECK(vxAddParameterToKernel(Kernel, 2, VX_INPUT, VX_TYPE_SCALAR, VX_PARAMETER_STATE_REQUIRED)); + PARAM_ERROR_CHECK(vxAddParameterToKernel(Kernel, 3, VX_INPUT, VX_TYPE_MATRIX, VX_PARAMETER_STATE_REQUIRED)); + PARAM_ERROR_CHECK(vxAddParameterToKernel(Kernel, 4, VX_INPUT, VX_TYPE_SCALAR, VX_PARAMETER_STATE_REQUIRED)); + PARAM_ERROR_CHECK(vxAddParameterToKernel(Kernel, 5, VX_INPUT, VX_TYPE_SCALAR, VX_PARAMETER_STATE_REQUIRED)); + PARAM_ERROR_CHECK(vxAddParameterToKernel(Kernel, 6, VX_INPUT, VX_TYPE_SCALAR, VX_PARAMETER_STATE_REQUIRED)); + PARAM_ERROR_CHECK(vxAddParameterToKernel(Kernel, 7, VX_INPUT, VX_TYPE_SCALAR, VX_PARAMETER_STATE_REQUIRED)); + PARAM_ERROR_CHECK(vxFinalizeKernel(Kernel)); + } + + + if (status != VX_SUCCESS) + { + exit: vxRemoveKernel(Kernel); return VX_FAILURE; + } + + return status; +} diff --git a/vx_ext_cv/OpenCV_multiply.cpp b/vx_ext_cv/OpenCV_multiply.cpp new file mode 100644 index 0000000..5b06fbc --- /dev/null +++ b/vx_ext_cv/OpenCV_multiply.cpp @@ -0,0 +1,196 @@ +/* +Copyright (c) 2015 Advanced Micro Devices, Inc. All rights reserved. + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. +*/ + + +#include"publishkernels.h" + +/************************************************************************************************************ +input parameter validator. +param [in] node The handle to the node. +param [in] index The index of the parameter to validate. +*************************************************************************************************************/ +static vx_status VX_CALLBACK CV_multiply_InputValidator(vx_node node, vx_uint32 index) +{ + vx_status status = VX_SUCCESS ; + vx_parameter param = vxGetParameterByIndex(node, index); + + if (index == 0) + { + vx_image image; + vx_df_image df_image = VX_DF_IMAGE_VIRT; + STATUS_ERROR_CHECK(vxQueryParameter(param, VX_PARAMETER_ATTRIBUTE_REF, &image, sizeof(vx_image))); + STATUS_ERROR_CHECK(vxQueryImage(image, VX_IMAGE_ATTRIBUTE_FORMAT, &df_image, sizeof(df_image))); + if (df_image != VX_DF_IMAGE_U8 && df_image != VX_DF_IMAGE_S16) + status = VX_ERROR_INVALID_VALUE; + vxReleaseImage(&image); + } + + if (index == 1) + { + vx_image image; + vx_df_image df_image = VX_DF_IMAGE_VIRT; + STATUS_ERROR_CHECK(vxQueryParameter(param, VX_PARAMETER_ATTRIBUTE_REF, &image, sizeof(vx_image))); + STATUS_ERROR_CHECK(vxQueryImage(image, VX_IMAGE_ATTRIBUTE_FORMAT, &df_image, sizeof(df_image))); + if (df_image != VX_DF_IMAGE_U8 && df_image != VX_DF_IMAGE_S16) + status = VX_ERROR_INVALID_VALUE; + vxReleaseImage(&image); + } + + else if (index == 2) + { + vx_image image; + vx_df_image df_image = VX_DF_IMAGE_VIRT; + STATUS_ERROR_CHECK(vxQueryParameter(param, VX_PARAMETER_ATTRIBUTE_REF, &image, sizeof(vx_image))); + STATUS_ERROR_CHECK(vxQueryImage(image, VX_IMAGE_ATTRIBUTE_FORMAT, &df_image, sizeof(df_image))); + if (df_image != VX_DF_IMAGE_U8 && df_image != VX_DF_IMAGE_S16) + status = VX_ERROR_INVALID_VALUE; + vxReleaseImage(&image); + } + + else if (index == 3) + { + vx_scalar scalar = 0; vx_enum type = 0; vx_float32 value = 0; + STATUS_ERROR_CHECK(vxQueryParameter(param, VX_PARAMETER_ATTRIBUTE_REF, &scalar, sizeof(scalar))); + STATUS_ERROR_CHECK(vxQueryScalar(scalar, VX_SCALAR_ATTRIBUTE_TYPE, &type, sizeof(type))); + STATUS_ERROR_CHECK(vxReadScalarValue(scalar, &value)); + if (value < 0 || type != VX_TYPE_FLOAT32) + status = VX_ERROR_INVALID_VALUE; + vxReleaseScalar(&scalar); + } + + else if (index == 4) + { + vx_scalar scalar = 0; vx_enum type = 0; vx_int32 value = 0; + STATUS_ERROR_CHECK(vxQueryParameter(param, VX_PARAMETER_ATTRIBUTE_REF, &scalar, sizeof(scalar))); + STATUS_ERROR_CHECK(vxQueryScalar(scalar, VX_SCALAR_ATTRIBUTE_TYPE, &type, sizeof(type))); + STATUS_ERROR_CHECK(vxReadScalarValue(scalar, &value)); + if (value < 0 || type != VX_TYPE_INT32) + status = VX_ERROR_INVALID_VALUE; + vxReleaseScalar(&scalar); + } + + vxReleaseParameter(¶m); + return status; +} + +/************************************************************************************************************ +output parameter validator. +*************************************************************************************************************/ +static vx_status VX_CALLBACK CV_multiply_OutputValidator(vx_node node, vx_uint32 index, vx_meta_format meta) +{ + vx_status status = VX_SUCCESS ; + if (index == 2) + { + vx_parameter output_param = vxGetParameterByIndex(node, 2); + vx_image output; vx_uint32 width = 0, height = 0; vx_df_image format = VX_DF_IMAGE_VIRT; + + STATUS_ERROR_CHECK(vxQueryParameter(output_param, VX_PARAMETER_ATTRIBUTE_REF, &output, sizeof(vx_image))); + STATUS_ERROR_CHECK(vxQueryImage(output, VX_IMAGE_ATTRIBUTE_FORMAT, &format, sizeof(format))); + STATUS_ERROR_CHECK(vxQueryImage(output, VX_IMAGE_ATTRIBUTE_WIDTH, &width, sizeof(width))); + STATUS_ERROR_CHECK(vxQueryImage(output, VX_IMAGE_ATTRIBUTE_HEIGHT, &height, sizeof(height))); + + if (format != VX_DF_IMAGE_U8 && format != VX_DF_IMAGE_S16) + status = VX_ERROR_INVALID_VALUE; + + STATUS_ERROR_CHECK(vxSetMetaFormatAttribute(meta, VX_IMAGE_ATTRIBUTE_WIDTH, &width, sizeof(width))); + STATUS_ERROR_CHECK(vxSetMetaFormatAttribute(meta, VX_IMAGE_ATTRIBUTE_HEIGHT, &height, sizeof(height))); + STATUS_ERROR_CHECK(vxSetMetaFormatAttribute(meta, VX_IMAGE_ATTRIBUTE_FORMAT, &format, sizeof(format))); + + vxReleaseImage(&output); + vxReleaseParameter(&output_param); + } + return status; +} + +/************************************************************************************************************ +Execution Kernel +*************************************************************************************************************/ +static vx_status VX_CALLBACK CV_multiply_Kernel(vx_node node, const vx_reference *parameters, vx_uint32 num) +{ + vx_status status = VX_SUCCESS; + + vx_image image_1 = (vx_image) parameters[0]; + vx_image image_2 = (vx_image) parameters[1]; + vx_image image_out = (vx_image) parameters[2]; + vx_scalar SCALE = (vx_scalar) parameters[3]; + vx_scalar DTYPE = (vx_scalar) parameters[4]; + + Mat *mat_1, *mat_2, bl; + vx_int32 value = 0; + int dtype; + vx_float32 value_f = 0; + float scale; + + //Extracting Values from the Scalar + STATUS_ERROR_CHECK(vxReadScalarValue(SCALE, &value_f)); scale = value_f; + STATUS_ERROR_CHECK(vxReadScalarValue(DTYPE, &value)); dtype = value; + + //Converting VX Image to OpenCV Mat 1 + STATUS_ERROR_CHECK(match_vx_image_parameters(image_1, image_2)); + STATUS_ERROR_CHECK(match_vx_image_parameters(image_1, image_out)); + STATUS_ERROR_CHECK(VX_to_CV_Image(&mat_1, image_1)); + STATUS_ERROR_CHECK(VX_to_CV_Image(&mat_2, image_2)); + + //Compute using OpenCV + cv::multiply(*mat_1, *mat_2, bl, scale, dtype); + + //Converting OpenCV Mat into VX Image + STATUS_ERROR_CHECK(CV_to_VX_Image(image_out, &bl)); + + return status; +} + +/************************************************************************************************************ +Function to Register the Kernel for Publish +*************************************************************************************************************/ +vx_status CV_multiply_Register(vx_context context) +{ + vx_status status = VX_SUCCESS; + vx_kernel kernel = vxAddKernel(context, + "org.opencv.multiply", + VX_KERNEL_EXT_CV_MULTIPLY, + CV_multiply_Kernel, + 5, + CV_multiply_InputValidator, + CV_multiply_OutputValidator, + nullptr, + nullptr); + + if (kernel) + { + PARAM_ERROR_CHECK(vxAddParameterToKernel(kernel, 0, VX_INPUT, VX_TYPE_IMAGE, VX_PARAMETER_STATE_REQUIRED)); + PARAM_ERROR_CHECK(vxAddParameterToKernel(kernel, 1, VX_INPUT, VX_TYPE_IMAGE, VX_PARAMETER_STATE_REQUIRED)); + PARAM_ERROR_CHECK(vxAddParameterToKernel(kernel, 2, VX_OUTPUT, VX_TYPE_IMAGE, VX_PARAMETER_STATE_REQUIRED)); + PARAM_ERROR_CHECK(vxAddParameterToKernel(kernel, 3, VX_INPUT, VX_TYPE_SCALAR, VX_PARAMETER_STATE_REQUIRED)); + PARAM_ERROR_CHECK(vxAddParameterToKernel(kernel, 4, VX_INPUT, VX_TYPE_SCALAR, VX_PARAMETER_STATE_REQUIRED)); + PARAM_ERROR_CHECK(vxFinalizeKernel(kernel)); + } + + if (status != VX_SUCCESS) + { + exit: vxRemoveKernel(kernel); return VX_FAILURE; + } + + return status; +} + + diff --git a/vx_ext_cv/OpenCV_norm.cpp b/vx_ext_cv/OpenCV_norm.cpp new file mode 100644 index 0000000..35d5eec --- /dev/null +++ b/vx_ext_cv/OpenCV_norm.cpp @@ -0,0 +1,153 @@ +/* +Copyright (c) 2015 Advanced Micro Devices, Inc. All rights reserved. + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. +*/ + + +#include"publishkernels.h" + +/************************************************************************************************************ +input parameter validator. +param [in] node The handle to the node. +param [in] index The index of the parameter to validate. +*************************************************************************************************************/ +static vx_status VX_CALLBACK CV_norm_InputValidator(vx_node node, vx_uint32 index) +{ + vx_status status = VX_SUCCESS; + vx_parameter param = vxGetParameterByIndex(node, index); + + if (index == 0) + { + vx_image image; + vx_df_image df_image = VX_DF_IMAGE_VIRT; + STATUS_ERROR_CHECK(vxQueryParameter(param, VX_PARAMETER_ATTRIBUTE_REF, &image, sizeof(vx_image))); + STATUS_ERROR_CHECK(vxQueryImage(image, VX_IMAGE_ATTRIBUTE_FORMAT, &df_image, sizeof(df_image))); + if (df_image != VX_DF_IMAGE_U8) + status = VX_ERROR_INVALID_VALUE; + vxReleaseImage(&image); + } + + else if (index == 1) + { + vx_scalar scalar = 0; vx_enum type = 0; vx_float32 value = 0; + STATUS_ERROR_CHECK(vxQueryParameter(param, VX_PARAMETER_ATTRIBUTE_REF, &scalar, sizeof(scalar))); + STATUS_ERROR_CHECK(vxQueryScalar(scalar, VX_SCALAR_ATTRIBUTE_TYPE, &type, sizeof(type))); + STATUS_ERROR_CHECK(vxReadScalarValue(scalar, &value)); + if (value < 0 || type != VX_TYPE_FLOAT32) + status = VX_ERROR_INVALID_VALUE; + vxReleaseScalar(&scalar); + } + + else if (index == 2) + { + vx_scalar scalar = 0; vx_enum type = 0; vx_int32 value = 0; + STATUS_ERROR_CHECK(vxQueryParameter(param, VX_PARAMETER_ATTRIBUTE_REF, &scalar, sizeof(scalar))); + STATUS_ERROR_CHECK(vxQueryScalar(scalar, VX_SCALAR_ATTRIBUTE_TYPE, &type, sizeof(type))); + STATUS_ERROR_CHECK(vxReadScalarValue(scalar, &value)); + if (value < 0 || type != VX_TYPE_INT32) + status = VX_ERROR_INVALID_VALUE; + vxReleaseScalar(&scalar); + } + + vxReleaseParameter(¶m); + return status; +} + +/************************************************************************************************************ +output parameter validator. +*************************************************************************************************************/ +static vx_status VX_CALLBACK CV_norm_OutputValidator(vx_node node, vx_uint32 index, vx_meta_format meta) +{ + vx_status status = VX_SUCCESS; + if (index == 1) + { + vx_parameter output_param = vxGetParameterByIndex(node, 1); + vx_scalar output; vx_scalar scalar = 0; vx_enum type = 0; vx_float32 value = 0; + + STATUS_ERROR_CHECK(vxQueryParameter(output_param, VX_PARAMETER_ATTRIBUTE_REF, &scalar, sizeof(scalar))); + STATUS_ERROR_CHECK(vxReadScalarValue(scalar, &value)); + + vxReleaseScalar(&output); + vxReleaseParameter(&output_param); + } + return status; +} + +/************************************************************************************************************ +Execution Kernel +*************************************************************************************************************/ +static vx_status VX_CALLBACK CV_norm_Kernel(vx_node node, const vx_reference *parameters, vx_uint32 num) +{ + vx_status status = VX_SUCCESS; + vx_image image_in = (vx_image) parameters[0]; + vx_scalar scalar = (vx_scalar) parameters[1]; + vx_scalar scalar1 = (vx_scalar) parameters[2]; + + Mat *mat; + int Type; + vx_int32 value = 0; + + //Extracting Values from the Scalar into Type + STATUS_ERROR_CHECK(vxReadScalarValue(scalar1, &value)); Type = value; + + //Converting VX Image to OpenCV Mat + STATUS_ERROR_CHECK(VX_to_CV_Image(&mat, image_in)); + + //Compute using OpenCV + float NORM_Val = 0; + NORM_Val = (float) norm(*mat, Type); + + //Converting int to Scalar + STATUS_ERROR_CHECK(vxWriteScalarValue(scalar, &NORM_Val)); + + return status; +} + +/************************************************************************************************************ +Function to Register the Kernel for Publish +*************************************************************************************************************/ +vx_status CV_norm_Register(vx_context context) +{ + vx_status status = VX_SUCCESS; + vx_kernel kernel = vxAddKernel(context, + "org.opencv.norm", + VX_KERNEL_EXT_CV_NORM, + CV_norm_Kernel, + 3, + CV_norm_InputValidator, + CV_norm_OutputValidator, + nullptr, + nullptr); + + if (kernel) + { + PARAM_ERROR_CHECK(vxAddParameterToKernel(kernel, 0, VX_INPUT, VX_TYPE_IMAGE, VX_PARAMETER_STATE_REQUIRED)); + PARAM_ERROR_CHECK(vxAddParameterToKernel(kernel, 1, VX_BIDIRECTIONAL, VX_TYPE_SCALAR, VX_PARAMETER_STATE_REQUIRED)); + PARAM_ERROR_CHECK(vxAddParameterToKernel(kernel, 2, VX_INPUT, VX_TYPE_SCALAR, VX_PARAMETER_STATE_REQUIRED)); + PARAM_ERROR_CHECK(vxFinalizeKernel(kernel)); + } + + if (status != VX_SUCCESS) + { + exit: vxRemoveKernel(kernel); return VX_FAILURE; + } + + return status; +} diff --git a/vx_ext_cv/OpenCV_orb_compute.cpp b/vx_ext_cv/OpenCV_orb_compute.cpp new file mode 100644 index 0000000..62934ec --- /dev/null +++ b/vx_ext_cv/OpenCV_orb_compute.cpp @@ -0,0 +1,283 @@ +/* +Copyright (c) 2015 Advanced Micro Devices, Inc. All rights reserved. + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. +*/ + + +#include"publishkernels.h" + +/*!*********************************************************************************************************** +input parameter validator. +param [in] node The handle to the node. +param [in] index The index of the parameter to validate. +*************************************************************************************************************/ +static vx_status VX_CALLBACK CV_orb_compute_InputValidator(vx_node node, vx_uint32 index) +{ + vx_status status = VX_SUCCESS ; + vx_parameter param = vxGetParameterByIndex(node, index); + + if (index == 0) + { + vx_image image; + vx_df_image df_image = VX_DF_IMAGE_VIRT; + STATUS_ERROR_CHECK(vxQueryParameter(param, VX_PARAMETER_ATTRIBUTE_REF, &image, sizeof(vx_image))); + STATUS_ERROR_CHECK(vxQueryImage(image, VX_IMAGE_ATTRIBUTE_FORMAT, &df_image, sizeof(df_image))); + if (df_image != VX_DF_IMAGE_U8) + status = VX_ERROR_INVALID_VALUE; + vxReleaseImage(&image); + } + + if (index == 1) + { + vx_image image; + vx_df_image df_image = VX_DF_IMAGE_VIRT; + STATUS_ERROR_CHECK(vxQueryParameter(param, VX_PARAMETER_ATTRIBUTE_REF, &image, sizeof(vx_image))); + STATUS_ERROR_CHECK(vxQueryImage(image, VX_IMAGE_ATTRIBUTE_FORMAT, &df_image, sizeof(df_image))); + if (df_image != VX_DF_IMAGE_U8) + status = VX_ERROR_INVALID_VALUE; + vxReleaseImage(&image); + } + + else if (index == 2) + { + vx_array array; vx_size size = 0; + STATUS_ERROR_CHECK(vxQueryParameter(param, VX_PARAMETER_ATTRIBUTE_REF, &array, sizeof(array))); + STATUS_ERROR_CHECK(vxQueryArray(array, VX_ARRAY_ATTRIBUTE_CAPACITY, &size, sizeof(size))); + vxReleaseArray(&array); + } + + else if (index == 3) + { + vx_array array; vx_size size = 0; + STATUS_ERROR_CHECK(vxQueryParameter(param, VX_PARAMETER_ATTRIBUTE_REF, &array, sizeof(array))); + STATUS_ERROR_CHECK(vxQueryArray(array, VX_ARRAY_ATTRIBUTE_CAPACITY, &size, sizeof(size))); + vxReleaseArray(&array); + } + + else if (index == 4) + { + vx_scalar scalar = 0; vx_enum type = 0; vx_int32 value = 0; + STATUS_ERROR_CHECK(vxQueryParameter(param, VX_PARAMETER_ATTRIBUTE_REF, &scalar, sizeof(scalar))); + STATUS_ERROR_CHECK(vxQueryScalar(scalar, VX_SCALAR_ATTRIBUTE_TYPE, &type, sizeof(type))); + STATUS_ERROR_CHECK(vxReadScalarValue(scalar, &value)); + if (value < 0 || type != VX_TYPE_INT32) + status = VX_ERROR_INVALID_VALUE; + vxReleaseScalar(&scalar); + } + + else if (index == 5) + { + vx_scalar scalar = 0; vx_enum type = 0; vx_float32 value = 0; + STATUS_ERROR_CHECK(vxQueryParameter(param, VX_PARAMETER_ATTRIBUTE_REF, &scalar, sizeof(scalar))); + STATUS_ERROR_CHECK(vxQueryScalar(scalar, VX_SCALAR_ATTRIBUTE_TYPE, &type, sizeof(type))); + STATUS_ERROR_CHECK(vxReadScalarValue(scalar, &value)); + if (value < 0 || type != VX_TYPE_FLOAT32) + status = VX_ERROR_INVALID_VALUE; + vxReleaseScalar(&scalar); + } + + else if (index == 6) + { + vx_scalar scalar = 0; vx_enum type = 0; vx_int32 value = 0; + STATUS_ERROR_CHECK(vxQueryParameter(param, VX_PARAMETER_ATTRIBUTE_REF, &scalar, sizeof(scalar))); + STATUS_ERROR_CHECK(vxQueryScalar(scalar, VX_SCALAR_ATTRIBUTE_TYPE, &type, sizeof(type))); + STATUS_ERROR_CHECK(vxReadScalarValue(scalar, &value)); + if (value < 0 || type != VX_TYPE_INT32) + status = VX_ERROR_INVALID_VALUE; + vxReleaseScalar(&scalar); + } + + else if (index == 7) + { + vx_scalar scalar = 0; vx_enum type = 0; vx_int32 value = 0; + STATUS_ERROR_CHECK(vxQueryParameter(param, VX_PARAMETER_ATTRIBUTE_REF, &scalar, sizeof(scalar))); + STATUS_ERROR_CHECK(vxQueryScalar(scalar, VX_SCALAR_ATTRIBUTE_TYPE, &type, sizeof(type))); + STATUS_ERROR_CHECK(vxReadScalarValue(scalar, &value)); + if (value < 0 || type != VX_TYPE_INT32) + status = VX_ERROR_INVALID_VALUE; + vxReleaseScalar(&scalar); + } + + else if (index == 8) + { + vx_scalar scalar = 0; vx_enum type = 0; vx_int32 value = 0; + STATUS_ERROR_CHECK(vxQueryParameter(param, VX_PARAMETER_ATTRIBUTE_REF, &scalar, sizeof(scalar))); + STATUS_ERROR_CHECK(vxQueryScalar(scalar, VX_SCALAR_ATTRIBUTE_TYPE, &type, sizeof(type))); + STATUS_ERROR_CHECK(vxReadScalarValue(scalar, &value)); + if (value != 0 || type != VX_TYPE_INT32) + status = VX_ERROR_INVALID_VALUE; + vxReleaseScalar(&scalar); + } + + else if (index == 9) + { + vx_scalar scalar = 0; vx_enum type = 0; vx_int32 value = 0; + STATUS_ERROR_CHECK(vxQueryParameter(param, VX_PARAMETER_ATTRIBUTE_REF, &scalar, sizeof(scalar))); + STATUS_ERROR_CHECK(vxQueryScalar(scalar, VX_SCALAR_ATTRIBUTE_TYPE, &type, sizeof(type))); + STATUS_ERROR_CHECK(vxReadScalarValue(scalar, &value)); + if ((value < 0 || value > 3) || type != VX_TYPE_INT32) + status = VX_ERROR_INVALID_VALUE; + vxReleaseScalar(&scalar); + } + + else if (index == 10) + { + vx_scalar scalar = 0; vx_enum type = 0; vx_int32 value = 0; + STATUS_ERROR_CHECK(vxQueryParameter(param, VX_PARAMETER_ATTRIBUTE_REF, &scalar, sizeof(scalar))); + STATUS_ERROR_CHECK(vxQueryScalar(scalar, VX_SCALAR_ATTRIBUTE_TYPE, &type, sizeof(type))); + STATUS_ERROR_CHECK(vxReadScalarValue(scalar, &value)); + if ((value != 0 && value != 1 )|| type != VX_TYPE_INT32) + status = VX_ERROR_INVALID_VALUE; + vxReleaseScalar(&scalar); + } + + else if (index == 11) + { + vx_scalar scalar = 0; vx_enum type = 0; vx_int32 value = 0; + STATUS_ERROR_CHECK(vxQueryParameter(param, VX_PARAMETER_ATTRIBUTE_REF, &scalar, sizeof(scalar))); + STATUS_ERROR_CHECK(vxQueryScalar(scalar, VX_SCALAR_ATTRIBUTE_TYPE, &type, sizeof(type))); + STATUS_ERROR_CHECK(vxReadScalarValue(scalar, &value)); + if (value < 0 || type != VX_TYPE_INT32) + status = VX_ERROR_INVALID_VALUE; + vxReleaseScalar(&scalar); + } + + vxReleaseParameter(¶m); + return status; +} + +/*!*********************************************************************************************************** +output parameter validator. +*************************************************************************************************************/ +static vx_status VX_CALLBACK CV_orb_compute_OutputValidator(vx_node node, vx_uint32 index, vx_meta_format meta) +{ + vx_status status = VX_SUCCESS ; + if (index == 2) + { + vx_parameter output_param = vxGetParameterByIndex(node, 2); + vx_array output; vx_size size = 0; + + STATUS_ERROR_CHECK(vxQueryParameter(output_param, VX_PARAMETER_ATTRIBUTE_REF, &output, sizeof(vx_array))); + STATUS_ERROR_CHECK(vxQueryArray(output, VX_ARRAY_ATTRIBUTE_CAPACITY, &size, sizeof(size))); + + if (size <= 0) + status = VX_ERROR_INVALID_VALUE; + + vxReleaseArray(&output); + vxReleaseParameter(&output_param); + } + + return status; +} + +/*!*********************************************************************************************************** +Execution Kernel +*************************************************************************************************************/ +static vx_status VX_CALLBACK CV_orb_compute_Kernel(vx_node node, const vx_reference *parameters, vx_uint32 num) +{ + + vx_status status = VX_SUCCESS; + + vx_image image_in = (vx_image) parameters[0]; + vx_image mask = (vx_image) parameters[1]; + vx_array array = (vx_array) parameters[2]; + vx_array DESP = (vx_array) parameters[3]; + vx_scalar NFEATURES = (vx_scalar) parameters[4]; + vx_scalar SCALEFAC = (vx_scalar) parameters[5]; + vx_scalar NLEVELS = (vx_scalar) parameters[6]; + vx_scalar EDGETHRES = (vx_scalar) parameters[7]; + vx_scalar FIRSTLEVEL = (vx_scalar) parameters[8]; + vx_scalar WTA_k = (vx_scalar) parameters[9]; + vx_scalar SCORETYPE = (vx_scalar) parameters[10]; + vx_scalar PATCHSIZE = (vx_scalar) parameters[11]; + + Mat *mat, *mask_mat, Img; + int nFeatures, nLevels, edgeThreshold, firstLevel, WTA_K, scoreType, patchSize; + float ScaleFactor; + vector key_points; + Mat Desp; + vx_int32 value = 0; + vx_float32 value_F = 0; + + //Extracting Values from the Scalar + STATUS_ERROR_CHECK(vxReadScalarValue(NFEATURES, &value));nFeatures = value; + STATUS_ERROR_CHECK(vxReadScalarValue(SCALEFAC, &value_F));ScaleFactor = value_F; + STATUS_ERROR_CHECK(vxReadScalarValue(NLEVELS, &value));nLevels = value; + STATUS_ERROR_CHECK(vxReadScalarValue(EDGETHRES, &value));edgeThreshold = value; + STATUS_ERROR_CHECK(vxReadScalarValue(FIRSTLEVEL, &value));firstLevel = value; + STATUS_ERROR_CHECK(vxReadScalarValue(WTA_k, &value));WTA_K = value; + STATUS_ERROR_CHECK(vxReadScalarValue(SCORETYPE, &value));scoreType = value; + STATUS_ERROR_CHECK(vxReadScalarValue(PATCHSIZE, &value));patchSize = value; + + //Converting VX Image to OpenCV Mat + STATUS_ERROR_CHECK(VX_to_CV_Image(&mat, image_in)); + STATUS_ERROR_CHECK(VX_to_CV_Image(&mask_mat, mask)); + + //Compute using OpenCV + Ptr orb = ORB::create(nFeatures, ScaleFactor, nLevels, edgeThreshold, firstLevel, WTA_K, scoreType, patchSize); + orb->detectAndCompute(*mat, *mask_mat, key_points, Desp); + + //Converting OpenCV Keypoints to OpenVX Keypoints + STATUS_ERROR_CHECK(CV_to_VX_keypoints(key_points, array)); + STATUS_ERROR_CHECK(CV_DESP_to_VX_DESP(Desp, DESP, 32));//32 bit Desp supported in this release + + return status; +} + +/************************************************************************************************************ +Function to Register the Kernel for Publish +*************************************************************************************************************/ +vx_status CV_ORB_compute_Register(vx_context context) +{ + vx_status status = VX_SUCCESS; + vx_kernel Kernel = vxAddKernel(context, + "org.opencv.orb_compute", + VX_KERNEL_EXT_CV_ORB_COMPUTE, + CV_orb_compute_Kernel, + 12, + CV_orb_compute_InputValidator, + CV_orb_compute_OutputValidator, + nullptr, + nullptr); + + if (Kernel) + { + PARAM_ERROR_CHECK(vxAddParameterToKernel(Kernel, 0, VX_INPUT, VX_TYPE_IMAGE, VX_PARAMETER_STATE_REQUIRED)); + PARAM_ERROR_CHECK(vxAddParameterToKernel(Kernel, 1, VX_INPUT, VX_TYPE_IMAGE, VX_PARAMETER_STATE_REQUIRED)); + PARAM_ERROR_CHECK(vxAddParameterToKernel(Kernel, 2, VX_BIDIRECTIONAL, VX_TYPE_ARRAY, VX_PARAMETER_STATE_REQUIRED)); + PARAM_ERROR_CHECK(vxAddParameterToKernel(Kernel, 3, VX_BIDIRECTIONAL, VX_TYPE_ARRAY, VX_PARAMETER_STATE_REQUIRED)); + PARAM_ERROR_CHECK(vxAddParameterToKernel(Kernel, 4, VX_INPUT, VX_TYPE_SCALAR, VX_PARAMETER_STATE_REQUIRED)); + PARAM_ERROR_CHECK(vxAddParameterToKernel(Kernel, 5, VX_INPUT, VX_TYPE_SCALAR, VX_PARAMETER_STATE_REQUIRED)); + PARAM_ERROR_CHECK(vxAddParameterToKernel(Kernel, 6, VX_INPUT, VX_TYPE_SCALAR, VX_PARAMETER_STATE_REQUIRED)); + PARAM_ERROR_CHECK(vxAddParameterToKernel(Kernel, 7, VX_INPUT, VX_TYPE_SCALAR, VX_PARAMETER_STATE_REQUIRED)); + PARAM_ERROR_CHECK(vxAddParameterToKernel(Kernel, 8, VX_INPUT, VX_TYPE_SCALAR, VX_PARAMETER_STATE_REQUIRED)); + PARAM_ERROR_CHECK(vxAddParameterToKernel(Kernel, 9, VX_INPUT, VX_TYPE_SCALAR, VX_PARAMETER_STATE_REQUIRED)); + PARAM_ERROR_CHECK(vxAddParameterToKernel(Kernel, 10, VX_INPUT, VX_TYPE_SCALAR, VX_PARAMETER_STATE_REQUIRED)); + PARAM_ERROR_CHECK(vxAddParameterToKernel(Kernel, 11, VX_INPUT, VX_TYPE_SCALAR, VX_PARAMETER_STATE_REQUIRED)); + PARAM_ERROR_CHECK(vxFinalizeKernel(Kernel)); + } + + if (status != VX_SUCCESS) + { + exit: vxRemoveKernel(Kernel); return VX_FAILURE; + } + + return status; +} \ No newline at end of file diff --git a/vx_ext_cv/OpenCV_pyrdown.cpp b/vx_ext_cv/OpenCV_pyrdown.cpp new file mode 100644 index 0000000..20d2fbb --- /dev/null +++ b/vx_ext_cv/OpenCV_pyrdown.cpp @@ -0,0 +1,191 @@ +/* +Copyright (c) 2015 Advanced Micro Devices, Inc. All rights reserved. + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. +*/ + + +#include"publishkernels.h" + +/************************************************************************************************************ +input parameter validator. +param [in] node The handle to the node. +param [in] index The index of the parameter to validate. +*************************************************************************************************************/ +static vx_status VX_CALLBACK CV_pyrdown_InputValidator(vx_node node, vx_uint32 index) +{ + vx_status status = VX_SUCCESS; + vx_parameter param = vxGetParameterByIndex(node, index); + + if (index == 0) + { + vx_image image; + vx_df_image df_image = VX_DF_IMAGE_VIRT; + STATUS_ERROR_CHECK(vxQueryParameter(param, VX_PARAMETER_ATTRIBUTE_REF, &image, sizeof(vx_image))); + STATUS_ERROR_CHECK(vxQueryImage(image, VX_IMAGE_ATTRIBUTE_FORMAT, &df_image, sizeof(df_image))); + if (df_image != VX_DF_IMAGE_U8) + status = VX_ERROR_INVALID_VALUE; + vxReleaseImage(&image); + } + + else if (index == 1) + { + vx_image image; + vx_df_image df_image = VX_DF_IMAGE_VIRT; + STATUS_ERROR_CHECK(vxQueryParameter(param, VX_PARAMETER_ATTRIBUTE_REF, &image, sizeof(vx_image))); + STATUS_ERROR_CHECK(vxQueryImage(image, VX_IMAGE_ATTRIBUTE_FORMAT, &df_image, sizeof(df_image))); + if (df_image != VX_DF_IMAGE_U8) + status = VX_ERROR_INVALID_VALUE; + vxReleaseImage(&image); + } + + else if (index == 2) + { + vx_scalar scalar = 0; vx_enum type = 0; vx_int32 value = 0; + STATUS_ERROR_CHECK(vxQueryParameter(param, VX_PARAMETER_ATTRIBUTE_REF, &scalar, sizeof(scalar))); + STATUS_ERROR_CHECK(vxQueryScalar(scalar, VX_SCALAR_ATTRIBUTE_TYPE, &type, sizeof(type))); + STATUS_ERROR_CHECK(vxReadScalarValue(scalar, &value)); + if (value < 0 || type != VX_TYPE_INT32) + status = VX_ERROR_INVALID_VALUE; + vxReleaseScalar(&scalar); + } + + else if (index == 3) + { + vx_scalar scalar = 0; vx_enum type = 0; vx_int32 value = 0; + STATUS_ERROR_CHECK(vxQueryParameter(param, VX_PARAMETER_ATTRIBUTE_REF, &scalar, sizeof(scalar))); + STATUS_ERROR_CHECK(vxQueryScalar(scalar, VX_SCALAR_ATTRIBUTE_TYPE, &type, sizeof(type))); + STATUS_ERROR_CHECK(vxReadScalarValue(scalar, &value)); + if (value < 0 || type != VX_TYPE_INT32) + status = VX_ERROR_INVALID_VALUE; + vxReleaseScalar(&scalar); + } + + else if (index == 4) + { + vx_scalar scalar = 0; vx_enum type = 0; vx_int32 value = 0; + STATUS_ERROR_CHECK(vxQueryParameter(param, VX_PARAMETER_ATTRIBUTE_REF, &scalar, sizeof(scalar))); + STATUS_ERROR_CHECK(vxQueryScalar(scalar, VX_SCALAR_ATTRIBUTE_TYPE, &type, sizeof(type))); + STATUS_ERROR_CHECK(vxReadScalarValue(scalar, &value)); + if (value < 0 || type != VX_TYPE_INT32) + status = VX_ERROR_INVALID_VALUE; + vxReleaseScalar(&scalar); + } + + vxReleaseParameter(¶m); + return status; +} + +/************************************************************************************************************ +output parameter validator. +*************************************************************************************************************/ +static vx_status VX_CALLBACK CV_pyrdown_OutputValidator(vx_node node, vx_uint32 index, vx_meta_format meta) +{ + vx_status status = VX_SUCCESS; + if (index == 1) + { + vx_parameter output_param = vxGetParameterByIndex(node, 1); + vx_image output; vx_uint32 width = 0, height = 0; vx_df_image format = VX_DF_IMAGE_VIRT; + + STATUS_ERROR_CHECK(vxQueryParameter(output_param, VX_PARAMETER_ATTRIBUTE_REF, &output, sizeof(vx_image))); + STATUS_ERROR_CHECK(vxQueryImage(output, VX_IMAGE_ATTRIBUTE_FORMAT, &format, sizeof(format))); + STATUS_ERROR_CHECK(vxQueryImage(output, VX_IMAGE_ATTRIBUTE_WIDTH, &width, sizeof(width))); + STATUS_ERROR_CHECK(vxQueryImage(output, VX_IMAGE_ATTRIBUTE_HEIGHT, &height, sizeof(height))); + + if (format != VX_DF_IMAGE_U8) + status = VX_ERROR_INVALID_VALUE; + + STATUS_ERROR_CHECK(vxSetMetaFormatAttribute(meta, VX_IMAGE_ATTRIBUTE_WIDTH, &width, sizeof(width))); + STATUS_ERROR_CHECK(vxSetMetaFormatAttribute(meta, VX_IMAGE_ATTRIBUTE_HEIGHT, &height, sizeof(height))); + STATUS_ERROR_CHECK(vxSetMetaFormatAttribute(meta, VX_IMAGE_ATTRIBUTE_FORMAT, &format, sizeof(format))); + + vxReleaseImage(&output); + vxReleaseParameter(&output_param); + } + return status; +} + +/************************************************************************************************************ +Execution Kernel +*************************************************************************************************************/ +static vx_status VX_CALLBACK CV_pyrdown_Kernel(vx_node node, const vx_reference *parameters, vx_uint32 num) +{ + vx_status status = VX_SUCCESS; + + vx_image image_in = (vx_image) parameters[0]; + vx_image image_out = (vx_image) parameters[1]; + vx_scalar S_width = (vx_scalar) parameters[2]; + vx_scalar S_height = (vx_scalar) parameters[3]; + vx_scalar BORDER = (vx_scalar) parameters[4]; + + Mat *mat; + int W, H, border; + vx_int32 value = 0; + + //Extracting Values from the Scalar into Ksize and Ddepth + STATUS_ERROR_CHECK(vxReadScalarValue(S_width, &value)); W = value; + STATUS_ERROR_CHECK(vxReadScalarValue(S_height, &value)); H = value; + STATUS_ERROR_CHECK(vxReadScalarValue(BORDER, &value)); border = value; + + //Converting VX Image to OpenCV Mat + STATUS_ERROR_CHECK(VX_to_CV_Image(&mat, image_in)); + + //Compute using OpenCV + Mat bl(Size(W, H), CV_8U);//only CV_8U supported in this release + cv::pyrDown(*mat, bl, Size(W, H), border); + + //Converting OpenCV Mat into VX Image + STATUS_ERROR_CHECK(CV_to_VX_Image(image_out, &bl)); + + return status; +} + +/************************************************************************************************************ +Function to Register the Kernel for Publish +*************************************************************************************************************/ +vx_status CV_pyrdown_Register(vx_context context) +{ + vx_status status = VX_SUCCESS; + vx_kernel Kernel = vxAddKernel(context, + "org.opencv.pyrdown", + VX_KERNEL_EXT_CV_PYRDOWN, + CV_pyrdown_Kernel, + 5, + CV_pyrdown_InputValidator, + CV_pyrdown_OutputValidator, + nullptr, + nullptr); + + if (Kernel) + { + PARAM_ERROR_CHECK(vxAddParameterToKernel(Kernel, 0, VX_INPUT, VX_TYPE_IMAGE, VX_PARAMETER_STATE_REQUIRED)); + PARAM_ERROR_CHECK(vxAddParameterToKernel(Kernel, 1, VX_OUTPUT, VX_TYPE_IMAGE, VX_PARAMETER_STATE_REQUIRED)); + PARAM_ERROR_CHECK(vxAddParameterToKernel(Kernel, 2, VX_INPUT, VX_TYPE_SCALAR, VX_PARAMETER_STATE_REQUIRED)); + PARAM_ERROR_CHECK(vxAddParameterToKernel(Kernel, 3, VX_INPUT, VX_TYPE_SCALAR, VX_PARAMETER_STATE_REQUIRED)); + PARAM_ERROR_CHECK(vxAddParameterToKernel(Kernel, 4, VX_INPUT, VX_TYPE_SCALAR, VX_PARAMETER_STATE_REQUIRED)); + PARAM_ERROR_CHECK(vxFinalizeKernel(Kernel)); + } + + if (status != VX_SUCCESS) + { + exit: vxRemoveKernel(Kernel); return VX_FAILURE; + } + + return status; +} \ No newline at end of file diff --git a/vx_ext_cv/OpenCV_pyrup.cpp b/vx_ext_cv/OpenCV_pyrup.cpp new file mode 100644 index 0000000..e406fdc --- /dev/null +++ b/vx_ext_cv/OpenCV_pyrup.cpp @@ -0,0 +1,191 @@ +/* +Copyright (c) 2015 Advanced Micro Devices, Inc. All rights reserved. + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. +*/ + + +#include"publishkernels.h" + +/************************************************************************************************************ +input parameter validator. +param [in] node The handle to the node. +param [in] index The index of the parameter to validate. +*************************************************************************************************************/ +static vx_status VX_CALLBACK CV_pyrup_InputValidator(vx_node node, vx_uint32 index) +{ + vx_status status = VX_SUCCESS; + vx_parameter param = vxGetParameterByIndex(node, index); + + if (index == 0) + { + vx_image image; + vx_df_image df_image = VX_DF_IMAGE_VIRT; + STATUS_ERROR_CHECK(vxQueryParameter(param, VX_PARAMETER_ATTRIBUTE_REF, &image, sizeof(vx_image))); + STATUS_ERROR_CHECK(vxQueryImage(image, VX_IMAGE_ATTRIBUTE_FORMAT, &df_image, sizeof(df_image))); + if (df_image != VX_DF_IMAGE_U8) + status = VX_ERROR_INVALID_VALUE; + vxReleaseImage(&image); + } + + else if (index == 1) + { + vx_image image; + vx_df_image df_image = VX_DF_IMAGE_VIRT; + STATUS_ERROR_CHECK(vxQueryParameter(param, VX_PARAMETER_ATTRIBUTE_REF, &image, sizeof(vx_image))); + STATUS_ERROR_CHECK(vxQueryImage(image, VX_IMAGE_ATTRIBUTE_FORMAT, &df_image, sizeof(df_image))); + if (df_image != VX_DF_IMAGE_U8) + status = VX_ERROR_INVALID_VALUE; + vxReleaseImage(&image); + } + + else if (index == 2) + { + vx_scalar scalar = 0; vx_enum type = 0; vx_int32 value = 0; + STATUS_ERROR_CHECK(vxQueryParameter(param, VX_PARAMETER_ATTRIBUTE_REF, &scalar, sizeof(scalar))); + STATUS_ERROR_CHECK(vxQueryScalar(scalar, VX_SCALAR_ATTRIBUTE_TYPE, &type, sizeof(type))); + STATUS_ERROR_CHECK(vxReadScalarValue(scalar, &value)); + if (value < 0 || type != VX_TYPE_INT32) + status = VX_ERROR_INVALID_VALUE; + vxReleaseScalar(&scalar); + } + + else if (index == 3) + { + vx_scalar scalar = 0; vx_enum type = 0; vx_int32 value = 0; + STATUS_ERROR_CHECK(vxQueryParameter(param, VX_PARAMETER_ATTRIBUTE_REF, &scalar, sizeof(scalar))); + STATUS_ERROR_CHECK(vxQueryScalar(scalar, VX_SCALAR_ATTRIBUTE_TYPE, &type, sizeof(type))); + STATUS_ERROR_CHECK(vxReadScalarValue(scalar, &value)); + if (value < 0 || type != VX_TYPE_INT32) + status = VX_ERROR_INVALID_VALUE; + vxReleaseScalar(&scalar); + } + + else if (index == 4) + { + vx_scalar scalar = 0; vx_enum type = 0; vx_int32 value = 0; + STATUS_ERROR_CHECK(vxQueryParameter(param, VX_PARAMETER_ATTRIBUTE_REF, &scalar, sizeof(scalar))); + STATUS_ERROR_CHECK(vxQueryScalar(scalar, VX_SCALAR_ATTRIBUTE_TYPE, &type, sizeof(type))); + STATUS_ERROR_CHECK(vxReadScalarValue(scalar, &value)); + if (value < 0 || type != VX_TYPE_INT32) + status = VX_ERROR_INVALID_VALUE; + vxReleaseScalar(&scalar); + } + + vxReleaseParameter(¶m); + return status; +} + +/************************************************************************************************************ +output parameter validator. +*************************************************************************************************************/ +static vx_status VX_CALLBACK CV_pyrup_OutputValidator(vx_node node, vx_uint32 index, vx_meta_format meta) +{ + vx_status status = VX_SUCCESS; + if (index == 1) + { + vx_parameter output_param = vxGetParameterByIndex(node, 1); + vx_image output; vx_uint32 width = 0, height = 0; vx_df_image format = VX_DF_IMAGE_VIRT; + + STATUS_ERROR_CHECK(vxQueryParameter(output_param, VX_PARAMETER_ATTRIBUTE_REF, &output, sizeof(vx_image))); + STATUS_ERROR_CHECK(vxQueryImage(output, VX_IMAGE_ATTRIBUTE_FORMAT, &format, sizeof(format))); + STATUS_ERROR_CHECK(vxQueryImage(output, VX_IMAGE_ATTRIBUTE_WIDTH, &width, sizeof(width))); + STATUS_ERROR_CHECK(vxQueryImage(output, VX_IMAGE_ATTRIBUTE_HEIGHT, &height, sizeof(height))); + + if (format != VX_DF_IMAGE_U8) + status = VX_ERROR_INVALID_VALUE; + + STATUS_ERROR_CHECK(vxSetMetaFormatAttribute(meta, VX_IMAGE_ATTRIBUTE_WIDTH, &width, sizeof(width))); + STATUS_ERROR_CHECK(vxSetMetaFormatAttribute(meta, VX_IMAGE_ATTRIBUTE_HEIGHT, &height, sizeof(height))); + STATUS_ERROR_CHECK(vxSetMetaFormatAttribute(meta, VX_IMAGE_ATTRIBUTE_FORMAT, &format, sizeof(format))); + + vxReleaseImage(&output); + vxReleaseParameter(&output_param); + } + return status; +} + +/************************************************************************************************************ +Execution Kernel +*************************************************************************************************************/ +static vx_status VX_CALLBACK CV_pyrup_Kernel(vx_node node, const vx_reference *parameters, vx_uint32 num) +{ + vx_status status = VX_SUCCESS; + + vx_image image_in = (vx_image) parameters[0]; + vx_image image_out = (vx_image) parameters[1]; + vx_scalar S_width = (vx_scalar) parameters[2]; + vx_scalar S_height = (vx_scalar) parameters[3]; + vx_scalar BORDER = (vx_scalar) parameters[4]; + + Mat *mat; + int W, H, border; + vx_int32 value = 0; + + //Extracting Values from the Scalar into Ksize and Ddepth + STATUS_ERROR_CHECK(vxReadScalarValue(S_width, &value)); W = value; + STATUS_ERROR_CHECK(vxReadScalarValue(S_height, &value)); H = value; + STATUS_ERROR_CHECK(vxReadScalarValue(BORDER, &value)); border = value; + + //Converting VX Image to OpenCV Mat + STATUS_ERROR_CHECK(VX_to_CV_Image(&mat, image_in)); + + //Compute using OpenCV + Mat bl(Size(W, H), CV_8U);//Only CV_8U supported in this release + cv::pyrUp(*mat, bl, Size(W, H), border); + + //Converting OpenCV Mat into VX Image + STATUS_ERROR_CHECK(CV_to_VX_Image(image_out, &bl)); + + return status; +} + +/************************************************************************************************************ +Function to Register the Kernel for Publish +*************************************************************************************************************/ +vx_status CV_pyrup_Register(vx_context context) +{ + vx_status status = VX_SUCCESS; + vx_kernel Kernel = vxAddKernel(context, + "org.opencv.pyrup", + VX_KERNEL_EXT_CV_PYRUP, + CV_pyrup_Kernel, + 5, + CV_pyrup_InputValidator, + CV_pyrup_OutputValidator, + nullptr, + nullptr); + + if (Kernel) + { + PARAM_ERROR_CHECK(vxAddParameterToKernel(Kernel, 0, VX_INPUT, VX_TYPE_IMAGE, VX_PARAMETER_STATE_REQUIRED)); + PARAM_ERROR_CHECK(vxAddParameterToKernel(Kernel, 1, VX_OUTPUT, VX_TYPE_IMAGE, VX_PARAMETER_STATE_REQUIRED)); + PARAM_ERROR_CHECK(vxAddParameterToKernel(Kernel, 2, VX_INPUT, VX_TYPE_SCALAR, VX_PARAMETER_STATE_REQUIRED)); + PARAM_ERROR_CHECK(vxAddParameterToKernel(Kernel, 3, VX_INPUT, VX_TYPE_SCALAR, VX_PARAMETER_STATE_REQUIRED)); + PARAM_ERROR_CHECK(vxAddParameterToKernel(Kernel, 4, VX_INPUT, VX_TYPE_SCALAR, VX_PARAMETER_STATE_REQUIRED)); + PARAM_ERROR_CHECK(vxFinalizeKernel(Kernel)); + } + + if (status != VX_SUCCESS) + { + exit: vxRemoveKernel(Kernel); return VX_FAILURE; + } + + return status; +} \ No newline at end of file diff --git a/vx_ext_cv/OpenCV_resize.cpp b/vx_ext_cv/OpenCV_resize.cpp new file mode 100644 index 0000000..4514391 --- /dev/null +++ b/vx_ext_cv/OpenCV_resize.cpp @@ -0,0 +1,228 @@ +/* +Copyright (c) 2015 Advanced Micro Devices, Inc. All rights reserved. + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. +*/ + + +#include"publishkernels.h" + +/************************************************************************************************************ +input parameter validator. +param [in] node The handle to the node. +param [in] index The index of the parameter to validate. +*************************************************************************************************************/ +static vx_status VX_CALLBACK CV_resize_InputValidator(vx_node node, vx_uint32 index) +{ + vx_status status = VX_SUCCESS; + vx_parameter param = vxGetParameterByIndex(node, index); + + if (index == 0) + { + vx_image image; + vx_df_image df_image = VX_DF_IMAGE_VIRT; + STATUS_ERROR_CHECK(vxQueryParameter(param, VX_PARAMETER_ATTRIBUTE_REF, &image, sizeof(vx_image))); + STATUS_ERROR_CHECK(vxQueryImage(image, VX_IMAGE_ATTRIBUTE_FORMAT, &df_image, sizeof(df_image))); + if (df_image != VX_DF_IMAGE_U8 && df_image != VX_DF_IMAGE_U16 && df_image != VX_DF_IMAGE_S16) + status = VX_ERROR_INVALID_VALUE; + vxReleaseImage(&image); + } + + else if (index == 1) + { + vx_image image; + vx_df_image df_image = VX_DF_IMAGE_VIRT; + STATUS_ERROR_CHECK(vxQueryParameter(param, VX_PARAMETER_ATTRIBUTE_REF, &image, sizeof(vx_image))); + STATUS_ERROR_CHECK(vxQueryImage(image, VX_IMAGE_ATTRIBUTE_FORMAT, &df_image, sizeof(df_image))); + if (df_image != VX_DF_IMAGE_U8) + status = VX_ERROR_INVALID_VALUE; + vxReleaseImage(&image); + } + + else if (index == 2) + { + vx_scalar scalar = 0; vx_enum type = 0; vx_int32 value = 0; + STATUS_ERROR_CHECK(vxQueryParameter(param, VX_PARAMETER_ATTRIBUTE_REF, &scalar, sizeof(scalar))); + STATUS_ERROR_CHECK(vxQueryScalar(scalar, VX_SCALAR_ATTRIBUTE_TYPE, &type, sizeof(type))); + STATUS_ERROR_CHECK(vxReadScalarValue(scalar, &value)); + if (value < 0 || type != VX_TYPE_INT32) + status = VX_ERROR_INVALID_VALUE; + vxReleaseScalar(&scalar); + } + + else if (index == 3) + { + vx_scalar scalar = 0; vx_enum type = 0; vx_int32 value = 0; + STATUS_ERROR_CHECK(vxQueryParameter(param, VX_PARAMETER_ATTRIBUTE_REF, &scalar, sizeof(scalar))); + STATUS_ERROR_CHECK(vxQueryScalar(scalar, VX_SCALAR_ATTRIBUTE_TYPE, &type, sizeof(type))); + STATUS_ERROR_CHECK(vxReadScalarValue(scalar, &value)); + if (value < 0 || type != VX_TYPE_INT32) + status = VX_ERROR_INVALID_VALUE; + vxReleaseScalar(&scalar); + } + + else if (index == 4) + { + vx_scalar scalar = 0; vx_enum type = 0; vx_float32 value = 0; + STATUS_ERROR_CHECK(vxQueryParameter(param, VX_PARAMETER_ATTRIBUTE_REF, &scalar, sizeof(scalar))); + STATUS_ERROR_CHECK(vxQueryScalar(scalar, VX_SCALAR_ATTRIBUTE_TYPE, &type, sizeof(type))); + STATUS_ERROR_CHECK(vxReadScalarValue(scalar, &value)); + if (value < 0 || type != VX_TYPE_FLOAT32) + status = VX_ERROR_INVALID_VALUE; + vxReleaseScalar(&scalar); + } + + else if (index == 5) + { + vx_scalar scalar = 0; vx_enum type = 0; vx_float32 value = 0; + STATUS_ERROR_CHECK(vxQueryParameter(param, VX_PARAMETER_ATTRIBUTE_REF, &scalar, sizeof(scalar))); + STATUS_ERROR_CHECK(vxQueryScalar(scalar, VX_SCALAR_ATTRIBUTE_TYPE, &type, sizeof(type))); + STATUS_ERROR_CHECK(vxReadScalarValue(scalar, &value)); + if (value < 0 || type != VX_TYPE_FLOAT32) + status = VX_ERROR_INVALID_VALUE; + vxReleaseScalar(&scalar); + } + + else if (index == 6) + { + vx_scalar scalar = 0; vx_enum type = 0; vx_int32 value = 0; + STATUS_ERROR_CHECK(vxQueryParameter(param, VX_PARAMETER_ATTRIBUTE_REF, &scalar, sizeof(scalar))); + STATUS_ERROR_CHECK(vxQueryScalar(scalar, VX_SCALAR_ATTRIBUTE_TYPE, &type, sizeof(type))); + STATUS_ERROR_CHECK(vxReadScalarValue(scalar, &value)); + if ((value < 0 || value > 4) || type != VX_TYPE_INT32) + status = VX_ERROR_INVALID_VALUE; + vxReleaseScalar(&scalar); + } + + vxReleaseParameter(¶m); + return status; +} + +/************************************************************************************************************ +output parameter validator. +*************************************************************************************************************/ +static vx_status VX_CALLBACK CV_resize_OutputValidator(vx_node node, vx_uint32 index, vx_meta_format meta) +{ + vx_status status = VX_SUCCESS; + if (index == 1) + { + vx_parameter output_param = vxGetParameterByIndex(node, 1); + vx_image output; vx_uint32 width = 0, height = 0; vx_df_image format = VX_DF_IMAGE_VIRT; + + STATUS_ERROR_CHECK(vxQueryParameter(output_param, VX_PARAMETER_ATTRIBUTE_REF, &output, sizeof(vx_image))); + STATUS_ERROR_CHECK(vxQueryImage(output, VX_IMAGE_ATTRIBUTE_FORMAT, &format, sizeof(format))); + STATUS_ERROR_CHECK(vxQueryImage(output, VX_IMAGE_ATTRIBUTE_WIDTH, &width, sizeof(width))); + STATUS_ERROR_CHECK(vxQueryImage(output, VX_IMAGE_ATTRIBUTE_HEIGHT, &height, sizeof(height))); + + if (format != VX_DF_IMAGE_U8) + status = VX_ERROR_INVALID_VALUE; + + STATUS_ERROR_CHECK(vxSetMetaFormatAttribute(meta, VX_IMAGE_ATTRIBUTE_WIDTH, &width, sizeof(width))); + STATUS_ERROR_CHECK(vxSetMetaFormatAttribute(meta, VX_IMAGE_ATTRIBUTE_HEIGHT, &height, sizeof(height))); + STATUS_ERROR_CHECK(vxSetMetaFormatAttribute(meta, VX_IMAGE_ATTRIBUTE_FORMAT, &format, sizeof(format))); + + vxReleaseImage(&output); + vxReleaseParameter(&output_param); + } + return status; +} + +/************************************************************************************************************ +Execution Kernel +*************************************************************************************************************/ +static vx_status VX_CALLBACK CV_resize_Kernel(vx_node node, const vx_reference *parameters, vx_uint32 num) +{ + vx_status status = VX_SUCCESS; + + vx_image image_in = (vx_image) parameters[0]; + vx_image image_out = (vx_image) parameters[1]; + vx_scalar A_X = (vx_scalar) parameters[2]; + vx_scalar A_Y = (vx_scalar) parameters[3]; + vx_scalar FX = (vx_scalar) parameters[4]; + vx_scalar FY = (vx_scalar) parameters[5]; + vx_scalar INTER = (vx_scalar) parameters[6]; + + Mat *mat, bl; + int interpolation; + int a_x = -1, a_y = -1; + float fx = 0, fy = 0; + vx_int32 value = 0; + vx_float32 value_f = 0; + + //Extracting Values from the Scalar into Ksize and Ddepth + STATUS_ERROR_CHECK(vxReadScalarValue(A_X, &value)); a_x = value; + STATUS_ERROR_CHECK(vxReadScalarValue(A_Y, &value)); a_y = value; + STATUS_ERROR_CHECK(vxReadScalarValue(FX, &value_f)); fx = value_f; + STATUS_ERROR_CHECK(vxReadScalarValue(FY, &value_f)); fy = value_f; + STATUS_ERROR_CHECK(vxReadScalarValue(INTER, &value)); interpolation = value; + + //Validation + vx_uint32 width_out = 0; + vx_uint32 height_out = 0; + STATUS_ERROR_CHECK(vxQueryImage(image_out, VX_IMAGE_ATTRIBUTE_WIDTH, &width_out, sizeof(width_out))); + STATUS_ERROR_CHECK(vxQueryImage(image_out, VX_IMAGE_ATTRIBUTE_HEIGHT, &height_out, sizeof(height_out))); + if (a_x != width_out || a_y != height_out) { status = VX_ERROR_INVALID_DIMENSION; return status; } + + //Converting VX Image to OpenCV Mat + STATUS_ERROR_CHECK(VX_to_CV_Image(&mat, image_in)); + + //Compute using OpenCV + cv::resize(*mat, bl, Size(a_x, a_y), fx, fy, interpolation); + + //Converting OpenCV Mat into VX Image + STATUS_ERROR_CHECK(CV_to_VX_Image(image_out, &bl)); + + return status; +} + +/************************************************************************************************************ +Function to Register the Kernel for Publish +*************************************************************************************************************/ +vx_status CV_resize_Register(vx_context context) +{ + vx_status status = VX_SUCCESS; + vx_kernel Kernel = vxAddKernel(context, + "org.opencv.resize", + VX_KERNEL_EXT_CV_RESIZE, + CV_resize_Kernel, + 7, + CV_resize_InputValidator, + CV_resize_OutputValidator, + nullptr, + nullptr); + + if (Kernel) + { + PARAM_ERROR_CHECK(vxAddParameterToKernel(Kernel, 0, VX_INPUT, VX_TYPE_IMAGE, VX_PARAMETER_STATE_REQUIRED)); + PARAM_ERROR_CHECK(vxAddParameterToKernel(Kernel, 1, VX_OUTPUT, VX_TYPE_IMAGE, VX_PARAMETER_STATE_REQUIRED)); + PARAM_ERROR_CHECK(vxAddParameterToKernel(Kernel, 2, VX_INPUT, VX_TYPE_SCALAR, VX_PARAMETER_STATE_REQUIRED)); + PARAM_ERROR_CHECK(vxAddParameterToKernel(Kernel, 3, VX_INPUT, VX_TYPE_SCALAR, VX_PARAMETER_STATE_REQUIRED)); + PARAM_ERROR_CHECK(vxAddParameterToKernel(Kernel, 4, VX_INPUT, VX_TYPE_SCALAR, VX_PARAMETER_STATE_REQUIRED)); + PARAM_ERROR_CHECK(vxAddParameterToKernel(Kernel, 5, VX_INPUT, VX_TYPE_SCALAR, VX_PARAMETER_STATE_REQUIRED)); + PARAM_ERROR_CHECK(vxAddParameterToKernel(Kernel, 6, VX_INPUT, VX_TYPE_SCALAR, VX_PARAMETER_STATE_REQUIRED)); + PARAM_ERROR_CHECK(vxFinalizeKernel(Kernel)); + } + + if (status != VX_SUCCESS) + { + exit: vxRemoveKernel(Kernel); return VX_FAILURE; + } + + return status; +} diff --git a/vx_ext_cv/OpenCV_sepFilter2D.cpp b/vx_ext_cv/OpenCV_sepFilter2D.cpp new file mode 100644 index 0000000..bb21ffa --- /dev/null +++ b/vx_ext_cv/OpenCV_sepFilter2D.cpp @@ -0,0 +1,245 @@ +/* +Copyright (c) 2015 Advanced Micro Devices, Inc. All rights reserved. + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. +*/ + + +#include"publishkernels.h" + +/************************************************************************************************************ +input parameter validator. +param [in] node The handle to the node. +param [in] index The index of the parameter to validate. +*************************************************************************************************************/ +static vx_status VX_CALLBACK CV_sepFilter2D_InputValidator(vx_node node, vx_uint32 index) +{ + vx_status status = VX_SUCCESS; + vx_parameter param = vxGetParameterByIndex(node, index); + + if (index == 0) + { + vx_image image; + vx_df_image df_image = VX_DF_IMAGE_VIRT; + STATUS_ERROR_CHECK(vxQueryParameter(param, VX_PARAMETER_ATTRIBUTE_REF, &image, sizeof(vx_image))); + STATUS_ERROR_CHECK(vxQueryImage(image, VX_IMAGE_ATTRIBUTE_FORMAT, &df_image, sizeof(df_image))); + if (df_image != VX_DF_IMAGE_U8) + status = VX_ERROR_INVALID_VALUE; + vxReleaseImage(&image); + } + + else if (index == 1) + { + vx_image image; + vx_df_image df_image = VX_DF_IMAGE_VIRT; + STATUS_ERROR_CHECK(vxQueryParameter(param, VX_PARAMETER_ATTRIBUTE_REF, &image, sizeof(vx_image))); + STATUS_ERROR_CHECK(vxQueryImage(image, VX_IMAGE_ATTRIBUTE_FORMAT, &df_image, sizeof(df_image))); + if (df_image != VX_DF_IMAGE_U8) + status = VX_ERROR_INVALID_VALUE; + vxReleaseImage(&image); + } + + else if (index == 2) + { + vx_scalar scalar = 0; vx_enum type = 0; vx_int32 value = 0; + STATUS_ERROR_CHECK(vxQueryParameter(param, VX_PARAMETER_ATTRIBUTE_REF, &scalar, sizeof(scalar))); + STATUS_ERROR_CHECK(vxQueryScalar(scalar, VX_SCALAR_ATTRIBUTE_TYPE, &type, sizeof(type))); + STATUS_ERROR_CHECK(vxReadScalarValue(scalar, &value)); + if (value < -1 || type != VX_TYPE_INT32) + status = VX_ERROR_INVALID_VALUE; + vxReleaseScalar(&scalar); + } + + else if (index == 3) + { + vx_matrix mat; + STATUS_ERROR_CHECK(vxQueryParameter(param, VX_PARAMETER_ATTRIBUTE_REF, &mat, sizeof(vx_matrix))); + vxReleaseMatrix(&mat); + } + + else if (index == 4) + { + vx_matrix mat; + STATUS_ERROR_CHECK(vxQueryParameter(param, VX_PARAMETER_ATTRIBUTE_REF, &mat, sizeof(vx_matrix))); + vxReleaseMatrix(&mat); + } + + else if (index == 5) + { + vx_scalar scalar = 0; vx_enum type = 0; vx_int32 value = 0; + STATUS_ERROR_CHECK(vxQueryParameter(param, VX_PARAMETER_ATTRIBUTE_REF, &scalar, sizeof(scalar))); + STATUS_ERROR_CHECK(vxQueryScalar(scalar, VX_SCALAR_ATTRIBUTE_TYPE, &type, sizeof(type))); + STATUS_ERROR_CHECK(vxReadScalarValue(scalar, &value)); + if (value < -1 || type != VX_TYPE_INT32) + status = VX_ERROR_INVALID_VALUE; + vxReleaseScalar(&scalar); + } + + else if (index == 6) + { + vx_scalar scalar = 0; vx_enum type = 0; vx_int32 value = 0; + STATUS_ERROR_CHECK(vxQueryParameter(param, VX_PARAMETER_ATTRIBUTE_REF, &scalar, sizeof(scalar))); + STATUS_ERROR_CHECK(vxQueryScalar(scalar, VX_SCALAR_ATTRIBUTE_TYPE, &type, sizeof(type))); + STATUS_ERROR_CHECK(vxReadScalarValue(scalar, &value)); + if (value < -1 || type != VX_TYPE_INT32) + status = VX_ERROR_INVALID_VALUE; + vxReleaseScalar(&scalar); + } + + else if (index == 7) + { + vx_scalar scalar = 0; vx_enum type = 0; vx_float32 value = 0; + STATUS_ERROR_CHECK(vxQueryParameter(param, VX_PARAMETER_ATTRIBUTE_REF, &scalar, sizeof(scalar))); + STATUS_ERROR_CHECK(vxQueryScalar(scalar, VX_SCALAR_ATTRIBUTE_TYPE, &type, sizeof(type))); + STATUS_ERROR_CHECK(vxReadScalarValue(scalar, &value)); + if (value < 0 || type != VX_TYPE_FLOAT32) + status = VX_ERROR_INVALID_VALUE; + vxReleaseScalar(&scalar); + } + + else if (index == 8) + { + vx_scalar scalar = 0; vx_enum type = 0; vx_int32 value = 0; + STATUS_ERROR_CHECK(vxQueryParameter(param, VX_PARAMETER_ATTRIBUTE_REF, &scalar, sizeof(scalar))); + STATUS_ERROR_CHECK(vxQueryScalar(scalar, VX_SCALAR_ATTRIBUTE_TYPE, &type, sizeof(type))); + STATUS_ERROR_CHECK(vxReadScalarValue(scalar, &value)); + if (value < 0 || type != VX_TYPE_INT32) + status = VX_ERROR_INVALID_VALUE; + vxReleaseScalar(&scalar); + } + + vxReleaseParameter(¶m); + return status; +} + +/************************************************************************************************************ +output parameter validator. +*************************************************************************************************************/ +static vx_status VX_CALLBACK CV_sepFilter2D_OutputValidator(vx_node node, vx_uint32 index, vx_meta_format meta) +{ + vx_status status = VX_SUCCESS; + if (index == 1) + { + vx_parameter output_param = vxGetParameterByIndex(node, 1); + vx_image output; vx_uint32 width = 0, height = 0; vx_df_image format = VX_DF_IMAGE_VIRT; + + STATUS_ERROR_CHECK(vxQueryParameter(output_param, VX_PARAMETER_ATTRIBUTE_REF, &output, sizeof(vx_image))); + STATUS_ERROR_CHECK(vxQueryImage(output, VX_IMAGE_ATTRIBUTE_FORMAT, &format, sizeof(format))); + STATUS_ERROR_CHECK(vxQueryImage(output, VX_IMAGE_ATTRIBUTE_WIDTH, &width, sizeof(width))); + STATUS_ERROR_CHECK(vxQueryImage(output, VX_IMAGE_ATTRIBUTE_HEIGHT, &height, sizeof(height))); + + if (format != VX_DF_IMAGE_U8) + status = VX_ERROR_INVALID_VALUE; + + STATUS_ERROR_CHECK(vxSetMetaFormatAttribute(meta, VX_IMAGE_ATTRIBUTE_WIDTH, &width, sizeof(width))); + STATUS_ERROR_CHECK(vxSetMetaFormatAttribute(meta, VX_IMAGE_ATTRIBUTE_HEIGHT, &height, sizeof(height))); + STATUS_ERROR_CHECK(vxSetMetaFormatAttribute(meta, VX_IMAGE_ATTRIBUTE_FORMAT, &format, sizeof(format))); + + vxReleaseImage(&output); + vxReleaseParameter(&output_param); + } + return status; +} + +/************************************************************************************************************ +Execution Kernel +*************************************************************************************************************/ +static vx_status VX_CALLBACK CV_sepFilter2D_Kernel(vx_node node, const vx_reference *parameters, vx_uint32 num) +{ + vx_status status = VX_SUCCESS; + + vx_image image_in = (vx_image) parameters[0]; + vx_image image_out = (vx_image) parameters[1]; + vx_scalar scalar = (vx_scalar) parameters[2]; + vx_matrix KERNELX = (vx_matrix) parameters[3]; + vx_matrix KERNELY = (vx_matrix) parameters[4]; + vx_scalar A_X = (vx_scalar) parameters[5]; + vx_scalar A_Y = (vx_scalar) parameters[6]; + vx_scalar DELTA = (vx_scalar) parameters[7]; + vx_scalar BORDER = (vx_scalar) parameters[8]; + + Mat *mat, bl; + int ddepth, a_x = -1, a_y = -1, border = 4; + float delta = 0; + vx_int32 value = 0; + vx_float32 value_f = 0; + + //Extracting Values from the Scalar into Ksize and Ddepth + STATUS_ERROR_CHECK(vxReadScalarValue(scalar, &value)); ddepth = value; + STATUS_ERROR_CHECK(vxReadScalarValue(A_X, &value)); a_x = value; + STATUS_ERROR_CHECK(vxReadScalarValue(A_Y, &value)); a_y = value; + STATUS_ERROR_CHECK(vxReadScalarValue(DELTA, &value_f)); delta = value_f; + STATUS_ERROR_CHECK(vxReadScalarValue(BORDER, &value)); border = value; + + //Converting VX Image to OpenCV Mat + STATUS_ERROR_CHECK(match_vx_image_parameters(image_in, image_out)); + STATUS_ERROR_CHECK(VX_to_CV_Image(&mat, image_in)); + + //Compute using OpenCV + Point point; + point.x = a_x; + point.y = a_y; + Mat *kernelX, *kernelY; + STATUS_ERROR_CHECK(VX_to_CV_MATRIX(&kernelX, KERNELX)); + STATUS_ERROR_CHECK(VX_to_CV_MATRIX(&kernelY, KERNELY)); + cv::sepFilter2D(*mat, bl, ddepth, *kernelX, *kernelY, point, delta, border); + + //Converting OpenCV Mat into VX Image + STATUS_ERROR_CHECK(CV_to_VX_Image(image_out, &bl)); + + return status; +} + +/************************************************************************************************************ +Function to Register the Kernel for Publish +*************************************************************************************************************/ +vx_status CV_sepFilter2D_Register(vx_context context) +{ + vx_status status = VX_SUCCESS; + vx_kernel kernel = vxAddKernel(context, + "org.opencv.sepfilter2d", + VX_KERNEL_EXT_CV_SEPFILTER_2D, + CV_sepFilter2D_Kernel, + 9, + CV_sepFilter2D_InputValidator, + CV_sepFilter2D_OutputValidator, + nullptr, + nullptr); + + if (kernel) + { + PARAM_ERROR_CHECK(vxAddParameterToKernel(kernel, 0, VX_INPUT, VX_TYPE_IMAGE, VX_PARAMETER_STATE_REQUIRED)); + PARAM_ERROR_CHECK(vxAddParameterToKernel(kernel, 1, VX_OUTPUT, VX_TYPE_IMAGE, VX_PARAMETER_STATE_REQUIRED)); + PARAM_ERROR_CHECK(vxAddParameterToKernel(kernel, 2, VX_INPUT, VX_TYPE_SCALAR, VX_PARAMETER_STATE_REQUIRED)); + PARAM_ERROR_CHECK(vxAddParameterToKernel(kernel, 3, VX_INPUT, VX_TYPE_MATRIX, VX_PARAMETER_STATE_REQUIRED)); + PARAM_ERROR_CHECK(vxAddParameterToKernel(kernel, 4, VX_INPUT, VX_TYPE_MATRIX, VX_PARAMETER_STATE_REQUIRED)); + PARAM_ERROR_CHECK(vxAddParameterToKernel(kernel, 5, VX_INPUT, VX_TYPE_SCALAR, VX_PARAMETER_STATE_REQUIRED)); + PARAM_ERROR_CHECK(vxAddParameterToKernel(kernel, 6, VX_INPUT, VX_TYPE_SCALAR, VX_PARAMETER_STATE_REQUIRED)); + PARAM_ERROR_CHECK(vxAddParameterToKernel(kernel, 7, VX_INPUT, VX_TYPE_SCALAR, VX_PARAMETER_STATE_REQUIRED)); + PARAM_ERROR_CHECK(vxAddParameterToKernel(kernel, 8, VX_INPUT, VX_TYPE_SCALAR, VX_PARAMETER_STATE_REQUIRED)); + PARAM_ERROR_CHECK(vxFinalizeKernel(kernel)); + } + + if (status != VX_SUCCESS) + { + exit: vxRemoveKernel(kernel); return VX_FAILURE; + } + + return status; +} diff --git a/vx_ext_cv/OpenCV_simple_blob_detector.cpp b/vx_ext_cv/OpenCV_simple_blob_detector.cpp new file mode 100644 index 0000000..ff4cd79 --- /dev/null +++ b/vx_ext_cv/OpenCV_simple_blob_detector.cpp @@ -0,0 +1,559 @@ +/* +Copyright (c) 2015 Advanced Micro Devices, Inc. All rights reserved. + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. +*/ + + +#include"publishkernels.h" + +/*!*********************************************************************************************************** +input parameter validator. +param [in] node The handle to the node. +param [in] index The index of the parameter to validate. +*************************************************************************************************************/ +static vx_status VX_CALLBACK CV_simple_blob_detector_InputValidator(vx_node node, vx_uint32 index) +{ + vx_status status = VX_SUCCESS; + vx_parameter param = vxGetParameterByIndex(node, index); + + if (index == 0) + { + vx_image image; + vx_df_image df_image = VX_DF_IMAGE_VIRT; + STATUS_ERROR_CHECK(vxQueryParameter(param, VX_PARAMETER_ATTRIBUTE_REF, &image, sizeof(vx_image))); + STATUS_ERROR_CHECK(vxQueryImage(image, VX_IMAGE_ATTRIBUTE_FORMAT, &df_image, sizeof(df_image))); + if (df_image != VX_DF_IMAGE_U8) + status = VX_ERROR_INVALID_VALUE; + vxReleaseImage(&image); + } + + else if (index == 1) + { + vx_array array; vx_size size = 0; + STATUS_ERROR_CHECK(vxQueryParameter(param, VX_PARAMETER_ATTRIBUTE_REF, &array, sizeof(array))); + STATUS_ERROR_CHECK(vxQueryArray(array, VX_ARRAY_ATTRIBUTE_CAPACITY, &size, sizeof(size))); + vxReleaseArray(&array); + } + + if (index == 2) + { + vx_image image; + vx_df_image df_image = VX_DF_IMAGE_VIRT; + STATUS_ERROR_CHECK(vxQueryParameter(param, VX_PARAMETER_ATTRIBUTE_REF, &image, sizeof(vx_image))); + STATUS_ERROR_CHECK(vxQueryImage(image, VX_IMAGE_ATTRIBUTE_FORMAT, &df_image, sizeof(df_image))); + if (df_image != VX_DF_IMAGE_U8) + status = VX_ERROR_INVALID_VALUE; + vxReleaseImage(&image); + } + + vxReleaseParameter(¶m); + return status; +} + +/*!*********************************************************************************************************** +output parameter validator. +*************************************************************************************************************/ +static vx_status VX_CALLBACK CV_simple_blob_detector_OutputValidator(vx_node node, vx_uint32 index, vx_meta_format meta) +{ + vx_status status = VX_SUCCESS; + if (index == 1) + { + vx_parameter output_param = vxGetParameterByIndex(node, 1); + vx_array output; vx_size size = 0; + + STATUS_ERROR_CHECK(vxQueryParameter(output_param, VX_PARAMETER_ATTRIBUTE_REF, &output, sizeof(vx_array))); + STATUS_ERROR_CHECK(vxQueryArray(output, VX_ARRAY_ATTRIBUTE_CAPACITY, &size, sizeof(size))); + + if (size <= 0) + status = VX_ERROR_INVALID_VALUE; + + vxReleaseArray(&output); + vxReleaseParameter(&output_param); + + } + + return status; +} + +/*!*********************************************************************************************************** +Execution Kernel +*************************************************************************************************************/ +static vx_status VX_CALLBACK CV_simple_blob_detector_Kernel(vx_node node, const vx_reference *parameters, vx_uint32 num) +{ + vx_status status = VX_SUCCESS; + vx_image image_in = (vx_image) parameters[0]; + vx_array array = (vx_array) parameters[1]; + vx_image mask = (vx_image) parameters[2]; + vector key_points; + Mat *mat, *mask_mat, Img; + + //Converting VX Image to OpenCV Mat + STATUS_ERROR_CHECK(VX_to_CV_Image(&mat, image_in)); + STATUS_ERROR_CHECK(VX_to_CV_Image(&mask_mat, mask)); + + //OpenCV Calls to Simple Blob Detector + Ptr simple = SimpleBlobDetector::create(); + simple->detect(*mat, key_points, *mask_mat); + + //Converting OpenCV Keypoints to OpenVX Keypoints + STATUS_ERROR_CHECK(CV_to_VX_keypoints(key_points, array)); + + return status; +} + +/************************************************************************************************************ +Function to Register the Kernel for Publish +*************************************************************************************************************/ +vx_status CV_simple_blob_detect_Register(vx_context context) +{ + vx_status status = VX_SUCCESS; + vx_kernel Kernel = vxAddKernel(context, + "org.opencv.simple_blob_detect", + VX_KERNEL_EXT_CV_SIMPLE_BLOB_DETECT, + CV_simple_blob_detector_Kernel, + 3, + CV_simple_blob_detector_InputValidator, + CV_simple_blob_detector_OutputValidator, + nullptr, + nullptr); + + if (Kernel) + { + PARAM_ERROR_CHECK(vxAddParameterToKernel(Kernel, 0, VX_INPUT, VX_TYPE_IMAGE, VX_PARAMETER_STATE_REQUIRED)); + PARAM_ERROR_CHECK(vxAddParameterToKernel(Kernel, 1, VX_BIDIRECTIONAL, VX_TYPE_ARRAY, VX_PARAMETER_STATE_REQUIRED)); + PARAM_ERROR_CHECK(vxAddParameterToKernel(Kernel, 2, VX_INPUT, VX_TYPE_IMAGE, VX_PARAMETER_STATE_REQUIRED)); + PARAM_ERROR_CHECK(vxFinalizeKernel(Kernel)); + } + + if (status != VX_SUCCESS) + { + exit: vxRemoveKernel(Kernel); return VX_FAILURE; + } + + return status; +} + + +/*!*********************************************************************************************************** +input parameter validator. +param [in] node The handle to the node. +param [in] index The index of the parameter to validate. +*************************************************************************************************************/ +static vx_status VX_CALLBACK CV_simple_blob_detector_INITIALIZE_InputValidator(vx_node node, vx_uint32 index) +{ + vx_status status = VX_SUCCESS; + vx_parameter param = vxGetParameterByIndex(node, index); + + if (index == 0) + { + vx_image image; + vx_df_image df_image = VX_DF_IMAGE_VIRT; + STATUS_ERROR_CHECK(vxQueryParameter(param, VX_PARAMETER_ATTRIBUTE_REF, &image, sizeof(vx_image))); + STATUS_ERROR_CHECK(vxQueryImage(image, VX_IMAGE_ATTRIBUTE_FORMAT, &df_image, sizeof(df_image))); + if (df_image != VX_DF_IMAGE_U8) + status = VX_ERROR_INVALID_VALUE; + vxReleaseImage(&image); + } + + else if (index == 1) + { + vx_array array; vx_size size = 0; + STATUS_ERROR_CHECK(vxQueryParameter(param, VX_PARAMETER_ATTRIBUTE_REF, &array, sizeof(array))); + STATUS_ERROR_CHECK(vxQueryArray(array, VX_ARRAY_ATTRIBUTE_CAPACITY, &size, sizeof(size))); + vxReleaseArray(&array); + } + + if (index == 2) + { + vx_image image; + vx_df_image df_image = VX_DF_IMAGE_VIRT; + STATUS_ERROR_CHECK(vxQueryParameter(param, VX_PARAMETER_ATTRIBUTE_REF, &image, sizeof(vx_image))); + STATUS_ERROR_CHECK(vxQueryImage(image, VX_IMAGE_ATTRIBUTE_FORMAT, &df_image, sizeof(df_image))); + if (df_image != VX_DF_IMAGE_U8) + status = VX_ERROR_INVALID_VALUE; + vxReleaseImage(&image); + } + + else if (index == 3) + { + vx_scalar scalar = 0; vx_enum type = 0; vx_float32 value = 0; + STATUS_ERROR_CHECK(vxQueryParameter(param, VX_PARAMETER_ATTRIBUTE_REF, &scalar, sizeof(scalar))); + STATUS_ERROR_CHECK(vxQueryScalar(scalar, VX_SCALAR_ATTRIBUTE_TYPE, &type, sizeof(type))); + STATUS_ERROR_CHECK(vxReadScalarValue(scalar, &value)); + if (value < 0 || type != VX_TYPE_FLOAT32) + status = VX_ERROR_INVALID_VALUE; + vxReleaseScalar(&scalar); + } + + else if (index == 4) + { + vx_scalar scalar = 0; vx_enum type = 0; vx_float32 value = 0; + STATUS_ERROR_CHECK(vxQueryParameter(param, VX_PARAMETER_ATTRIBUTE_REF, &scalar, sizeof(scalar))); + STATUS_ERROR_CHECK(vxQueryScalar(scalar, VX_SCALAR_ATTRIBUTE_TYPE, &type, sizeof(type))); + STATUS_ERROR_CHECK(vxReadScalarValue(scalar, &value)); + if (value < 0 || type != VX_TYPE_FLOAT32) + status = VX_ERROR_INVALID_VALUE; + vxReleaseScalar(&scalar); + } + + else if (index == 5) + { + vx_scalar scalar = 0; vx_enum type = 0; vx_float32 value = 0; + STATUS_ERROR_CHECK(vxQueryParameter(param, VX_PARAMETER_ATTRIBUTE_REF, &scalar, sizeof(scalar))); + STATUS_ERROR_CHECK(vxQueryScalar(scalar, VX_SCALAR_ATTRIBUTE_TYPE, &type, sizeof(type))); + STATUS_ERROR_CHECK(vxReadScalarValue(scalar, &value)); + if (value < 0 || type != VX_TYPE_FLOAT32) + status = VX_ERROR_INVALID_VALUE; + vxReleaseScalar(&scalar); + } + + else if (index == 6) + { + vx_scalar scalar = 0; vx_enum type = 0; vx_size value = 0; + STATUS_ERROR_CHECK(vxQueryParameter(param, VX_PARAMETER_ATTRIBUTE_REF, &scalar, sizeof(scalar))); + STATUS_ERROR_CHECK(vxQueryScalar(scalar, VX_SCALAR_ATTRIBUTE_TYPE, &type, sizeof(type))); + STATUS_ERROR_CHECK(vxReadScalarValue(scalar, &value)); + if (type != VX_TYPE_SIZE) + status = VX_ERROR_INVALID_VALUE; + vxReleaseScalar(&scalar); + } + else if (index == 7) + { + vx_scalar scalar = 0; vx_enum type = 0; vx_float32 value = 0; + STATUS_ERROR_CHECK(vxQueryParameter(param, VX_PARAMETER_ATTRIBUTE_REF, &scalar, sizeof(scalar))); + STATUS_ERROR_CHECK(vxQueryScalar(scalar, VX_SCALAR_ATTRIBUTE_TYPE, &type, sizeof(type))); + STATUS_ERROR_CHECK(vxReadScalarValue(scalar, &value)); + if (value < 0 || type != VX_TYPE_FLOAT32) + status = VX_ERROR_INVALID_VALUE; + vxReleaseScalar(&scalar); + } + + else if (index == 8) + { + vx_scalar scalar = 0; vx_enum type = 0; vx_bool value = vx_true_e; + STATUS_ERROR_CHECK(vxQueryParameter(param, VX_PARAMETER_ATTRIBUTE_REF, &scalar, sizeof(scalar))); + STATUS_ERROR_CHECK(vxQueryScalar(scalar, VX_SCALAR_ATTRIBUTE_TYPE, &type, sizeof(type))); + STATUS_ERROR_CHECK(vxReadScalarValue(scalar, &value)); + if ((value != vx_true_e && value != vx_false_e) || type != VX_TYPE_BOOL) + status = VX_ERROR_INVALID_VALUE; + vxReleaseScalar(&scalar); + } + + else if (index == 9) + { + vx_scalar scalar = 0; vx_enum type = 0; vx_uint16 value = 0; + STATUS_ERROR_CHECK(vxQueryParameter(param, VX_PARAMETER_ATTRIBUTE_REF, &scalar, sizeof(scalar))); + STATUS_ERROR_CHECK(vxQueryScalar(scalar, VX_SCALAR_ATTRIBUTE_TYPE, &type, sizeof(type))); + STATUS_ERROR_CHECK(vxReadScalarValue(scalar, &value)); + if (type != VX_TYPE_UINT16) + status = VX_ERROR_INVALID_VALUE; + vxReleaseScalar(&scalar); + } + + else if (index == 10) + { + vx_scalar scalar = 0; vx_enum type = 0; vx_bool value = vx_true_e; + STATUS_ERROR_CHECK(vxQueryParameter(param, VX_PARAMETER_ATTRIBUTE_REF, &scalar, sizeof(scalar))); + STATUS_ERROR_CHECK(vxQueryScalar(scalar, VX_SCALAR_ATTRIBUTE_TYPE, &type, sizeof(type))); + STATUS_ERROR_CHECK(vxReadScalarValue(scalar, &value)); + if ((value != vx_true_e && value != vx_false_e) || type != VX_TYPE_BOOL) + status = VX_ERROR_INVALID_VALUE; + vxReleaseScalar(&scalar); + } + + else if (index == 11) + { + vx_scalar scalar = 0; vx_enum type = 0; vx_float32 value = 0; + STATUS_ERROR_CHECK(vxQueryParameter(param, VX_PARAMETER_ATTRIBUTE_REF, &scalar, sizeof(scalar))); + STATUS_ERROR_CHECK(vxQueryScalar(scalar, VX_SCALAR_ATTRIBUTE_TYPE, &type, sizeof(type))); + STATUS_ERROR_CHECK(vxReadScalarValue(scalar, &value)); + if (value < 0 || type != VX_TYPE_FLOAT32) + status = VX_ERROR_INVALID_VALUE; + vxReleaseScalar(&scalar); + } + + else if (index == 12) + { + vx_scalar scalar = 0; vx_enum type = 0; vx_float32 value = 0; + STATUS_ERROR_CHECK(vxQueryParameter(param, VX_PARAMETER_ATTRIBUTE_REF, &scalar, sizeof(scalar))); + STATUS_ERROR_CHECK(vxQueryScalar(scalar, VX_SCALAR_ATTRIBUTE_TYPE, &type, sizeof(type))); + STATUS_ERROR_CHECK(vxReadScalarValue(scalar, &value)); + if (value < 0 || type != VX_TYPE_FLOAT32) + status = VX_ERROR_INVALID_VALUE; + vxReleaseScalar(&scalar); + } + + else if (index == 13) + { + vx_scalar scalar = 0; vx_enum type = 0; vx_bool value = vx_true_e; + STATUS_ERROR_CHECK(vxQueryParameter(param, VX_PARAMETER_ATTRIBUTE_REF, &scalar, sizeof(scalar))); + STATUS_ERROR_CHECK(vxQueryScalar(scalar, VX_SCALAR_ATTRIBUTE_TYPE, &type, sizeof(type))); + STATUS_ERROR_CHECK(vxReadScalarValue(scalar, &value)); + if ((value != vx_true_e && value != vx_false_e) || type != VX_TYPE_BOOL) + status = VX_ERROR_INVALID_VALUE; + vxReleaseScalar(&scalar); + } + + else if (index == 14) + { + vx_scalar scalar = 0; vx_enum type = 0; vx_float32 value = 0; + STATUS_ERROR_CHECK(vxQueryParameter(param, VX_PARAMETER_ATTRIBUTE_REF, &scalar, sizeof(scalar))); + STATUS_ERROR_CHECK(vxQueryScalar(scalar, VX_SCALAR_ATTRIBUTE_TYPE, &type, sizeof(type))); + STATUS_ERROR_CHECK(vxReadScalarValue(scalar, &value)); + if (value < 0 || type != VX_TYPE_FLOAT32) + status = VX_ERROR_INVALID_VALUE; + vxReleaseScalar(&scalar); + } + + else if (index == 15) + { + vx_scalar scalar = 0; vx_enum type = 0; vx_float32 value = 0; + STATUS_ERROR_CHECK(vxQueryParameter(param, VX_PARAMETER_ATTRIBUTE_REF, &scalar, sizeof(scalar))); + STATUS_ERROR_CHECK(vxQueryScalar(scalar, VX_SCALAR_ATTRIBUTE_TYPE, &type, sizeof(type))); + STATUS_ERROR_CHECK(vxReadScalarValue(scalar, &value)); + if (value < 0 || type != VX_TYPE_FLOAT32) + status = VX_ERROR_INVALID_VALUE; + vxReleaseScalar(&scalar); + } + + else if (index == 16) + { + vx_scalar scalar = 0; vx_enum type = 0; vx_bool value = vx_true_e; + STATUS_ERROR_CHECK(vxQueryParameter(param, VX_PARAMETER_ATTRIBUTE_REF, &scalar, sizeof(scalar))); + STATUS_ERROR_CHECK(vxQueryScalar(scalar, VX_SCALAR_ATTRIBUTE_TYPE, &type, sizeof(type))); + STATUS_ERROR_CHECK(vxReadScalarValue(scalar, &value)); + if ((value != vx_true_e && value != vx_false_e) || type != VX_TYPE_BOOL) + status = VX_ERROR_INVALID_VALUE; + vxReleaseScalar(&scalar); + } + + else if (index == 17) + { + vx_scalar scalar = 0; vx_enum type = 0; vx_float32 value = 0; + STATUS_ERROR_CHECK(vxQueryParameter(param, VX_PARAMETER_ATTRIBUTE_REF, &scalar, sizeof(scalar))); + STATUS_ERROR_CHECK(vxQueryScalar(scalar, VX_SCALAR_ATTRIBUTE_TYPE, &type, sizeof(type))); + STATUS_ERROR_CHECK(vxReadScalarValue(scalar, &value)); + if (value < 0 || type != VX_TYPE_FLOAT32) + status = VX_ERROR_INVALID_VALUE; + vxReleaseScalar(&scalar); + } + + else if (index == 18) + { + vx_scalar scalar = 0; vx_enum type = 0; vx_float32 value = 0; + STATUS_ERROR_CHECK(vxQueryParameter(param, VX_PARAMETER_ATTRIBUTE_REF, &scalar, sizeof(scalar))); + STATUS_ERROR_CHECK(vxQueryScalar(scalar, VX_SCALAR_ATTRIBUTE_TYPE, &type, sizeof(type))); + STATUS_ERROR_CHECK(vxReadScalarValue(scalar, &value)); + if (value < 0 || type != VX_TYPE_FLOAT32) + status = VX_ERROR_INVALID_VALUE; + vxReleaseScalar(&scalar); + } + + else if (index == 19) + { + vx_scalar scalar = 0; vx_enum type = 0; vx_bool value = vx_true_e; + STATUS_ERROR_CHECK(vxQueryParameter(param, VX_PARAMETER_ATTRIBUTE_REF, &scalar, sizeof(scalar))); + STATUS_ERROR_CHECK(vxQueryScalar(scalar, VX_SCALAR_ATTRIBUTE_TYPE, &type, sizeof(type))); + STATUS_ERROR_CHECK(vxReadScalarValue(scalar, &value)); + if ((value != vx_true_e && value != vx_false_e) || type != VX_TYPE_BOOL) + status = VX_ERROR_INVALID_VALUE; + vxReleaseScalar(&scalar); + } + + else if (index == 20) + { + vx_scalar scalar = 0; vx_enum type = 0; vx_float32 value = 0; + STATUS_ERROR_CHECK(vxQueryParameter(param, VX_PARAMETER_ATTRIBUTE_REF, &scalar, sizeof(scalar))); + STATUS_ERROR_CHECK(vxQueryScalar(scalar, VX_SCALAR_ATTRIBUTE_TYPE, &type, sizeof(type))); + STATUS_ERROR_CHECK(vxReadScalarValue(scalar, &value)); + if (value < 0 || type != VX_TYPE_FLOAT32) + status = VX_ERROR_INVALID_VALUE; + vxReleaseScalar(&scalar); + } + + else if (index == 21) + { + vx_scalar scalar = 0; vx_enum type = 0; vx_float32 value = 0; + STATUS_ERROR_CHECK(vxQueryParameter(param, VX_PARAMETER_ATTRIBUTE_REF, &scalar, sizeof(scalar))); + STATUS_ERROR_CHECK(vxQueryScalar(scalar, VX_SCALAR_ATTRIBUTE_TYPE, &type, sizeof(type))); + STATUS_ERROR_CHECK(vxReadScalarValue(scalar, &value)); + if (value < 0 || type != VX_TYPE_FLOAT32) + status = VX_ERROR_INVALID_VALUE; + vxReleaseScalar(&scalar); + } + + vxReleaseParameter(¶m); + return status; +} + +/*!*********************************************************************************************************** +Execution Kernel +*************************************************************************************************************/ +static vx_status VX_CALLBACK CV_simple_blob_detector_INITIALIZE_Kernel(vx_node node, const vx_reference *parameters, vx_uint32 num) +{ + vx_status status = VX_SUCCESS; + + vx_image image_in = (vx_image) parameters[0]; + vx_array array = (vx_array) parameters[1]; + vx_image mask = (vx_image) parameters[2]; + + vector key_points; + Mat *mat, *mask_mat, Img; + + vx_scalar THRESHOLDSTEP = (vx_scalar) parameters[3]; + vx_scalar MINTHRESHOLD = (vx_scalar) parameters[4]; + vx_scalar MAXTHRESHOLD = (vx_scalar) parameters[5]; + vx_scalar MINREPEAT = (vx_scalar) parameters[6]; + vx_scalar MINDISTBTW = (vx_scalar) parameters[7]; + vx_scalar FILTERBYCOLOR = (vx_scalar) parameters[8]; + vx_scalar BLOBCOLOR = (vx_scalar) parameters[9]; + vx_scalar FILTERBYAREA = (vx_scalar) parameters[10]; + vx_scalar MINAREA = (vx_scalar) parameters[11]; + vx_scalar MAXAREA = (vx_scalar) parameters[12]; + vx_scalar FILTERBYCIR = (vx_scalar) parameters[13]; + vx_scalar MINCIR = (vx_scalar) parameters[14]; + vx_scalar MAXCIR = (vx_scalar) parameters[15]; + vx_scalar FILTERBYINER = (vx_scalar) parameters[16]; + vx_scalar MININER = (vx_scalar) parameters[17]; + vx_scalar MAXINER = (vx_scalar) parameters[18]; + vx_scalar FILTERBYCON = (vx_scalar) parameters[19]; + vx_scalar MINCON = (vx_scalar) parameters[20]; + vx_scalar MAXCON = (vx_scalar) parameters[21]; + + size_t minRepeatability; + vx_bool filterByColor, filterByArea, filterByCircularity, filterByInertia, filterByConvexity; + vx_uint16 blobColor; + float thresholdStep, minThreshold, maxThreshold, minDistBetweenBlobs, minArea, maxArea, minCircularity, maxCircularity, minInertiaRatio, maxInertiaRatio, minConvexity, maxConvexity; + vx_float32 FloatValue = 0; + vx_bool value; + vx_size value_s = 0; + + //Extracting Values from the Scalar + STATUS_ERROR_CHECK(vxReadScalarValue(MINREPEAT, &value_s)); minRepeatability = value_s; + STATUS_ERROR_CHECK(vxReadScalarValue(THRESHOLDSTEP, &FloatValue)); thresholdStep = FloatValue; + STATUS_ERROR_CHECK(vxReadScalarValue(MINTHRESHOLD, &FloatValue)); minThreshold = FloatValue; + STATUS_ERROR_CHECK(vxReadScalarValue(MAXTHRESHOLD, &FloatValue)); maxThreshold = FloatValue; + STATUS_ERROR_CHECK(vxReadScalarValue(MINDISTBTW, &FloatValue)); minDistBetweenBlobs = FloatValue; + STATUS_ERROR_CHECK(vxReadScalarValue(MINAREA, &FloatValue)); minArea = FloatValue; + STATUS_ERROR_CHECK(vxReadScalarValue(MAXAREA, &FloatValue)); maxArea = FloatValue; + STATUS_ERROR_CHECK(vxReadScalarValue(MINCIR, &FloatValue)); minCircularity = FloatValue; + STATUS_ERROR_CHECK(vxReadScalarValue(MAXCIR, &FloatValue)); maxCircularity = FloatValue; + STATUS_ERROR_CHECK(vxReadScalarValue(MININER, &FloatValue)); minInertiaRatio = FloatValue; + STATUS_ERROR_CHECK(vxReadScalarValue(MAXINER, &FloatValue)); maxInertiaRatio = FloatValue; + STATUS_ERROR_CHECK(vxReadScalarValue(MINCON, &FloatValue)); minConvexity = FloatValue; + STATUS_ERROR_CHECK(vxReadScalarValue(MAXCON, &FloatValue)); maxConvexity = FloatValue; + STATUS_ERROR_CHECK(vxReadScalarValue(FILTERBYCOLOR, &value)); filterByColor = value; + STATUS_ERROR_CHECK(vxReadScalarValue(FILTERBYAREA, &value)); filterByArea = value; + STATUS_ERROR_CHECK(vxReadScalarValue(FILTERBYCIR, &value)); filterByCircularity = value; + STATUS_ERROR_CHECK(vxReadScalarValue(FILTERBYINER, &value)); filterByInertia = value; + STATUS_ERROR_CHECK(vxReadScalarValue(FILTERBYCON, &value)); filterByConvexity = value; + STATUS_ERROR_CHECK(vxReadScalarValue(BLOBCOLOR, &blobColor)); + + //Converting VX Image to OpenCV Mat + STATUS_ERROR_CHECK(VX_to_CV_Image(&mat, image_in)); + STATUS_ERROR_CHECK(VX_to_CV_Image(&mask_mat, mask)); + + //OpenCV Calls to Simple Blob Detector + bool filterByColor_bool, filterByArea_bool, filterByCircularity_bool, filterByConvexity_bool, filterByInertia_bool; + if (filterByColor == vx_true_e) filterByColor_bool = true; else filterByColor_bool = false; + if (filterByArea == vx_true_e) filterByArea_bool = true; else filterByArea_bool = false; + if (filterByCircularity == vx_true_e) filterByCircularity_bool = true; else filterByCircularity_bool = false; + if (filterByConvexity == vx_true_e) filterByConvexity_bool = true; else filterByConvexity_bool = false; + if (filterByInertia == vx_true_e) filterByInertia_bool = true; else filterByInertia_bool = false; + cv::SimpleBlobDetector::Params params; + params.blobColor = (uchar)blobColor; + params.thresholdStep = thresholdStep; + params.filterByArea = filterByArea_bool; + params.filterByCircularity = filterByCircularity_bool; + params.filterByColor = filterByColor_bool; + params.filterByConvexity = filterByCircularity_bool; + params.filterByInertia = filterByInertia_bool; + params.maxThreshold = maxThreshold; + params.maxArea = maxArea; + params.maxConvexity = maxConvexity; + params.maxInertiaRatio = maxInertiaRatio; + params.maxCircularity = maxCircularity; + params.maxCircularity = minCircularity; + params.maxInertiaRatio = minInertiaRatio; + params.minThreshold = minThreshold; + params.minRepeatability = minRepeatability; + params.minDistBetweenBlobs = minDistBetweenBlobs; + params.minArea = minArea; + params.minConvexity = minConvexity; + + Ptr simple = SimpleBlobDetector::create(params); + simple->detect(*mat, key_points, *mask_mat); + + //Converting OpenCV Keypoints to OpenVX Keypoints + STATUS_ERROR_CHECK(CV_to_VX_keypoints(key_points, array)); + + return status; +} + +/************************************************************************************************************ +Function to Register the Kernel for Publish +*************************************************************************************************************/ +vx_status CV_simple_blob_detect_initialize_Register(vx_context context) +{ + vx_status status = VX_SUCCESS; + vx_kernel Kernel = vxAddKernel(context, + "org.opencv.simple_blob_detect_initialize", + VX_KERNEL_EXT_CV_SIMPLE_BLOB_DETECT_INITIALIZE, + CV_simple_blob_detector_INITIALIZE_Kernel, + 22, + CV_simple_blob_detector_INITIALIZE_InputValidator, + CV_simple_blob_detector_OutputValidator, + nullptr, + nullptr); + + if (Kernel) + { + PARAM_ERROR_CHECK(vxAddParameterToKernel(Kernel, 0, VX_INPUT, VX_TYPE_IMAGE, VX_PARAMETER_STATE_REQUIRED)); + PARAM_ERROR_CHECK(vxAddParameterToKernel(Kernel, 1, VX_BIDIRECTIONAL, VX_TYPE_ARRAY, VX_PARAMETER_STATE_REQUIRED)); + PARAM_ERROR_CHECK(vxAddParameterToKernel(Kernel, 2, VX_INPUT, VX_TYPE_IMAGE, VX_PARAMETER_STATE_REQUIRED)); + PARAM_ERROR_CHECK(vxAddParameterToKernel(Kernel, 3, VX_INPUT, VX_TYPE_SCALAR, VX_PARAMETER_STATE_REQUIRED)); + PARAM_ERROR_CHECK(vxAddParameterToKernel(Kernel, 4, VX_INPUT, VX_TYPE_SCALAR, VX_PARAMETER_STATE_REQUIRED)); + PARAM_ERROR_CHECK(vxAddParameterToKernel(Kernel, 5, VX_INPUT, VX_TYPE_SCALAR, VX_PARAMETER_STATE_REQUIRED)); + PARAM_ERROR_CHECK(vxAddParameterToKernel(Kernel, 6, VX_INPUT, VX_TYPE_SCALAR, VX_PARAMETER_STATE_REQUIRED)); + PARAM_ERROR_CHECK(vxAddParameterToKernel(Kernel, 7, VX_INPUT, VX_TYPE_SCALAR, VX_PARAMETER_STATE_REQUIRED)); + PARAM_ERROR_CHECK(vxAddParameterToKernel(Kernel, 8, VX_INPUT, VX_TYPE_SCALAR, VX_PARAMETER_STATE_REQUIRED)); + PARAM_ERROR_CHECK(vxAddParameterToKernel(Kernel, 9, VX_INPUT, VX_TYPE_SCALAR, VX_PARAMETER_STATE_REQUIRED)); + PARAM_ERROR_CHECK(vxAddParameterToKernel(Kernel, 10, VX_INPUT, VX_TYPE_SCALAR, VX_PARAMETER_STATE_REQUIRED)); + PARAM_ERROR_CHECK(vxAddParameterToKernel(Kernel, 11, VX_INPUT, VX_TYPE_SCALAR, VX_PARAMETER_STATE_REQUIRED)); + PARAM_ERROR_CHECK(vxAddParameterToKernel(Kernel, 12, VX_INPUT, VX_TYPE_SCALAR, VX_PARAMETER_STATE_REQUIRED)); + PARAM_ERROR_CHECK(vxAddParameterToKernel(Kernel, 13, VX_INPUT, VX_TYPE_SCALAR, VX_PARAMETER_STATE_REQUIRED)); + PARAM_ERROR_CHECK(vxAddParameterToKernel(Kernel, 14, VX_INPUT, VX_TYPE_SCALAR, VX_PARAMETER_STATE_REQUIRED)); + PARAM_ERROR_CHECK(vxAddParameterToKernel(Kernel, 15, VX_INPUT, VX_TYPE_SCALAR, VX_PARAMETER_STATE_REQUIRED)); + PARAM_ERROR_CHECK(vxAddParameterToKernel(Kernel, 16, VX_INPUT, VX_TYPE_SCALAR, VX_PARAMETER_STATE_REQUIRED)); + PARAM_ERROR_CHECK(vxAddParameterToKernel(Kernel, 17, VX_INPUT, VX_TYPE_SCALAR, VX_PARAMETER_STATE_REQUIRED)); + PARAM_ERROR_CHECK(vxAddParameterToKernel(Kernel, 18, VX_INPUT, VX_TYPE_SCALAR, VX_PARAMETER_STATE_REQUIRED)); + PARAM_ERROR_CHECK(vxAddParameterToKernel(Kernel, 19, VX_INPUT, VX_TYPE_SCALAR, VX_PARAMETER_STATE_REQUIRED)); + PARAM_ERROR_CHECK(vxAddParameterToKernel(Kernel, 20, VX_INPUT, VX_TYPE_SCALAR, VX_PARAMETER_STATE_REQUIRED)); + PARAM_ERROR_CHECK(vxAddParameterToKernel(Kernel, 21, VX_INPUT, VX_TYPE_SCALAR, VX_PARAMETER_STATE_REQUIRED)); + PARAM_ERROR_CHECK(vxFinalizeKernel(Kernel)); + } + + if (status != VX_SUCCESS) + { + exit: vxRemoveKernel(Kernel); return VX_FAILURE; + } + + return status; +} diff --git a/vx_ext_cv/OpenCV_subtract.cpp b/vx_ext_cv/OpenCV_subtract.cpp new file mode 100644 index 0000000..1552a4a --- /dev/null +++ b/vx_ext_cv/OpenCV_subtract.cpp @@ -0,0 +1,159 @@ +/* +Copyright (c) 2015 Advanced Micro Devices, Inc. All rights reserved. + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. +*/ + + +#include"publishkernels.h" + +/************************************************************************************************************ +input parameter validator. +param [in] node The handle to the node. +param [in] index The index of the parameter to validate. +*************************************************************************************************************/ +static vx_status VX_CALLBACK CV_subtract_InputValidator(vx_node node, vx_uint32 index) +{ + vx_status status = VX_SUCCESS; + vx_parameter param = vxGetParameterByIndex(node, index); + + if (index == 0) + { + vx_image image; + vx_df_image df_image = VX_DF_IMAGE_VIRT; + STATUS_ERROR_CHECK(vxQueryParameter(param, VX_PARAMETER_ATTRIBUTE_REF, &image, sizeof(vx_image))); + STATUS_ERROR_CHECK(vxQueryImage(image, VX_IMAGE_ATTRIBUTE_FORMAT, &df_image, sizeof(df_image))); + if (df_image != VX_DF_IMAGE_U8 && df_image != VX_DF_IMAGE_S16) + status = VX_ERROR_INVALID_VALUE; + vxReleaseImage(&image); + } + + if (index == 1) + { + vx_image image; + vx_df_image df_image = VX_DF_IMAGE_VIRT; + STATUS_ERROR_CHECK(vxQueryParameter(param, VX_PARAMETER_ATTRIBUTE_REF, &image, sizeof(vx_image))); + STATUS_ERROR_CHECK(vxQueryImage(image, VX_IMAGE_ATTRIBUTE_FORMAT, &df_image, sizeof(df_image))); + if (df_image != VX_DF_IMAGE_U8 && df_image != VX_DF_IMAGE_S16) + status = VX_ERROR_INVALID_VALUE; + vxReleaseImage(&image); + } + + else if (index == 2) + { + vx_image image; + vx_df_image df_image = VX_DF_IMAGE_VIRT; + STATUS_ERROR_CHECK(vxQueryParameter(param, VX_PARAMETER_ATTRIBUTE_REF, &image, sizeof(vx_image))); + STATUS_ERROR_CHECK(vxQueryImage(image, VX_IMAGE_ATTRIBUTE_FORMAT, &df_image, sizeof(df_image))); + if (df_image != VX_DF_IMAGE_U8 && df_image != VX_DF_IMAGE_S16) + status = VX_ERROR_INVALID_VALUE; + vxReleaseImage(&image); + } + + vxReleaseParameter(¶m); + return status; +} + +/************************************************************************************************************ +output parameter validator. +*************************************************************************************************************/ +static vx_status VX_CALLBACK CV_subtract_OutputValidator(vx_node node, vx_uint32 index, vx_meta_format meta) +{ + vx_status status = VX_SUCCESS; + if (index == 2) + { + vx_parameter output_param = vxGetParameterByIndex(node, 2); + vx_image output; vx_uint32 width = 0, height = 0; vx_df_image format = VX_DF_IMAGE_VIRT; + + STATUS_ERROR_CHECK(vxQueryParameter(output_param, VX_PARAMETER_ATTRIBUTE_REF, &output, sizeof(vx_image))); + STATUS_ERROR_CHECK(vxQueryImage(output, VX_IMAGE_ATTRIBUTE_FORMAT, &format, sizeof(format))); + STATUS_ERROR_CHECK(vxQueryImage(output, VX_IMAGE_ATTRIBUTE_WIDTH, &width, sizeof(width))); + STATUS_ERROR_CHECK(vxQueryImage(output, VX_IMAGE_ATTRIBUTE_HEIGHT, &height, sizeof(height))); + + if (format != VX_DF_IMAGE_U8 && format != VX_DF_IMAGE_S16) + status = VX_ERROR_INVALID_VALUE; + + STATUS_ERROR_CHECK(vxSetMetaFormatAttribute(meta, VX_IMAGE_ATTRIBUTE_WIDTH, &width, sizeof(width))); + STATUS_ERROR_CHECK(vxSetMetaFormatAttribute(meta, VX_IMAGE_ATTRIBUTE_HEIGHT, &height, sizeof(height))); + STATUS_ERROR_CHECK(vxSetMetaFormatAttribute(meta, VX_IMAGE_ATTRIBUTE_FORMAT, &format, sizeof(format))); + + vxReleaseImage(&output); + vxReleaseParameter(&output_param); + } + return status; +} + +/************************************************************************************************************ +Execution Kernel +*************************************************************************************************************/ +static vx_status VX_CALLBACK CV_subtract_Kernel(vx_node node, const vx_reference *parameters, vx_uint32 num) +{ + vx_status status = VX_SUCCESS; + + vx_image image_1 = (vx_image) parameters[0]; + vx_image image_2 = (vx_image) parameters[1]; + vx_image image_out = (vx_image) parameters[2]; + Mat *mat_1, *mat_2, bl; + + //Converting VX Image to OpenCV Mat + STATUS_ERROR_CHECK(match_vx_image_parameters(image_1, image_2)); + STATUS_ERROR_CHECK(match_vx_image_parameters(image_1, image_out)); + STATUS_ERROR_CHECK(VX_to_CV_Image(&mat_1, image_1)); + STATUS_ERROR_CHECK(VX_to_CV_Image(&mat_2, image_2)); + + //Compute using OpenCV + subtract(*mat_1, *mat_2, bl); + + //Converting OpenCV Mat into VX Image + STATUS_ERROR_CHECK(CV_to_VX_Image(image_out, &bl)); + + return status; +} + +/************************************************************************************************************ +Function to Register the Kernel for Publish +*************************************************************************************************************/ +vx_status CV_subtract_Register(vx_context context) +{ + vx_status status = VX_SUCCESS; + vx_kernel kernel = vxAddKernel(context, + "org.opencv.subtract", + VX_KERNEL_EXT_CV_SUBTRACT, + CV_subtract_Kernel, + 3, + CV_subtract_InputValidator, + CV_subtract_OutputValidator, + nullptr, + nullptr); + + if (kernel) + { + PARAM_ERROR_CHECK(vxAddParameterToKernel(kernel, 0, VX_INPUT, VX_TYPE_IMAGE, VX_PARAMETER_STATE_REQUIRED)); + PARAM_ERROR_CHECK(vxAddParameterToKernel(kernel, 1, VX_INPUT, VX_TYPE_IMAGE, VX_PARAMETER_STATE_REQUIRED)); + PARAM_ERROR_CHECK(vxAddParameterToKernel(kernel, 2, VX_OUTPUT, VX_TYPE_IMAGE, VX_PARAMETER_STATE_REQUIRED)); + PARAM_ERROR_CHECK(vxFinalizeKernel(kernel)); + } + + if (status != VX_SUCCESS) + { + exit: vxRemoveKernel(kernel); return VX_FAILURE; + } + + return status; +} diff --git a/vx_ext_cv/OpenCV_threshold.cpp b/vx_ext_cv/OpenCV_threshold.cpp new file mode 100644 index 0000000..8ff2125 --- /dev/null +++ b/vx_ext_cv/OpenCV_threshold.cpp @@ -0,0 +1,193 @@ +/* +Copyright (c) 2015 Advanced Micro Devices, Inc. All rights reserved. + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. +*/ + + +#include"publishkernels.h" + +/************************************************************************************************************ +input parameter validator. +param [in] node The handle to the node. +param [in] index The index of the parameter to validate. +*************************************************************************************************************/ +static vx_status VX_CALLBACK CV_threshold_InputValidator(vx_node node, vx_uint32 index) +{ + vx_status status = VX_SUCCESS; + vx_parameter param = vxGetParameterByIndex(node, index); + + if (index == 0) + { + vx_image image; + vx_df_image df_image = VX_DF_IMAGE_VIRT; + STATUS_ERROR_CHECK(vxQueryParameter(param, VX_PARAMETER_ATTRIBUTE_REF, &image, sizeof(vx_image))); + STATUS_ERROR_CHECK(vxQueryImage(image, VX_IMAGE_ATTRIBUTE_FORMAT, &df_image, sizeof(df_image))); + if (df_image != VX_DF_IMAGE_U8) + status = VX_ERROR_INVALID_VALUE; + vxReleaseImage(&image); + } + + else if (index == 1) + { + vx_image image; + vx_df_image df_image = VX_DF_IMAGE_VIRT; + STATUS_ERROR_CHECK(vxQueryParameter(param, VX_PARAMETER_ATTRIBUTE_REF, &image, sizeof(vx_image))); + STATUS_ERROR_CHECK(vxQueryImage(image, VX_IMAGE_ATTRIBUTE_FORMAT, &df_image, sizeof(df_image))); + if (df_image != VX_DF_IMAGE_U8) + status = VX_ERROR_INVALID_VALUE; + vxReleaseImage(&image); + } + + else if (index == 2) + { + vx_scalar scalar = 0; vx_enum type = 0; vx_float32 value = 0; + STATUS_ERROR_CHECK(vxQueryParameter(param, VX_PARAMETER_ATTRIBUTE_REF, &scalar, sizeof(scalar))); + STATUS_ERROR_CHECK(vxQueryScalar(scalar, VX_SCALAR_ATTRIBUTE_TYPE, &type, sizeof(type))); + STATUS_ERROR_CHECK(vxReadScalarValue(scalar, &value)); + if (value < 0 || type != VX_TYPE_FLOAT32) + status = VX_ERROR_INVALID_VALUE; + vxReleaseScalar(&scalar); + } + + else if (index == 3) + { + vx_scalar scalar = 0; vx_enum type = 0; vx_float32 value = 0; + STATUS_ERROR_CHECK(vxQueryParameter(param, VX_PARAMETER_ATTRIBUTE_REF, &scalar, sizeof(scalar))); + STATUS_ERROR_CHECK(vxQueryScalar(scalar, VX_SCALAR_ATTRIBUTE_TYPE, &type, sizeof(type))); + STATUS_ERROR_CHECK(vxReadScalarValue(scalar, &value)); + if (value < 0 || type != VX_TYPE_FLOAT32) + status = VX_ERROR_INVALID_VALUE; + vxReleaseScalar(&scalar); + } + + else if (index == 4) + { + vx_scalar scalar = 0; vx_enum type = 0; vx_int32 value = 0; + STATUS_ERROR_CHECK(vxQueryParameter(param, VX_PARAMETER_ATTRIBUTE_REF, &scalar, sizeof(scalar))); + STATUS_ERROR_CHECK(vxQueryScalar(scalar, VX_SCALAR_ATTRIBUTE_TYPE, &type, sizeof(type))); + STATUS_ERROR_CHECK(vxReadScalarValue(scalar, &value)); + if (value < 0 || type != VX_TYPE_INT32) + status = VX_ERROR_INVALID_VALUE; + vxReleaseScalar(&scalar); + } + + vxReleaseParameter(¶m); + return status; +} + +/************************************************************************************************************ +output parameter validator. +*************************************************************************************************************/ +static vx_status VX_CALLBACK CV_threshold_OutputValidator(vx_node node, vx_uint32 index, vx_meta_format meta) +{ + vx_status status = VX_SUCCESS; + if (index == 1) + { + vx_parameter output_param = vxGetParameterByIndex(node, 1); + vx_image output; vx_uint32 width = 0, height = 0; vx_df_image format = VX_DF_IMAGE_VIRT; + + STATUS_ERROR_CHECK(vxQueryParameter(output_param, VX_PARAMETER_ATTRIBUTE_REF, &output, sizeof(vx_image))); + STATUS_ERROR_CHECK(vxQueryImage(output, VX_IMAGE_ATTRIBUTE_FORMAT, &format, sizeof(format))); + STATUS_ERROR_CHECK(vxQueryImage(output, VX_IMAGE_ATTRIBUTE_WIDTH, &width, sizeof(width))); + STATUS_ERROR_CHECK(vxQueryImage(output, VX_IMAGE_ATTRIBUTE_HEIGHT, &height, sizeof(height))); + + if (format != VX_DF_IMAGE_U8) + status = VX_ERROR_INVALID_VALUE; + + STATUS_ERROR_CHECK(vxSetMetaFormatAttribute(meta, VX_IMAGE_ATTRIBUTE_WIDTH, &width, sizeof(width))); + STATUS_ERROR_CHECK(vxSetMetaFormatAttribute(meta, VX_IMAGE_ATTRIBUTE_HEIGHT, &height, sizeof(height))); + STATUS_ERROR_CHECK(vxSetMetaFormatAttribute(meta, VX_IMAGE_ATTRIBUTE_FORMAT, &format, sizeof(format))); + + vxReleaseImage(&output); + vxReleaseParameter(&output_param); + } + return status; +} + +/************************************************************************************************************ +Execution Kernel +*************************************************************************************************************/ +static vx_status VX_CALLBACK CV_threshold_Kernel(vx_node node, const vx_reference *parameters, vx_uint32 num) +{ + vx_status status = VX_SUCCESS; + + vx_image image_in = (vx_image) parameters[0]; + vx_image image_out = (vx_image) parameters[1]; + vx_scalar THRESH = (vx_scalar) parameters[2]; + vx_scalar MAXVAL = (vx_scalar) parameters[3]; + vx_scalar TYPE = (vx_scalar) parameters[4]; + + Mat *mat, bl; + int type; + float thresh, maxVal; + vx_float32 value_f = 0; + vx_int32 value = 0; + + //Extracting Values from the Scalar into Ksize and Ddepth + STATUS_ERROR_CHECK(vxReadScalarValue(THRESH, &value_f)); thresh = value_f; + STATUS_ERROR_CHECK(vxReadScalarValue(MAXVAL, &value_f)); maxVal = value_f; + STATUS_ERROR_CHECK(vxReadScalarValue(TYPE, &value)); type = value; + + //Converting VX Image to OpenCV Mat + STATUS_ERROR_CHECK(match_vx_image_parameters(image_in, image_out)); + STATUS_ERROR_CHECK(VX_to_CV_Image(&mat, image_in)); + + //Compute using OpenCV + cv::threshold(*mat, bl, thresh, maxVal, type); + + //Converting OpenCV Mat into VX Image + STATUS_ERROR_CHECK(CV_to_VX_Image(image_out, &bl)); + + return status; +} + +/************************************************************************************************************ +Function to Register the Kernel for Publish +*************************************************************************************************************/ +vx_status CV_threshold_Register(vx_context context) +{ + vx_status status = VX_SUCCESS; + vx_kernel Kernel = vxAddKernel(context, + "org.opencv.threshold", + VX_KERNEL_EXT_CV_THRESHOLD, + CV_threshold_Kernel, + 5, + CV_threshold_InputValidator, + CV_threshold_OutputValidator, + nullptr, + nullptr); + + if (Kernel) + { + PARAM_ERROR_CHECK(vxAddParameterToKernel(Kernel, 0, VX_INPUT, VX_TYPE_IMAGE, VX_PARAMETER_STATE_REQUIRED)); + PARAM_ERROR_CHECK(vxAddParameterToKernel(Kernel, 1, VX_OUTPUT, VX_TYPE_IMAGE, VX_PARAMETER_STATE_REQUIRED)); + PARAM_ERROR_CHECK(vxAddParameterToKernel(Kernel, 2, VX_INPUT, VX_TYPE_SCALAR, VX_PARAMETER_STATE_REQUIRED)); + PARAM_ERROR_CHECK(vxAddParameterToKernel(Kernel, 3, VX_INPUT, VX_TYPE_SCALAR, VX_PARAMETER_STATE_REQUIRED)); + PARAM_ERROR_CHECK(vxAddParameterToKernel(Kernel, 4, VX_INPUT, VX_TYPE_SCALAR, VX_PARAMETER_STATE_REQUIRED)); + PARAM_ERROR_CHECK(vxFinalizeKernel(Kernel)); + } + + if (status != VX_SUCCESS) + { + exit: vxRemoveKernel(Kernel); return VX_FAILURE; + } + + return status; +} diff --git a/vx_ext_cv/OpenCV_transpose.cpp b/vx_ext_cv/OpenCV_transpose.cpp new file mode 100644 index 0000000..52ffb26 --- /dev/null +++ b/vx_ext_cv/OpenCV_transpose.cpp @@ -0,0 +1,152 @@ +/* +Copyright (c) 2015 Advanced Micro Devices, Inc. All rights reserved. + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. +*/ + + +#include"publishkernels.h" +/************************************************************************************************************ +input parameter validator. +param [in] node The handle to the node. +param [in] index The index of the parameter to validate. +*************************************************************************************************************/ +static vx_status VX_CALLBACK CV_transpose_InputValidator(vx_node node, vx_uint32 index) +{ + vx_status status = VX_SUCCESS; + vx_parameter param = vxGetParameterByIndex(node, index); + + if (index == 0) + { + vx_image image; + vx_df_image df_image = VX_DF_IMAGE_VIRT; + STATUS_ERROR_CHECK(vxQueryParameter(param, VX_PARAMETER_ATTRIBUTE_REF, &image, sizeof(vx_image))); + STATUS_ERROR_CHECK(vxQueryImage(image, VX_IMAGE_ATTRIBUTE_FORMAT, &df_image, sizeof(df_image))); + if (df_image != VX_DF_IMAGE_U8 && df_image != VX_DF_IMAGE_S16) + status = VX_ERROR_INVALID_VALUE; + vxReleaseImage(&image); + } + + else if (index == 1) + { + vx_image image; + vx_df_image df_image = VX_DF_IMAGE_VIRT; + STATUS_ERROR_CHECK(vxQueryParameter(param, VX_PARAMETER_ATTRIBUTE_REF, &image, sizeof(vx_image))); + STATUS_ERROR_CHECK(vxQueryImage(image, VX_IMAGE_ATTRIBUTE_FORMAT, &df_image, sizeof(df_image))); + if (df_image != VX_DF_IMAGE_U8 && df_image != VX_DF_IMAGE_S16) + status = VX_ERROR_INVALID_VALUE; + vxReleaseImage(&image); + } + + vxReleaseParameter(¶m); + return status; +} + +/************************************************************************************************************ +output parameter validator. +*************************************************************************************************************/ +static vx_status VX_CALLBACK CV_transpose_OutputValidator(vx_node node, vx_uint32 index, vx_meta_format meta) +{ + vx_status status = VX_SUCCESS; + if (index == 1) + { + vx_parameter output_param = vxGetParameterByIndex(node, 1); + vx_image output; vx_uint32 width = 0, height = 0; vx_df_image format = VX_DF_IMAGE_VIRT; + + STATUS_ERROR_CHECK(vxQueryParameter(output_param, VX_PARAMETER_ATTRIBUTE_REF, &output, sizeof(vx_image))); + STATUS_ERROR_CHECK(vxQueryImage(output, VX_IMAGE_ATTRIBUTE_FORMAT, &format, sizeof(format))); + STATUS_ERROR_CHECK(vxQueryImage(output, VX_IMAGE_ATTRIBUTE_WIDTH, &width, sizeof(width))); + STATUS_ERROR_CHECK(vxQueryImage(output, VX_IMAGE_ATTRIBUTE_HEIGHT, &height, sizeof(height))); + + if (format != VX_DF_IMAGE_U8 && format != VX_DF_IMAGE_S16) + status = VX_ERROR_INVALID_VALUE; + + STATUS_ERROR_CHECK(vxSetMetaFormatAttribute(meta, VX_IMAGE_ATTRIBUTE_WIDTH, &width, sizeof(width))); + STATUS_ERROR_CHECK(vxSetMetaFormatAttribute(meta, VX_IMAGE_ATTRIBUTE_HEIGHT, &height, sizeof(height))); + STATUS_ERROR_CHECK(vxSetMetaFormatAttribute(meta, VX_IMAGE_ATTRIBUTE_FORMAT, &format, sizeof(format))); + + vxReleaseImage(&output); + vxReleaseParameter(&output_param); + } + return status; +} + +/************************************************************************************************************ +Execution Kernel +*************************************************************************************************************/ +static vx_status VX_CALLBACK CV_transpose_Kernel(vx_node node, const vx_reference *parameters, vx_uint32 num) +{ + vx_status status = VX_SUCCESS; + + vx_image image_in = (vx_image) parameters[0]; + vx_image image_out = (vx_image) parameters[1]; + + Mat *mat, bl; + + //Validation + vx_uint32 width_in, height_in, width_out, height_out; + width_in = height_in = width_out = height_out = 0; + STATUS_ERROR_CHECK(vxQueryImage(image_in, VX_IMAGE_ATTRIBUTE_WIDTH, &width_in, sizeof(width_in))); + STATUS_ERROR_CHECK(vxQueryImage(image_in, VX_IMAGE_ATTRIBUTE_HEIGHT, &height_in, sizeof(height_in))); + STATUS_ERROR_CHECK(vxQueryImage(image_out, VX_IMAGE_ATTRIBUTE_WIDTH, &width_out, sizeof(width_out))); + STATUS_ERROR_CHECK(vxQueryImage(image_out, VX_IMAGE_ATTRIBUTE_HEIGHT, &height_out, sizeof(height_out))); + if (height_in != width_out || width_in != height_out) { status = VX_ERROR_INVALID_DIMENSION; return status; } + + //Converting VX Image to OpenCV Mat + STATUS_ERROR_CHECK(VX_to_CV_Image(&mat, image_in)); + + //Compute using OpenCV + cv::transpose(*mat, bl); + + //Converting OpenCV Mat into VX Image + STATUS_ERROR_CHECK(CV_to_VX_Image(image_out, &bl)); + + return status; +} + +/************************************************************************************************************ +Function to Register the Kernel for Publish +*************************************************************************************************************/ +vx_status CV_transpose_Register(vx_context context) +{ + vx_status status = VX_SUCCESS; + vx_kernel kernel = vxAddKernel(context, + "org.opencv.transpose", + VX_KERNEL_EXT_CV_TRANSPOSE, + CV_transpose_Kernel, + 2, + CV_transpose_InputValidator, + CV_transpose_OutputValidator, + nullptr, + nullptr); + + if (kernel) + { + PARAM_ERROR_CHECK(vxAddParameterToKernel(kernel, 0, VX_INPUT, VX_TYPE_IMAGE, VX_PARAMETER_STATE_REQUIRED)); + PARAM_ERROR_CHECK(vxAddParameterToKernel(kernel, 1, VX_OUTPUT, VX_TYPE_IMAGE, VX_PARAMETER_STATE_REQUIRED)); + PARAM_ERROR_CHECK(vxFinalizeKernel(kernel)); + } + + if (status != VX_SUCCESS) + { + exit: vxRemoveKernel(kernel); return VX_FAILURE; + } + + return status; +} diff --git a/vx_ext_cv/OpenCV_warpAffine.cpp b/vx_ext_cv/OpenCV_warpAffine.cpp new file mode 100644 index 0000000..d82051a --- /dev/null +++ b/vx_ext_cv/OpenCV_warpAffine.cpp @@ -0,0 +1,217 @@ +/* +Copyright (c) 2015 Advanced Micro Devices, Inc. All rights reserved. + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. +*/ + + +#include"publishkernels.h" + +/************************************************************************************************************ +input parameter validator. +param [in] node The handle to the node. +param [in] index The index of the parameter to validate. +*************************************************************************************************************/ +static vx_status VX_CALLBACK CV_warpAffine_InputValidator(vx_node node, vx_uint32 index) +{ + vx_status status = VX_SUCCESS; + vx_parameter param = vxGetParameterByIndex(node, index); + + if (index == 0) + { + vx_image image; + vx_df_image df_image = VX_DF_IMAGE_VIRT; + STATUS_ERROR_CHECK(vxQueryParameter(param, VX_PARAMETER_ATTRIBUTE_REF, &image, sizeof(vx_image))); + STATUS_ERROR_CHECK(vxQueryImage(image, VX_IMAGE_ATTRIBUTE_FORMAT, &df_image, sizeof(df_image))); + if (df_image != VX_DF_IMAGE_U8 && df_image != VX_DF_IMAGE_S16 && df_image != VX_DF_IMAGE_U16) + status = VX_ERROR_INVALID_VALUE; + vxReleaseImage(&image); + } + + else if (index == 1) + { + vx_image image; + vx_df_image df_image = VX_DF_IMAGE_VIRT; + STATUS_ERROR_CHECK(vxQueryParameter(param, VX_PARAMETER_ATTRIBUTE_REF, &image, sizeof(vx_image))); + STATUS_ERROR_CHECK(vxQueryImage(image, VX_IMAGE_ATTRIBUTE_FORMAT, &df_image, sizeof(df_image))); + if (df_image != VX_DF_IMAGE_U8) + status = VX_ERROR_INVALID_VALUE; + vxReleaseImage(&image); + } + + else if (index == 2) + { + vx_matrix mat; + STATUS_ERROR_CHECK(vxQueryParameter(param, VX_PARAMETER_ATTRIBUTE_REF, &mat, sizeof(vx_matrix))); + vxReleaseMatrix(&mat); + } + + else if (index == 3) + { + vx_scalar scalar = 0; vx_enum type = 0; vx_int32 value = 0; + STATUS_ERROR_CHECK(vxQueryParameter(param, VX_PARAMETER_ATTRIBUTE_REF, &scalar, sizeof(scalar))); + STATUS_ERROR_CHECK(vxQueryScalar(scalar, VX_SCALAR_ATTRIBUTE_TYPE, &type, sizeof(type))); + STATUS_ERROR_CHECK(vxReadScalarValue(scalar, &value)); + if (value < 0 || type != VX_TYPE_INT32) + status = VX_ERROR_INVALID_VALUE; + vxReleaseScalar(&scalar); + } + + else if (index == 4) + { + vx_scalar scalar = 0; vx_enum type = 0; vx_int32 value = 0; + STATUS_ERROR_CHECK(vxQueryParameter(param, VX_PARAMETER_ATTRIBUTE_REF, &scalar, sizeof(scalar))); + STATUS_ERROR_CHECK(vxQueryScalar(scalar, VX_SCALAR_ATTRIBUTE_TYPE, &type, sizeof(type))); + STATUS_ERROR_CHECK(vxReadScalarValue(scalar, &value)); + if (value < 0 || type != VX_TYPE_INT32) + status = VX_ERROR_INVALID_VALUE; + vxReleaseScalar(&scalar); + } + + else if (index == 5) + { + vx_scalar scalar = 0; vx_enum type = 0; vx_int32 value = 0; + STATUS_ERROR_CHECK(vxQueryParameter(param, VX_PARAMETER_ATTRIBUTE_REF, &scalar, sizeof(scalar))); + STATUS_ERROR_CHECK(vxQueryScalar(scalar, VX_SCALAR_ATTRIBUTE_TYPE, &type, sizeof(type))); + STATUS_ERROR_CHECK(vxReadScalarValue(scalar, &value)); + if (value < 0 || type != VX_TYPE_INT32) + status = VX_ERROR_INVALID_VALUE; + vxReleaseScalar(&scalar); + } + + else if (index == 6) + { + vx_scalar scalar = 0; vx_enum type = 0; vx_int32 value = 0; + STATUS_ERROR_CHECK(vxQueryParameter(param, VX_PARAMETER_ATTRIBUTE_REF, &scalar, sizeof(scalar))); + STATUS_ERROR_CHECK(vxQueryScalar(scalar, VX_SCALAR_ATTRIBUTE_TYPE, &type, sizeof(type))); + STATUS_ERROR_CHECK(vxReadScalarValue(scalar, &value)); + if (value < 0 || type != VX_TYPE_INT32) + status = VX_ERROR_INVALID_VALUE; + vxReleaseScalar(&scalar); + } + + vxReleaseParameter(¶m); + return status; +} + +/************************************************************************************************************ +output parameter validator. +*************************************************************************************************************/ +static vx_status VX_CALLBACK CV_warpAffine_OutputValidator(vx_node node, vx_uint32 index, vx_meta_format meta) +{ + vx_status status = VX_SUCCESS; + if (index == 1) + { + vx_parameter output_param = vxGetParameterByIndex(node, 1); + vx_image output; vx_uint32 width = 0, height = 0; vx_df_image format = VX_DF_IMAGE_VIRT; + + STATUS_ERROR_CHECK(vxQueryParameter(output_param, VX_PARAMETER_ATTRIBUTE_REF, &output, sizeof(vx_image))); + STATUS_ERROR_CHECK(vxQueryImage(output, VX_IMAGE_ATTRIBUTE_FORMAT, &format, sizeof(format))); + STATUS_ERROR_CHECK(vxQueryImage(output, VX_IMAGE_ATTRIBUTE_WIDTH, &width, sizeof(width))); + STATUS_ERROR_CHECK(vxQueryImage(output, VX_IMAGE_ATTRIBUTE_HEIGHT, &height, sizeof(height))); + + if (format != VX_DF_IMAGE_U8) + status = VX_ERROR_INVALID_VALUE; + + STATUS_ERROR_CHECK(vxSetMetaFormatAttribute(meta, VX_IMAGE_ATTRIBUTE_WIDTH, &width, sizeof(width))); + STATUS_ERROR_CHECK(vxSetMetaFormatAttribute(meta, VX_IMAGE_ATTRIBUTE_HEIGHT, &height, sizeof(height))); + STATUS_ERROR_CHECK(vxSetMetaFormatAttribute(meta, VX_IMAGE_ATTRIBUTE_FORMAT, &format, sizeof(format))); + + vxReleaseImage(&output); + vxReleaseParameter(&output_param); + } + return status; +} + +/************************************************************************************************************ +Execution Kernel +*************************************************************************************************************/ +static vx_status VX_CALLBACK CV_warpAffine_Kernel(vx_node node, const vx_reference *parameters, vx_uint32 num) +{ + vx_status status = VX_SUCCESS; + + vx_image image_in = (vx_image) parameters[0]; + vx_image image_out = (vx_image) parameters[1]; + vx_matrix KERNEL = (vx_matrix) parameters[2]; + vx_scalar A_X = (vx_scalar) parameters[3]; + vx_scalar A_Y = (vx_scalar) parameters[4]; + vx_scalar FLAGS = (vx_scalar) parameters[5]; + vx_scalar BORDER = (vx_scalar) parameters[6]; + + Mat *mat, bl; + int flags; + int a_x = -1, a_y = -1, border = 4; + vx_int32 value = 0; + + //Extracting Values from the Scalar + STATUS_ERROR_CHECK(vxReadScalarValue(FLAGS, &value)); flags = value; + STATUS_ERROR_CHECK(vxReadScalarValue(A_X, &value)); a_x = value; + STATUS_ERROR_CHECK(vxReadScalarValue(A_Y, &value)); a_y = value; + STATUS_ERROR_CHECK(vxReadScalarValue(BORDER, &value)); border = value; + + //Converting VX Image to OpenCV Mat + STATUS_ERROR_CHECK(match_vx_image_parameters(image_in, image_out)); + STATUS_ERROR_CHECK(VX_to_CV_Image(&mat, image_in)); + + //Compute using OpenCV + Mat *M; + STATUS_ERROR_CHECK(VX_to_CV_MATRIX(&M, KERNEL)); + cv::warpAffine(*mat, bl, *M, Size(a_x, a_y), flags, border); + + //Converting OpenCV Mat into VX Image + STATUS_ERROR_CHECK(CV_to_VX_Image(image_out, &bl)); + + return status; +} + +/************************************************************************************************************ +Function to Register the Kernel for Publish +*************************************************************************************************************/ +vx_status CV_warpAffine_Register(vx_context context) +{ + vx_status status = VX_SUCCESS; + vx_kernel Kernel = vxAddKernel(context, + "org.opencv.warpaffine", + VX_KERNEL_EXT_CV_WARP_AFFINE, + CV_warpAffine_Kernel, + 7, + CV_warpAffine_InputValidator, + CV_warpAffine_OutputValidator, + nullptr, + nullptr); + + if (Kernel) + { + PARAM_ERROR_CHECK(vxAddParameterToKernel(Kernel, 0, VX_INPUT, VX_TYPE_IMAGE, VX_PARAMETER_STATE_REQUIRED)); + PARAM_ERROR_CHECK(vxAddParameterToKernel(Kernel, 1, VX_OUTPUT, VX_TYPE_IMAGE, VX_PARAMETER_STATE_REQUIRED)); + PARAM_ERROR_CHECK(vxAddParameterToKernel(Kernel, 2, VX_INPUT, VX_TYPE_MATRIX, VX_PARAMETER_STATE_REQUIRED)); + PARAM_ERROR_CHECK(vxAddParameterToKernel(Kernel, 3, VX_INPUT, VX_TYPE_SCALAR, VX_PARAMETER_STATE_REQUIRED)); + PARAM_ERROR_CHECK(vxAddParameterToKernel(Kernel, 4, VX_INPUT, VX_TYPE_SCALAR, VX_PARAMETER_STATE_REQUIRED)); + PARAM_ERROR_CHECK(vxAddParameterToKernel(Kernel, 5, VX_INPUT, VX_TYPE_SCALAR, VX_PARAMETER_STATE_REQUIRED)); + PARAM_ERROR_CHECK(vxAddParameterToKernel(Kernel, 6, VX_INPUT, VX_TYPE_SCALAR, VX_PARAMETER_STATE_REQUIRED)); + PARAM_ERROR_CHECK(vxFinalizeKernel(Kernel)); + } + + if (status != VX_SUCCESS) + { + exit: vxRemoveKernel(Kernel); return VX_FAILURE; + } + + return status; +} diff --git a/vx_ext_cv/OpenCV_warpPerspective.cpp b/vx_ext_cv/OpenCV_warpPerspective.cpp new file mode 100644 index 0000000..46a5a7f --- /dev/null +++ b/vx_ext_cv/OpenCV_warpPerspective.cpp @@ -0,0 +1,217 @@ +/* +Copyright (c) 2015 Advanced Micro Devices, Inc. All rights reserved. + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. +*/ + + +#include"publishkernels.h" + +/************************************************************************************************************ +input parameter validator. +param [in] node The handle to the node. +param [in] index The index of the parameter to validate. +*************************************************************************************************************/ +static vx_status VX_CALLBACK CV_warpPerspective_InputValidator(vx_node node, vx_uint32 index) +{ + vx_status status = VX_SUCCESS; + vx_parameter param = vxGetParameterByIndex(node, index); + + if (index == 0) + { + vx_image image; + vx_df_image df_image = VX_DF_IMAGE_VIRT; + STATUS_ERROR_CHECK(vxQueryParameter(param, VX_PARAMETER_ATTRIBUTE_REF, &image, sizeof(vx_image))); + STATUS_ERROR_CHECK(vxQueryImage(image, VX_IMAGE_ATTRIBUTE_FORMAT, &df_image, sizeof(df_image))); + if (df_image != VX_DF_IMAGE_U8 && df_image != VX_DF_IMAGE_S16 && df_image != VX_DF_IMAGE_U16) + status = VX_ERROR_INVALID_VALUE; + vxReleaseImage(&image); + } + + else if (index == 1) + { + vx_image image; + vx_df_image df_image = VX_DF_IMAGE_VIRT; + STATUS_ERROR_CHECK(vxQueryParameter(param, VX_PARAMETER_ATTRIBUTE_REF, &image, sizeof(vx_image))); + STATUS_ERROR_CHECK(vxQueryImage(image, VX_IMAGE_ATTRIBUTE_FORMAT, &df_image, sizeof(df_image))); + if (df_image != VX_DF_IMAGE_U8) + status = VX_ERROR_INVALID_VALUE; + vxReleaseImage(&image); + } + + else if (index == 2) + { + vx_matrix mat; + STATUS_ERROR_CHECK(vxQueryParameter(param, VX_PARAMETER_ATTRIBUTE_REF, &mat, sizeof(vx_matrix))); + vxReleaseMatrix(&mat); + } + + else if (index == 3) + { + vx_scalar scalar = 0; vx_enum type = 0; vx_int32 value = 0; + STATUS_ERROR_CHECK(vxQueryParameter(param, VX_PARAMETER_ATTRIBUTE_REF, &scalar, sizeof(scalar))); + STATUS_ERROR_CHECK(vxQueryScalar(scalar, VX_SCALAR_ATTRIBUTE_TYPE, &type, sizeof(type))); + STATUS_ERROR_CHECK(vxReadScalarValue(scalar, &value)); + if (value < 0 || type != VX_TYPE_INT32) + status = VX_ERROR_INVALID_VALUE; + vxReleaseScalar(&scalar); + } + + else if (index == 4) + { + vx_scalar scalar = 0; vx_enum type = 0; vx_int32 value = 0; + STATUS_ERROR_CHECK(vxQueryParameter(param, VX_PARAMETER_ATTRIBUTE_REF, &scalar, sizeof(scalar))); + STATUS_ERROR_CHECK(vxQueryScalar(scalar, VX_SCALAR_ATTRIBUTE_TYPE, &type, sizeof(type))); + STATUS_ERROR_CHECK(vxReadScalarValue(scalar, &value)); + if (value < 0 || type != VX_TYPE_INT32) + status = VX_ERROR_INVALID_VALUE; + vxReleaseScalar(&scalar); + } + + else if (index == 5) + { + vx_scalar scalar = 0; vx_enum type = 0; vx_int32 value = 0; + STATUS_ERROR_CHECK(vxQueryParameter(param, VX_PARAMETER_ATTRIBUTE_REF, &scalar, sizeof(scalar))); + STATUS_ERROR_CHECK(vxQueryScalar(scalar, VX_SCALAR_ATTRIBUTE_TYPE, &type, sizeof(type))); + STATUS_ERROR_CHECK(vxReadScalarValue(scalar, &value)); + if (value < 0 || type != VX_TYPE_INT32) + status = VX_ERROR_INVALID_VALUE; + vxReleaseScalar(&scalar); + } + + else if (index == 6) + { + vx_scalar scalar = 0; vx_enum type = 0; vx_int32 value = 0; + STATUS_ERROR_CHECK(vxQueryParameter(param, VX_PARAMETER_ATTRIBUTE_REF, &scalar, sizeof(scalar))); + STATUS_ERROR_CHECK(vxQueryScalar(scalar, VX_SCALAR_ATTRIBUTE_TYPE, &type, sizeof(type))); + STATUS_ERROR_CHECK(vxReadScalarValue(scalar, &value)); + if (value < 0 || type != VX_TYPE_INT32) + status = VX_ERROR_INVALID_VALUE; + vxReleaseScalar(&scalar); + } + + vxReleaseParameter(¶m); + return status; +} + +/************************************************************************************************************ +output parameter validator. +*************************************************************************************************************/ +static vx_status VX_CALLBACK CV_warpPerspective_OutputValidator(vx_node node, vx_uint32 index, vx_meta_format meta) +{ + vx_status status = VX_SUCCESS; + if (index == 1) + { + vx_parameter output_param = vxGetParameterByIndex(node, 1); + vx_image output; vx_uint32 width = 0, height = 0; vx_df_image format = VX_DF_IMAGE_VIRT; + + STATUS_ERROR_CHECK(vxQueryParameter(output_param, VX_PARAMETER_ATTRIBUTE_REF, &output, sizeof(vx_image))); + STATUS_ERROR_CHECK(vxQueryImage(output, VX_IMAGE_ATTRIBUTE_FORMAT, &format, sizeof(format))); + STATUS_ERROR_CHECK(vxQueryImage(output, VX_IMAGE_ATTRIBUTE_WIDTH, &width, sizeof(width))); + STATUS_ERROR_CHECK(vxQueryImage(output, VX_IMAGE_ATTRIBUTE_HEIGHT, &height, sizeof(height))); + + if (format != VX_DF_IMAGE_U8) + status = VX_ERROR_INVALID_VALUE; + + STATUS_ERROR_CHECK(vxSetMetaFormatAttribute(meta, VX_IMAGE_ATTRIBUTE_WIDTH, &width, sizeof(width))); + STATUS_ERROR_CHECK(vxSetMetaFormatAttribute(meta, VX_IMAGE_ATTRIBUTE_HEIGHT, &height, sizeof(height))); + STATUS_ERROR_CHECK(vxSetMetaFormatAttribute(meta, VX_IMAGE_ATTRIBUTE_FORMAT, &format, sizeof(format))); + + vxReleaseImage(&output); + vxReleaseParameter(&output_param); + } + return status; +} + +/************************************************************************************************************ +Execution Kernel +*************************************************************************************************************/ +static vx_status VX_CALLBACK CV_warpPerspective_Kernel(vx_node node, const vx_reference *parameters, vx_uint32 num) +{ + vx_status status = VX_SUCCESS; + + vx_image image_in = (vx_image) parameters[0]; + vx_image image_out = (vx_image) parameters[1]; + vx_matrix KERNEL = (vx_matrix) parameters[2]; + vx_scalar A_X = (vx_scalar) parameters[3]; + vx_scalar A_Y = (vx_scalar) parameters[4]; + vx_scalar FLAGS = (vx_scalar) parameters[5]; + vx_scalar BORDER = (vx_scalar) parameters[6]; + + Mat *mat, bl; + int flags; + int a_x = -1, a_y = -1, border = 4; + vx_int32 value = 0; + + //Extracting Values from the Scalar into Ksize and Ddepth + STATUS_ERROR_CHECK(vxReadScalarValue(FLAGS, &value)); flags = value; + STATUS_ERROR_CHECK(vxReadScalarValue(A_X, &value)); a_x = value; + STATUS_ERROR_CHECK(vxReadScalarValue(A_Y, &value)); a_y = value; + STATUS_ERROR_CHECK(vxReadScalarValue(BORDER, &value)); border = value; + + //Converting VX Image to OpenCV Mat + STATUS_ERROR_CHECK(match_vx_image_parameters(image_in, image_out)); + STATUS_ERROR_CHECK(VX_to_CV_Image(&mat, image_in)); + + //Compute using OpenCV + Mat *M; + STATUS_ERROR_CHECK(VX_to_CV_MATRIX(&M, KERNEL)); + cv::warpPerspective(*mat, bl, *M, Size(a_x, a_y), flags, border); + + //Converting OpenCV Mat into VX Image + STATUS_ERROR_CHECK(CV_to_VX_Image(image_out, &bl)); + + return status; +} + +/************************************************************************************************************ +Function to Register the Kernel for Publish +*************************************************************************************************************/ +vx_status CV_warpPerspective_Register(vx_context context) +{ + vx_status status = VX_SUCCESS; + vx_kernel Kernel = vxAddKernel(context, + "org.opencv.warpperspective", + VX_KERNEL_EXT_CV_WARP_PERSPECTIVE, + CV_warpPerspective_Kernel, + 7, + CV_warpPerspective_InputValidator, + CV_warpPerspective_OutputValidator, + nullptr, + nullptr); + + if (Kernel) + { + PARAM_ERROR_CHECK(vxAddParameterToKernel(Kernel, 0, VX_INPUT, VX_TYPE_IMAGE, VX_PARAMETER_STATE_REQUIRED)); + PARAM_ERROR_CHECK(vxAddParameterToKernel(Kernel, 1, VX_OUTPUT, VX_TYPE_IMAGE, VX_PARAMETER_STATE_REQUIRED)); + PARAM_ERROR_CHECK(vxAddParameterToKernel(Kernel, 2, VX_INPUT, VX_TYPE_MATRIX, VX_PARAMETER_STATE_REQUIRED)); + PARAM_ERROR_CHECK(vxAddParameterToKernel(Kernel, 3, VX_INPUT, VX_TYPE_SCALAR, VX_PARAMETER_STATE_REQUIRED)); + PARAM_ERROR_CHECK(vxAddParameterToKernel(Kernel, 4, VX_INPUT, VX_TYPE_SCALAR, VX_PARAMETER_STATE_REQUIRED)); + PARAM_ERROR_CHECK(vxAddParameterToKernel(Kernel, 5, VX_INPUT, VX_TYPE_SCALAR, VX_PARAMETER_STATE_REQUIRED)); + PARAM_ERROR_CHECK(vxAddParameterToKernel(Kernel, 6, VX_INPUT, VX_TYPE_SCALAR, VX_PARAMETER_STATE_REQUIRED)); + PARAM_ERROR_CHECK(vxFinalizeKernel(Kernel)); + } + + if (status != VX_SUCCESS) + { + exit: vxRemoveKernel(Kernel); return VX_FAILURE; + } + + return status; +} diff --git a/vx_ext_cv/README.md b/vx_ext_cv/README.md new file mode 100644 index 0000000..d815412 --- /dev/null +++ b/vx_ext_cv/README.md @@ -0,0 +1,75 @@ +## AMD Module for OpenCV-interop from OpenVX (vx_ext_cv) +The vx_ext_cv is an OpenVX module that implemented a mechanism to access OpenCV functionality as OpenVX kernels. These kernels can be access from within OpenVX framework using OpenVX API call [vxLoadKernels](https://www.khronos.org/registry/vx/specs/1.0.1/html/da/d83/group__group__user__kernels.html#gae00b6343fbb0126e3bf0f587b09393a3)(context, "vx_ext_cv"). + +## List of OpenCV-interop kernels +The following is a list of OpenCV functions that have been included in the vx_ext_cv module. + + bilateralFilter​ org.opencv.bilateralfilter + blur​ org.opencv.blur + boxfilter org.opencv.boxfilter + buildPyramid​ org.opencv.buildpyramid + Dilate org.opencv.dilate + Erode org.opencv.erode + filter2D​ org.opencv.filter2d + GaussianBlur org.opencv.gaussianblur + MedianBlur org.opencv.medianblur + morphologyEx​ org.opencv.morphologyex + Laplacian​ org.opencv.laplacian + pyrDown​ org.opencv.pyrdown + pyrUp​ org.opencv.pyrup + sepFilter2D​ org.opencv.sepfilter2d + Sobel org.opencv.sobel + Scharr​ org.opencv.scharr + FAST​ org.opencv.fast + MSER org.opencv.mser_detect + ORB org.opencv.orb_detect + ORB_Compute org.opencv.orb_compute + BRISK org.opencv.brisk_detect + BRISK_Compute org.opencv.brisk_compute + SimpleBlobDetector org.opencv.simple_blob_detect + SimpleBlobDetector_Init org.opencv.simple_blob_detect_initialize + SIFT_Detect org.opencv.sift_detect + SIFT_Compute org.opencv.sift_compute + SURF_Detect org.opencv.surf_detect + SURF_Compute org.opencv.surf_compute + STAR_FEATURE_Detector org.opencv.star_detect + Canny org.opencv.canny + GoodFeature_Detector org.opencv.good_features_to_track + buildOpticalFlowPyramid org.opencv.buildopticalflowpyramid + DistanceTransform org.opencv.distancetransform + Convert_Scale_Abs org.opencv.convertscaleabs + addWeighted​ org.opencv.addweighted + Transpose org.opencv.transpose + Resize org.opencv.resize + AdaptiveThreshold org.opencv.adaptivethreshold + Threshold org.opencv.threshold + cvtcolor org.opencv.cvtcolor + Flip org.opencv.flip + fastNlMeansDenoising org.opencv.fastnlmeansdenoising + fastNlMeansDenoisingColored org.opencv.fastnlmeansdenoisingcolored + AbsDiff org.opencv.absdiff + Compare org.opencv.compare + bitwise_and org.opencv.bitwise_and + bitwise_not org.opencv.bitwise_not + bitwise_or org.opencv.bitwise_or + bitwise_xor org.opencv.bitwise_xor + Add org.opencv.add + Subtract org.opencv.subtract + Multiply org.opencv.multiply + Divide org.opencv.divide + WarpAffine org.opencv.warpaffine + WarpPerspective org.opencv.warpperspective + +## Build Instructions + +#### Pre-requisites +* OpenCV 3.0 [download](http://opencv.org/downloads.html). +* CMake 3.1 or newer [download](http://cmake.org/download/). +* Build amdovx-core project at the same level folder as amdovx-modules build folder +* OpenCV_DIR environment variable should point to OpenCV/build folder + +#### Build using Visual Studio Professional 2013 on 64-bit Windows 10/8.1/7 +* Use amdovx-modules/vx_ext_cv/vx_ext_cv.sln to build for x64 platform + +#### Build using CMake on Linux (Ubuntu 15.10 64-bit) +* Use CMake to configure and generate Makefile diff --git a/vx_ext_cv/include/VX/vx.h b/vx_ext_cv/include/VX/vx.h new file mode 100644 index 0000000..f3f085f --- /dev/null +++ b/vx_ext_cv/include/VX/vx.h @@ -0,0 +1,96 @@ +/* +Copyright (c) 2015 Advanced Micro Devices, Inc. All rights reserved. + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. +*/ + + +/* + * Copyright (c) 2012-2015 The Khronos Group Inc. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and/or associated documentation files (the + * "Materials"), to deal in the Materials without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Materials, and to + * permit persons to whom the Materials are furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Materials. + * + * THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY + * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS. + */ + +#ifndef _OPENVX_H_ +#define _OPENVX_H_ + +/*! + * \file + * \brief The top level OpenVX Header. + */ + +/*! \brief Defines the maximum number of characters in a implementation string. + * \ingroup group_context + */ +#define VX_MAX_IMPLEMENTATION_NAME (64) + +/*! \brief Defines the maximum string length of a kernel name to be added to OpenVX. + * \ingroup group_kernel + */ +#define VX_MAX_KERNEL_NAME (256) + +/*! \brief Defines the maximum length of a message buffer to copy from the log. + * \ingroup group_basic_features + */ +#define VX_MAX_LOG_MESSAGE_LEN (1024) + +#include +#include +#include +#include +#include + +/*! Defines the major version number macro. + * \ingroup group_basic_features + */ +#define VX_VERSION_MAJOR(x) ((x & 0xFF) << 8) + +/*! Defines the minor version number macro. + * \ingroup group_basic_features + */ +#define VX_VERSION_MINOR(x) ((x & 0xFF) << 0) + +/*! \brief Defines the predefined version number for 1.0. + * \ingroup group_basic_features + */ +#define VX_VERSION_1_0 (VX_VERSION_MAJOR(1) | VX_VERSION_MINOR(0)) + +/*! Defines the OpenVX Version Number. + * \ingroup group_basic_features + */ +#define VX_VERSION VX_VERSION_1_0 + +#endif diff --git a/vx_ext_cv/include/VX/vx_api.h b/vx_ext_cv/include/VX/vx_api.h new file mode 100644 index 0000000..6dc7119 --- /dev/null +++ b/vx_ext_cv/include/VX/vx_api.h @@ -0,0 +1,1925 @@ +/* +Copyright (c) 2015 Advanced Micro Devices, Inc. All rights reserved. + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. +*/ + + +/* + * Copyright (c) 2012-2015 The Khronos Group Inc. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and/or associated documentation files (the + * "Materials"), to deal in the Materials without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Materials, and to + * permit persons to whom the Materials are furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Materials. + * + * THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY + * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS. + */ + +#ifndef _OPENVX_API_H_ +#define _OPENVX_API_H_ + +/*! + * \file + * \brief The API definition for OpenVX. + */ + +#ifdef __cplusplus +extern "C" { +#endif + +/*============================================================================== + CONTEXT + =============================================================================*/ + +/*! \brief Creates a \ref vx_context. + * \details This creates a top-level object context for OpenVX. + * \note This is required to do anything else. + * \returns The reference to the implementation context \ref vx_context. Any possible errors + * preventing a successful creation should be checked using \ref vxGetStatus. + * \ingroup group_context + * \post \ref vxReleaseContext + */ +VX_API_ENTRY vx_context VX_API_CALL vxCreateContext(); + +/*! \brief Releases the OpenVX object context. + * \details All reference counted objects are garbage-collected by the return of this call. + * No calls are possible using the parameter context after the context has been + * released until a new reference from \ref vxCreateContext is returned. + * All outstanding references to OpenVX objects from this context are invalid + * after this call. + * \param [in] context The pointer to the reference to the context. + * \post After returning from this function the reference is zeroed. + * \return A \ref vx_status_e enumeration. + * \retval VX_SUCCESS No errors. + * \retval VX_ERROR_INVALID_REFERENCE If context is not a \ref vx_context. + * \ingroup group_context + * \pre \ref vxCreateContext + */ +VX_API_ENTRY vx_status VX_API_CALL vxReleaseContext(vx_context *context); + +/*! \brief Retrieves the context from any reference from within a context. + * \param [in] reference The reference from which to extract the context. + * \ingroup group_context + * \return The overall context that created the particular + * reference. + */ +VX_API_ENTRY vx_context VX_API_CALL vxGetContext(vx_reference reference); + +/*! \brief Queries the context for some specific information. + * \param [in] context The reference to the context. + * \param [in] attribute The attribute to query. Use a \ref vx_context_attribute_e. + * \param [out] ptr The location at which to store the resulting value. + * \param [in] size The size in bytes of the container to which \a ptr points. + * \return A \ref vx_status_e enumeration. + * \retval VX_SUCCESS No errors. + * \retval VX_ERROR_INVALID_REFERENCE If the context is not a \ref vx_context. + * \retval VX_ERROR_INVALID_PARAMETERS If any of the other parameters are incorrect. + * \retval VX_ERROR_NOT_SUPPORTED If the attribute is not supported on this implementation. + * \ingroup group_context + */ +VX_API_ENTRY vx_status VX_API_CALL vxQueryContext(vx_context context, vx_enum attribute, void *ptr, vx_size size); + +/*! \brief Sets an attribute on the context. + * \param [in] context The handle to the overall context. + * \param [in] attribute The attribute to set from \ref vx_context_attribute_e. + * \param [in] ptr The pointer to the data to which to set the attribute. + * \param [in] size The size in bytes of the data to which \a ptr points. + * \return A \ref vx_status_e enumeration. + * \retval VX_SUCCESS No errors. + * \retval VX_ERROR_INVALID_REFERENCE If the context is not a \ref vx_context. + * \retval VX_ERROR_INVALID_PARAMETERS If any of the other parameters are incorrect. + * \retval VX_ERROR_NOT_SUPPORTED If the attribute is not settable. + * \ingroup group_context + */ +VX_API_ENTRY vx_status VX_API_CALL vxSetContextAttribute(vx_context context, vx_enum attribute, const void *ptr, vx_size size); + +/*! \brief Provides a generic API to give platform-specific hints to the implementation. + * \param [in] reference The reference to the object to hint at. + * This could be \ref vx_context, \ref vx_graph, \ref vx_node, \ref vx_image, \ref vx_array, or any other reference. + * \param [in] hint A \ref vx_hint_e \a hint to give the OpenVX context. This is a platform-specific optimization or implementation mechanism. + * \return A \ref vx_status_e enumeration. + * \retval VX_SUCCESS No error. + * \retval VX_ERROR_INVALID_REFERENCE If context or reference is invalid. + * \retval VX_ERROR_NOT_SUPPORTED If the hint is not supported. + * \ingroup group_hint + */ +VX_API_ENTRY vx_status VX_API_CALL vxHint(vx_reference reference, vx_enum hint); + +/*! \brief Provides a generic API to give platform-specific directives to the implementations. + * \param [in] reference The reference to the object to set the directive on. + * This could be \ref vx_context, \ref vx_graph, \ref vx_node, \ref vx_image, \ref vx_array, or any other reference. + * \param [in] directive The directive to set. + * \return A \ref vx_status_e enumeration. + * \retval VX_SUCCESS No error. + * \retval VX_ERROR_INVALID_REFERENCE If context or reference is invalid. + * \retval VX_ERROR_NOT_SUPPORTED If the directive is not supported. + * \ingroup group_directive + */ +VX_API_ENTRY vx_status VX_API_CALL vxDirective(vx_reference reference, vx_enum directive); + +/*! \brief Provides a generic API to return status values from Object constructors if they + * fail. + * \note Users do not need to strictly check every object creator as the errors + * should properly propogate and be detected during verification time or run-time. + * \code + * vx_image img = vxCreateImage(context, 639, 480, VX_DF_IMAGE_UYVY); + * vx_status status = vxGetStatus((vx_reference)img); + * // status == VX_ERROR_INVALID_DIMENSIONS + * vxReleaseImage(&img); + * \endcode + * \pre Appropriate Object Creator function. + * \post Appropriate Object Release function. + * \param [in] reference The reference to check for construction errors. + * \return A \ref vx_status_e enumeration. + * \retval VX_SUCCESS No error. + * \retval * Some error occurred, please check enumeration list and constructor. + * \ingroup group_basic_features + */ +VX_API_ENTRY vx_status VX_API_CALL vxGetStatus(vx_reference reference); + +/*! + * \brief Registers user-defined structures to the context. + * \param [in] context The reference to the implementation context. + * \param [in] size The size of user struct in bytes. + * \return A \ref vx_enum value that is a type given to the User + * to refer to their custom structure when declaring a \ref vx_array + * of that structure. + * \retval VX_TYPE_INVALID If the namespace of types has been exhausted. + * \note This call should only be used once within the lifetime of a context for + * a specific structure. + * + * \snippet vx_arrayrange.c array define + * \ingroup group_adv_array + */ +VX_API_ENTRY vx_enum VX_API_CALL vxRegisterUserStruct(vx_context context, vx_size size); + +/*============================================================================== + IMAGE + =============================================================================*/ + +/*! \brief Creates an opaque reference to an image buffer. + * \details Not guaranteed to exist until the \ref vx_graph containing it has been verified. + * \param [in] context The reference to the implementation context. + * \param [in] width The image width in pixels. + * \param [in] height The image height in pixels. + * \param [in] color The VX_DF_IMAGE (\ref vx_df_image_e) code that represents the format of the image and the color space. + * \returns An image reference \ref vx_image. Any possible errors preventing a successful + * creation should be checked using \ref vxGetStatus. + * \see vxAccessImagePatch to obtain direct memory access to the image data. + * \ingroup group_image + */ +VX_API_ENTRY vx_image VX_API_CALL vxCreateImage(vx_context context, vx_uint32 width, vx_uint32 height, vx_df_image color); + +/*! \brief Creates an image from another image given a rectangle. This second + * reference refers to the data in the original image. Updates to this image + * updates the parent image. The rectangle must be defined within the pixel space + * of the parent image. + * \param [in] img The reference to the parent image. + * \param [in] rect The region of interest rectangle. Must contain points within + * the parent image pixel space. + * \returns An image reference \ref vx_image to the sub-image. Any possible errors preventing a + * successful creation should be checked using \ref vxGetStatus. + * \ingroup group_image + */ +VX_API_ENTRY vx_image VX_API_CALL vxCreateImageFromROI(vx_image img, const vx_rectangle_t *rect); + +/*! \brief Creates a reference to an image object that has a singular, + * uniform value in all pixels. + * \details The value pointer must reflect the specific format of the desired + * image. For example: + * | Color | Value Ptr | + * |:------------|:-----------| + * | \ref VX_DF_IMAGE_U8 | vx_uint8 * | + * | \ref VX_DF_IMAGE_S16 | vx_int16 * | + * | \ref VX_DF_IMAGE_U16 | vx_uint16 *| + * | \ref VX_DF_IMAGE_S32 | vx_int32 * | + * | \ref VX_DF_IMAGE_U32 | vx_uint32 *| + * | \ref VX_DF_IMAGE_RGB | vx_uint8 pixel[3] in R, G, B order | + * | \ref VX_DF_IMAGE_RGBX | vx_uint8 pixels[4] | + * | Any YUV | vx_uint8 pixel[3] in Y, U, V order | + * + * \param [in] context The reference to the implementation context. + * \param [in] width The image width in pixels. + * \param [in] height The image height in pixels. + * \param [in] color The VX_DF_IMAGE (\ref vx_df_image_e) code that represents the format of the image and the color space. + * \param [in] value The pointer to the pixel value to which to set all pixels. + * \returns An image reference \ref vx_image. Any possible errors preventing a + * successful creation should be checked using \ref vxGetStatus. + * \see vxAccessImagePatch to obtain direct memory access to the image data. + * \note \ref vxAccessImagePatch and \ref vxCommitImagePatch may be called with + * a uniform image reference. + * \ingroup group_image + */ +VX_API_ENTRY vx_image VX_API_CALL vxCreateUniformImage(vx_context context, vx_uint32 width, vx_uint32 height, vx_df_image color, const void *value); + +/*! \brief Creates an opaque reference to an image buffer with no direct + * user access. This function allows setting the image width, height, or format. + * \details Virtual data objects allow users to connect various nodes within a + * graph via data references without access to that data, but they also permit the + * implementation to take maximum advantage of possible optimizations. Use this + * API to create a data reference to link two or more nodes together when the + * intermediate data are not required to be accessed by outside entities. This API + * in particular allows the user to define the image format of the data without + * requiring the exact dimensions. Virtual objects are scoped within the graph + * they are declared a part of, and can't be shared outside of this scope. + * All of the following constructions of virtual images are valid. + * \code + * vx_context context = vxCreateContext(); + * vx_graph graph = vxCreateGraph(context); + * vx_image virt[] = { + * vxCreateVirtualImage(graph, 0, 0, VX_DF_IMAGE_U8), // no specified dimension + * vxCreateVirtualImage(graph, 320, 240, VX_DF_IMAGE_VIRT), // no specified format + * vxCreateVirtualImage(graph, 640, 480, VX_DF_IMAGE_U8), // no user access + * }; + * \endcode + * \param [in] graph The reference to the parent graph. + * \param [in] width The width of the image in pixels. A value of zero informs the interface that the value is unspecified. + * \param [in] height The height of the image in pixels. A value of zero informs the interface that the value is unspecified. + * \param [in] color The VX_DF_IMAGE (\ref vx_df_image_e) code that represents the format of the image and the color space. A value of \ref VX_DF_IMAGE_VIRT informs the interface that the format is unspecified. + * \returns An image reference \ref vx_image. Any possible errors preventing a + * successful creation should be checked using \ref vxGetStatus. + * \note Passing this reference to \ref vxAccessImagePatch will return an error. + * \ingroup group_image + */ +VX_API_ENTRY vx_image VX_API_CALL vxCreateVirtualImage(vx_graph graph, vx_uint32 width, vx_uint32 height, vx_df_image color); + +/*! \brief Creates a reference to an image object that was externally allocated. + * \param [in] context The reference to the implementation context. + * \param [in] color See the \ref vx_df_image_e codes. This mandates the + * number of planes needed to be valid in the \a addrs and \a ptrs arrays based on the format given. + * \param [in] addrs[] The array of image patch addressing structures that + * define the dimension and stride of the array of pointers. + * \param [in] ptrs[] The array of platform-defined references to each plane. + * \param [in] import_type \ref vx_import_type_e. When giving \ref VX_IMPORT_TYPE_HOST + * the \a ptrs array is assumed to be HOST accessible pointers to memory. + * \returns An image reference \ref vx_image. Any possible errors preventing a + * successful creation should be checked using \ref vxGetStatus. + * \note The user must call vxAccessImagePatch prior to accessing the pixels of an image, even if the + * image was created via \ref vxCreateImageFromHandle. Reads or writes to memory referenced + * by ptrs[ ] after calling \ref vxCreateImageFromHandle without first calling + * \ref vxAccessImagePatch will result in undefined behavior. + * \ingroup group_image + */ +VX_API_ENTRY vx_image VX_API_CALL vxCreateImageFromHandle(vx_context context, vx_df_image color, vx_imagepatch_addressing_t addrs[], void *ptrs[], vx_enum import_type); + +/*! \brief Retrieves various attributes of an image. + * \param [in] image The reference to the image to query. + * \param [in] attribute The attribute to query. Use a \ref vx_image_attribute_e. + * \param [out] ptr The location at which to store the resulting value. + * \param [in] size The size in bytes of the container to which \a ptr points. + * \return A \ref vx_status_e enumeration. + * \retval VX_SUCCESS No errors. + * \retval VX_ERROR_INVALID_REFERENCE If the image is not a \ref vx_image. + * \retval VX_ERROR_INVALID_PARAMETERS If any of the other parameters are incorrect. + * \retval VX_ERROR_NOT_SUPPORTED If the attribute is not supported on this implementation. + * \ingroup group_image + */ +VX_API_ENTRY vx_status VX_API_CALL vxQueryImage(vx_image image, vx_enum attribute, void *ptr, vx_size size); + +/*! \brief Allows setting attributes on the image. + * \param [in] image The reference to the image on which to set the attribute. + * \param [in] attribute The attribute to set. Use a \ref vx_image_attribute_e enumeration. + * \param [in] ptr The pointer to the location from which to read the value. + * \param [in] size The size in bytes of the object pointed to by \a ptr. + * \return A \ref vx_status_e enumeration. + * \retval VX_SUCCESS No errors. + * \retval VX_ERROR_INVALID_REFERENCE If the image is not a \ref vx_image. + * \retval VX_ERROR_INVALID_PARAMETERS If any of the other parameters are incorrect. + * \ingroup group_image + */ +VX_API_ENTRY vx_status VX_API_CALL vxSetImageAttribute(vx_image image, vx_enum attribute, const void *ptr, vx_size size); + +/*! \brief Releases a reference to an image object. + * The object may not be garbage collected until its total reference count is zero. + * \param [in] image The pointer to the image to release. + * \post After returning from this function the reference is zeroed. + * \return A \ref vx_status_e enumeration. + * \retval VX_SUCCESS No errors. + * \retval VX_ERROR_INVALID_REFERENCE If image is not a \ref vx_image. + * \ingroup group_image + */ +VX_API_ENTRY vx_status VX_API_CALL vxReleaseImage(vx_image *image); + +/*! \brief This computes the size needed to retrieve an image patch from an image. + * \param [in] image The reference to the image from which to extract the patch. + * \param [in] rect The coordinates. Must be 0 <= start < end <= dimension where + * dimension is width for x and height for y. + * \param [in] plane_index The plane index from which to get the data. + * \return vx_size + * \ingroup group_image + */ +VX_API_ENTRY vx_size VX_API_CALL vxComputeImagePatchSize(vx_image image, + const vx_rectangle_t *rect, + vx_uint32 plane_index); + +/*! \brief Allows the User to extract a rectangular patch (subset) of an image from a single plane. + * \param [in] image The reference to the image from which to extract the patch. + * \param [in] rect The coordinates from which to get the patch. Must be 0 <= start < end. + * \param [in] plane_index The plane index from which to get the data. + * \param [in, out] addr A pointer to a structure describing the addressing information of the + * image patch to accessed. + * \arg Input case: ptr is a pointer to a non-NULL pointer. The addr parameter must be the + * address of an addressing + * structure that describes how the user will access the requested image data at address (*ptr). + * \arg Output case: ptr is a pointer to a NULL pointer. The function fills the structure pointed by + * addr with the + * addressing information that the user must consult to access the pixel data at address (*ptr). + * If the image being accessed was created via \ref vxCreateImageFromHandle, then the + * returned addressing information will be the identical to that of the addressing structure provided + * when \ref vxCreateImageFromHandle was called. + + * \param [in, out] ptr A pointer to a pointer to a location to store the requested data. + * \arg Input case: ptr is a pointer to a non-NULL pointer to a valid pixel buffer. This buffer + * will be used in one + * of two ways, depending on the value of the usage parameter. If usage is VX_WRITE_ONLY, then the + * buffer must contain pixel data that the user wants to replace the image's pixel data with. + * Otherwise (i.e., usage is not VX_WRITE_ONLY), the image's current pixel data will be written to the + * memory starting at address (*ptr) as storage memory for the access request. The caller must ensure + * enough memory has been allocated for the requested patch with the requested addressing. + * If image was created via \ref vxCreateImageFromHandle, and the pixel buffer pointed to by (*ptr) overlaps + * the original pixel buffer provided when image was created, then the results of such a call to + * \ref vxAccessImagePatch are undefined. + * \arg Output case: ptr is a pointer to a NULL pointer. This NULL pointer will be overwritten + * with a pointer to the + * address where the requested data can be accessed. If image was created via + * \ref vxCreateImageFromHandle + * then the overwriting pointer must be within the original pixel buffer provided when image was created. + * \arg (*ptr) must eventually be provided as the ptr parameter of a call to + * \ref vxCommitImagePatch. + + * \param [in] usage This declares the intended usage of the pointer using the \ref vx_accessor_e enumeration. For uniform images Only VX_READ_ONLY is supported. + * \note The addr and ptr parameters must both be input, or both be output, otherwise the behavior is undefined. + * \return A \ref vx_status_e enumeration. + * \retval VX_ERROR_OPTIMIZED_AWAY The reference is a virtual image and cannot be accessed or committed. + * \retval VX_ERROR_INVALID_PARAMETERS The \a start, \a end, \a plane_index, \a stride_x, or \a stride_y pointer is incorrect. + * \retval VX_ERROR_INVALID_REFERENCE The image reference is not actually an image reference. + * \note The user may ask for data outside the bounds of the valid region, but + * such data has an undefined value. + * \note Users must be cautious to prevent passing in \e uninitialized pointers or + * addresses of uninitialized pointers to this function. + * \pre \ref vxComputeImagePatchSize if users wish to allocate their own memory. + * \post \ref vxCommitImagePatch with same (*ptr) value. + * \ingroup group_image + * \include vx_imagepatch.c + */ +VX_API_ENTRY vx_status VX_API_CALL vxAccessImagePatch(vx_image image, + const vx_rectangle_t *rect, + vx_uint32 plane_index, + vx_imagepatch_addressing_t *addr, + void **ptr, + vx_enum usage); + +/*! \brief This allows the User to commit a rectangular patch (subset) of an image from a single plane. + * \param [in] image The reference to the image from which to extract the patch. + * \param [in] rect The coordinates to which to set the patch. Must be 0 <= start <= end. + * This may be 0 or a rectangle of zero area in order to indicate that the commit + * must only decrement the reference count. + * \param [in] plane_index The plane index to which to set the data. + * \param [in] addr The addressing information for the image patch. + * \param [in] ptr A pointer to a pixel buffer to be committed. If the user previously provided a + * pointer to this buffer to \ref vxAccessImagePatch, the buffer can be + * freed or re-used after \ref vxCommitImagePatch completes. If the pointer was returned by + * \ref vxAccessImagePatch, reads or writes to the location pointed by ptr after + * \ref vxCommitImagePatch completes will result in undefined behavior. + * \return A \ref vx_status_e enumeration. + * \retval VX_ERROR_OPTIMIZED_AWAY The reference is a virtual image and cannot be accessed or committed. + * \retval VX_ERROR_INVALID_PARAMETERS The \a start, \a end, \a plane_index, \a stride_x, or \a stride_y pointer is incorrect. + * \retval VX_ERROR_INVALID_REFERENCE The image reference is not actually an image reference. + * \ingroup group_image + * \include vx_imagepatch.c + * \note If the implementation gives the client a pointer from + * \ref vxAccessImagePatch then implementation-specific behavior may occur. + * If not, then a copy occurs from the users pointer to the internal data of the object. + * \note If the rectangle intersects bounds of the current valid region, the + * valid region grows to the union of the two rectangles as long as they occur + * within the bounds of the original image dimensions. + */ +VX_API_ENTRY vx_status VX_API_CALL vxCommitImagePatch(vx_image image, + vx_rectangle_t *rect, + vx_uint32 plane_index, + vx_imagepatch_addressing_t *addr, + const void *ptr); + +/*! + * \brief Accesses a specific indexed pixel in an image patch. + * \param [in] ptr The base pointer of the patch as returned from \ref vxAccessImagePatch. + * \param [in] index The 0 based index of the pixel count in the patch. Indexes increase horizontally by 1 then wrap around to the next row. + * \param [in] addr The pointer to the addressing mode information returned from \ref vxAccessImagePatch. + * \return void * Returns the pointer to the specified pixel. + * \pre \ref vxAccessImagePatch + * \include vx_imagepatch.c + * \ingroup group_image + */ +VX_API_ENTRY void * VX_API_CALL vxFormatImagePatchAddress1d(void *ptr, vx_uint32 index, const vx_imagepatch_addressing_t *addr); + +/*! + * \brief Accesses a specific pixel at a 2d coordinate in an image patch. + * \param [in] ptr The base pointer of the patch as returned from \ref vxAccessImagePatch. + * \param [in] x The x dimension within the patch. + * \param [in] y The y dimension within the patch. + * \param [in] addr The pointer to the addressing mode information returned from \ref vxAccessImagePatch. + * \return void * Returns the pointer to the specified pixel. + * \pre \ref vxAccessImagePatch + * \include vx_imagepatch.c + * \ingroup group_image + */ +VX_API_ENTRY void * VX_API_CALL vxFormatImagePatchAddress2d(void *ptr, vx_uint32 x, vx_uint32 y, const vx_imagepatch_addressing_t *addr); + +/*! \brief Retrieves the valid region of the image as a rectangle. + * \details After the image is allocated but has not been written to this + * returns the full rectangle of the image so that functions do not have to manage + * a case for uninitialized data. The image still retains an uninitialized + * value, but once the image is written to via any means such as \ref vxCommitImagePatch, + * the valid region is altered to contain the maximum bounds of the written + * area. + * \param [in] image The image from which to retrieve the valid region. + * \param [out] rect The destination rectangle. + * \return vx_status + * \retval VX_ERROR_INVALID_REFERENCE Invalid image. + * \retval VX_ERROR_INVALID_PARAMETERS Invalid rect. + * \retval VX_SUCCESS Valid image. + * \note This rectangle can be passed directly to \ref vxAccessImagePatch to get + * the full valid region of the image. Modifications from \ref vxCommitImagePatch + * grows the valid region. + * \ingroup group_image + */ +VX_API_ENTRY vx_status VX_API_CALL vxGetValidRegionImage(vx_image image, vx_rectangle_t *rect); + +/*============================================================================== + KERNEL + =============================================================================*/ + +/*! \brief Loads one or more kernels into the OpenVX context. This is the interface + * by which OpenVX is extensible. Once the set of kernels is loaded new kernels + * and their parameters can be queried. + * \note When all references to loaded kernels are released, the module + * may be automatically unloaded. + * \param [in] context The reference to the implementation context. + * \param [in] module The short name of the module to load. On systems where + * there are specific naming conventions for modules, the name passed + * should ignore such conventions. For example: \c libxyz.so should be + * passed as just \c xyz and the implementation will do the right thing that + * the platform requires. + * \note This API uses the system pre-defined paths for modules. + * \return A \ref vx_status_e enumeration. + * \retval VX_SUCCESS No errors. + * \retval VX_ERROR_INVALID_REFERENCE If the context is not a \ref vx_context. + * \retval VX_ERROR_INVALID_PARAMETERS If any of the other parameters are incorrect. + * \ingroup group_user_kernels + * \see vxGetKernelByName + */ +VX_API_ENTRY vx_status VX_API_CALL vxLoadKernels(vx_context context, const vx_char *module); + +/*! \brief Obtains a reference to a kernel using a string to specify the name. + * \details User Kernels follow a "dotted" heirarchical syntax. For example: + * "com.company.example.xyz". The following are strings specifying the kernel names: + + * org.khronos.openvx.color_convert + + * org.khronos.openvx.channel_extract + + * org.khronos.openvx.channel_combine + + * org.khronos.openvx.sobel_3x3 + + * org.khronos.openvx.magnitude + + * org.khronos.openvx.phase + + * org.khronos.openvx.scale_image + + * org.khronos.openvx.table_lookup + + * org.khronos.openvx.histogram + + * org.khronos.openvx.equalize_histogram + + * org.khronos.openvx.absdiff + + * org.khronos.openvx.mean_stddev + + * org.khronos.openvx.threshold + + * org.khronos.openvx.integral_image + + * org.khronos.openvx.dilate_3x3 + + * org.khronos.openvx.erode_3x3 + + * org.khronos.openvx.median_3x3 + + * org.khronos.openvx.box_3x3 + + * org.khronos.openvx.gaussian_3x3 + + * org.khronos.openvx.custom_convolution + + * org.khronos.openvx.gaussian_pyramid + + * org.khronos.openvx.accumulate + + * org.khronos.openvx.accumulate_weighted + + * org.khronos.openvx.accumulate_square + + * org.khronos.openvx.minmaxloc + + * org.khronos.openvx.convertdepth + + * org.khronos.openvx.canny_edge_detector + + * org.khronos.openvx.and + + * org.khronos.openvx.or + + * org.khronos.openvx.xor + + * org.khronos.openvx.not + + * org.khronos.openvx.multiply + + * org.khronos.openvx.add + + * org.khronos.openvx.subtract + + * org.khronos.openvx.warp_affine + + * org.khronos.openvx.warp_perspective + + * org.khronos.openvx.harris_corners + + * org.khronos.openvx.fast_corners + + * org.khronos.openvx.optical_flow_pyr_lk + + * org.khronos.openvx.remap + + * org.khronos.openvx.halfscale_gaussian + + * \param [in] context The reference to the implementation context. + * \param [in] name The string of the name of the kernel to get. + * \return A kernel reference or zero if an error occurred. + * \retval 0 The kernel name is not found in the context. + * \ingroup group_kernel + * \pre \ref vxLoadKernels if the kernel is not provided by the + * OpenVX implementation. + * \note User Kernels should follow a "dotted" heirarchical syntax. For example: + * "com.company.example.xyz". + */ +VX_API_ENTRY vx_kernel VX_API_CALL vxGetKernelByName(vx_context context, const vx_char *name); + +/*! \brief Obtains a reference to the kernel using the \ref vx_kernel_e enumeration. + * \details Enum values above the standard set are assumed to apply to + * loaded libraries. + * \param [in] context The reference to the implementation context. + * \param [in] kernel A value from \ref vx_kernel_e or a vendor or client-defined value. + * \return A \ref vx_kernel. + * \retval 0 The kernel enumeration is not found in the context. + * \ingroup group_kernel + * \pre \ref vxLoadKernels if the kernel is not provided by the + * OpenVX implementation. + */ +VX_API_ENTRY vx_kernel VX_API_CALL vxGetKernelByEnum(vx_context context, vx_enum kernel); + +/*! \brief This allows the client to query the kernel to get information about + * the number of parameters, enum values, etc. + * \param [in] kernel The kernel reference to query. + * \param [in] attribute The attribute to query. Use a \ref vx_kernel_attribute_e. + * \param [out] ptr The pointer to the location at which to store the resulting value. + * \param [in] size The size of the container to which \a ptr points. + * \return A \ref vx_status_e enumeration. + * \retval VX_SUCCESS No errors. + * \retval VX_ERROR_INVALID_REFERENCE If the kernel is not a \ref vx_kernel. + * \retval VX_ERROR_INVALID_PARAMETERS If any of the other parameters are incorrect. + * \retval VX_ERROR_NOT_SUPPORTED If the attribute value is not supported in this implementation. + * \ingroup group_kernel + */ +VX_API_ENTRY vx_status VX_API_CALL vxQueryKernel(vx_kernel kernel, vx_enum attribute, void *ptr, vx_size size); + +/*! \brief Release the reference to the kernel. + * The object may not be garbage collected until its total reference count is zero. + * \param [in] kernel The pointer to the kernel reference to release. + * \post After returning from this function the reference is zeroed. + * \return A \ref vx_status_e enumeration. + * \retval VX_SUCCESS No errors. + * \retval VX_ERROR_INVALID_REFERENCE If kernel is not a \ref vx_kernel. + * \ingroup group_kernel + */ +VX_API_ENTRY vx_status VX_API_CALL vxReleaseKernel(vx_kernel *kernel); + +/*! \brief Allows users to add custom kernels to the known kernel + * database in OpenVX at run-time. This would primarily be used by the module function + * \c vxPublishKernels. + * \param [in] context The reference to the implementation context. + * \param [in] name The string to use to match the kernel. + * \param [in] enumeration The enumerated value of the kernel to be used by clients. + * \param [in] func_ptr The process-local function pointer to be invoked. + * \param [in] numParams The number of parameters for this kernel. + * \param [in] input The pointer to \ref vx_kernel_input_validate_f, which validates the + * input parameters to this kernel. + * \param [in] output The pointer to \ref vx_kernel_output_validate_f , which validates the + * output parameters to this kernel. + * \param [in] init The kernel initialization function. + * \param [in] deinit The kernel de-initialization function. + * \ingroup group_user_kernels + * \return \ref vx_kernel + * \retval 0 Indicates that an error occurred when adding the kernel. + * \retval * Kernel added to OpenVX. + */ +VX_API_ENTRY vx_kernel VX_API_CALL vxAddKernel(vx_context context, + const vx_char name[VX_MAX_KERNEL_NAME], + vx_enum enumeration, + vx_kernel_f func_ptr, + vx_uint32 numParams, + vx_kernel_input_validate_f input, + vx_kernel_output_validate_f output, + vx_kernel_initialize_f init, + vx_kernel_deinitialize_f deinit); + +/*! \brief This API is called after all parameters have been added to the + * kernel and the kernel is \e ready to be used. Notice that the reference to the kernel created + * by vxAddKernel is still valid after the call to vxFinalizeKernel. + * \param [in] kernel The reference to the loaded kernel from \ref vxAddKernel. + * \return A \ref vx_status_e enumeration. If an error occurs, the kernel is not available + * for usage by the clients of OpenVX. Typically this is due to a mismatch + * between the number of parameters requested and given. + * \pre \ref vxAddKernel and \ref vxAddParameterToKernel + * \ingroup group_user_kernels + */ +VX_API_ENTRY vx_status VX_API_CALL vxFinalizeKernel(vx_kernel kernel); + +/*! \brief Allows users to set the signatures of the custom kernel. + * \param [in] kernel The reference to the kernel added with \ref vxAddKernel. + * \param [in] index The index of the parameter to add. + * \param [in] dir The direction of the parameter. This must be either \ref VX_INPUT or + * \ref VX_OUTPUT. \ref VX_BIDIRECTIONAL is not supported for this function. + * \param [in] data_type The type of parameter. This must be a value from \ref vx_type_e. + * \param [in] state The state of the parameter (required or not). This must be a value from \ref vx_parameter_state_e. + * \return A \ref vx_status_e enumerated value. + * \retval VX_SUCCESS Parameter is successfully set on kernel. + * \retval VX_ERROR_INVALID_REFERENCE The value passed as kernel was not a \c vx_kernel. + * \pre \ref vxAddKernel + * \ingroup group_user_kernels + */ +VX_API_ENTRY vx_status VX_API_CALL vxAddParameterToKernel(vx_kernel kernel, vx_uint32 index, vx_enum dir, vx_enum data_type, vx_enum state); + +/*! \brief Removes a non-finalized \ref vx_kernel from the \ref vx_context + * and releases it. Once a \ref vx_kernel has been finalized it cannot be removed. + * \param [in] kernel The reference to the kernel to remove. Returned from \ref vxAddKernel. + * \note Any kernel enumerated in the base standard + * cannot be removed; only kernels added through \ref vxAddKernel can + * be removed. + * \return A \ref vx_status_e enumeration. + * \retval VX_ERROR_INVALID_REFERENCE If an invalid kernel is passed in. + * \retval VX_ERROR_INVALID_PARAMETER If a base kernel is passed in. + * \ingroup group_user_kernels + */ +VX_API_ENTRY vx_status VX_API_CALL vxRemoveKernel(vx_kernel kernel); + +/*! \brief Sets kernel attributes. + * \param [in] kernel The reference to the kernel. + * \param [in] attribute The enumeration of the attributes. See \ref vx_kernel_attribute_e. + * \param [in] ptr The pointer to the location from which to read the attribute. + * \param [in] size The size in bytes of the data area indicated by \a ptr in bytes. + * \note After a kernel has been passed to \ref vxFinalizeKernel, no attributes + * can be altered. + * \return A \ref vx_status_e enumeration. + * \ingroup group_user_kernels + */ +VX_API_ENTRY vx_status VX_API_CALL vxSetKernelAttribute(vx_kernel kernel, vx_enum attribute, const void *ptr, vx_size size); + +/*! \brief Retrieves a \ref vx_parameter from a \ref vx_kernel. + * \param [in] kernel The reference to the kernel. + * \param [in] index The index of the parameter. + * \return A \ref vx_parameter. + * \retval 0 Either the kernel or index is invalid. + * \retval * The parameter reference. + * \ingroup group_parameter + */ +VX_API_ENTRY vx_parameter VX_API_CALL vxGetKernelParameterByIndex(vx_kernel kernel, vx_uint32 index); + +/*============================================================================== + GRAPH + =============================================================================*/ + +/*! \brief Creates an empty graph. + * \param [in] context The reference to the implementation context. + * \returns A graph reference \ref vx_graph. Any possible errors preventing a + * successful creation should be checked using \ref vxGetStatus. + * \ingroup group_graph + */ +VX_API_ENTRY vx_graph VX_API_CALL vxCreateGraph(vx_context context); + +/*! \brief Releases a reference to a graph. + * The object may not be garbage collected until its total reference count is zero. + * Once the reference count is zero, all node references in the graph are automatically + * released as well. Data referenced by those nodes may not be released as + * the user may have external references to the data. + * \param [in] graph The pointer to the graph to release. + * \post After returning from this function the reference is zeroed. + * \return A \ref vx_status_e enumeration. + * \retval VX_SUCCESS No errors. + * \retval VX_ERROR_INVALID_REFERENCE If graph is not a \ref vx_graph. + * \ingroup group_graph + */ +VX_API_ENTRY vx_status VX_API_CALL vxReleaseGraph(vx_graph *graph); + +/*! \brief Verifies the state of the graph before it is executed. + * This is useful to catch programmer errors and contract errors. If not verified, + * the graph verifies before being processed. + * \pre Memory for data objects is not guarenteed to exist before + * this call. \post After this call data objects exist unless + * the implementation optimized them out. + * \param [in] graph The reference to the graph to verify. + * \return A status code for graphs with more than one error; it is + * undefined which error will be returned. Register a log callback using \ref vxRegisterLogCallback + * to receive each specific error in the graph. + * \return A \ref vx_status_e enumeration. + * \retval VX_SUCCESS No errors. + * \retval VX_ERROR_INVALID_REFERENCE If graph is not a \ref vx_graph. + * \retval VX_ERROR_MULTIPLE_WRITERS If the graph contains more than one writer + * to any data object. + * \retval VX_ERROR_INVALID_NODE If a node in the graph is invalid or failed be created. + * \retval VX_ERROR_INVALID_GRAPH If the graph contains cycles or some other invalid topology. + * \retval VX_ERROR_INVALID_TYPE If any parameter on a node is given the wrong type. + * \retval VX_ERROR_INVALID_VALUE If any value of any parameter is out of bounds of specification. + * \retval VX_ERROR_INVALID_FORMAT If the image format is not compatible. + * \ingroup group_graph + * \see vxProcessGraph + */ +VX_API_ENTRY vx_status VX_API_CALL vxVerifyGraph(vx_graph graph); + +/*! \brief This function causes the synchronous processing of a graph. If the graph + * has not been verified, then the implementation verifies the graph + * immediately. If verification fails this function returns a status + * identical to what \ref vxVerifyGraph would return. After + * the graph verfies successfully then processing occurs. If the graph was + * previously verified via \ref vxVerifyGraph or \ref vxProcessGraph + * then the graph is processed. This function blocks until the graph is completed. + * \param [in] graph The graph to execute. + * \return A \ref vx_status_e enumeration. + * \retval VX_SUCCESS Graph has been processed. + * \retval VX_FAILURE A catastrophic error occurred during processing. + * \retval * See \ref vxVerifyGraph. + * \pre \ref vxVerifyGraph must return \ref VX_SUCCESS before this function will pass. + * \ingroup group_graph + * \see vxVerifyGraph + */ +VX_API_ENTRY vx_status VX_API_CALL vxProcessGraph(vx_graph graph); + +/*! \brief Schedules a graph for future execution. + * \param [in] graph The graph to schedule. + * \return A \ref vx_status_e enumeration. + * \retval VX_ERROR_NO_RESOURCES The graph cannot be scheduled now. + * \retval VX_ERROR_NOT_SUFFICIENT The graph is not verified and has failed +forced verification. + * \retval VX_SUCCESS The graph has been scheduled. + * \pre \ref vxVerifyGraph must return \ref VX_SUCCESS before this function will pass. + * \ingroup group_graph + */ +VX_API_ENTRY vx_status VX_API_CALL vxScheduleGraph(vx_graph graph); + +/*! \brief Waits for a specific graph to complete. If the graph has been scheduled multiple + * times since the last call to vxWaitGraph, then vxWaitGraph returns only when the last + * scheduled execution completes. + * \param [in] graph The graph to wait on. + * \return A \ref vx_status_e enumeration. + * \retval VX_SUCCESS The graph has successfully completed execution and its outputs are the + * valid results of the most recent execution. + * \retval VX_FAILURE An error occurred or the graph was never scheduled. Use \ref vxQueryGraph + * for the VX_GRAPH_ATTRIBUTE_STATUS attribute to determine the details. Output data of the + * graph is undefined. + * \pre \ref vxScheduleGraph + * \ingroup group_graph + */ +VX_API_ENTRY vx_status VX_API_CALL vxWaitGraph(vx_graph graph); + +/*! \brief Allows the user to query attributes of the Graph. + * \param [in] graph The reference to the created graph. + * \param [in] attribute The \ref vx_graph_attribute_e type needed. + * \param [out] ptr The location at which to store the resulting value. + * \param [in] size The size in bytes of the container to which \a ptr points. + * \return A \ref vx_status_e enumeration. + * \ingroup group_graph + */ +VX_API_ENTRY vx_status VX_API_CALL vxQueryGraph(vx_graph graph, vx_enum attribute, void *ptr, vx_size size); + +/*! \brief Allows the set to attributes on the Graph. + * \param [in] graph The reference to the graph. + * \param [in] attribute The \ref vx_graph_attribute_e type needed. + * \param [in] ptr The location from which to read the value. + * \param [in] size The size in bytes of the container to which \a ptr points. + * \return A \ref vx_status_e enumeration. + * \ingroup group_graph + */ +VX_API_ENTRY vx_status VX_API_CALL vxSetGraphAttribute(vx_graph graph, vx_enum attribute, const void *ptr, vx_size size); + +/*! \brief Adds the given parameter extracted from a \ref vx_node to the graph. + * \param [in] graph The graph reference that contains the node. + * \param [in] parameter The parameter reference to add to the graph from the node. + * \return A \ref vx_status_e enumeration. + * \retval VX_SUCCESS Parameter added to Graph. + * \retval VX_ERROR_INVALID_REFERENCE The parameter is not a valid \ref vx_parameter. + * \retval VX_ERROR_INVALID_PARAMETER The parameter is of a node not in this + * graph. + * \ingroup group_graph_parameters + */ +VX_API_ENTRY vx_status VX_API_CALL vxAddParameterToGraph(vx_graph graph, vx_parameter parameter); + +/*! \brief Sets a reference to the parameter on the graph. The implementation + * must set this parameter on the originating node as well. + * \param [in] graph The graph reference. + * \param [in] index The parameter index. + * \param [in] value The reference to set to the parameter. + * \return A \ref vx_status_e enumeration. + * \retval VX_SUCCESS Parameter set to Graph. + * \retval VX_ERROR_INVALID_REFERENCE The value is not a valid \ref vx_reference. + * \retval VX_ERROR_INVALID_PARAMETER The parameter index is out of bounds or the + * dir parameter is incorrect. + * \ingroup group_graph_parameters + */ +VX_API_ENTRY vx_status VX_API_CALL vxSetGraphParameterByIndex(vx_graph graph, vx_uint32 index, vx_reference value); + +/*! \brief Retrieves a \ref vx_parameter from a \ref vx_graph. + * \param [in] graph The graph. + * \param [in] index The index of the parameter. + * \return \ref vx_parameter reference. + * \retval 0 if the index is out of bounds. + * \retval * The parameter reference. + * \ingroup group_graph_parameters + */ +VX_API_ENTRY vx_parameter VX_API_CALL vxGetGraphParameterByIndex(vx_graph graph, vx_uint32 index); + +/*! \brief Returns a Boolean to indicate the state of graph verification. + * \param [in] graph The reference to the graph to check. + * \return A \ref vx_bool value. + * \retval vx_true_e The graph is verified. + * \retval vx_false_e The graph is not verified. It must be verified before + * execution either through \ref vxVerifyGraph or automatically through + * \ref vxProcessGraph or \ref vxScheduleGraph. + * \ingroup group_graph + */ +VX_API_ENTRY vx_bool VX_API_CALL vxIsGraphVerified(vx_graph graph); + +/*============================================================================== + NODE + =============================================================================*/ + +/*! \brief Creates a reference to a node object for a given kernel. + * \details This node has no references assigned as parameters after completion. + * The client is then required to set these parameters manually by \ref vxSetParameterByIndex. + * When clients supply their own node creation functions (for use with User Kernels), this is the API + * to use along with the parameter setting API. + * \param [in] graph The reference to the graph in which this node exists. + * \param [in] kernel The kernel reference to associate with this new node. + * \returns A node reference \ref vx_node. Any possible errors preventing a + * successful creation should be checked using \ref vxGetStatus. + * \ingroup group_adv_node + * \post Call \ref vxSetParameterByIndex for as many parameters as needed to be set. + */ +VX_API_ENTRY vx_node VX_API_CALL vxCreateGenericNode(vx_graph graph, vx_kernel kernel); + +/*! \brief Allows a user to query information out of a node. + * \param [in] node The reference to the node to query. + * \param [in] attribute Use \ref vx_node_attribute_e value to query for information. + * \param [out] ptr The location at which to store the resulting value. + * \param [in] size The size in bytesin bytes of the container to which \a ptr points. + * \return A \ref vx_status_e enumeration. + * \retval VX_SUCCESS Successful + * \retval VX_ERROR_INVALID_PARAMETERS The type or size is incorrect. + * \ingroup group_node + */ +VX_API_ENTRY vx_status VX_API_CALL vxQueryNode(vx_node node, vx_enum attribute, void *ptr, vx_size size); + +/*! \brief Allows a user to set attribute of a node before Graph Validation. + * \param [in] node The reference to the node to set. + * \param [in] attribute Use \ref vx_node_attribute_e value to query for information. + * \param [out] ptr The output pointer to where to send the value. + * \param [in] size The size in bytes of the objects to which \a ptr points. + * \note Some attributes are inherited from the \ref vx_kernel, which was used + * to create the node. Some of these can be overridden using this API, notably + * \ref VX_NODE_ATTRIBUTE_LOCAL_DATA_SIZE and \ref VX_NODE_ATTRIBUTE_LOCAL_DATA_PTR. + * \ingroup group_node + * \return A \ref vx_status_e enumeration. + * \retval VX_SUCCESS The attribute was set. + * \retval VX_ERROR_INVALID_REFERENCE node is not a vx_node. + * \retval VX_ERROR_INVALID_PARAMETER size is not correct for the type needed. + */ +VX_API_ENTRY vx_status VX_API_CALL vxSetNodeAttribute(vx_node node, vx_enum attribute, const void *ptr, vx_size size); + +/*! \brief Releases a reference to a Node object. + * The object may not be garbage collected until its total reference count is zero. + * \param [in] node The pointer to the reference of the node to release. + * \ingroup group_node + * \post After returning from this function the reference is zeroed. + * \return A \ref vx_status_e enumeration. + * \retval VX_SUCCESS No errors. + * \retval VX_ERROR_INVALID_REFERENCE If node is not a \ref vx_node. + */ +VX_API_ENTRY vx_status VX_API_CALL vxReleaseNode(vx_node *node); + +/*! \brief Removes a Node from its parent Graph and releases it. + * \param [in] node The pointer to the node to remove and release. + * \ingroup group_node + * \post After returning from this function the reference is zeroed. + * \return A \ref vx_status_e enumeration. + * \retval VX_SUCCESS No errors. + * \retval VX_ERROR_INVALID_REFERENCE If node is not a \ref vx_node. + */ +VX_API_ENTRY vx_status VX_API_CALL vxRemoveNode(vx_node *node); + +/*! \brief Assigns a callback to a node. + * If a callback already exists in this node, this function must return an error + * and the user may clear the callback by passing a NULL pointer as the callback. + * \param [in] node The reference to the node. + * \param [in] callback The callback to associate with completion of this + * specific node. + * \warning This must be used with extreme caution as it can \e ruin + * optimizations in the power/performance efficiency of a graph. + * \return A \ref vx_status_e enumeration. + * \retval VX_SUCCESS Callback assigned. + * \retval VX_ERROR_INVALID_REFERENCE The value passed as node was not a \ref vx_node. + * \ingroup group_node_callback + */ +VX_API_ENTRY vx_status VX_API_CALL vxAssignNodeCallback(vx_node node, vx_nodecomplete_f callback); + +/*! \brief Retrieves the current node callback function pointer set on the node. + * \param [in] node The reference to the \ref vx_node object. + * \ingroup group_node_callback + * \return vx_nodecomplete_f The pointer to the callback function. + * \retval NULL No callback is set. + * \retval * The node callback function. + */ +VX_API_ENTRY vx_nodecomplete_f VX_API_CALL vxRetrieveNodeCallback(vx_node node); + +/*============================================================================== + PARAMETER + =============================================================================*/ + +/*! \brief Retrieves a \ref vx_parameter from a \ref vx_node. + * \param [in] node The node from which to extract the parameter. + * \param [in] index The index of the parameter to which to get a reference. + * \return \ref vx_parameter + * \ingroup group_parameter + */ +VX_API_ENTRY vx_parameter VX_API_CALL vxGetParameterByIndex(vx_node node, vx_uint32 index); + +/*! \brief Releases a reference to a parameter object. + * The object may not be garbage collected until its total reference count is zero. + * \param [in] param The pointer to the parameter to release. + * \ingroup group_parameter + * \post After returning from this function the reference is zeroed. + * \return A \ref vx_status_e enumeration. + * \retval VX_SUCCESS No errors. + * \retval VX_ERROR_INVALID_REFERENCE If param is not a \ref vx_parameter. + */ +VX_API_ENTRY vx_status VX_API_CALL vxReleaseParameter(vx_parameter *param); + +/*! \brief Sets the specified parameter data for a kernel on the node. + * \param [in] node The node that contains the kernel. + * \param [in] index The index of the parameter desired. + * \param [in] value The reference to the parameter. + * \return A \ref vx_status_e enumeration. + * \ingroup group_parameter + * \see vxSetParameterByReference + */ +VX_API_ENTRY vx_status VX_API_CALL vxSetParameterByIndex(vx_node node, vx_uint32 index, vx_reference value); + +/*! \brief Associates a parameter reference and a data reference with a kernel + * on a node. + * \param [in] parameter The reference to the kernel parameter. + * \param [in] value The value to associate with the kernel parameter. + * \return A \ref vx_status_e enumeration. + * \ingroup group_parameter + * \see vxGetParameterByIndex + */ +VX_API_ENTRY vx_status VX_API_CALL vxSetParameterByReference(vx_parameter parameter, vx_reference value); + +/*! \brief Allows the client to query a parameter to determine its meta-information. + * \param [in] param The reference to the parameter. + * \param [in] attribute The attribute to query. Use a \ref vx_parameter_attribute_e. + * \param [out] ptr The location at which to store the resulting value. + * \param [in] size The size in bytes of the container to which \a ptr points. + * \return A \ref vx_status_e enumeration. + * \ingroup group_parameter + */ +VX_API_ENTRY vx_status VX_API_CALL vxQueryParameter(vx_parameter param, vx_enum attribute, void *ptr, vx_size size); + +/*============================================================================== + SCALAR + =============================================================================*/ + +/*! \brief Creates a reference to a scalar object. Also see \ref sub_node_parameters. + * \param [in] context The reference to the system context. + * \param [in] data_type The \ref vx_type_e of the scalar. Must be greater than + * \ref VX_TYPE_INVALID and less than \ref VX_TYPE_SCALAR_MAX. + * \param [in] ptr The pointer to the initial value of the scalar. + * \ingroup group_scalar + * \returns A scaler reference \ref vx_scalar. Any possible errors preventing a + * successful creation should be checked using \ref vxGetStatus. + */ +VX_API_ENTRY vx_scalar VX_API_CALL vxCreateScalar(vx_context context, vx_enum data_type, const void *ptr); + +/*! \brief Releases a reference to a scalar object. + * The object may not be garbage collected until its total reference count is zero. + * \param [in] scalar The pointer to the scalar to release. + * \ingroup group_scalar + * \post After returning from this function the reference is zeroed. + * \return A \ref vx_status_e enumeration. + * \retval VX_SUCCESS No errors. + * \retval VX_ERROR_INVALID_REFERENCE If scalar is not a \ref vx_scalar. + */ +VX_API_ENTRY vx_status VX_API_CALL vxReleaseScalar(vx_scalar *scalar); + +/*! \brief Queries attributes from a scalar. + * \param [in] scalar The scalar object. + * \param [in] attribute The enumeration to query. Use a \ref vx_scalar_attribute_e enumeration. + * \param [out] ptr The location at which to store the resulting value. + * \param [in] size The size of the container to which \a ptr points. + * \return A \ref vx_status_e enumeration. + * \ingroup group_scalar + */ +VX_API_ENTRY vx_status VX_API_CALL vxQueryScalar(vx_scalar scalar, vx_enum attribute, void *ptr, vx_size size); + +/*! \brief Gets the scalar value out of a reference. + * \note Use this in conjunction with Query APIs that return references which + * should be converted into values. + * \ingroup group_scalar + * \param [in] ref The reference from which to get the scalar value. + * \param [out] ptr An appropriate typed pointer that points to a location to which to copy + * the scalar value. + * \return A \ref vx_status_e enumeration. + * \retval VX_ERROR_INVALID_REFERENCE If the ref is not a valid + * reference. + * \retval VX_ERROR_INVALID_PARAMETERS If \a ptr is NULL. + * \retval VX_ERROR_INVALID_TYPE If the type does not match the type in the reference or is a bad value. + */ +VX_API_ENTRY vx_status VX_API_CALL vxReadScalarValue(vx_scalar ref, void *ptr); + +/*! \brief Sets the scalar value in a reference. + * \note Use this in conjunction with Parameter APIs that return references + * to parameters that need to be altered. + * \ingroup group_scalar + * \param [in] ref The reference from which to get the scalar value. + * \param [in] ptr An appropriately typed pointer that points to a location to which to copy + * the scalar value. + * \return A \ref vx_status_e enumeration. + * \retval VX_ERROR_INVALID_REFERENCE If the ref is not a valid + * reference. + * \retval VX_ERROR_INVALID_PARAMETERS If \a ptr is NULL. + * \retval VX_ERROR_INVALID_TYPE If the type does not match the type in the reference or is a bad value. + */ +VX_API_ENTRY vx_status VX_API_CALL vxWriteScalarValue(vx_scalar ref, const void *ptr); + +/*============================================================================== + REFERENCE + =============================================================================*/ + +/*! \brief Queries any reference type for some basic information (count, type). + * \param [in] ref The reference to query. + * \param [in] attribute The value for which to query. Use \ref vx_reference_attribute_e. + * \param [out] ptr The location at which to store the resulting value. + * \param [in] size The size in bytes of the container to which \a ptr points. + * \return A \ref vx_status_e enumeration. + * \ingroup group_reference + */ +VX_API_ENTRY vx_status VX_API_CALL vxQueryReference(vx_reference ref, vx_enum attribute, void *ptr, vx_size size); + +/*============================================================================== + DELAY + =============================================================================*/ + +/*! \brief Queries a \ref vx_delay object attribute. + * \param [in] delay A pointer to a delay object. + * \param [in] attribute The attribute to query. Use a \ref vx_delay_attribute_e enumeration. + * \param [out] ptr The location at which to store the resulting value. + * \param [in] size The size of the container to which \a ptr points. + * \return A \ref vx_status_e enumeration. + * \ingroup group_delay + */ +VX_API_ENTRY vx_status VX_API_CALL vxQueryDelay(vx_delay delay, vx_enum attribute, void *ptr, vx_size size); + +/*! \brief Releases a reference to a delay object. + * The object may not be garbage collected until its total reference count is zero. + * \param [in] delay The pointer to the delay to release. + * \post After returning from this function the reference is zeroed. + * \ingroup group_delay + * \return A \ref vx_status_e enumeration. + * \retval VX_SUCCESS No errors. + * \retval VX_ERROR_INVALID_REFERENCE If delay is not a \ref vx_delay. + */ +VX_API_ENTRY vx_status VX_API_CALL vxReleaseDelay(vx_delay *delay); + +/*! \brief Creates a Delay object. + * \details This function uses a subset of the attributes defining the metadata of + * the exemplar, ignoring the object. It does not alter the exemplar or keep or release + * the reference to the exemplar. For the definition of supported attributes + * see \ref vxSetMetaFormatAttribute. + * + * \param [in] context The reference to the system context. + * \param [in] exemplar The exemplar object. + * \param [in] slots The number of reference in the delay. + * \returns A delay reference \ref vx_delay. Any possible errors preventing a + * successful creation should be checked using \ref vxGetStatus. + * \ingroup group_delay + */ +VX_API_ENTRY vx_delay VX_API_CALL vxCreateDelay(vx_context context, + vx_reference exemplar, + vx_size slots); + +/*! \brief Retrieves a reference from a delay object. + * \param [in] delay The reference to the delay object. + * \param [in] index An index into the delay from which to extract the + * reference. + * \return \ref vx_reference + * \note The delay index is in the range \f$ [-count+1,0] \f$. 0 is always the + * \e current object. + * \ingroup group_delay + * \note A reference from a delay object must not be given to its associated + * release API (e.g. \ref vxReleaseImage). Use the \ref vxReleaseDelay only. + */ +VX_API_ENTRY vx_reference VX_API_CALL vxGetReferenceFromDelay(vx_delay delay, vx_int32 index); + +/*! \brief Ages the internal delay ring by one. This means that once this API is + * called the reference from index 0 will go to index -1 and so forth until + * \f$ -count+1 \f$ is reached. This last object will become 0. Once the delay has + * been aged, it updates the reference in any associated nodes. + * \param [in] delay + * \return A \ref vx_status_e enumeration. + * \retval VX_SUCCESS Delay was aged. + * \retval VX_ERROR_INVALID_REFERENCE The value passed as delay was not a \ref vx_delay. + * \ingroup group_delay + */ +VX_API_ENTRY vx_status VX_API_CALL vxAgeDelay(vx_delay delay); + + +/*============================================================================== + LOGGING + =============================================================================*/ + +/*! \brief Adds a line to the log. + * \param [in] ref The reference to add the log entry against. Some valid value must be provided. + * \param [in] status The status code. \ref VX_SUCCESS status entries are ignored and not added. + * \param [in] message The human readable message to add to the log. + * \param [in] ... a list of variable arguments to the message. + * \note Messages may not exceed \ref VX_MAX_LOG_MESSAGE_LEN bytes and will be truncated in the log if they exceed this limit. + * \ingroup group_log + */ +VX_API_ENTRY void VX_API_CALL vxAddLogEntry(vx_reference ref, vx_status status, const char *message, ...); + +/*! \brief Registers a callback facility to the OpenVX implementation to receive error logs. + * \param [in] context The overall context to OpenVX. + * \param [in] callback The callback function. If NULL, the previous callback is removed. + * \param [in] reentrant If reentrancy flag is \ref vx_true_e, then the callback may be entered from multiple + * simultaneous tasks or threads (if the host OS supports this). + * \ingroup group_log + */ +VX_API_ENTRY void VX_API_CALL vxRegisterLogCallback(vx_context context, vx_log_callback_f callback, vx_bool reentrant); + +/*============================================================================== + LUT + =============================================================================*/ + +/*! \brief Creates LUT object of a given type. + * \param [in] context The reference to the context. + * \param [in] data_type The type of data stored in the LUT. + * \param [in] count The number of entries desired. + * \if OPENVX_STRICT_1_0 + * \note For OpenVX 1.0, count must be equal to 256 and data_type can only be \ref VX_TYPE_UINT8. + * \endif + * \returns An LUT reference \ref vx_lut. Any possible errors preventing a + * successful creation should be checked using \ref vxGetStatus. + * \ingroup group_lut + */ +VX_API_ENTRY vx_lut VX_API_CALL vxCreateLUT(vx_context context, vx_enum data_type, vx_size count); + +/*! \brief Releases a reference to a LUT object. + * The object may not be garbage collected until its total reference count is zero. + * \param [in] lut The pointer to the LUT to release. + * \post After returning from this function the reference is zeroed. + * \return A \ref vx_status_e enumeration. + * \retval VX_SUCCESS No errors. + * \retval VX_ERROR_INVALID_REFERENCE If lut is not a \ref vx_lut. + * \ingroup group_lut + */ +VX_API_ENTRY vx_status VX_API_CALL vxReleaseLUT(vx_lut *lut); + +/*! \brief Queries attributes from a LUT. + * \param [in] lut The LUT to query. + * \param [in] attribute The attribute to query. Use a \ref vx_lut_attribute_e enumeration. + * \param [out] ptr The location at which to store the resulting value. + * \param [in] size The size in bytes of the container to which \a ptr points. + * \return A \ref vx_status_e enumeration. + * \ingroup group_lut + */ +VX_API_ENTRY vx_status VX_API_CALL vxQueryLUT(vx_lut lut, vx_enum attribute, void *ptr, vx_size size); + +/*! \brief Grants access to a LUT table and increments the object reference count in case of success. + * \details There are several variations of call methodology: + * \arg If \a ptr is NULL (which means the current data of the LUT is not desired), + * the LUT reference count is incremented. + * \arg If \a ptr is not NULL but (*ptr) is NULL, (*ptr) will contain the address of the LUT data when the function returns and + * the reference count will be incremented. Whether the (*ptr) address is mapped + * or allocated is undefined. (*ptr) must be returned to \ref vxCommitLUT. + * \arg If \a ptr is not NULL and (*ptr) is not NULL, the user is signalling the implementation to copy the LUT data into the location specified + * by (*ptr). Users must use \ref vxQueryLUT with \ref VX_LUT_ATTRIBUTE_SIZE to + * determine how much memory to allocate for the LUT data. + * + * In any case, \ref vxCommitLUT must be called after LUT access is complete. + * \param [in] lut The LUT from which to get the data. + * \param [in,out] ptr ptr The user-supplied address to a pointer, via which the requested contents + * are returned. + * \arg If ptr is NULL, an error occurs. + * \arg If ptr is not NULL and (*ptr) is NULL, (*ptr) will be set to the address of a memory area + * managed by the OpenVX framework containing the requested data. + * \arg If both ptr and (*ptr) are not NULL, requested data will be copied to (*ptr) (optionally in + * case of write-only access). + * \param [in] usage This declares the intended usage of the pointer using the * \ref vx_accessor_e enumeration. + * \return A \ref vx_status_e enumeration. + * \post \ref vxCommitLUT + * \ingroup group_lut + */ +VX_API_ENTRY vx_status VX_API_CALL vxAccessLUT(vx_lut lut, void **ptr, vx_enum usage); + +/*! \brief Commits the Lookup Table and decrements the object reference count in case of success. + * \details Commits the data back to the LUT object and decrements the reference count. + * There are several variations of call methodology: + * \arg If a user should allocated their own memory for the LUT data copy, the user is + * obligated to free this memory. + * \arg If \a ptr is not NULL and the (*ptr) for \ref vxAccessLUT was NULL, + * it is undefined whether the implementation will unmap or copy and free the memory. + * \param [in] lut The LUT to modify. + * \param [in] ptr The pointer provided or returned by \ref vxAccessLUT. This cannot be NULL. + * \return A \ref vx_status_e enumeration. + * \pre \ref vxAccessLUT. + * \ingroup group_lut + */ +VX_API_ENTRY vx_status VX_API_CALL vxCommitLUT(vx_lut lut, const void *ptr); + +/*============================================================================== + DISTRIBUTION + =============================================================================*/ + +/*! \brief Creates a reference to a 1D Distribution of a consecutive interval [offset, offset + range - 1] + * defined by a start offset and valid range, divided equally into numBins parts. + * \param [in] context The reference to the overall context. + * \param [in] numBins The number of bins in the distribution. + * \param [in] offset The start offset into the range value that marks the begining of the 1D Distribution. + * \param [in] range The total number of the values. + * \returns A distribution reference \ref vx_distribution. Any possible errors preventing a + * successful creation should be checked using \ref vxGetStatus. + * \ingroup group_distribution + */ +VX_API_ENTRY vx_distribution VX_API_CALL vxCreateDistribution(vx_context context, vx_size numBins, vx_int32 offset, vx_uint32 range); + +/*! \brief Releases a reference to a distribution object. + * The object may not be garbage collected until its total reference count is zero. + * \param [in] distribution The reference to the distribution to release. + * \post After returning from this function the reference is zeroed. + * \return A \ref vx_status_e enumeration. + * \retval VX_SUCCESS No errors. + * \retval VX_ERROR_INVALID_REFERENCE If distribution is not a \ref vx_distribution. + * \ingroup group_distribution + */ +VX_API_ENTRY vx_status VX_API_CALL vxReleaseDistribution(vx_distribution *distribution); + +/*! \brief Queries a Distribution object. + * \param [in] distribution The reference to the distribution to query. + * \param [in] attribute The attribute to query. Use a \ref vx_distribution_attribute_e enumeration. + * \param [out] ptr The location at which to store the resulting value. + * \param [in] size The size in bytes of the container to which \a ptr points. + * \return A \ref vx_status_e enumeration. + * \ingroup group_distribution + */ +VX_API_ENTRY vx_status VX_API_CALL vxQueryDistribution(vx_distribution distribution, vx_enum attribute, void *ptr, vx_size size); + +/*! \brief Grants access to a distribution object and increments the object reference count in + * case of success. + * \param [in] distribution The reference to the distribution to access. + * \param [in, out] ptr The user-supplied address to a pointer, via which the requested contents + * are returned. + * \arg If ptr is NULL, an error occurs. + * \arg If ptr is not NULL and (*ptr) is NULL, (*ptr) will be set to the address of a memory area + * managed by the OpenVX framework containing the requested data. + * \arg If both ptr and (*ptr) are not NULL, requested data will be copied to (*ptr) (optionally in + * case of write-only access). + * \param [in] usage The \ref vx_accessor_e value to describe the access of the object. + * \return A \ref vx_status_e enumeration. + * \post \ref vxCommitDistribution + * \ingroup group_distribution + */ +VX_API_ENTRY vx_status VX_API_CALL vxAccessDistribution(vx_distribution distribution, void **ptr, vx_enum usage); + +/*! \brief Commits the distribution objec> and decrements the object reference count in case of success. + * The memory must be a vx_uint32 array of a value at least as big as the value returned via + * \ref VX_DISTRIBUTION_ATTRIBUTE_BINS. + * \param [in] distribution The Distribution to modify. + * \param [in] ptr The pointer provided or returned by \ref vxAccessDistribution. The ptr cannot + * be NULL. + * \return A \ref vx_status_e enumeration. + * \pre \ref vxAccessDistribution. + * \ingroup group_distribution + */ +VX_API_ENTRY vx_status VX_API_CALL vxCommitDistribution(vx_distribution distribution, const void * ptr); + +/*============================================================================== + THRESHOLD + =============================================================================*/ + +/*! \brief Creates a reference to a threshold object of a given type. + * \param [in] c The reference to the overall context. + * \param [in] thresh_type The type of threshold to create. + * \param [in] data_type The data type of the threshold's value(s). + * \if OPENVX_STRICT_1_0 + * \note For OpenVX 1.0, data_type can only be \ref VX_TYPE_UINT8. + * \endif + * \returns An threshold reference \ref vx_threshold. Any possible errors preventing a + * successful creation should be checked using \ref vxGetStatus. + * \ingroup group_threshold + */ +VX_API_ENTRY vx_threshold VX_API_CALL vxCreateThreshold(vx_context c, vx_enum thresh_type, vx_enum data_type); + +/*! \brief Releases a reference to a threshold object. + * The object may not be garbage collected until its total reference count is zero. + * \param [in] thresh The pointer to the threshold to release. + * \post After returning from this function the reference is zeroed. + * \return A \ref vx_status_e enumeration. + * \retval VX_SUCCESS No errors. + * \retval VX_ERROR_INVALID_REFERENCE If thresh is not a \ref vx_threshold. + * \ingroup group_threshold + */ +VX_API_ENTRY vx_status VX_API_CALL vxReleaseThreshold(vx_threshold *thresh); + +/*! \brief Sets attributes on the threshold object. + * \param [in] thresh The threshold object to set. + * \param [in] attribute The attribute to modify. Use a \ref vx_threshold_attribute_e enumeration. + * \param [in] ptr The pointer to the value to which to set the attribute. + * \param [in] size The size of the data pointed to by \a ptr. + * \return A \ref vx_status_e enumeration. + * \ingroup group_threshold + */ +VX_API_ENTRY vx_status VX_API_CALL vxSetThresholdAttribute(vx_threshold thresh, vx_enum attribute, const void *ptr, vx_size size); + +/*! \brief Queries an attribute on the threshold object. + * \param [in] thresh The threshold object to set. + * \param [in] attribute The attribute to query. Use a \ref vx_threshold_attribute_e enumeration. + * \param [out] ptr The location at which to store the resulting value. + * \param [in] size The size of the container to which \a ptr points. + * \return A \ref vx_status_e enumeration. + * \ingroup group_threshold + */ +VX_API_ENTRY vx_status VX_API_CALL vxQueryThreshold(vx_threshold thresh, vx_enum attribute, void *ptr, vx_size size); + +/*============================================================================== + MATRIX + =============================================================================*/ + +/*! \brief Creates a reference to a matrix object. + * \param [in] c The reference to the overall context. + * \param [in] data_type The unit format of the matrix. \ref VX_TYPE_INT32 or \ref VX_TYPE_FLOAT32. + * \param [in] columns The first dimensionality. + * \param [in] rows The second dimensionality. + * \returns An matrix reference \ref vx_matrix. Any possible errors preventing a + * successful creation should be checked using \ref vxGetStatus. + * \ingroup group_matrix + */ +VX_API_ENTRY vx_matrix VX_API_CALL vxCreateMatrix(vx_context c, vx_enum data_type, vx_size columns, vx_size rows); + +/*! \brief Releases a reference to a matrix object. + * The object may not be garbage collected until its total reference count is zero. + * \param [in] mat The matrix reference to release. + * \post After returning from this function the reference is zeroed. + * \return A \ref vx_status_e enumeration. + * \retval VX_SUCCESS No errors. + * \retval VX_ERROR_INVALID_REFERENCE If mat is not a \ref vx_matrix. + * \ingroup group_matrix + */ +VX_API_ENTRY vx_status VX_API_CALL vxReleaseMatrix(vx_matrix *mat); + +/*! \brief Queries an attribute on the matrix object. + * \param [in] mat The matrix object to set. + * \param [in] attribute The attribute to query. Use a \ref vx_matrix_attribute_e enumeration. + * \param [out] ptr The location at which to store the resulting value. + * \param [in] size The size in bytes of the container to which \a ptr points. + * \return A \ref vx_status_e enumeration. + * \ingroup group_matrix + */ +VX_API_ENTRY vx_status VX_API_CALL vxQueryMatrix(vx_matrix mat, vx_enum attribute, void *ptr, vx_size size); + +/*! \brief Gets the matrix data (copy). + * \param [in] mat The reference to the matrix. + * \param [out] array The array in which to place the matrix. + * \see vxQueryMatrix and \ref VX_MATRIX_ATTRIBUTE_COLUMNS and \ref VX_MATRIX_ATTRIBUTE_ROWS + * to get the needed number of elements of the array. + * \return A \ref vx_status_e enumeration. + * \ingroup group_matrix + */ +VX_API_ENTRY vx_status VX_API_CALL vxReadMatrix(vx_matrix mat, void *array); + +/*! \brief Sets the matrix data (copy) + * \param [in] mat The reference to the matrix. + * \param [in] array The array containing the matrix to be written. + * \see vxQueryMatrix and \ref VX_MATRIX_ATTRIBUTE_COLUMNS and \ref VX_MATRIX_ATTRIBUTE_ROWS + * to get the needed number of elements of the array.' + * \return A \ref vx_status_e enumeration. + * \ingroup group_matrix + */ +VX_API_ENTRY vx_status VX_API_CALL vxWriteMatrix(vx_matrix mat, const void *array); + +/*============================================================================== + CONVOLUTION + =============================================================================*/ + +/*! \brief Creates a reference to a convolution matrix object. + * \param [in] context The reference to the overall context. + * \param [in] columns The columns dimension of the convolution. + * Must be odd and greater than or equal to 3 and less than the value returned + * from \ref VX_CONTEXT_ATTRIBUTE_CONVOLUTION_MAXIMUM_DIMENSION. + * \param [in] rows The rows dimension of the convolution. + * Must be odd and greater than or equal to 3 and less than the value returned + * from \ref VX_CONTEXT_ATTRIBUTE_CONVOLUTION_MAXIMUM_DIMENSION. + * \returns A convolution reference \ref vx_convolution. Any possible errors preventing a + * successful creation should be checked using \ref vxGetStatus. + * \ingroup group_convolution + */ +VX_API_ENTRY vx_convolution VX_API_CALL vxCreateConvolution(vx_context context, vx_size columns, vx_size rows); + +/*! \brief Releases the reference to a convolution matrix. + * The object may not be garbage collected until its total reference count is zero. + * \param [in] conv The pointer to the convolution matrix to release. + * \post After returning from this function the reference is zeroed. + * \return A \ref vx_status_e enumeration. + * \retval VX_SUCCESS No errors. + * \retval VX_ERROR_INVALID_REFERENCE If conv is not a \ref vx_convolution. + * \ingroup group_convolution + */ +VX_API_ENTRY vx_status VX_API_CALL vxReleaseConvolution(vx_convolution *conv); + +/*! \brief Queries an attribute on the convolution matrix object. + * \param [in] conv The convolution matrix object to set. + * \param [in] attribute The attribute to query. Use a \ref vx_convolution_attribute_e enumeration. + * \param [out] ptr The location at which to store the resulting value. + * \param [in] size The size in bytes of the container to which \a ptr points. + * \return A \ref vx_status_e enumeration. + * \ingroup group_convolution + */ +VX_API_ENTRY vx_status VX_API_CALL vxQueryConvolution(vx_convolution conv, vx_enum attribute, void *ptr, vx_size size); + +/*! \brief Sets attributes on the convolution object. + * \param [in] conv The coordinates object to set. + * \param [in] attribute The attribute to modify. Use a \ref vx_convolution_attribute_e enumeration. + * \param [in] ptr The pointer to the value to which to set the attribute. + * \param [in] size The size in bytes of the data pointed to by \a ptr. + * \return A \ref vx_status_e enumeration. + * \ingroup group_convolution + */ +VX_API_ENTRY vx_status VX_API_CALL vxSetConvolutionAttribute(vx_convolution conv, vx_enum attribute, const void *ptr, vx_size size); + +/*! \brief Gets the convolution data (copy). + * \param [in] conv The reference to the convolution. + * \param [out] array The array to place the convolution. + * \see vxQueryConvolution and \ref VX_CONVOLUTION_ATTRIBUTE_SIZE to get the + * needed number of bytes of the array. + * \return A \ref vx_status_e enumeration. + * \ingroup group_convolution + */ +VX_API_ENTRY vx_status VX_API_CALL vxReadConvolutionCoefficients(vx_convolution conv, vx_int16 *array); + +/*! \brief Sets the convolution data (copy) + * \param [in] conv The reference to the convolution. + * \param [in] array The array containing the convolution to be written. + * \see \ref vxQueryConvolution and \ref VX_CONVOLUTION_ATTRIBUTE_SIZE to get the + * needed number of bytes of the array. + * \return A \ref vx_status_e enumeration. + * \ingroup group_convolution + */ +VX_API_ENTRY vx_status VX_API_CALL vxWriteConvolutionCoefficients(vx_convolution conv, const vx_int16 *array); + +/*============================================================================== + PYRAMID + =============================================================================*/ + +/*! \brief Creates a reference to a pyramid object of the supplied number of levels. + * \param [in] context The reference to the overall context. + * \param [in] levels The number of levels desired. This is required to be a non-zero value. + * \param [in] scale Used to indicate the scale between pyramid levels. This is required to be a non-zero positive value. + * \if OPENVX_STRICT_1_0 + * In OpenVX 1.0, the only permissible values are \ref VX_SCALE_PYRAMID_HALF or \ref VX_SCALE_PYRAMID_ORB. + * \endif + * \param [in] width The width of the 0th level image in pixels. + * \param [in] height The height of the 0th level image in pixels. + * \param [in] format The format of all images in the pyramid. NV12, NV21, IYUV, UYVY and YUYV formats are not supported. + * \returns A pyramid reference \ref vx_pyramid to the sub-image. Any possible errors preventing a + * successful creation should be checked using \ref vxGetStatus. + * \ingroup group_pyramid + */ +VX_API_ENTRY vx_pyramid VX_API_CALL vxCreatePyramid(vx_context context, vx_size levels, vx_float32 scale, vx_uint32 width, vx_uint32 height, vx_df_image format); + +/*! \brief Creates a reference to a virtual pyramid object of the supplied number of levels. + * \details Virtual Pyramids can be used to connect Nodes together when the contents of the pyramids will + * not be accessed by the user of the API. + * All of the following constructions are valid: + * \code + * vx_context context = vxCreateContext(); + * vx_graph graph = vxCreateGraph(context); + * vx_pyramid virt[] = { + * vxCreateVirtualPyramid(graph, 4, VX_SCALE_PYRAMID_HALF, 0, 0, VX_DF_IMAGE_VIRT), // no dimension and format specified for level 0 + * vxCreateVirtualPyramid(graph, 4, VX_SCALE_PYRAMID_HALF, 640, 480, VX_DF_IMAGE_VIRT), // no format specified. + * vxCreateVirtualPyramid(graph, 4, VX_SCALE_PYRAMID_HALF, 640, 480, VX_DF_IMAGE_U8), // no access + * }; + * \endcode + * \param [in] graph The reference to the parent graph. + * \param [in] levels The number of levels desired. This is required to be a non-zero value. + * \param [in] scale Used to indicate the scale between pyramid levels. This is required to be a non-zero positive value. + * \if OPENVX_STRICT_1_0 + * In OpenVX 1.0, the only permissible values are \ref VX_SCALE_PYRAMID_HALF or \ref VX_SCALE_PYRAMID_ORB. + * \endif + * \param [in] width The width of the 0th level image in pixels. This may be set to zero to indicate to the interface that the value is unspecified. + * \param [in] height The height of the 0th level image in pixels. This may be set to zero to indicate to the interface that the value is unspecified. + * \param [in] format The format of all images in the pyramid. This may be set to \ref VX_DF_IMAGE_VIRT to indicate that the format is unspecified. + * \returns A pyramid reference \ref vx_pyramid. Any possible errors preventing a + * successful creation should be checked using \ref vxGetStatus. + * \note Images extracted with \ref vxGetPyramidLevel behave as Virtual Images and + * cause \ref vxAccessImagePatch to return errors. + * \ingroup group_pyramid + */ +VX_API_ENTRY vx_pyramid VX_API_CALL vxCreateVirtualPyramid(vx_graph graph, vx_size levels, vx_float32 scale, vx_uint32 width, vx_uint32 height, vx_df_image format); + + +/*! \brief Releases a reference to a pyramid object. + * The object may not be garbage collected until its total reference count is zero. + * \param [in] pyr The pointer to the pyramid to release. + * \ingroup group_pyramid + * \return A \ref vx_status_e enumeration. + * \retval VX_SUCCESS No errors. + * \retval VX_ERROR_INVALID_REFERENCE If pyr is not a \ref vx_pyramid. + * \post After returning from this function the reference is zeroed. + */ +VX_API_ENTRY vx_status VX_API_CALL vxReleasePyramid(vx_pyramid *pyr); + +/*! \brief Queries an attribute from an image pyramid. + * \param [in] pyr The pyramid to query. + * \param [in] attribute The attribute for which to query. Use a \ref vx_pyramid_attribute_e enumeration. + * \param [out] ptr The location at which to store the resulting value. + * \param [in] size The size in bytes of the container to which \a ptr points. + * \return A \ref vx_status_e enumeration. + * \ingroup group_pyramid + */ +VX_API_ENTRY vx_status VX_API_CALL vxQueryPyramid(vx_pyramid pyr, vx_enum attribute, void *ptr, vx_size size); + +/*! \brief Retrieves a level of the pyramid as a \ref vx_image, which can be used + * elsewhere in OpenVX. A call to vxReleaseImage is necessary to release an image for each + * call of vxGetPyramidLevel. + * \param [in] pyr The pyramid object. + * \param [in] index The index of the level, such that index is less than levels. + * \return A \ref vx_image reference. + * \retval 0 Indicates that the index or the object is invalid. + * \ingroup group_pyramid + */ +VX_API_ENTRY vx_image VX_API_CALL vxGetPyramidLevel(vx_pyramid pyr, vx_uint32 index); + +/*============================================================================== + REMAP + =============================================================================*/ + +/*! \brief Creates a remap table object. + * \param [in] context The reference to the overall context. + * \param [in] src_width Width of the source image in pixel. + * \param [in] src_height Height of the source image in pixels. + * \param [in] dst_width Width of the destination image in pixels. + * \param [in] dst_height Height of the destination image in pixels. + * \ingroup group_remap + * \returns A remap reference \ref vx_remap. Any possible errors preventing a + * successful creation should be checked using \ref vxGetStatus. + */ +VX_API_ENTRY vx_remap VX_API_CALL vxCreateRemap(vx_context context, + vx_uint32 src_width, + vx_uint32 src_height, + vx_uint32 dst_width, + vx_uint32 dst_height); + +/*! \brief Releases a reference to a remap table object. The object may not be + * garbage collected until its total reference count is zero. + * \param [in] table The pointer to the remap table to release. + * \post After returning from this function the reference is zeroed. + * \return A \ref vx_status_e enumeration. + * \retval VX_SUCCESS No errors. + * \retval VX_ERROR_INVALID_REFERENCE If table is not a \ref vx_remap. + * \ingroup group_remap + */ +VX_API_ENTRY vx_status VX_API_CALL vxReleaseRemap(vx_remap *table); + +/*! \brief Assigns a destination pixel mapping to the source pixel. + * \param [in] table The remap table reference. + * \param [in] dst_x The destination x coordinate. + * \param [in] dst_y The destination y coordinate. + * \param [in] src_x The source x coordinate in float representation to allow interpolation. + * \param [in] src_y The source y coordinate in float representation to allow interpolation. + * \ingroup group_remap + * \return A \ref vx_status_e enumeration. + */ +VX_API_ENTRY vx_status VX_API_CALL vxSetRemapPoint(vx_remap table, + vx_uint32 dst_x, vx_uint32 dst_y, + vx_float32 src_x, vx_float32 src_y); + +/*! \brief Retrieves the source pixel point from a destination pixel. + * \param [in] table The remap table reference. + * \param [in] dst_x The destination x coordinate. + * \param [in] dst_y The destination y coordinate. + * \param [out] src_x The pointer to the location to store the source x coordinate in float representation to allow interpolation. + * \param [out] src_y The pointer to the location to store the source y coordinate in float representation to allow interpolation. + * \ingroup group_remap + * \return A \ref vx_status_e enumeration. + */ +VX_API_ENTRY vx_status VX_API_CALL vxGetRemapPoint(vx_remap table, + vx_uint32 dst_x, vx_uint32 dst_y, + vx_float32 *src_x, vx_float32 *src_y); + +/*! \brief Queries attributes from a Remap table. + * \param [in] r The remap to query. + * \param [in] attribute The attribute to query. Use a \ref vx_remap_attribute_e enumeration. + * \param [out] ptr The location at which to store the resulting value. + * \param [in] size The size in bytes of the container to which \a ptr points. + * \return A \ref vx_status_e enumeration. + * \ingroup group_remap + */ +VX_API_ENTRY vx_status VX_API_CALL vxQueryRemap(vx_remap r, vx_enum attribute, void *ptr, vx_size size); + +/*============================================================================== + ARRAY + =============================================================================*/ + +/*! + * \brief Creates a reference to an Array object. + * + * User must specify the Array capacity (i.e., the maximal number of items that the array can hold). + * + * \param [in] context The reference to the overall Context. + * \param [in] item_type The type of objects to hold. Use: + * \arg \ref VX_TYPE_RECTANGLE for \ref vx_rectangle_t. + * \arg \ref VX_TYPE_KEYPOINT for \ref vx_keypoint_t. + * \arg \ref VX_TYPE_COORDINATES2D for \ref vx_coordinates2d_t. + * \arg \ref VX_TYPE_COORDINATES3D for \ref vx_coordinates3d_t. + * \arg \ref vx_enum Returned from \ref vxRegisterUserStruct. + * \param [in] capacity The maximal number of items that the array can hold. + * + * \returns An array reference \ref vx_array. Any possible errors preventing a + * successful creation should be checked using \ref vxGetStatus. + * + * \ingroup group_array + */ +VX_API_ENTRY vx_array VX_API_CALL vxCreateArray(vx_context context, vx_enum item_type, vx_size capacity); + +/*! + * \brief Creates an opaque reference to a virtual Array with no direct user access. + * + * Virtual Arrays are useful when item type or capacity are unknown ahead of time + * and the Array is used as internal graph edge. Virtual arrays are scoped within the parent graph only. + * + * All of the following constructions are allowed. + * \code + * vx_context context = vxCreateContext(); + * vx_graph graph = vxCreateGraph(context); + * vx_array virt[] = { + * vxCreateVirtualArray(graph, 0, 0), // totally unspecified + * vxCreateVirtualArray(graph, VX_TYPE_KEYPOINT, 0), // unspecified capacity + * vxCreateVirtualArray(graph, VX_TYPE_KEYPOINT, 1000), // no access + * }; + * \endcode + * + * \param [in] graph The reference to the parent graph. + * \param [in] item_type The type of objects to hold. + * This may to set to zero to indicate an unspecified item type. + * \param [in] capacity The maximal number of items that the array can hold. + * This may be to set to zero to indicate an unspecified capacity. + * \see vxCreateArray for a type list. + * \returns A array reference \ref vx_array. Any possible errors preventing a + * successful creation should be checked using \ref vxGetStatus. + * + * \ingroup group_array + */ +VX_API_ENTRY vx_array VX_API_CALL vxCreateVirtualArray(vx_graph graph, vx_enum item_type, vx_size capacity); + +/*! + * \brief Releases a reference of an Array object. + * The object may not be garbage collected until its total reference count is zero. + * After returning from this function the reference is zeroed. + * \param [in] arr The pointer to the Array to release. + * \return A \ref vx_status_e enumeration. + * \retval VX_SUCCESS No errors. + * \retval VX_ERROR_INVALID_REFERENCE If arr is not a \ref vx_array. + * \ingroup group_array + */ +VX_API_ENTRY vx_status VX_API_CALL vxReleaseArray(vx_array *arr); + +/*! + * \brief Queries the Array for some specific information. + * + * \param [in] arr The reference to the Array. + * \param [in] attribute The attribute to query. Use a \ref vx_array_attribute_e. + * \param [out] ptr The location at which to store the resulting value. + * \param [in] size The size in bytes of the container to which \a ptr points. + * + * \return A \ref vx_status_e enumeration. + * \retval VX_SUCCESS No errors. + * \retval VX_ERROR_INVALID_REFERENCE If the \a arr is not a \ref vx_array. + * \retval VX_ERROR_NOT_SUPPORTED If the \a attribute is not a value supported on this implementation. + * \retval VX_ERROR_INVALID_PARAMETERS If any of the other parameters are incorrect. + * + * \ingroup group_array + */ +VX_API_ENTRY vx_status VX_API_CALL vxQueryArray(vx_array arr, vx_enum attribute, void *ptr, vx_size size); + +/*! + * \brief Adds items to the Array. + * + * This function increases the container size. + * + * By default, the function does not reallocate memory, + * so if the container is already full (number of elements is equal to capacity) + * or it doesn't have enough space, + * the function returns \ref VX_FAILURE error code. + * + * \param [in] arr The reference to the Array. + * \param [in] count The total number of elements to insert. + * \param [in] ptr The location at which to store the input values. + * \param [in] stride The number of bytes between the beginning of two consecutive elements. + * + * \return A \ref vx_status_e enumeration. + * \retval VX_SUCCESS No errors. + * \retval VX_ERROR_INVALID_REFERENCE If the \a arr is not a \ref vx_array. + * \retval VX_FAILURE If the Array is full. + * \retval VX_ERROR_INVALID_PARAMETERS If any of the other parameters are incorrect. + * + * \ingroup group_array + */ +VX_API_ENTRY vx_status VX_API_CALL vxAddArrayItems(vx_array arr, vx_size count, const void *ptr, vx_size stride); + +/*! + * \brief Truncates an Array (remove items from the end). + * + * \param [in,out] arr The reference to the Array. + * \param [in] new_num_items The new number of items for the Array. + * + * \return A \ref vx_status_e enumeration. + * \retval VX_SUCCESS No errors. + * \retval VX_ERROR_INVALID_REFERENCE If the \a arr is not a \ref vx_array. + * \retval VX_ERROR_INVALID_PARAMETERS The \a new_size is greater than the current size. + * + * \ingroup group_array + */ +VX_API_ENTRY vx_status VX_API_CALL vxTruncateArray(vx_array arr, vx_size new_num_items); + +/*! + * \brief Grants access to a sub-range of an Array. The number of elements in the sub-range is given by (end - start). + * + * \param [in] arr The reference to the Array. + * \param [in] start The start index. + * \param [in] end The end index. (end - start) elements are accessed from start. + * \param [in, out] stride A pointer to 'number of bytes' between the beginning of two consequent + * elements. + * \arg Input case: ptr is a pointer to a non-NULL pointer. The stride parameter must be the address + * of a vx_size scalar that describes how the user will access the requested array data at address + * (*ptr). + * \arg Output Case: ptr is a pointer to a NULL pointer. The function fills the vx_size scalar + * pointed by stride with the element stride information that the user must consult to access the + * array elements at address (*ptr). + * \param [out] ptr A pointer to a pointer to a location to store the requested data. + * \arg Input Case: ptr is a pointer to a non-NULL pointer to a valid buffer. This buffer will be + * used in one of two ways, depending on the value of the usage parameter. If usage is + * VX_WRITE_ONLY, then the buffer must contain element data that the user wants to replace the + * array's element data with. Otherwise (i.e., usage is not VX_WRITE_ONLY), the array's current + * element data will be written to the memory starting at address (*ptr) as storage memory for the + * access request. The caller must ensure enough memory has been allocated for the requested array + * range with the requested stride. + * \arg Output Case: ptr is a pointer to a NULL pointer. This NULL pointer will be overwritten with + * a pointer to the address where the requested data can be accessed. (*ptr) must eventually be provided + * as the ptr parameter of a call to vxCommitArrayRange. + * \param [in] usage This declares the intended usage of the pointer using the \ref vx_accessor_e enumeration. + * + * \note The stride and ptr parameters must both be input, or both be output, otherwise the behavior + * is undefined. + * + * \return A \ref vx_status_e enumeration. + * \retval VX_SUCCESS No errors. + * \retval VX_ERROR_OPTIMIZED_AWAY If the reference is a virtual array and cannot be accessed or committed. + * \retval VX_ERROR_INVALID_REFERENCE If the \a arr is not a \ref vx_array. + * \retval VX_ERROR_INVALID_PARAMETERS If any of the other parameters are incorrect. + * \post \ref vxCommitArrayRange + * \ingroup group_array + */ +VX_API_ENTRY vx_status VX_API_CALL vxAccessArrayRange(vx_array arr, vx_size start, vx_size end, vx_size *stride, void **ptr, vx_enum usage); + +/*! + * \brief Commits data back to the Array object. + * + * \details This allows a user to commit data to a sub-range of an Array. The number of elements in the sub-range is given by (end - start). + * + * \param [in] arr The reference to the Array. + * \param [in] start The start index. + * \param [in] end The end index. (end - start) elements are accessed from start. + * \param [in] ptr The user supplied pointer. + * + * \return A \ref vx_status_e enumeration. + * \retval VX_SUCCESS No errors. + * \retval VX_ERROR_OPTIMIZED_AWAY If the reference is a virtual array and cannot be accessed or committed. + * \retval VX_ERROR_INVALID_REFERENCE If the \a arr is not a \ref vx_array. + * \retval VX_ERROR_INVALID_PARAMETERS If any of the other parameters are incorrect. + * + * \ingroup group_array + */ +VX_API_ENTRY vx_status VX_API_CALL vxCommitArrayRange(vx_array arr, vx_size start, vx_size end, const void *ptr); + +/*! + * \brief Accesses a specific indexed element in an array. + * \param [in] ptr The base pointer for the array range. + * \param [in] index The index of the element, not byte, to access. + * \param [in] stride The 'number of bytes' between the beginning of two consecutive elements. + * \ingroup group_array + */ +#define vxFormatArrayPointer(ptr, index, stride) \ + (&(((vx_uint8*)(ptr))[(index) * (stride)])) + +/*! + * \brief Allows access to an array item as a typecast pointer deference. + * \param [in] type The type of the item to access. + * \param [in] ptr The base pointer for the array range. + * \param [in] index The index of the element, not byte, to access. + * \param [in] stride The 'number of bytes' between the beginning of two consecutive elements. + * \ingroup group_array + */ +#define vxArrayItem(type, ptr, index, stride) \ + (*(type *)(vxFormatArrayPointer((ptr), (index), (stride)))) + +/*============================================================================== + META FORMAT + =============================================================================*/ + +/*! \brief This function allows a user to set the attributes of a \ref vx_meta_format object in a kernel output validator. + * + * The \ref vx_meta_format object contains two types of information : data object meta data and + * some specific information that defines how the valid region of an image changes + * + * The meta data attributes that can be set are identified by this list: + * - \ref vx_image : \ref VX_IMAGE_ATTRIBUTE_FORMAT, \ref VX_IMAGE_ATTRIBUTE_HEIGHT, \ref VX_IMAGE_ATTRIBUTE_WIDTH + * - \ref vx_array : \ref VX_ARRAY_ATTRIBUTE_CAPACITY, \ref VX_ARRAY_ATTRIBUTE_ITEMTYPE + * - \ref vx_pyramid : \ref VX_PYRAMID_ATTRIBUTE_FORMAT, \ref VX_PYRAMID_ATTRIBUTE_HEIGHT, \ref VX_PYRAMID_ATTRIBUTE_WIDTH, \ref VX_PYRAMID_ATTRIBUTE_LEVELS, \ref VX_PYRAMID_ATTRIBUTE_SCALE + * - \ref vx_scalar : \ref VX_SCALAR_ATTRIBUTE_TYPE + * - \ref vx_matrix : \ref VX_MATRIX_ATTRIBUTE_TYPE, \ref VX_MATRIX_ATTRIBUTE_ROWS, \ref VX_MATRIX_ATTRIBUTE_COLUMNS + * - \ref vx_distribution : \ref VX_DISTRIBUTION_ATTRIBUTE_BINS, \ref VX_DISTRIBUTION_ATTRIBUTE_OFFSET, \ref VX_DISTRIBUTION_ATTRIBUTE_RANGE + * - \ref vx_remap : \ref VX_REMAP_ATTRIBUTE_SOURCE_WIDTH, \ref VX_REMAP_ATTRIBUTE_SOURCE_HEIGHT, \ref VX_REMAP_ATTRIBUTE_DESTINATION_WIDTH, \ref VX_REMAP_ATTRIBUTE_DESTINATION_HEIGHT + * - \ref vx_lut : \ref VX_LUT_ATTRIBUTE_TYPE, \ref VX_LUT_ATTRIBUTE_COUNT + * - \ref vx_threshold : \ref VX_THRESHOLD_ATTRIBUTE_TYPE + * - \ref VX_META_FORMAT_ATTRIBUTE_DELTA_RECTANGLE + * \note For vx_image, a specific attribute can be used to specify the valid region evolution. This information is not a meta data. + * + * \param [in] meta The reference to the \ref vx_meta_format struct to set + * \param [in] attribute Use the subset of data object attributes that define the meta data of this object or attributes from \ref vx_meta_format_attribute_e. + * \param [in] ptr The input pointer of the value to set on the meta format object. + * \param [in] size The size in bytes of the object to which \a ptr points. + * \ingroup group_user_kernels + * \return A \ref vx_status_e enumeration. + * \retval VX_SUCCESS The attribute was set. + * \retval VX_ERROR_INVALID_REFERENCE meta was not a \ref vx_meta_format. + * \retval VX_ERROR_INVALID_PARAMETER size was not correct for the type needed. + * \retval VX_ERROR_NOT_SUPPORTED the object attribute was not supported on the meta format object. + * \retval VX_ERROR_INVALID_TYPE attribute type did not match known meta format type. + */ +VX_API_ENTRY vx_status VX_API_CALL vxSetMetaFormatAttribute(vx_meta_format meta, vx_enum attribute, const void *ptr, vx_size size); + + +#ifdef __cplusplus +} +#endif + +#endif + diff --git a/vx_ext_cv/include/VX/vx_kernels.h b/vx_ext_cv/include/VX/vx_kernels.h new file mode 100644 index 0000000..6519b04 --- /dev/null +++ b/vx_ext_cv/include/VX/vx_kernels.h @@ -0,0 +1,320 @@ +/* +Copyright (c) 2015 Advanced Micro Devices, Inc. All rights reserved. + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. +*/ + + +/* + * Copyright (c) 2012-2015 The Khronos Group Inc. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and/or associated documentation files (the + * "Materials"), to deal in the Materials without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Materials, and to + * permit persons to whom the Materials are furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Materials. + * + * THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY + * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS. + */ + +#ifndef _OPENVX_KERNELS_H_ +#define _OPENVX_KERNELS_H_ + +/*! + * \file + * \brief The list of supported kernels in the OpenVX standard. + */ + +#ifdef __cplusplus +extern "C" { +#endif + +/*! \brief The standard list of available libraries */ +enum vx_library_e { + /*! \brief The base set of kernels as defined by Khronos. */ + VX_LIBRARY_KHR_BASE = 0x0, +}; + +/*! + * \brief The standard list of available vision kernels. + * + * Each kernel listed here can be used with the \ref vxGetKernelByEnum call. + * When programming the parameters, use + * \arg \ref VX_INPUT for [in] + * \arg \ref VX_OUTPUT for [out] + * \arg \ref VX_BIDIRECTIONAL for [in,out] + * + * When programming the parameters, use + * \arg \ref VX_TYPE_IMAGE for a \ref vx_image in the size field of \ref vxGetParameterByIndex or \ref vxSetParameterByIndex * \arg \ref VX_TYPE_ARRAY for a \ref vx_array in the size field of \ref vxGetParameterByIndex or \ref vxSetParameterByIndex * \arg or other appropriate types in \ref vx_type_e. + * \ingroup group_kernel + */ +enum vx_kernel_e { + + /*! + * \brief The invalid kernel is used to for conformance failure in relation to + * some kernel operation (Get/Release). + * \details If the kernel is executed it shall always return an error. + * The kernel has no parameters. To address by name use "org.khronos.openvx.invalid". + */ + VX_KERNEL_INVALID = VX_KERNEL_BASE(VX_ID_KHRONOS, VX_LIBRARY_KHR_BASE) + 0x0, + + /*! + * \brief The Color Space conversion kernel. + * \details The conversions are based on the \ref vx_df_image_e code in the images. + * \see group_vision_function_colorconvert + */ + VX_KERNEL_COLOR_CONVERT = VX_KERNEL_BASE(VX_ID_KHRONOS, VX_LIBRARY_KHR_BASE) + 0x1, + + /*! + * \brief The Generic Channel Extraction Kernel. + * \details This kernel can remove individual color channels from an interleaved + * or semi-planar, planar, sub-sampled planar image. A client could extract + * a red channel from an interleaved RGB image or do a Luma extract from a + * YUV format. + * \see group_vision_function_channelextract + */ + VX_KERNEL_CHANNEL_EXTRACT = VX_KERNEL_BASE(VX_ID_KHRONOS, VX_LIBRARY_KHR_BASE) + 0x2, + + /*! + * \brief The Generic Channel Combine Kernel. + * \details This kernel combine multiple individual planes into a single + * multiplanar image of the type specified in the output image. + * \see group_vision_function_channelcombine + */ + VX_KERNEL_CHANNEL_COMBINE = VX_KERNEL_BASE(VX_ID_KHRONOS, VX_LIBRARY_KHR_BASE) + 0x3, + + /*! \brief The Sobel 3x3 Filter Kernel. + * \see group_vision_function_sobel3x3 + */ + VX_KERNEL_SOBEL_3x3 = VX_KERNEL_BASE(VX_ID_KHRONOS, VX_LIBRARY_KHR_BASE) + 0x4, + + /*! + * \brief The Magnitude Kernel. + * \details This kernel produces a magnitude plane from two input gradients. + * \see group_vision_function_magnitude + */ + VX_KERNEL_MAGNITUDE = VX_KERNEL_BASE(VX_ID_KHRONOS, VX_LIBRARY_KHR_BASE) + 0x5, + + /*! + * \brief The Phase Kernel. + * \details This kernel produces a phase plane from two input gradients. + * \see group_vision_function_phase + */ + VX_KERNEL_PHASE = VX_KERNEL_BASE(VX_ID_KHRONOS, VX_LIBRARY_KHR_BASE) + 0x6, + + /*! + * \brief The Scale Image Kernel. + * \details This kernel provides resizing of an input image to an output image. + * The scaling factor is determined but the relative sizes of the input and + * output. + * \see group_vision_function_scale_image + */ + VX_KERNEL_SCALE_IMAGE = VX_KERNEL_BASE(VX_ID_KHRONOS, VX_LIBRARY_KHR_BASE) + 0x7, + + /*! \brief The Table Lookup kernel + * \see group_vision_function_lut + */ + VX_KERNEL_TABLE_LOOKUP = VX_KERNEL_BASE(VX_ID_KHRONOS, VX_LIBRARY_KHR_BASE) + 0x8, + + /*! \brief The Histogram Kernel. + * \see group_vision_function_histogram + */ + VX_KERNEL_HISTOGRAM = VX_KERNEL_BASE(VX_ID_KHRONOS, VX_LIBRARY_KHR_BASE) + 0x9, + + /*! \brief The Histogram Equalization Kernel. + * \see group_vision_function_equalize_hist + */ + VX_KERNEL_EQUALIZE_HISTOGRAM = VX_KERNEL_BASE(VX_ID_KHRONOS, VX_LIBRARY_KHR_BASE) + 0xA, + + /*! \brief The Absolute Difference Kernel. + * \see group_vision_function_absdiff + */ + VX_KERNEL_ABSDIFF = VX_KERNEL_BASE(VX_ID_KHRONOS, VX_LIBRARY_KHR_BASE) + 0xB, + + /*! \brief The Mean and Standard Deviation Kernel. + * \see group_vision_function_meanstddev + */ + VX_KERNEL_MEAN_STDDEV = VX_KERNEL_BASE(VX_ID_KHRONOS, VX_LIBRARY_KHR_BASE) + 0xC, + + /*! \brief The Threshold Kernel. + * \see group_vision_function_threshold + */ + VX_KERNEL_THRESHOLD = VX_KERNEL_BASE(VX_ID_KHRONOS, VX_LIBRARY_KHR_BASE) + 0xD, + + /*! \brief The Integral Image Kernel. + * \see group_vision_function_integral_image + */ + VX_KERNEL_INTEGRAL_IMAGE = VX_KERNEL_BASE(VX_ID_KHRONOS, VX_LIBRARY_KHR_BASE) + 0xE, + + /*! \brief The dilate kernel. + * \see group_vision_function_dilate_image + */ + VX_KERNEL_DILATE_3x3 = VX_KERNEL_BASE(VX_ID_KHRONOS, VX_LIBRARY_KHR_BASE) + 0xF, + + /*! \brief The erode kernel. + * \see group_vision_function_erode_image + */ + VX_KERNEL_ERODE_3x3 = VX_KERNEL_BASE(VX_ID_KHRONOS, VX_LIBRARY_KHR_BASE) + 0x10, + + /*! \brief The median image filter. + * \see group_vision_function_median_image + */ + VX_KERNEL_MEDIAN_3x3 = VX_KERNEL_BASE(VX_ID_KHRONOS, VX_LIBRARY_KHR_BASE) + 0x11, + + /*! \brief The box filter kernel. + * \see group_vision_function_box_image + */ + VX_KERNEL_BOX_3x3 = VX_KERNEL_BASE(VX_ID_KHRONOS, VX_LIBRARY_KHR_BASE) + 0x12, + + /*! \brief The gaussian filter kernel. + * \see group_vision_function_gaussian_image + */ + VX_KERNEL_GAUSSIAN_3x3 = VX_KERNEL_BASE(VX_ID_KHRONOS, VX_LIBRARY_KHR_BASE) + 0x13, + + /*! \brief The custom convolution kernel. + * \see group_vision_function_custom_convolution + */ + VX_KERNEL_CUSTOM_CONVOLUTION = VX_KERNEL_BASE(VX_ID_KHRONOS, VX_LIBRARY_KHR_BASE) + 0x14, + + /*! \brief The gaussian image pyramid kernel. + * \see group_vision_function_gaussian_pyramid + */ + VX_KERNEL_GAUSSIAN_PYRAMID = VX_KERNEL_BASE(VX_ID_KHRONOS, VX_LIBRARY_KHR_BASE) + 0x15, + + /*! \brief The accumulation kernel. + * \see group_vision_function_accumulate + */ + VX_KERNEL_ACCUMULATE = VX_KERNEL_BASE(VX_ID_KHRONOS, VX_LIBRARY_KHR_BASE) + 0x16, + + /*! \brief The weigthed accumulation kernel. + * \see group_vision_function_accumulate_weighted + */ + VX_KERNEL_ACCUMULATE_WEIGHTED = VX_KERNEL_BASE(VX_ID_KHRONOS, VX_LIBRARY_KHR_BASE) + 0x17, + + /*! \brief The squared accumulation kernel. + * \see group_vision_function_accumulate_square + */ + VX_KERNEL_ACCUMULATE_SQUARE = VX_KERNEL_BASE(VX_ID_KHRONOS, VX_LIBRARY_KHR_BASE) + 0x18, + + /*! \brief The min and max location kernel. + * \see group_vision_function_minmaxloc + */ + VX_KERNEL_MINMAXLOC = VX_KERNEL_BASE(VX_ID_KHRONOS, VX_LIBRARY_KHR_BASE) + 0x19, + + /*! \brief The bit-depth conversion kernel. + * \see group_vision_function_convertdepth + */ + VX_KERNEL_CONVERTDEPTH = VX_KERNEL_BASE(VX_ID_KHRONOS, VX_LIBRARY_KHR_BASE) + 0x1A, + + /*! \brief The Canny Edge Detector. + * \see group_vision_function_canny + */ + VX_KERNEL_CANNY_EDGE_DETECTOR = VX_KERNEL_BASE(VX_ID_KHRONOS, VX_LIBRARY_KHR_BASE) + 0x1B, + + /*! \brief The Bitwise And Kernel. + * \see group_vision_function_and + */ + VX_KERNEL_AND = VX_KERNEL_BASE(VX_ID_KHRONOS, VX_LIBRARY_KHR_BASE) + 0x1C, + + /*! \brief The Bitwise Inclusive Or Kernel. + * \see group_vision_function_or + */ + VX_KERNEL_OR = VX_KERNEL_BASE(VX_ID_KHRONOS, VX_LIBRARY_KHR_BASE) + 0x1D, + + /*! \brief The Bitwise Exclusive Or Kernel. + * \see group_vision_function_xor + */ + VX_KERNEL_XOR = VX_KERNEL_BASE(VX_ID_KHRONOS, VX_LIBRARY_KHR_BASE) + 0x1E, + + /*! \brief The Bitwise Not Kernel. + * \see group_vision_function_not + */ + VX_KERNEL_NOT = VX_KERNEL_BASE(VX_ID_KHRONOS, VX_LIBRARY_KHR_BASE) + 0x1F, + + /*! \brief The Pixelwise Multiplication Kernel. + * \see group_vision_function_mult + */ + VX_KERNEL_MULTIPLY = VX_KERNEL_BASE(VX_ID_KHRONOS, VX_LIBRARY_KHR_BASE) + 0x20, + + /*! \brief The Addition Kernel. + * \see group_vision_function_add + */ + VX_KERNEL_ADD = VX_KERNEL_BASE(VX_ID_KHRONOS, VX_LIBRARY_KHR_BASE) + 0x21, + + /*! \brief The Subtraction Kernel. + * \see group_vision_function_sub + */ + VX_KERNEL_SUBTRACT = VX_KERNEL_BASE(VX_ID_KHRONOS, VX_LIBRARY_KHR_BASE) + 0x22, + + /*! \brief The Warp Affine Kernel. + * \see group_vision_function_warp_affine + */ + VX_KERNEL_WARP_AFFINE = VX_KERNEL_BASE(VX_ID_KHRONOS, VX_LIBRARY_KHR_BASE) + 0x23, + + /*! \brief The Warp Perspective Kernel. + * \see group_vision_function_warp_perspective + */ + VX_KERNEL_WARP_PERSPECTIVE = VX_KERNEL_BASE(VX_ID_KHRONOS, VX_LIBRARY_KHR_BASE) + 0x24, + + /*! \brief The Harris Corners Kernel. + * \see group_vision_function_harris + */ + VX_KERNEL_HARRIS_CORNERS = VX_KERNEL_BASE(VX_ID_KHRONOS, VX_LIBRARY_KHR_BASE) + 0x25, + + /*! \brief The FAST Corners Kernel. + * \see group_vision_function_fast + */ + VX_KERNEL_FAST_CORNERS = VX_KERNEL_BASE(VX_ID_KHRONOS, VX_LIBRARY_KHR_BASE) + 0x26, + + /*! \brief The Optical Flow Pyramid (LK) Kernel. + * \see group_vision_function_opticalflowpyrlk + */ + VX_KERNEL_OPTICAL_FLOW_PYR_LK = VX_KERNEL_BASE(VX_ID_KHRONOS, VX_LIBRARY_KHR_BASE) + 0x27, + + /*! \brief The Remap Kernel. + * \see group_vision_function_remap + */ + VX_KERNEL_REMAP = VX_KERNEL_BASE(VX_ID_KHRONOS, VX_LIBRARY_KHR_BASE) + 0x28, + + + /*! \brief The Half Scale Gaussian Kernel. + * \see group_vision_function_scale_image + */ + VX_KERNEL_HALFSCALE_GAUSSIAN = VX_KERNEL_BASE(VX_ID_KHRONOS, VX_LIBRARY_KHR_BASE) + 0x29, + + /* insert new kernels here */ + VX_KERNEL_MAX_1_0, /*!< \internal Used for bounds checking in the conformance test. */ +}; + +#ifdef __cplusplus +} +#endif + +#endif /* _OPEN_VISION_LIBRARY_KERNELS_H_ */ diff --git a/vx_ext_cv/include/VX/vx_nodes.h b/vx_ext_cv/include/VX/vx_nodes.h new file mode 100644 index 0000000..3ff6bdf --- /dev/null +++ b/vx_ext_cv/include/VX/vx_nodes.h @@ -0,0 +1,615 @@ +/* +Copyright (c) 2015 Advanced Micro Devices, Inc. All rights reserved. + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. +*/ + + +/******************************************************************************* +* Copyright (c) 2012-2015 The Khronos Group Inc. +* +* Permission is hereby granted, free of charge, to any person obtaining a +* copy of this software and/or associated documentation files (the +* "Materials"), to deal in the Materials without restriction, including +* without limitation the rights to use, copy, modify, merge, publish, +* distribute, sublicense, and/or sell copies of the Materials, and to +* permit persons to whom the Materials are furnished to do so, subject to +* the following conditions: +* +* The above copyright notice and this permission notice shall be included +* in all copies or substantial portions of the Materials. +* +* THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. +* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY +* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, +* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE +* MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS. +******************************************************************************/ + +#ifndef _OPENVX_NODES_H_ +#define _OPENVX_NODES_H_ + +/*! + * \file vx_nodes.h + * \brief The "Simple" API interface for OpenVX. These APIs are just + * wrappers around the more verbose functions defined in \ref vx_api.h. + */ + +#ifdef __cplusplus +extern "C" { +#endif + +/*! \brief [Graph] Creates a color conversion node. + * \param [in] graph The reference to the graph. + * \param [in] input The input image from which to convert. + * \param [out] output The output image to which to convert. + * \see VX_KERNEL_COLOR_CONVERT + * \ingroup group_vision_function_colorconvert + * \return \ref vx_node. + * \retval vx_node A node reference. Any possible errors preventing a successful creation should be checked using \ref vxGetStatus + */ +VX_API_ENTRY vx_node VX_API_CALL vxColorConvertNode(vx_graph graph, vx_image input, vx_image output); + +/*! \brief [Graph] Creates a channel extract node. + * \param [in] graph The reference to the graph. + * \param [in] input The input image. Must be one of the defined \ref vx_df_image_e multi-planar formats. + * \param [in] channel The \ref vx_channel_e channel to extract. + * \param [out] output The output image. Must be \ref VX_DF_IMAGE_U8. + * \see VX_KERNEL_CHANNEL_EXTRACT + * \ingroup group_vision_function_channelextract + * \return \ref vx_node. + * \retval vx_node A node reference. Any possible errors preventing a successful creation should be checked using \ref vxGetStatus + */ +VX_API_ENTRY vx_node VX_API_CALL vxChannelExtractNode(vx_graph graph, + vx_image input, + vx_enum channel, + vx_image output); + +/*! \brief [Graph] Creates a channel combine node. + * \param [in] graph The graph reference. + * \param [in] plane0 The plane that forms channel 0. Must be \ref VX_DF_IMAGE_U8. + * \param [in] plane1 The plane that forms channel 1. Must be \ref VX_DF_IMAGE_U8. + * \param [in] plane2 [optional] The plane that forms channel 2. Must be \ref VX_DF_IMAGE_U8. + * \param [in] plane3 [optional] The plane that forms channel 3. Must be \ref VX_DF_IMAGE_U8. + * \param [out] output The output image. The format of the image must be defined, even if the image is virtual. + * \see VX_KERNEL_CHANNEL_COMBINE + * \ingroup group_vision_function_channelcombine + * \return \ref vx_node. + * \retval vx_node A node reference. Any possible errors preventing a successful creation should be checked using \ref vxGetStatus + */ +VX_API_ENTRY vx_node VX_API_CALL vxChannelCombineNode(vx_graph graph, + vx_image plane0, + vx_image plane1, + vx_image plane2, + vx_image plane3, + vx_image output); + +/*! \brief [Graph] Creates a Phase node. + * \param [in] graph The reference to the graph. + * \param [in] grad_x The input x image. This must be in \ref VX_DF_IMAGE_S16 format. + * \param [in] grad_y The input y image. This must be in \ref VX_DF_IMAGE_S16 format. + * \param [out] orientation The phase image. This is in \ref VX_DF_IMAGE_U8 format. + * \see VX_KERNEL_PHASE + * \ingroup group_vision_function_phase + * \return \ref vx_node. + * \retval vx_node A node reference. Any possible errors preventing a successful creation should be checked using \ref vxGetStatus + */ +VX_API_ENTRY vx_node VX_API_CALL vxPhaseNode(vx_graph graph, vx_image grad_x, vx_image grad_y, vx_image orientation); + +/*! \brief [Graph] Creates a Sobel3x3 node. + * \param [in] graph The reference to the graph. + * \param [in] input The input image in \ref VX_DF_IMAGE_U8 format. + * \param [out] output_x [optional] The output gradient in the x direction in \ref VX_DF_IMAGE_S16. + * \param [out] output_y [optional] The output gradient in the y direction in \ref VX_DF_IMAGE_S16. + * \see VX_KERNEL_SOBEL_3x3 + * \ingroup group_vision_function_sobel3x3 + * \return \ref vx_node. + * \retval vx_node A node reference. Any possible errors preventing a successful creation should be checked using \ref vxGetStatus + */ +VX_API_ENTRY vx_node VX_API_CALL vxSobel3x3Node(vx_graph graph, vx_image input, vx_image output_x, vx_image output_y); + + +/*! \brief [Graph] Create a Magnitude node. + * \param [in] graph The reference to the graph. + * \param [in] grad_x The input x image. This must be in \ref VX_DF_IMAGE_S16 format. + * \param [in] grad_y The input y image. This must be in \ref VX_DF_IMAGE_S16 format. + * \param [out] mag The magnitude image. This is in \ref VX_DF_IMAGE_S16 format. + * \see VX_KERNEL_MAGNITUDE + * \ingroup group_vision_function_magnitude + * \return \ref vx_node. + * \retval vx_node A node reference. Any possible errors preventing a successful creation should be checked using \ref vxGetStatus + */ +VX_API_ENTRY vx_node VX_API_CALL vxMagnitudeNode(vx_graph graph, vx_image grad_x, vx_image grad_y, vx_image mag); + +/*! \brief [Graph] Creates a Scale Image Node. + * \param [in] graph The reference to the graph. + * \param [in] src The source image of type \ref VX_DF_IMAGE_U8. + * \param [out] dst The destination image of type \ref VX_DF_IMAGE_U8. + * \param [in] type The interpolation type to use. \see vx_interpolation_type_e. + * \ingroup group_vision_function_scale_image + * \note The destination image must have a defined size and format. Only + * \ref VX_NODE_ATTRIBUTE_BORDER_MODE value \ref VX_BORDER_MODE_UNDEFINED, + * \ref VX_BORDER_MODE_REPLICATE or \ref VX_BORDER_MODE_CONSTANT is supported. + * \return \ref vx_node. + * \retval vx_node A node reference. Any possible errors preventing a successful creation should be checked using \ref vxGetStatus + */ +VX_API_ENTRY vx_node VX_API_CALL vxScaleImageNode(vx_graph graph, vx_image src, vx_image dst, vx_enum type); + +/*! \brief [Graph] Creates a Table Lookup node. + * \param [in] graph The reference to the graph. + * \param [in] input The input image in \ref VX_DF_IMAGE_U8. + * \param [in] lut The LUT which is of type \ref VX_TYPE_UINT8. + * \param [out] output The output image of type \ref VX_DF_IMAGE_U8. + * \ingroup group_vision_function_lut + * \return \ref vx_node. + * \retval vx_node A node reference. Any possible errors preventing a successful creation should be checked using \ref vxGetStatus + */ +VX_API_ENTRY vx_node VX_API_CALL vxTableLookupNode(vx_graph graph, vx_image input, vx_lut lut, vx_image output); + +/*! \brief [Graph] Creates a Histogram node. + * \param [in] graph The reference to the graph. + * \param [in] input The input image in \ref VX_DF_IMAGE_U8. + * \param [out] distribution The output distribution. + * \ingroup group_vision_function_histogram + * \return \ref vx_node. + * \retval vx_node A node reference. Any possible errors preventing a successful creation should be checked using \ref vxGetStatus + */ +VX_API_ENTRY vx_node VX_API_CALL vxHistogramNode(vx_graph graph, vx_image input, vx_distribution distribution); + +/*! \brief [Graph] Creates a Histogram Equalization node. + * \param [in] graph The reference to the graph. + * \param [in] input The grayscale input image in \ref VX_DF_IMAGE_U8. + * \param [out] output The grayscale output image of type \ref VX_DF_IMAGE_U8 with equalized brightness and contrast. + * \ingroup group_vision_function_equalize_hist + * \return \ref vx_node. + * \retval vx_node A node reference. Any possible errors preventing a successful creation should be checked using \ref vxGetStatus + */ +VX_API_ENTRY vx_node VX_API_CALL vxEqualizeHistNode(vx_graph graph, vx_image input, vx_image output); + +/*! \brief [Graph] Creates an AbsDiff node. + * \param [in] graph The reference to the graph. + * \param [in] in1 An input image in \ref VX_DF_IMAGE_U8 or \ref VX_DF_IMAGE_S16 format. + * \param [in] in2 An input image in \ref VX_DF_IMAGE_U8 or \ref VX_DF_IMAGE_S16 format. + * \param [out] out The output image in \ref VX_DF_IMAGE_U8 or \ref VX_DF_IMAGE_S16 format. + * \ingroup group_vision_function_absdiff + * \retval vx_node A node reference. Any possible errors preventing a successful creation should be checked using \ref vxGetStatus + */ +VX_API_ENTRY vx_node VX_API_CALL vxAbsDiffNode(vx_graph graph, vx_image in1, vx_image in2, vx_image out); + +/*! \brief [Graph] Creates a mean value and standard deviation node. + * \param [in] graph The reference to the graph. + * \param [in] input The input image. \ref VX_DF_IMAGE_U8 is supported. + * \param [out] mean The \ref VX_TYPE_FLOAT32 average pixel value. + * \param [out] stddev The \ref VX_TYPE_FLOAT32 standard deviation of the pixel values. + * \ingroup group_vision_function_meanstddev + * \return \ref vx_node. + * \retval vx_node A node reference. Any possible errors preventing a successful creation should be checked using \ref vxGetStatus + */ +VX_API_ENTRY vx_node VX_API_CALL vxMeanStdDevNode(vx_graph graph, vx_image input, vx_scalar mean, vx_scalar stddev); + +/*! \brief [Graph] Creates a Threshold node. + * \param [in] graph The reference to the graph. + * \param [in] input The input image. \ref VX_DF_IMAGE_U8 is supported. + * \param [in] thresh The thresholding object that defines the parameters of + * the operation. + * \param [out] output The output Boolean image. Values are either 0 or 255. + * \ingroup group_vision_function_threshold + * \return \ref vx_node. + * \retval vx_node A node reference. Any possible errors preventing a successful creation should be checked using \ref vxGetStatus + */ +VX_API_ENTRY vx_node VX_API_CALL vxThresholdNode(vx_graph graph, vx_image input, vx_threshold thresh, vx_image output); + +/*! \brief [Graph] Creates an Integral Image Node. + * \param [in] graph The reference to the graph. + * \param [in] input The input image in \ref VX_DF_IMAGE_U8 format. + * \param [out] output The output image in \ref VX_DF_IMAGE_U32 format. + * \ingroup group_vision_function_integral_image + * \return \ref vx_node. + * \retval vx_node A node reference. Any possible errors preventing a successful creation should be checked using \ref vxGetStatus + */ +VX_API_ENTRY vx_node VX_API_CALL vxIntegralImageNode(vx_graph graph, vx_image input, vx_image output); + +/*! \brief [Graph] Creates an Erosion Image Node. + * \param [in] graph The reference to the graph. + * \param [in] input The input image in \ref VX_DF_IMAGE_U8 format. + * \param [out] output The output image in \ref VX_DF_IMAGE_U8 format. + * \ingroup group_vision_function_erode_image + * \return \ref vx_node. + * \retval vx_node A node reference. Any possible errors preventing a successful creation should be checked using \ref vxGetStatus + */ +VX_API_ENTRY vx_node VX_API_CALL vxErode3x3Node(vx_graph graph, vx_image input, vx_image output); + +/*! \brief [Graph] Creates a Dilation Image Node. + * \param [in] graph The reference to the graph. + * \param [in] input The input image in \ref VX_DF_IMAGE_U8 format. + * \param [out] output The output image in \ref VX_DF_IMAGE_U8 format. + * \ingroup group_vision_function_dilate_image + * \return \ref vx_node. + * \retval vx_node A node reference. Any possible errors preventing a successful creation should be checked using \ref vxGetStatus + */ +VX_API_ENTRY vx_node VX_API_CALL vxDilate3x3Node(vx_graph graph, vx_image input, vx_image output); + +/*! \brief [Graph] Creates a Median Image Node. + * \param [in] graph The reference to the graph. + * \param [in] input The input image in \ref VX_DF_IMAGE_U8 format. + * \param [out] output The output image in \ref VX_DF_IMAGE_U8 format. + * \ingroup group_vision_function_median_image + * \return \ref vx_node. + * \retval vx_node A node reference. Any possible errors preventing a successful creation should be checked using \ref vxGetStatus + */ +VX_API_ENTRY vx_node VX_API_CALL vxMedian3x3Node(vx_graph graph, vx_image input, vx_image output); + +/*! \brief [Graph] Creates a Box Filter Node. + * \param [in] graph The reference to the graph. + * \param [in] input The input image in \ref VX_DF_IMAGE_U8 format. + * \param [out] output The output image in \ref VX_DF_IMAGE_U8 format. + * \ingroup group_vision_function_box_image + * \return \ref vx_node. + * \retval vx_node A node reference. Any possible errors preventing a successful creation should be checked using \ref vxGetStatus + */ +VX_API_ENTRY vx_node VX_API_CALL vxBox3x3Node(vx_graph graph, vx_image input, vx_image output); + +/*! \brief [Graph] Creates a Gaussian Filter Node. + * \param [in] graph The reference to the graph. + * \param [in] input The input image in \ref VX_DF_IMAGE_U8 format. + * \param [out] output The output image in \ref VX_DF_IMAGE_U8 format. + * \ingroup group_vision_function_gaussian_image + * \return \ref vx_node. + * \retval vx_node A node reference. Any possible errors preventing a successful creation should be checked using \ref vxGetStatus + */ +VX_API_ENTRY vx_node VX_API_CALL vxGaussian3x3Node(vx_graph graph, vx_image input, vx_image output); + +/*! \brief [Graph] Creates a custom convolution node. + * \param [in] graph The reference to the graph. + * \param [in] input The input image in \ref VX_DF_IMAGE_U8 format. + * \param [in] conv The vx_int16 convolution matrix. + * \param [out] output The output image in \ref VX_DF_IMAGE_U8 or \ref VX_DF_IMAGE_S16 format. + * \ingroup group_vision_function_custom_convolution + * \return \ref vx_node. + * \retval vx_node A node reference. Any possible errors preventing a successful creation should be checked using \ref vxGetStatus + */ +VX_API_ENTRY vx_node VX_API_CALL vxConvolveNode(vx_graph graph, vx_image input, vx_convolution conv, vx_image output); + +/*! \brief [Graph] Creates a node for a Gaussian Image Pyramid. + * \param [in] graph The reference to the graph. + * \param [in] input The input image in \ref VX_DF_IMAGE_U8 format. + * \param [out] gaussian The Gaussian pyramid with \ref VX_DF_IMAGE_U8 to construct. + * \ingroup group_vision_function_gaussian_pyramid + * \see group_pyramid + * \return \ref vx_node. + * \retval vx_node A node reference. Any possible errors preventing a successful creation should be checked using \ref vxGetStatus + */ +VX_API_ENTRY vx_node VX_API_CALL vxGaussianPyramidNode(vx_graph graph, vx_image input, vx_pyramid gaussian); + +/*! \brief [Graph] Creates an accumulate node. + * \param [in] graph The reference to the graph. + * \param [in] input The input \ref VX_DF_IMAGE_U8 image. + * \param [in,out] accum The accumulation image in \ref VX_DF_IMAGE_S16. + * \ingroup group_vision_function_accumulate + * \return \ref vx_node. + * \retval vx_node A node reference. Any possible errors preventing a successful creation should be checked using \ref vxGetStatus + */ +VX_API_ENTRY vx_node VX_API_CALL vxAccumulateImageNode(vx_graph graph, vx_image input, vx_image accum); + +/*! \brief [Graph] Creates a weighted accumulate node. + * \param [in] graph The reference to the graph. + * \param [in] input The input \ref VX_DF_IMAGE_U8 image. + * \param [in] alpha The input \ref VX_TYPE_FLOAT32 scalar value with a value in the range of \f$ 0.0 \le \alpha \le 1.0 \f$. + * \param [in,out] accum The \ref VX_DF_IMAGE_U8 accumulation image. + * \ingroup group_vision_function_accumulate_weighted + * \return \ref vx_node. + * \retval vx_node A node reference. Any possible errors preventing a successful creation should be checked using \ref vxGetStatus + */ +VX_API_ENTRY vx_node VX_API_CALL vxAccumulateWeightedImageNode(vx_graph graph, vx_image input, vx_scalar alpha, vx_image accum); + +/*! \brief [Graph] Creates an accumulate square node. + * \param [in] graph The reference to the graph. + * \param [in] input The input \ref VX_DF_IMAGE_U8 image. + * \param [in] shift The input \ref VX_TYPE_UINT32 with a value in the range of \f$ 0 \le shift \le 15 \f$. + * \param [in,out] accum The accumulation image in \ref VX_DF_IMAGE_S16. + * \ingroup group_vision_function_accumulate_square + * \return \ref vx_node. + * \retval vx_node A node reference. Any possible errors preventing a successful creation should be checked using \ref vxGetStatus + */ +VX_API_ENTRY vx_node VX_API_CALL vxAccumulateSquareImageNode(vx_graph graph, vx_image input, vx_scalar shift, vx_image accum); + +/*! \brief [Graph] Creates a min,max,loc node. + * \param [in] graph The reference to create the graph. + * \param [in] input The input image in \ref VX_DF_IMAGE_U8 or \ref VX_DF_IMAGE_S16 format. + * \param [out] minVal The minimum value in the image, which corresponds to the type of the input. + * \param [out] maxVal The maximum value in the image, which corresponds to the type of the input. + * \param [out] minLoc The minimum \ref VX_TYPE_COORDINATES2D locations (optional). If the input image has several minimums, the kernel will return up to the capacity of the array. + * \param [out] maxLoc The maximum \ref VX_TYPE_COORDINATES2D locations (optional). If the input image has several maximums, the kernel will return up to the capacity of the array. + * \param [out] minCount The total number of detected minimums in image (optional). Use a \ref VX_TYPE_UINT32 scalar. + * \param [out] maxCount The total number of detected maximums in image (optional). Use a \ref VX_TYPE_UINT32 scalar. + * \ingroup group_vision_function_minmaxloc + * \return \ref vx_node. + * \retval vx_node A node reference. Any possible errors preventing a successful creation should be checked using \ref vxGetStatus + */ +VX_API_ENTRY vx_node VX_API_CALL vxMinMaxLocNode(vx_graph graph, + vx_image input, + vx_scalar minVal, vx_scalar maxVal, + vx_array minLoc, vx_array maxLoc, + vx_scalar minCount, vx_scalar maxCount); + +/*! \brief [Graph] Creates a bitwise AND node. + * \param [in] graph The reference to the graph. + * \param [in] in1 A \ref VX_DF_IMAGE_U8 input image. + * \param [in] in2 A \ref VX_DF_IMAGE_U8 input image. + * \param [out] out The \ref VX_DF_IMAGE_U8 output image. + * \ingroup group_vision_function_and + * \return \ref vx_node. + * \retval vx_node A node reference. Any possible errors preventing a successful creation should be checked using \ref vxGetStatus + */ +VX_API_ENTRY vx_node VX_API_CALL vxAndNode(vx_graph graph, vx_image in1, vx_image in2, vx_image out); + +/*! \brief [Graph] Creates a bitwise INCLUSIVE OR node. + * \param [in] graph The reference to the graph. + * \param [in] in1 A \ref VX_DF_IMAGE_U8 input image. + * \param [in] in2 A \ref VX_DF_IMAGE_U8 input image. + * \param [out] out The \ref VX_DF_IMAGE_U8 output image. + * \ingroup group_vision_function_or + * \return \ref vx_node. + * \retval vx_node A node reference. Any possible errors preventing a successful creation should be checked using \ref vxGetStatus + */ +VX_API_ENTRY vx_node VX_API_CALL vxOrNode(vx_graph graph, vx_image in1, vx_image in2, vx_image out); + +/*! \brief [Graph] Creates a bitwise EXCLUSIVE OR node. + * \param [in] graph The reference to the graph. + * \param [in] in1 A \ref VX_DF_IMAGE_U8 input image. + * \param [in] in2 A \ref VX_DF_IMAGE_U8 input image. + * \param [out] out The \ref VX_DF_IMAGE_U8 output image. + * \ingroup group_vision_function_xor + * \return \ref vx_node. + * \retval vx_node A node reference. Any possible errors preventing a successful creation should be checked using \ref vxGetStatus + */ +VX_API_ENTRY vx_node VX_API_CALL vxXorNode(vx_graph graph, vx_image in1, vx_image in2, vx_image out); + +/*! \brief [Graph] Creates a bitwise NOT node. + * \param [in] graph The reference to the graph. + * \param [in] input A \ref VX_DF_IMAGE_U8 input image. + * \param [out] output The \ref VX_DF_IMAGE_U8 output image. + * \ingroup group_vision_function_not + * \return \ref vx_node. + * \retval vx_node A node reference. Any possible errors preventing a successful creation should be checked using \ref vxGetStatus + */ +VX_API_ENTRY vx_node VX_API_CALL vxNotNode(vx_graph graph, vx_image input, vx_image output); + +/*! \brief [Graph] Creates an pixelwise-multiplication node. + * \param [in] graph The reference to the graph. + * \param [in] in1 An input image, \ref VX_DF_IMAGE_U8 or \ref VX_DF_IMAGE_S16. + * \param [in] in2 An input image, \ref VX_DF_IMAGE_U8 or \ref VX_DF_IMAGE_S16. + * \param [in] scale A non-negative \ref VX_TYPE_FLOAT32 multiplied to each product before overflow handling. + * \param [in] overflow_policy A \ref VX_TYPE_ENUM of the \ref vx_convert_policy_e enumeration. + * \param [in] rounding_policy A \ref VX_TYPE_ENUM of the \ref vx_round_policy_e enumeration. + * \param [out] out The output image, a \ref VX_DF_IMAGE_U8 or \ref VX_DF_IMAGE_S16 image. + * \ingroup group_vision_function_mult + * \return \ref vx_node. + * \retval vx_node A node reference. Any possible errors preventing a successful creation should be checked using \ref vxGetStatus + */ +VX_API_ENTRY vx_node VX_API_CALL vxMultiplyNode(vx_graph graph, + vx_image in1, vx_image in2, + vx_scalar scale, + vx_enum overflow_policy, + vx_enum rounding_policy, + vx_image out); + +/*! \brief [Graph] Creates an arithmetic addition node. + * \param [in] graph The reference to the graph. + * \param [in] in1 An input image, \ref VX_DF_IMAGE_U8 or \ref VX_DF_IMAGE_S16. + * \param [in] in2 An input image, \ref VX_DF_IMAGE_U8 or \ref VX_DF_IMAGE_S16. + * \param [in] policy A \ref VX_TYPE_ENUM of the \ref vx_convert_policy_e enumeration. + * \param [out] out The output image, a \ref VX_DF_IMAGE_U8 or \ref VX_DF_IMAGE_S16 image. + * \ingroup group_vision_function_add + * \return \ref vx_node. + * \retval vx_node A node reference. Any possible errors preventing a successful creation should be checked using \ref vxGetStatus + */ +VX_API_ENTRY vx_node VX_API_CALL vxAddNode(vx_graph graph, + vx_image in1, vx_image in2, + vx_enum policy, + vx_image out); + +/*! \brief [Graph] Creates an arithmetic subtraction node. + * \param [in] graph The reference to the graph. + * \param [in] in1 An input image, \ref VX_DF_IMAGE_U8 or \ref VX_DF_IMAGE_S16, the minuend. + * \param [in] in2 An input image, \ref VX_DF_IMAGE_U8 or \ref VX_DF_IMAGE_S16, the subtrahend. + * \param [in] policy A \ref VX_TYPE_ENUM of the \ref vx_convert_policy_e enumeration. + * \param [out] out The output image, a \ref VX_DF_IMAGE_U8 or \ref VX_DF_IMAGE_S16 image. + * \ingroup group_vision_function_sub + * \return \ref vx_node. + * \retval vx_node A node reference. Any possible errors preventing a successful creation should be checked using \ref vxGetStatus + */ +VX_API_ENTRY vx_node VX_API_CALL vxSubtractNode(vx_graph graph, + vx_image in1, vx_image in2, + vx_enum policy, + vx_image out); + +/*! \brief [Graph] Creates a bit-depth conversion node. + * \param [in] graph The reference to the graph. + * \param [in] input The input image. + * \param [out] output The output image. + * \param [in] policy A scalar containing a \ref VX_TYPE_ENUM of the \ref vx_convert_policy_e enumeration. + * \param [in] shift A scalar containing a \ref VX_TYPE_INT32 of the shift value. + * \ingroup group_vision_function_convertdepth + * \return \ref vx_node. + * \retval vx_node A node reference. Any possible errors preventing a successful creation should be checked using \ref vxGetStatus + */ +VX_API_ENTRY vx_node VX_API_CALL vxConvertDepthNode(vx_graph graph, vx_image input, vx_image output, vx_enum policy, vx_scalar shift); + +/*! \brief [Graph] Creates a Canny Edge Detection Node. + * \param [in] graph The reference to the graph. + * \param [in] input The input \ref VX_DF_IMAGE_U8 image. + * \param [in] hyst The double threshold for hysteresis. + * \param [in] gradient_size The size of the Sobel filter window, must support at least 3, 5, and 7. + * \param [in] norm_type A flag indicating the norm used to compute the gradient, \ref VX_NORM_L1 or VX_NORM_L2. + * \param [out] output The output image in \ref VX_DF_IMAGE_U8 format with values either 0 or 255. + * \ingroup group_vision_function_canny + * \return \ref vx_node. + * \retval vx_node A node reference. Any possible errors preventing a successful creation should be checked using \ref vxGetStatus + */ +VX_API_ENTRY vx_node VX_API_CALL vxCannyEdgeDetectorNode(vx_graph graph, vx_image input, vx_threshold hyst, + vx_int32 gradient_size, vx_enum norm_type, + vx_image output); + +/*! \brief [Graph] Creates an Affine Warp Node. + * \param [in] graph The reference to the graph. + * \param [in] input The input \ref VX_DF_IMAGE_U8 image. + * \param [in] matrix The affine matrix. Must be 2x3 of type \ref VX_TYPE_FLOAT32. + * \param [in] type The interpolation type from \ref vx_interpolation_type_e. + * \ref VX_INTERPOLATION_TYPE_AREA is not supported. + * \param [out] output The output \ref VX_DF_IMAGE_U8 image. + * \ingroup group_vision_function_warp_affine + * \note Only \ref VX_NODE_ATTRIBUTE_BORDER_MODE value \ref VX_BORDER_MODE_UNDEFINED or + * \ref VX_BORDER_MODE_CONSTANT is supported. + * \return \ref vx_node. + * \retval vx_node A node reference. Any possible errors preventing a successful creation should be checked using \ref vxGetStatus + */ +VX_API_ENTRY vx_node VX_API_CALL vxWarpAffineNode(vx_graph graph, vx_image input, vx_matrix matrix, vx_enum type, vx_image output); + +/*! \brief [Graph] Creates a Perspective Warp Node. + * \param [in] graph The reference to the graph. + * \param [in] input The input \ref VX_DF_IMAGE_U8 image. + * \param [in] matrix The perspective matrix. Must be 3x3 of type \ref VX_TYPE_FLOAT32. + * \param [in] type The interpolation type from \ref vx_interpolation_type_e. + * \ref VX_INTERPOLATION_TYPE_AREA is not supported. + * \param [out] output The output \ref VX_DF_IMAGE_U8 image. + * \ingroup group_vision_function_warp_perspective + * \note Only \ref VX_NODE_ATTRIBUTE_BORDER_MODE value \ref VX_BORDER_MODE_UNDEFINED or + * \ref VX_BORDER_MODE_CONSTANT is supported. + * \return \ref vx_node. + * \retval vx_node A node reference. Any possible errors preventing a successful creation should be checked using \ref vxGetStatus + */ +VX_API_ENTRY vx_node VX_API_CALL vxWarpPerspectiveNode(vx_graph graph, vx_image input, vx_matrix matrix, vx_enum type, vx_image output); + +/*! \brief [Graph] Creates a Harris Corners Node. + * \param [in] graph The reference to the graph. + * \param [in] input The input \ref VX_DF_IMAGE_U8 image. + * \param [in] strength_thresh The \ref VX_TYPE_FLOAT32 minimum threshold with which to eliminate Harris Corner scores (computed using the normalized Sobel kernel). + * \param [in] min_distance The \ref VX_TYPE_FLOAT32 radial Euclidean distance for non-maximum suppression. + * \param [in] sensitivity The \ref VX_TYPE_FLOAT32 scalar sensitivity threshold \f$ k \f$ from the Harris-Stephens equation. + * \param [in] gradient_size The gradient window size to use on the input. The + * implementation must support at least 3, 5, and 7. + * \param [in] block_size The block window size used to compute the Harris Corner score. + * The implementation must support at least 3, 5, and 7. + * \param [out] corners The array of \ref VX_TYPE_KEYPOINT objects. + * \param [out] num_corners The total number of detected corners in image (optional). Use a \ref VX_TYPE_SIZE scalar. + * \ingroup group_vision_function_harris + * \return \ref vx_node. + * \retval vx_node A node reference. Any possible errors preventing a successful creation should be checked using \ref vxGetStatus + */ +VX_API_ENTRY vx_node VX_API_CALL vxHarrisCornersNode(vx_graph graph, + vx_image input, + vx_scalar strength_thresh, + vx_scalar min_distance, + vx_scalar sensitivity, + vx_int32 gradient_size, + vx_int32 block_size, + vx_array corners, + vx_scalar num_corners); + +/*! \brief [Graph] Creates a FAST Corners Node. + * \param [in] graph The reference to the graph. + * \param [in] input The input \ref VX_DF_IMAGE_U8 image. + * \param [in] strength_thresh Threshold on difference between intensity of the central pixel and pixels on Bresenham's circle of radius 3 (\ref VX_TYPE_FLOAT32 scalar). + * \param [in] nonmax_suppression If true, non-maximum suppression is applied to + * detected corners before being placed in the \ref vx_array of \ref VX_TYPE_KEYPOINT objects. + * \param [out] corners Output corner \ref vx_array of \ref VX_TYPE_KEYPOINT. + * \param [out] num_corners The total number of detected corners in image (optional). Use a \ref VX_TYPE_SIZE scalar. + * \ingroup group_vision_function_fast + * \return \ref vx_node. + * \retval vx_node A node reference. Any possible errors preventing a successful creation should be checked using \ref vxGetStatus + */ +VX_API_ENTRY vx_node VX_API_CALL vxFastCornersNode(vx_graph graph, vx_image input, vx_scalar strength_thresh, vx_bool nonmax_suppression, vx_array corners, vx_scalar num_corners); + +/*! \brief [Graph] Creates a Lucas Kanade Tracking Node. + * \param [in] graph The reference to the graph. + * \param [in] old_images Input of first (old) image pyramid in \ref VX_DF_IMAGE_U8. + * \param [in] new_images Input of destination (new) image pyramid \ref VX_DF_IMAGE_U8. + * \param [in] old_points An array of key points in a \ref vx_array of \ref VX_TYPE_KEYPOINT; those key points are defined at + * the \a old_images high resolution pyramid. + * \param [in] new_points_estimates An array of estimation on what is the output key points in a \ref vx_array of + * \ref VX_TYPE_KEYPOINT; those keypoints are defined at the \a new_images high resolution pyramid. + * \param [out] new_points An output array of key points in a \ref vx_array of \ref VX_TYPE_KEYPOINT; those key points are + * defined at the \a new_images high resolution pyramid. + * \param [in] termination The termination can be \ref VX_TERM_CRITERIA_ITERATIONS or \ref VX_TERM_CRITERIA_EPSILON or + * \ref VX_TERM_CRITERIA_BOTH. + * \param [in] epsilon The \ref vx_float32 error for terminating the algorithm. + * \param [in] num_iterations The number of iterations. Use a \ref VX_TYPE_UINT32 scalar. + * \param [in] use_initial_estimate Use a \ref VX_TYPE_BOOL scalar. + * \param [in] window_dimension The size of the window on which to perform the algorithm. See + * \ref VX_CONTEXT_ATTRIBUTE_OPTICAL_FLOW_WINDOW_MAXIMUM_DIMENSION + * \ingroup group_vision_function_opticalflowpyrlk + * \return \ref vx_node. + * \retval vx_node A node reference. Any possible errors preventing a successful creation should be checked using \ref vxGetStatus + */ +VX_API_ENTRY vx_node VX_API_CALL vxOpticalFlowPyrLKNode(vx_graph graph, + vx_pyramid old_images, + vx_pyramid new_images, + vx_array old_points, + vx_array new_points_estimates, + vx_array new_points, + vx_enum termination, + vx_scalar epsilon, + vx_scalar num_iterations, + vx_scalar use_initial_estimate, + vx_size window_dimension); + +/*! \brief [Graph] Creates a Remap Node. + * \param [in] graph The reference to the graph that will contain the node. + * \param [in] input The input \ref VX_DF_IMAGE_U8 image. + * \param [in] table The remap table object. + * \param [in] policy An interpolation type from \ref vx_interpolation_type_e. + * \ref VX_INTERPOLATION_TYPE_AREA is not supported. + * \param [out] output The output \ref VX_DF_IMAGE_U8 image. + * \note Only \ref VX_NODE_ATTRIBUTE_BORDER_MODE value \ref VX_BORDER_MODE_UNDEFINED or + * \ref VX_BORDER_MODE_CONSTANT is supported. + * \return A \ref vx_node. + * \retval vx_node A node reference. Any possible errors preventing a successful creation should be checked using \ref vxGetStatus + * \ingroup group_vision_function_remap + */ +VX_API_ENTRY vx_node VX_API_CALL vxRemapNode(vx_graph graph, + vx_image input, + vx_remap table, + vx_enum policy, + vx_image output); + +/*! \brief [Graph] Performs a Gaussian Blur on an image then half-scales it. + * \details The output image size is determined by: + * \f[ + * W_{output} = \frac{W_{input} + 1}{2} \\ + * , + * H_{output} = \frac{H_{input} + 1}{2} + * \f] + * \param [in] graph The reference to the graph. + * \param [in] input The input \ref VX_DF_IMAGE_U8 image. + * \param [out] output The output \ref VX_DF_IMAGE_U8 image. + * \param [in] kernel_size The input size of the Gaussian filter. Supported values are 3 and 5. + * \ingroup group_vision_function_scale_image + * \return \ref vx_node. + * \retval vx_node A node reference. Any possible errors preventing a successful creation should be checked using \ref vxGetStatus + */ +VX_API_ENTRY vx_node VX_API_CALL vxHalfScaleGaussianNode(vx_graph graph, vx_image input, vx_image output, vx_int32 kernel_size); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/vx_ext_cv/include/VX/vx_types.h b/vx_ext_cv/include/VX/vx_types.h new file mode 100644 index 0000000..efb85b1 --- /dev/null +++ b/vx_ext_cv/include/VX/vx_types.h @@ -0,0 +1,1472 @@ +/* +Copyright (c) 2015 Advanced Micro Devices, Inc. All rights reserved. + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. +*/ + + +/* + * Copyright (c) 2012-2015 The Khronos Group Inc. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and/or associated documentation files (the + * "Materials"), to deal in the Materials without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Materials, and to + * permit persons to whom the Materials are furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Materials. + * + * THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY + * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS. + */ + +#ifndef _OPENVX_TYPES_H_ +#define _OPENVX_TYPES_H_ + +/*! + * \file vx_types.h + * \brief The type definitions required by OpenVX Library. + */ + +#include +#include +#include + +/*! + * \internal + * \def VX_API_ENTRY + * \brief This is a tag used to identify exported, public API functions as + * distinct from internal functions, helpers, and other non-public interfaces. + * It can optionally be defined in the make system according the the compiler and intent. + * \ingroup group_basic_features + */ +#ifndef VX_API_ENTRY +#define VX_API_ENTRY +#endif +#ifndef VX_API_CALL +#if defined(_WIN32) +#define VX_API_CALL __stdcall +#else +#define VX_API_CALL +#endif +#endif +#ifndef VX_CALLBACK +#if defined(_WIN32) +#define VX_CALLBACK __stdcall +#else +#define VX_CALLBACK +#endif +#endif + +/*! \brief An 8 bit ASCII character. + * \ingroup group_basic_features + */ +typedef char vx_char; + +/*! \brief An 8-bit unsigned value. + * \ingroup group_basic_features + */ +typedef uint8_t vx_uint8; + +/*! \brief A 16-bit unsigned value. + * \ingroup group_basic_features + */ +typedef uint16_t vx_uint16; + +/*! \brief A 32-bit unsigned value. + * \ingroup group_basic_features + */ +typedef uint32_t vx_uint32; + +/*! \brief A 64-bit unsigned value. + * \ingroup group_basic_features + */ +typedef uint64_t vx_uint64; + +/*! \brief An 8-bit signed value. + * \ingroup group_basic_features + */ +typedef int8_t vx_int8; + +/*! \brief A 16-bit signed value. + * \ingroup group_basic_features + */ +typedef int16_t vx_int16; + +/*! \brief A 32-bit signed value. + * \ingroup group_basic_features + */ +typedef int32_t vx_int32; + +/*! \brief A 64-bit signed value. + * \ingroup group_basic_features + */ +typedef int64_t vx_int64; + +#if defined(EXPERIMENTAL_PLATFORM_SUPPORTS_16_FLOAT) + +/*! \brief A 16-bit float value. + * \ingroup group_basic_features + */ +typedef hfloat vx_float16; +#endif + +/*! \brief A 32-bit float value. + * \ingroup group_basic_features + */ +typedef float vx_float32; + +/*! \brief A 64-bit float value (aka double). + * \ingroup group_basic_features + */ +typedef double vx_float64; + +/*! \brief A generic opaque reference to any object within OpenVX. + * \details A user of OpenVX should not assume that this can be cast directly to anything; + * however, any object in OpenVX can be cast back to this for the purposes of + * querying attributes of the object or for passing the object as a parameter to + * functions that take a \ref vx_reference type. + * If the API does not take that specific type but may take others, an + * error may be returned from the API. + * \ingroup group_reference + */ +typedef struct _vx_reference *vx_reference; + +/*! \brief Sets the standard enumeration type size to be a fixed quantity. + * \details All enumerable fields must use this type as the container to + * enforce enumeration ranges and sizeof() operations. + * \ingroup group_basic_features + */ +typedef int32_t vx_enum; + +/*! \brief A wrapper of size_t to keep the naming convention uniform. + * \ingroup group_basic_features + */ +typedef size_t vx_size; + +/*! \brief Used to hold a VX_DF_IMAGE code to describe the pixel format and color space. + * \ingroup group_basic_features + */ +typedef uint32_t vx_df_image; + +/*! \brief An opaque reference to a scalar. + * \details A scalar can be up to 64 bits wide. + * \see vxCreateScalar + * \ingroup group_scalar + * \extends vx_reference + */ +typedef struct _vx_scalar *vx_scalar; + +/*! \brief An opaque reference to an image. + * \see vxCreateImage + * \ingroup group_image + * \extends vx_reference + */ +typedef struct _vx_image *vx_image; + +/*! \brief An opaque reference to the descriptor of a kernel. + * \see vxGetKernelByName + * \see vxGetKernelByEnum + * \ingroup group_kernel + * \extends vx_reference + */ +typedef struct _vx_kernel *vx_kernel; + +/*! \brief An opaque reference to a single parameter. + * \see vxGetParameterByIndex + * \ingroup group_parameter + * \extends vx_reference + */ +typedef struct _vx_parameter *vx_parameter; + +/*! \brief An opaque reference to a kernel node. + * \see vxCreateGenericNode + * \ingroup group_node + * \extends vx_reference + */ +typedef struct _vx_node *vx_node; + +/*! \brief An opaque reference to a graph + * \see vxCreateGraph + * \ingroup group_graph + * \extends vx_reference + */ +typedef struct _vx_graph *vx_graph; + +/*! \brief An opaque reference to the implementation context. + * \see vxCreateContext + * \ingroup group_context + * \extends vx_reference + */ +typedef struct _vx_context *vx_context; + +/*! \brief The delay object. This is like a ring buffer of objects that is + * maintained by the OpenVX implementation. + * \see vxCreateDelay + * \extends vx_reference + * \ingroup group_delay + */ +typedef struct _vx_delay *vx_delay; + +/*! \brief The Look-Up Table (LUT) Object. + * \extends vx_reference + * \ingroup group_lut + */ +typedef struct _vx_lut *vx_lut; + +/*! \brief The Distribution object. This has a user-defined number of bins over + * a user-defined range (within a uint32_t range). + * \extends vx_reference + * \ingroup group_distribution + */ +typedef struct _vx_distribution *vx_distribution; + +/*! \brief The Matrix Object. An MxN matrix of some unit type. + * \extends vx_reference + * \ingroup group_matrix + */ +typedef struct _vx_matrix *vx_matrix; + +/*! \brief The Image Pyramid object. A set of scaled images. + * \extends vx_reference + * \ingroup group_pyramid + */ +typedef struct _vx_pyramid *vx_pyramid; + +/*! \brief The Threshold Object. A thresholding object contains the types and + * limit values of the thresholding required. + * \extends vx_reference + * \ingroup group_threshold + */ +typedef struct _vx_threshold *vx_threshold; + +/*! \brief The Convolution Object. A user-defined convolution kernel of MxM elements. + * \extends vx_reference + * \ingroup group_convolution + */ +typedef struct _vx_convolution *vx_convolution; + +/*! \brief The remap table Object. A remap table contains per-pixel mapping of + * output pixels to input pixels. + * \ingroup group_remap + */ +typedef struct _vx_remap *vx_remap; + +/*! \brief The Array Object. Array is a strongly-typed container for other data structures. + * \ingroup group_array + */ +typedef struct _vx_array *vx_array; + +/*! \brief A Boolean value. + * This allows 0 to be FALSE, as it is in C, and any non-zero to be TRUE. + * \code + * vx_bool ret = vx_true_e; + * if (ret) printf("true!\n"); + * ret = vx_false_e; + * if (!ret) printf("false!\n"); + * \endcode + * This would print both strings. + * \ingroup group_basic_features + */ +typedef enum _vx_bool_e { + /*! \brief The "false" value. */ + vx_false_e = 0, + /*! \brief The "true" value. */ + vx_true_e, +} vx_bool; + +/*! + * \brief This object is used by output validation functions to specify the meta data + * of the expected output data object. If the output object is an image, + * the vx_meta_format object can additionally store the valid region delta rectangle. + * \note when the actual output object of the user node is virtual, the information + * given through the vx_meta_format object allows the OpenVX framework to automatically + * create the data object when meta data were not specified by the application at object + * creation time. + * \ingroup group_user_kernels + */ +typedef struct _vx_meta_format* vx_meta_format; + +/*! \brief The type enumeration lists all the known types in OpenVX. + * \ingroup group_basic_features + */ +enum vx_type_e { + VX_TYPE_INVALID = 0x000,/*!< \brief An invalid type value. When passed an error must be returned. */ + VX_TYPE_CHAR = 0x001,/*!< \brief A \ref vx_char. */ + VX_TYPE_INT8 = 0x002,/*!< \brief A \ref vx_int8. */ + VX_TYPE_UINT8 = 0x003,/*!< \brief A \ref vx_uint8. */ + VX_TYPE_INT16 = 0x004,/*!< \brief A \ref vx_int16. */ + VX_TYPE_UINT16 = 0x005,/*!< \brief A \ref vx_uint16. */ + VX_TYPE_INT32 = 0x006,/*!< \brief A \ref vx_int32. */ + VX_TYPE_UINT32 = 0x007,/*!< \brief A \ref vx_uint32. */ + VX_TYPE_INT64 = 0x008,/*!< \brief A \ref vx_int64. */ + VX_TYPE_UINT64 = 0x009,/*!< \brief A \ref vx_uint64. */ + VX_TYPE_FLOAT32 = 0x00A,/*!< \brief A \ref vx_float32. */ + VX_TYPE_FLOAT64 = 0x00B,/*!< \brief A \ref vx_float64. */ + VX_TYPE_ENUM = 0x00C,/*!< \brief A \ref vx_enum. Equivalent in size to a \ref vx_int32. */ + VX_TYPE_SIZE = 0x00D,/*!< \brief A \ref vx_size. */ + VX_TYPE_DF_IMAGE = 0x00E,/*!< \brief A \ref vx_df_image. */ +#if defined(EXPERIMENTAL_PLATFORM_SUPPORTS_16_FLOAT) + VX_TYPE_FLOAT16 = 0x00F,/*!< \brief A \ref vx_float16. */ +#endif + VX_TYPE_BOOL = 0x010,/*!< \brief A \ref vx_bool. */ + + /* add new scalar types here */ + + VX_TYPE_SCALAR_MAX, /*!< \brief A floating value for comparison between OpenVX scalars and OpenVX structs. */ + + VX_TYPE_RECTANGLE = 0x020,/*!< \brief A \ref vx_rectangle_t. */ + VX_TYPE_KEYPOINT = 0x021,/*!< \brief A \ref vx_keypoint_t. */ + VX_TYPE_COORDINATES2D = 0x022,/*!< \brief A \ref vx_coordinates2d_t. */ + VX_TYPE_COORDINATES3D = 0x023,/*!< \brief A \ref vx_coordinates3d_t. */ + VX_TYPE_USER_STRUCT_START = 0x100, + /*!< \brief A floating value for user-defined struct base index.*/ + VX_TYPE_STRUCT_MAX = VX_TYPE_USER_STRUCT_START - 1, + /*!< \brief A floating value for comparison between OpenVX + structs and user structs. */ + VX_TYPE_VENDOR_STRUCT_START = 0x400, + /*!< \brief A floating value for vendor-defined struct base index.*/ + VX_TYPE_USER_STRUCT_END = VX_TYPE_VENDOR_STRUCT_START - 1, + /*!< \brief A floating value for comparison between user structs and + vendor structs. */ + VX_TYPE_VENDOR_STRUCT_END = 0x7FF, + /*!< \brief A floating value for comparison between vendor + structs and OpenVX objects. */ + VX_TYPE_REFERENCE = 0x800,/*!< \brief A \ref vx_reference. */ + VX_TYPE_CONTEXT = 0x801,/*!< \brief A \ref vx_context. */ + VX_TYPE_GRAPH = 0x802,/*!< \brief A \ref vx_graph. */ + VX_TYPE_NODE = 0x803,/*!< \brief A \ref vx_node. */ + VX_TYPE_KERNEL = 0x804,/*!< \brief A \ref vx_kernel. */ + VX_TYPE_PARAMETER = 0x805,/*!< \brief A \ref vx_parameter. */ + VX_TYPE_DELAY = 0x806,/*!< \brief A \ref vx_delay. */ + VX_TYPE_LUT = 0x807,/*!< \brief A \ref vx_lut. */ + VX_TYPE_DISTRIBUTION = 0x808,/*!< \brief A \ref vx_distribution. */ + VX_TYPE_PYRAMID = 0x809,/*!< \brief A \ref vx_pyramid. */ + VX_TYPE_THRESHOLD = 0x80A,/*!< \brief A \ref vx_threshold. */ + VX_TYPE_MATRIX = 0x80B,/*!< \brief A \ref vx_matrix. */ + VX_TYPE_CONVOLUTION = 0x80C,/*!< \brief A \ref vx_convolution. */ + VX_TYPE_SCALAR = 0x80D,/*!< \brief A \ref vx_scalar. when needed to be completely generic for kernel validation. */ + VX_TYPE_ARRAY = 0x80E,/*!< \brief A \ref vx_array. */ + VX_TYPE_IMAGE = 0x80F,/*!< \brief A \ref vx_image. */ + VX_TYPE_REMAP = 0x810,/*!< \brief A \ref vx_remap. */ + VX_TYPE_ERROR = 0x811,/*!< \brief An error object which has no type. */ + VX_TYPE_META_FORMAT = 0x812,/*!< \brief A \ref vx_meta_format. */ + + /* \todo add new object types here */ + + VX_TYPE_VENDOR_OBJECT_START = 0xC00,/*!< \brief A floating value for vendor defined object base index. */ + VX_TYPE_OBJECT_MAX = VX_TYPE_VENDOR_OBJECT_START - 1,/*!< \brief A value used for bound checking the OpenVX object types. */ + VX_TYPE_VENDOR_OBJECT_END = 0xFFF,/*!< \brief A value used for bound checking of vendor objects */ +}; + +/*! \brief The enumeration of all status codes. + * \see vx_status. + * \ingroup group_basic_features + */ +enum vx_status_e { + VX_STATUS_MIN = -25,/*!< \brief Indicates the lower bound of status codes in VX. Used for bounds checks only. */ + /* add new codes here */ + VX_ERROR_REFERENCE_NONZERO = -24,/*!< \brief Indicates that an operation did not complete due to a reference count being non-zero. */ + VX_ERROR_MULTIPLE_WRITERS = -23,/*!< \brief Indicates that the graph has more than one node outputting to the same data object. This is an invalid graph structure. */ + VX_ERROR_GRAPH_ABANDONED = -22,/*!< \brief Indicates that the graph is stopped due to an error or a callback that abandoned execution. */ + VX_ERROR_GRAPH_SCHEDULED = -21,/*!< \brief Indicates that the supplied graph already has been scheduled and may be currently executing. */ + VX_ERROR_INVALID_SCOPE = -20,/*!< \brief Indicates that the supplied parameter is from another scope and cannot be used in the current scope. */ + VX_ERROR_INVALID_NODE = -19,/*!< \brief Indicates that the supplied node could not be created.*/ + VX_ERROR_INVALID_GRAPH = -18,/*!< \brief Indicates that the supplied graph has invalid connections (cycles). */ + VX_ERROR_INVALID_TYPE = -17,/*!< \brief Indicates that the supplied type parameter is incorrect. */ + VX_ERROR_INVALID_VALUE = -16,/*!< \brief Indicates that the supplied parameter has an incorrect value. */ + VX_ERROR_INVALID_DIMENSION = -15,/*!< \brief Indicates that the supplied parameter is too big or too small in dimension. */ + VX_ERROR_INVALID_FORMAT = -14,/*!< \brief Indicates that the supplied parameter is in an invalid format. */ + VX_ERROR_INVALID_LINK = -13,/*!< \brief Indicates that the link is not possible as specified. The parameters are incompatible. */ + VX_ERROR_INVALID_REFERENCE = -12,/*!< \brief Indicates that the reference provided is not valid. */ + VX_ERROR_INVALID_MODULE = -11,/*!< \brief This is returned from \ref vxLoadKernels when the module does not contain the entry point. */ + VX_ERROR_INVALID_PARAMETERS = -10,/*!< \brief Indicates that the supplied parameter information does not match the kernel contract. */ + VX_ERROR_OPTIMIZED_AWAY = -9,/*!< \brief Indicates that the object refered to has been optimized out of existence. */ + VX_ERROR_NO_MEMORY = -8,/*!< \brief Indicates that an internal or implicit allocation failed. Typically catastrophic. After detection, deconstruct the context. \see vxVerifyGraph. */ + VX_ERROR_NO_RESOURCES = -7,/*!< \brief Indicates that an internal or implicit resource can not be acquired (not memory). This is typically catastrophic. After detection, deconstruct the context. \see vxVerifyGraph. */ + VX_ERROR_NOT_COMPATIBLE = -6,/*!< \brief Indicates that the attempt to link two parameters together failed due to type incompatibilty. */ + VX_ERROR_NOT_ALLOCATED = -5,/*!< \brief Indicates to the system that the parameter must be allocated by the system. */ + VX_ERROR_NOT_SUFFICIENT = -4,/*!< \brief Indicates that the given graph has failed verification due to an insufficient number of required parameters, which cannot be automatically created. Typically this indicates required atomic parameters. \see vxVerifyGraph. */ + VX_ERROR_NOT_SUPPORTED = -3,/*!< \brief Indicates that the requested set of parameters produce a configuration that cannot be supported. Refer to the supplied documentation on the configured kernels. \see vx_kernel_e. */ + VX_ERROR_NOT_IMPLEMENTED = -2,/*!< \brief Indicates that the requested kernel is missing. \see vx_kernel_e vxGetKernelByName. */ + VX_FAILURE = -1,/*!< \brief Indicates a generic error code, used when no other describes the error. */ + VX_SUCCESS = 0,/*!< \brief No error. */ +}; + +/*! \brief A formal status type with known fixed size. + * \see vx_status_e + * \ingroup group_basic_features + */ +typedef vx_enum vx_status; + +/*! \brief The formal typedef of the response from the callback. + * \see vx_action_e + * \ingroup group_node_callback + */ +typedef vx_enum vx_action; + +/*! \brief A callback to the client after a particular node has completed. + * \see vx_action + * \see vxAssignNodeCallback + * \param [in] node The node to which the callback was attached. + * \return An action code from \ref vx_action_e. + * \ingroup group_node_callback + */ +typedef vx_action (VX_CALLBACK *vx_nodecomplete_f)(vx_node node); + +/*! \brief Vendor IDs are 2 nibbles in size and are located in the upper byte of + * the 4 bytes of an enumeration. + * \ingroup group_basic_features + */ +#define VX_VENDOR_MASK (0xFFF00000) + +/*! \brief A type mask removes the scalar/object type from the attribute. + * It is 3 nibbles in size and is contained between the third and second byte. + * \see vx_type_e + * \ingroup group_basic_features + */ +#define VX_TYPE_MASK (0x000FFF00) + +/*! \brief A library is a set of vision kernels with its own ID supplied by a vendor. + * The vendor defines the library ID. The range is \f$ [0,2^{8}-1] \f$ inclusive. + * \ingroup group_basic_features + */ +#define VX_LIBRARY_MASK (0x000FF000) + +/*! \brief An individual kernel in a library has its own unique ID within \f$ [0,2^{12}-1] \f$ (inclusive). + * \ingroup group_basic_features + */ +#define VX_KERNEL_MASK (0x00000FFF) + +/*! \brief An object's attribute ID is within the range of \f$ [0,2^{8}-1] \f$ (inclusive). + * \ingroup group_basic_features + */ +#define VX_ATTRIBUTE_ID_MASK (0x000000FF) + +/*! \brief A type of enumeration. The valid range is between \f$ [0,2^{8}-1] \f$ (inclusive). + * \ingroup group_basic_features + */ +#define VX_ENUM_TYPE_MASK (0x000FF000) + +/*! \brief A generic enumeration list can have values between \f$ [0,2^{12}-1] \f$ (inclusive). + * \ingroup group_basic_features + */ +#define VX_ENUM_MASK (0x00000FFF) + +/*! \brief A macro to extract the vendor ID from the enumerated value. + * \ingroup group_basic_features + */ +#define VX_VENDOR(e) (((vx_uint32)e & VX_VENDOR_MASK) >> 20) + +/*! \brief A macro to extract the type from an enumerated attribute value. + * \ingroup group_basic_features + */ +#define VX_TYPE(e) (((vx_uint32)e & VX_TYPE_MASK) >> 8) + +/*! \brief A macro to extract the enum type from an enumerated value. + * \ingroup group_basic_features + */ +#define VX_ENUM_TYPE(e) (((vx_uint32)e & VX_ENUM_TYPE_MASK) >> 12) + +/*! \brief A macro to extract the kernel library enumeration from a enumerated kernel value. + * \ingroup group_basic_features + */ +#define VX_LIBRARY(e) (((vx_uint32)e & VX_LIBRARY_MASK) >> 12) + +#if defined(_LITTLE_ENDIAN_) || (__BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__) || defined(_WIN32) +#define VX_DF_IMAGE(a,b,c,d) ((a) | (b << 8) | (c << 16) | (d << 24)) +#define VX_ATTRIBUTE_BASE(vendor, object) (((vendor) << 20) | (object << 8)) +#define VX_KERNEL_BASE(vendor, lib) (((vendor) << 20) | (lib << 12)) +#define VX_ENUM_BASE(vendor, id) (((vendor) << 20) | (id << 12)) +#elif defined(_BIG_ENDIAN_) || (__BYTE_ORDER__ == __ORDER_BIG_ENDIAN__) +#define VX_DF_IMAGE(a,b,c,d) ((d) | (c << 8) | (b << 16) | (a << 24)) +#define VX_ATTRIBUTE_BASE(vendor, object) ((vendor) | (object << 12)) +#define VX_KERNEL_BASE(vendor, lib) ((vendor) | (lib << 12)) +#define VX_ENUM_BASE(vendor, id) ((vendor) | (id << 12)) +#else +#error "Endian-ness must be defined!" +#endif + +/*! \def VX_DF_IMAGE + * \brief Converts a set of four chars into a \c uint32_t container of a VX_DF_IMAGE code. + * \note Use a \ref vx_df_image variable to hold the value. + * \ingroup group_basic_features + */ + +/*! \def VX_ATTRIBUTE_BASE + * \brief Defines the manner in which to combine the Vendor and Object IDs to get + * the base value of the enumeration. + * \ingroup group_basic_features + */ + +/*! \def VX_KERNEL_BASE + * \brief Defines the manner in which to combine the Vendor and Library IDs to get + * the base value of the enumeration. + * \ingroup group_basic_features + */ + +/*! \def VX_ENUM_BASE + * \brief Defines the manner in which to combine the Vendor and Object IDs to get + * the base value of the enumeration. + * \details From any enumerated value (with exceptions), the vendor, and enumeration + * type should be extractable. Those types that are exceptions are + * \ref vx_vendor_id_e, \ref vx_type_e, \ref vx_enum_e, \ref vx_df_image_e, and \c vx_bool. + * \ingroup group_basic_features + */ + +/*! \brief The set of supported enumerations in OpenVX. + * \details These can be extracted from enumerated values using \ref VX_ENUM_TYPE. + * \ingroup group_basic_features + */ +enum vx_enum_e { + VX_ENUM_DIRECTION = 0x00, /*!< \brief Parameter Direction. */ + VX_ENUM_ACTION = 0x01, /*!< \brief Action Codes. */ + VX_ENUM_HINT = 0x02, /*!< \brief Hint Values. */ + VX_ENUM_DIRECTIVE = 0x03, /*!< \brief Directive Values. */ + VX_ENUM_INTERPOLATION = 0x04, /*!< \brief Interpolation Types. */ + VX_ENUM_OVERFLOW = 0x05, /*!< \brief Overflow Policies. */ + VX_ENUM_COLOR_SPACE = 0x06, /*!< \brief Color Space. */ + VX_ENUM_COLOR_RANGE = 0x07, /*!< \brief Color Space Range. */ + VX_ENUM_PARAMETER_STATE = 0x08, /*!< \brief Parameter State. */ + VX_ENUM_CHANNEL = 0x09, /*!< \brief Channel Name. */ + VX_ENUM_CONVERT_POLICY = 0x0A, /*!< \brief Convert Policy. */ + VX_ENUM_THRESHOLD_TYPE = 0x0B, /*!< \brief Threshold Type List. */ + VX_ENUM_BORDER_MODE = 0x0C, /*!< \brief Border Mode List. */ + VX_ENUM_COMPARISON = 0x0D, /*!< \brief Comparison Values. */ + VX_ENUM_IMPORT_MEM = 0x0E, /*!< \brief The memory import enumeration. */ + VX_ENUM_TERM_CRITERIA = 0x0F, /*!< \brief A termination criteria. */ + VX_ENUM_NORM_TYPE = 0x10, /*!< \brief A norm type. */ + VX_ENUM_ACCESSOR = 0x11, /*!< \brief An accessor flag type. */ + VX_ENUM_ROUND_POLICY = 0x12, /*!< \brief Rounding Policy. */ +}; + +/*! \brief A return code enumeration from a \ref vx_nodecomplete_f during execution. + * \see vxAssignNodeCallback + * \ingroup group_node_callback + */ +enum vx_action_e { + /*! \brief Continue executing the graph with no changes. */ + VX_ACTION_CONTINUE = VX_ENUM_BASE(VX_ID_KHRONOS, VX_ENUM_ACTION) + 0x0, + /*! \brief Stop executing the graph. */ + VX_ACTION_ABANDON = VX_ENUM_BASE(VX_ID_KHRONOS, VX_ENUM_ACTION) + 0x1, +}; + +/*! \brief An indication of how a kernel will treat the given parameter. + * \ingroup group_parameter + */ +enum vx_direction_e { + /*! \brief The parameter is an input only. */ + VX_INPUT = VX_ENUM_BASE(VX_ID_KHRONOS, VX_ENUM_DIRECTION) + 0x0, + /*! \brief The parameter is an output only. */ + VX_OUTPUT = VX_ENUM_BASE(VX_ID_KHRONOS, VX_ENUM_DIRECTION) + 0x1, + /*! \brief The parameter is both an input and output. */ + VX_BIDIRECTIONAL = VX_ENUM_BASE(VX_ID_KHRONOS, VX_ENUM_DIRECTION) + 0x2, +}; + +/*! \brief These enumerations are given to the \c vxHint API to enable/disable platform + * optimizations and/or features. Hints are optional and usually are vendor-specific. + * \see vxHint + * \ingroup group_hint + */ +enum vx_hint_e { + /*! \brief Indicates to the implementation that the user wants to disable + * any parallelization techniques. Implementations may not be parallelized, + * so this is a hint only. + */ + VX_HINT_SERIALIZE = VX_ENUM_BASE(VX_ID_KHRONOS, VX_ENUM_HINT) + 0x0, +}; + +/*! \brief These enumerations are given to the \c vxDirective API to enable/disable + * platform optimizations and/or features. Directives are not optional and + * usually are vendor-specific, by defining a vendor range of directives and + * starting their enumeration from there. + * \see vxDirective + * \ingroup group_directive + */ +enum vx_directive_e { + /*! \brief Disables recording information for graph debugging. */ + VX_DIRECTIVE_DISABLE_LOGGING = VX_ENUM_BASE(VX_ID_KHRONOS, VX_ENUM_DIRECTIVE) + 0x0, + /*! \brief Enables recording information for graph debugging. */ + VX_DIRECTIVE_ENABLE_LOGGING = VX_ENUM_BASE(VX_ID_KHRONOS, VX_ENUM_DIRECTIVE) + 0x1, +}; + +/*! \brief The Conversion Policy Enumeration. + * \ingroup group_basic_features + */ +enum vx_convert_policy_e { + /*! \brief Results are the least significant bits of the output operand, as if + * stored in two's complement binary format in the size of its bit-depth. + */ + VX_CONVERT_POLICY_WRAP = VX_ENUM_BASE(VX_ID_KHRONOS, VX_ENUM_CONVERT_POLICY) + 0x0, + /*! \brief Results are saturated to the bit depth of the output operand. */ + VX_CONVERT_POLICY_SATURATE = VX_ENUM_BASE(VX_ID_KHRONOS, VX_ENUM_CONVERT_POLICY) + 0x1, +}; + +/*! \brief Based on the VX_DF_IMAGE definition. + * \note Use \ref vx_df_image to contain these values. + * \ingroup group_basic_features + */ +enum vx_df_image_e { + /*! \brief A virtual image of no defined type. */ + VX_DF_IMAGE_VIRT = VX_DF_IMAGE('V','I','R','T'), + /*! \brief A single plane of 24-bit pixel as 3 interleaved 8-bit units of + * R then G then B data. This uses the BT709 full range by default. + */ + VX_DF_IMAGE_RGB = VX_DF_IMAGE('R','G','B','2'), + /*! \brief A single plane of 32-bit pixel as 4 interleaved 8-bit units of + * R then G then B data, then a don't care byte. + * This uses the BT709 full range by default. + */ + VX_DF_IMAGE_RGBX = VX_DF_IMAGE('R','G','B','A'), + /*! \brief A 2-plane YUV format of Luma (Y) and interleaved UV data at + * 4:2:0 sampling. This uses the BT709 full range by default. + */ + VX_DF_IMAGE_NV12 = VX_DF_IMAGE('N','V','1','2'), + /*! \brief A 2-lane YUV format of Luma (Y) and interleaved VU data at + * 4:2:0 sampling. This uses the BT709 full range by default. + */ + VX_DF_IMAGE_NV21 = VX_DF_IMAGE('N','V','2','1'), + /*! \brief A single plane of 32-bit macro pixel of U0, Y0, V0, Y1 bytes. + * This uses the BT709 full range by default. + */ + VX_DF_IMAGE_UYVY = VX_DF_IMAGE('U','Y','V','Y'), + /*! \brief A single plane of 32-bit macro pixel of Y0, U0, Y1, V0 bytes. + * This uses the BT709 full range by default. + */ + VX_DF_IMAGE_YUYV = VX_DF_IMAGE('Y','U','Y','V'), + /*! \brief A 3 plane of 8-bit 4:2:0 sampled Y, U, V planes. + * This uses the BT709 full range by default. + */ + VX_DF_IMAGE_IYUV = VX_DF_IMAGE('I','Y','U','V'), + /*! \brief A 3 plane of 8 bit 4:4:4 sampled Y, U, V planes. + * This uses the BT709 full range by default. + */ + VX_DF_IMAGE_YUV4 = VX_DF_IMAGE('Y','U','V','4'), + /*! \brief A single plane of unsigned 8-bit data. + * The range of data is not specified, as it may be extracted from a YUV or + * generated. + */ + VX_DF_IMAGE_U8 = VX_DF_IMAGE('U','0','0','8'), + /*! \brief A single plane of unsigned 16-bit data. + * The range of data is not specified, as it may be extracted from a YUV or + * generated. + */ + VX_DF_IMAGE_U16 = VX_DF_IMAGE('U','0','1','6'), + /*! \brief A single plane of signed 16-bit data. + * The range of data is not specified, as it may be extracted from a YUV or + * generated. + */ + VX_DF_IMAGE_S16 = VX_DF_IMAGE('S','0','1','6'), + /*! \brief A single plane of unsigned 32-bit data. + * The range of data is not specified, as it may be extracted from a YUV or + * generated. + */ + VX_DF_IMAGE_U32 = VX_DF_IMAGE('U','0','3','2'), + /*! \brief A single plane of unsigned 32-bit data. + * The range of data is not specified, as it may be extracted from a YUV or + * generated. + */ + VX_DF_IMAGE_S32 = VX_DF_IMAGE('S','0','3','2'), +}; + +/*! \brief The reference attributes list. + * \ingroup group_reference + */ +enum vx_reference_attribute_e { + /*! \brief Returns the reference count of the object. Use a \ref vx_uint32 parameter. */ + VX_REF_ATTRIBUTE_COUNT = VX_ATTRIBUTE_BASE(VX_ID_KHRONOS, VX_TYPE_REFERENCE) + 0x0, + /*! \brief Returns the \ref vx_type_e of the reference. Use a \ref vx_enum parameter. */ + VX_REF_ATTRIBUTE_TYPE = VX_ATTRIBUTE_BASE(VX_ID_KHRONOS, VX_TYPE_REFERENCE) + 0x1, +}; + +/*! \brief A list of context attributes. + * \ingroup group_context + */ +enum vx_context_attribute_e { + /*! \brief Queries the unique vendor ID. Use a \ref vx_uint16. */ + VX_CONTEXT_ATTRIBUTE_VENDOR_ID = VX_ATTRIBUTE_BASE(VX_ID_KHRONOS, VX_TYPE_CONTEXT) + 0x0, + /*! \brief Queries the OpenVX Version Number. Use a \ref vx_uint16 */ + VX_CONTEXT_ATTRIBUTE_VERSION = VX_ATTRIBUTE_BASE(VX_ID_KHRONOS, VX_TYPE_CONTEXT) + 0x1, + /*! \brief Queries the context for the number of \e unique kernels. Use a \ref vx_uint32 parameter. */ + VX_CONTEXT_ATTRIBUTE_UNIQUE_KERNELS = VX_ATTRIBUTE_BASE(VX_ID_KHRONOS, VX_TYPE_CONTEXT) + 0x2, + /*! \brief Queries the context for the number of active modules. Use a \ref vx_uint32 parameter. */ + VX_CONTEXT_ATTRIBUTE_MODULES = VX_ATTRIBUTE_BASE(VX_ID_KHRONOS, VX_TYPE_CONTEXT) + 0x3, + /*! \brief Queries the context for the number of active references. Use a \ref vx_uint32 parameter. */ + VX_CONTEXT_ATTRIBUTE_REFERENCES = VX_ATTRIBUTE_BASE(VX_ID_KHRONOS, VX_TYPE_CONTEXT) + 0x4, + /*! \brief Queries the context for it's implementation name. Use a \ref vx_char[\ref VX_MAX_IMPLEMENTATION_NAME] array */ + VX_CONTEXT_ATTRIBUTE_IMPLEMENTATION = VX_ATTRIBUTE_BASE(VX_ID_KHRONOS, VX_TYPE_CONTEXT) + 0x5, + /*! \brief Queries the number of bytes in the extensions string. Use a \ref vx_size parameter. */ + VX_CONTEXT_ATTRIBUTE_EXTENSIONS_SIZE = VX_ATTRIBUTE_BASE(VX_ID_KHRONOS, VX_TYPE_CONTEXT) + 0x6, + /*! \brief Retrieves the extensions string. This is a space-separated string of extension names. Use a \ref vx_char pointer allocated to the size returned from \ref VX_CONTEXT_ATTRIBUTE_EXTENSIONS_SIZE. */ + VX_CONTEXT_ATTRIBUTE_EXTENSIONS = VX_ATTRIBUTE_BASE(VX_ID_KHRONOS, VX_TYPE_CONTEXT) + 0x7, + /*! \brief The maximum width or height of a convolution matrix. + * Use a \ref vx_size parameter. + * Each vendor must support centered kernels of size w X h, where both w + * and h are odd numbers, 3 <= w <= n and 3 <= h <= n, where n is the value of the + * \ref VX_CONTEXT_ATTRIBUTE_CONVOLUTION_MAXIMUM_DIMENSION attribute. n is an odd + * number that should not be smaller than 9. w and h may or may not be equal to + * each other. All combinations of w and h meeting the conditions above must be + * supported. The behavior of \ref vxCreateConvolution is undefined for values + * larger than the value returned by this attribute. + */ + VX_CONTEXT_ATTRIBUTE_CONVOLUTION_MAXIMUM_DIMENSION = VX_ATTRIBUTE_BASE(VX_ID_KHRONOS, VX_TYPE_CONTEXT) + 0x8, + /*! \brief The maximum window dimension of the OpticalFlowPyrLK kernel. + * \see \ref VX_KERNEL_OPTICAL_FLOW_PYR_LK. Use a \ref vx_size parameter. + */ + VX_CONTEXT_ATTRIBUTE_OPTICAL_FLOW_WINDOW_MAXIMUM_DIMENSION = VX_ATTRIBUTE_BASE(VX_ID_KHRONOS, VX_TYPE_CONTEXT) + 0x9, + /*! \brief The border mode for immediate mode functions. + * \details Graph mode functions are unaffected by this attribute. Use a pointer to a \ref vx_border_mode_t structure as parameter. + * \note The assumed default value for immediate mode functions is \ref VX_BORDER_MODE_UNDEFINED. + */ + VX_CONTEXT_ATTRIBUTE_IMMEDIATE_BORDER_MODE = VX_ATTRIBUTE_BASE(VX_ID_KHRONOS, VX_TYPE_CONTEXT) + 0xA, + /*! \brief Returns the table of all unique the kernels that exist in the context. + * Use a \ref vx_kernel_info_t array. + * \pre You must call \ref vxQueryContext with \ref VX_CONTEXT_ATTRIBUTE_UNIQUE_KERNELS + * to compute the necessary size of the array. + */ + VX_CONTEXT_ATTRIBUTE_UNIQUE_KERNEL_TABLE = VX_ATTRIBUTE_BASE(VX_ID_KHRONOS, VX_TYPE_CONTEXT) + 0xB, +}; + +/*! \brief The kernel attributes list + * \ingroup group_kernel + */ +enum vx_kernel_attribute_e { + /*! \brief Queries a kernel for the number of parameters the kernel + * supports. Use a \ref vx_uint32 parameter. + */ + VX_KERNEL_ATTRIBUTE_PARAMETERS = VX_ATTRIBUTE_BASE(VX_ID_KHRONOS, VX_TYPE_KERNEL) + 0x0, + /*! \brief Queries the name of the kernel. Not settable. + * Use a \ref vx_char[\ref VX_MAX_KERNEL_NAME] array (not a \ref vx_array). + */ + VX_KERNEL_ATTRIBUTE_NAME = VX_ATTRIBUTE_BASE(VX_ID_KHRONOS, VX_TYPE_KERNEL) + 0x1, + /*! \brief Queries the enum of the kernel. Not settable. + * Use a \ref vx_enum parameter. + */ + VX_KERNEL_ATTRIBUTE_ENUM = VX_ATTRIBUTE_BASE(VX_ID_KHRONOS, VX_TYPE_KERNEL) + 0x2, + /*! \brief The local data area allocated with each kernel when it becomes a + * node. Use a \ref vx_size parameter. + * \note If not set it will default to zero. + */ + VX_KERNEL_ATTRIBUTE_LOCAL_DATA_SIZE = VX_ATTRIBUTE_BASE(VX_ID_KHRONOS, VX_TYPE_KERNEL) + 0x3, + /*! \brief The local data pointer allocated with each kernel when it becomes + * a node. Use a void pointer parameter. + * Use a \ref vx_size parameter. + */ + VX_KERNEL_ATTRIBUTE_LOCAL_DATA_PTR = VX_ATTRIBUTE_BASE(VX_ID_KHRONOS, VX_TYPE_KERNEL) + 0x4, +}; + +/*! \brief The node attributes list. + * \ingroup group_node + */ +enum vx_node_attribute_e { + /*! \brief Queries the status of node execution. Use a \ref vx_status parameter. */ + VX_NODE_ATTRIBUTE_STATUS = VX_ATTRIBUTE_BASE(VX_ID_KHRONOS, VX_TYPE_NODE) + 0x0, + /*! \brief Queries the performance of the node execution. Use a \ref vx_perf_t parameter. */ + VX_NODE_ATTRIBUTE_PERFORMANCE = VX_ATTRIBUTE_BASE(VX_ID_KHRONOS, VX_TYPE_NODE) + 0x1, + /*! \brief Gets or sets the border mode of the node. + * Use a \ref vx_border_mode_t structure. + */ + VX_NODE_ATTRIBUTE_BORDER_MODE = VX_ATTRIBUTE_BASE(VX_ID_KHRONOS, VX_TYPE_NODE) + 0x2, + /*! \brief Indicates the size of the kernel local memory area. + * Use a \ref vx_size parameter. + */ + VX_NODE_ATTRIBUTE_LOCAL_DATA_SIZE = VX_ATTRIBUTE_BASE(VX_ID_KHRONOS, VX_TYPE_NODE) + 0x3, + /*! \brief Indicates the pointer kernel local memory area. + * Use a void * parameter. + */ + VX_NODE_ATTRIBUTE_LOCAL_DATA_PTR = VX_ATTRIBUTE_BASE(VX_ID_KHRONOS, VX_TYPE_NODE) + 0x4, +}; + +/*! \brief The parameter attributes list + * \ingroup group_parameter + */ +enum vx_parameter_attribute_e { + /*! \brief Queries a parameter for its index value on the kernel with which it is associated. Use a \ref vx_uint32 parameter. */ + VX_PARAMETER_ATTRIBUTE_INDEX = VX_ATTRIBUTE_BASE(VX_ID_KHRONOS, VX_TYPE_PARAMETER) + 0x0, + /*! \brief Queries a parameter for its direction value on the kernel with which it is associated. Use a \ref vx_enum parameter. */ + VX_PARAMETER_ATTRIBUTE_DIRECTION = VX_ATTRIBUTE_BASE(VX_ID_KHRONOS, VX_TYPE_PARAMETER) + 0x1, + /*! \brief Queries a parameter for its type, \ref vx_type_e is returned. The size of the parameter is implied for plain data objects. For opaque data objects like images and arrays a query to their attributes has to be called to determine the size. */ + VX_PARAMETER_ATTRIBUTE_TYPE = VX_ATTRIBUTE_BASE(VX_ID_KHRONOS, VX_TYPE_PARAMETER) + 0x2, + /*! \brief Queries a parameter for its state. A value in \ref vx_parameter_state_e is returned. Use a \ref vx_enum parameter. */ + VX_PARAMETER_ATTRIBUTE_STATE = VX_ATTRIBUTE_BASE(VX_ID_KHRONOS, VX_TYPE_PARAMETER) + 0x3, + /*! \brief Use to extract the reference contained in the parameter. Use a \ref vx_reference parameter. */ + VX_PARAMETER_ATTRIBUTE_REF = VX_ATTRIBUTE_BASE(VX_ID_KHRONOS, VX_TYPE_PARAMETER) + 0x4, +}; + +/*! \brief The image attributes list. + * \ingroup group_image + */ +enum vx_image_attribute_e { + /*! \brief Queries an image for its height. Use a \ref vx_uint32 parameter. */ + VX_IMAGE_ATTRIBUTE_WIDTH = VX_ATTRIBUTE_BASE(VX_ID_KHRONOS, VX_TYPE_IMAGE) + 0x0, + /*! \brief Queries an image for its width. Use a \ref vx_uint32 parameter. */ + VX_IMAGE_ATTRIBUTE_HEIGHT = VX_ATTRIBUTE_BASE(VX_ID_KHRONOS, VX_TYPE_IMAGE) + 0x1, + /*! \brief Queries an image for its format. Use a \ref vx_df_image parameter. */ + VX_IMAGE_ATTRIBUTE_FORMAT = VX_ATTRIBUTE_BASE(VX_ID_KHRONOS, VX_TYPE_IMAGE) + 0x2, + /*! \brief Queries an image for its number of planes. Use a \ref vx_size parameter. */ + VX_IMAGE_ATTRIBUTE_PLANES = VX_ATTRIBUTE_BASE(VX_ID_KHRONOS, VX_TYPE_IMAGE) + 0x3, + /*! \brief Queries an image for its color space (see \ref vx_color_space_e). Use a \ref vx_enum parameter. */ + VX_IMAGE_ATTRIBUTE_SPACE = VX_ATTRIBUTE_BASE(VX_ID_KHRONOS, VX_TYPE_IMAGE) + 0x4, + /*! \brief Queries an image for its channel range (see \ref vx_channel_range_e). Use a \ref vx_enum parameter. */ + VX_IMAGE_ATTRIBUTE_RANGE = VX_ATTRIBUTE_BASE(VX_ID_KHRONOS, VX_TYPE_IMAGE) + 0x5, + /*! \brief Queries an image for its total number of bytes. Use a \ref vx_size parameter. */ + VX_IMAGE_ATTRIBUTE_SIZE = VX_ATTRIBUTE_BASE(VX_ID_KHRONOS, VX_TYPE_IMAGE) + 0x6, +}; + +/*! \brief The scalar attributes list. + * \ingroup group_scalar + */ +enum vx_scalar_attribute_e { + /*! \brief Queries the type of atomic that is contained in the scalar. Use a \ref vx_enum parameter.*/ + VX_SCALAR_ATTRIBUTE_TYPE = VX_ATTRIBUTE_BASE(VX_ID_KHRONOS, VX_TYPE_SCALAR) + 0x0, +}; + +/*! \brief The graph attributes list. + * \ingroup group_graph + */ +enum vx_graph_attribute_e { + /*! \brief Returns the number of nodes in a graph. Use a \ref vx_uint32 parameter.*/ + VX_GRAPH_ATTRIBUTE_NUMNODES = VX_ATTRIBUTE_BASE(VX_ID_KHRONOS, VX_TYPE_GRAPH) + 0x0, + /*! \brief Returns the overall status of the graph. Use a \ref vx_status parameter.*/ + VX_GRAPH_ATTRIBUTE_STATUS = VX_ATTRIBUTE_BASE(VX_ID_KHRONOS, VX_TYPE_GRAPH) + 0x1, + /*! \brief Returns the overall performance of the graph. Use a \ref vx_perf_t parameter. */ + VX_GRAPH_ATTRIBUTE_PERFORMANCE = VX_ATTRIBUTE_BASE(VX_ID_KHRONOS, VX_TYPE_GRAPH) + 0x2, + /*! \brief Returns the number of explicitly declared parameters on the graph. Use a \ref vx_uint32 parameter. */ + VX_GRAPH_ATTRIBUTE_NUMPARAMETERS = VX_ATTRIBUTE_BASE(VX_ID_KHRONOS, VX_TYPE_GRAPH) + 0x3, +}; + +/*! \brief The Look-Up Table (LUT) attribute list. + * \ingroup group_lut + */ +enum vx_lut_attribute_e { + /*! \brief Indicates the value type of the LUT. Use a \ref vx_enum. */ + VX_LUT_ATTRIBUTE_TYPE = VX_ATTRIBUTE_BASE(VX_ID_KHRONOS,VX_TYPE_LUT) + 0x0, + /*! \brief Indicates the number of elements in the LUT. Use a \ref vx_size. */ + VX_LUT_ATTRIBUTE_COUNT = VX_ATTRIBUTE_BASE(VX_ID_KHRONOS,VX_TYPE_LUT) + 0x1, + /*! \brief Indicates the total size of the LUT in bytes. Uses a \ref vx_size. */ + VX_LUT_ATTRIBUTE_SIZE = VX_ATTRIBUTE_BASE(VX_ID_KHRONOS,VX_TYPE_LUT) + 0x2, +}; + +/*! \brief The distribution attribute list. + * \ingroup group_distribution + */ +enum vx_distribution_attribute_e { + /*! \brief Indicates the number of dimensions in the distribution. Use a \ref vx_size parameter. */ + VX_DISTRIBUTION_ATTRIBUTE_DIMENSIONS = VX_ATTRIBUTE_BASE(VX_ID_KHRONOS, VX_TYPE_DISTRIBUTION) + 0x0, + /*! \brief Indicates the start of the values to use (inclusive). Use a \ref vx_int32 parameter. */ + VX_DISTRIBUTION_ATTRIBUTE_OFFSET = VX_ATTRIBUTE_BASE(VX_ID_KHRONOS, VX_TYPE_DISTRIBUTION) + 0x1, + /*! \brief Indicates end value to use as the range. Use a \ref vx_uint32 parameter. */ + VX_DISTRIBUTION_ATTRIBUTE_RANGE = VX_ATTRIBUTE_BASE(VX_ID_KHRONOS, VX_TYPE_DISTRIBUTION) + 0x2, + /*! \brief Indicates the number of bins. Use a \ref vx_size parameter. */ + VX_DISTRIBUTION_ATTRIBUTE_BINS = VX_ATTRIBUTE_BASE(VX_ID_KHRONOS, VX_TYPE_DISTRIBUTION) + 0x3, + /*! \brief Indicates the range of a bin. Use a \ref vx_uint32 parameter. */ + VX_DISTRIBUTION_ATTRIBUTE_WINDOW = VX_ATTRIBUTE_BASE(VX_ID_KHRONOS, VX_TYPE_DISTRIBUTION) + 0x4, + /*! \brief Indicates the total size of the distribution in bytes. Use a \ref vx_size parameter. */ + VX_DISTRIBUTION_ATTRIBUTE_SIZE = VX_ATTRIBUTE_BASE(VX_ID_KHRONOS, VX_TYPE_DISTRIBUTION) + 0x5, +}; + +/*! \brief The Threshold types. + * \ingroup group_threshold + */ +enum vx_threshold_type_e { + /*! \brief A threshold with only 1 value. */ + VX_THRESHOLD_TYPE_BINARY = VX_ENUM_BASE(VX_ID_KHRONOS, VX_ENUM_THRESHOLD_TYPE) + 0x0, + /*! \brief A threshold with 2 values (upper/lower). Use with Canny Edge Detection. */ + VX_THRESHOLD_TYPE_RANGE = VX_ENUM_BASE(VX_ID_KHRONOS, VX_ENUM_THRESHOLD_TYPE) + 0x1, +}; + +/*! \brief The threshold attributes. + * \ingroup group_threshold + */ +enum vx_threshold_attribute_e { + /*! \brief The value type of the threshold. Use a \ref vx_enum parameter. Will contain a \ref vx_threshold_type_e. */ + VX_THRESHOLD_ATTRIBUTE_TYPE = VX_ATTRIBUTE_BASE(VX_ID_KHRONOS, VX_TYPE_THRESHOLD) + 0x0, + /*! \brief The value of the single threshold. Use a \ref vx_int32 parameter. */ + VX_THRESHOLD_ATTRIBUTE_THRESHOLD_VALUE = VX_ATTRIBUTE_BASE(VX_ID_KHRONOS, VX_TYPE_THRESHOLD) + 0x1, + /*! \brief The value of the lower threshold. Use a \ref vx_int32 parameter. */ + VX_THRESHOLD_ATTRIBUTE_THRESHOLD_LOWER = VX_ATTRIBUTE_BASE(VX_ID_KHRONOS, VX_TYPE_THRESHOLD) + 0x2, + /*! \brief The value of the higher threshold. Use a \ref vx_int32 parameter. */ + VX_THRESHOLD_ATTRIBUTE_THRESHOLD_UPPER = VX_ATTRIBUTE_BASE(VX_ID_KHRONOS, VX_TYPE_THRESHOLD) + 0x3, + /*! \brief The value of the TRUE threshold. Use a \ref vx_int32 parameter. */ + VX_THRESHOLD_ATTRIBUTE_TRUE_VALUE = VX_ATTRIBUTE_BASE(VX_ID_KHRONOS, VX_TYPE_THRESHOLD) + 0x4, + /*! \brief The value of the FALSE threshold. Use a \ref vx_int32 parameter. */ + VX_THRESHOLD_ATTRIBUTE_FALSE_VALUE = VX_ATTRIBUTE_BASE(VX_ID_KHRONOS, VX_TYPE_THRESHOLD) + 0x5, + /*! \brief The data type of the threshold's value. Use a \ref vx_enum parameter. Will contain a \ref vx_type_e.*/ + VX_THRESHOLD_ATTRIBUTE_DATA_TYPE = VX_ATTRIBUTE_BASE(VX_ID_KHRONOS, VX_TYPE_THRESHOLD) + 0x6, +}; + +/*! \brief The matrix attributes. + * \ingroup group_matrix + */ +enum vx_matrix_attribute_e { + /*! \brief The value type of the matrix. Use a \ref vx_enum parameter. */ + VX_MATRIX_ATTRIBUTE_TYPE = VX_ATTRIBUTE_BASE(VX_ID_KHRONOS, VX_TYPE_MATRIX) + 0x0, + /*! \brief The M dimension of the matrix. Use a \ref vx_size parameter. */ + VX_MATRIX_ATTRIBUTE_ROWS = VX_ATTRIBUTE_BASE(VX_ID_KHRONOS, VX_TYPE_MATRIX) + 0x1, + /*! \brief The N dimension of the matrix. Use a \ref vx_size parameter. */ + VX_MATRIX_ATTRIBUTE_COLUMNS = VX_ATTRIBUTE_BASE(VX_ID_KHRONOS, VX_TYPE_MATRIX) + 0x2, + /*! \brief The total size of the matrix in bytes. Use a \ref vx_size parameter. */ + VX_MATRIX_ATTRIBUTE_SIZE = VX_ATTRIBUTE_BASE(VX_ID_KHRONOS, VX_TYPE_MATRIX) + 0x3, +}; + +/*! \brief The convolution attributes. + * \ingroup group_convolution + */ +enum vx_convolution_attribute_e { + /*! \brief The number of rows of the convolution matrix. Use a \ref vx_size parameter. */ + VX_CONVOLUTION_ATTRIBUTE_ROWS = VX_ATTRIBUTE_BASE(VX_ID_KHRONOS, VX_TYPE_CONVOLUTION) + 0x0, + /*! \brief The number of columns of the convolution matrix. Use a \ref vx_size parameter. */ + VX_CONVOLUTION_ATTRIBUTE_COLUMNS = VX_ATTRIBUTE_BASE(VX_ID_KHRONOS, VX_TYPE_CONVOLUTION) + 0x1, + /*! \brief The scale of the convolution matrix. Use a \ref vx_uint32 parameter. + * \if OPENVX_STRICT_1_0 + * \note For 1.0, only powers of 2 are supported up to 2^31. + * \endif + */ + VX_CONVOLUTION_ATTRIBUTE_SCALE = VX_ATTRIBUTE_BASE(VX_ID_KHRONOS, VX_TYPE_CONVOLUTION) + 0x2, + /*! \brief The total size of the convolution matrix in bytes. Use a \ref vx_size parameter. */ + VX_CONVOLUTION_ATTRIBUTE_SIZE = VX_ATTRIBUTE_BASE(VX_ID_KHRONOS, VX_TYPE_CONVOLUTION) + 0x3, +}; + +/*! \brief The pyramid object attributes. + * \ingroup group_pyramid + */ +enum vx_pyramid_attribute_e { + /*! \brief The number of levels of the pyramid. Use a \ref vx_size parameter. */ + VX_PYRAMID_ATTRIBUTE_LEVELS = VX_ATTRIBUTE_BASE(VX_ID_KHRONOS, VX_TYPE_PYRAMID) + 0x0, + /*! \brief The scale factor between each level of the pyramid. Use a \ref vx_float32 parameter. */ + VX_PYRAMID_ATTRIBUTE_SCALE = VX_ATTRIBUTE_BASE(VX_ID_KHRONOS, VX_TYPE_PYRAMID) + 0x1, + /*! \brief The width of the 0th image in pixels. Use a \ref vx_uint32 parameter. */ + VX_PYRAMID_ATTRIBUTE_WIDTH = VX_ATTRIBUTE_BASE(VX_ID_KHRONOS, VX_TYPE_PYRAMID) + 0x2, + /*! \brief The height of the 0th image in pixels. Use a \ref vx_uint32 parameter. */ + VX_PYRAMID_ATTRIBUTE_HEIGHT = VX_ATTRIBUTE_BASE(VX_ID_KHRONOS, VX_TYPE_PYRAMID) + 0x3, + /*! \brief The \ref vx_df_image_e format of the image. Use a \ref vx_df_image parameter. */ + VX_PYRAMID_ATTRIBUTE_FORMAT = VX_ATTRIBUTE_BASE(VX_ID_KHRONOS, VX_TYPE_PYRAMID) + 0x4, +}; + +/*! \brief The remap object attributes. + * \ingroup group_remap + */ +enum vx_remap_attribute_e { + /*! \brief The source width. Use a \ref vx_uint32 parameter. */ + VX_REMAP_ATTRIBUTE_SOURCE_WIDTH = VX_ATTRIBUTE_BASE(VX_ID_KHRONOS, VX_TYPE_REMAP) + 0x0, + /*! \brief The source height. Use a \ref vx_uint32 parameter. */ + VX_REMAP_ATTRIBUTE_SOURCE_HEIGHT = VX_ATTRIBUTE_BASE(VX_ID_KHRONOS, VX_TYPE_REMAP) + 0x1, + /*! \brief The destination width. Use a \ref vx_uint32 parameter. */ + VX_REMAP_ATTRIBUTE_DESTINATION_WIDTH = VX_ATTRIBUTE_BASE(VX_ID_KHRONOS, VX_TYPE_REMAP) + 0x2, + /*! \brief The destination height. Use a \ref vx_uint32 parameter. */ + VX_REMAP_ATTRIBUTE_DESTINATION_HEIGHT = VX_ATTRIBUTE_BASE(VX_ID_KHRONOS, VX_TYPE_REMAP) + 0x3, +}; + +/*! \brief The array object attributes. + * \ingroup group_array + */ +enum vx_array_attribute_e { + /*! \brief The type of the Array items. Use a \ref vx_enum parameter. */ + VX_ARRAY_ATTRIBUTE_ITEMTYPE = VX_ATTRIBUTE_BASE(VX_ID_KHRONOS, VX_TYPE_ARRAY) + 0x0, + /*! \brief The number of items in the Array. Use a \ref vx_size parameter. */ + VX_ARRAY_ATTRIBUTE_NUMITEMS = VX_ATTRIBUTE_BASE(VX_ID_KHRONOS, VX_TYPE_ARRAY) + 0x1, + /*! \brief The maximal number of items that the Array can hold. Use a \ref vx_size parameter. */ + VX_ARRAY_ATTRIBUTE_CAPACITY = VX_ATTRIBUTE_BASE(VX_ID_KHRONOS, VX_TYPE_ARRAY) + 0x2, + /*! \brief Queries an array item size. Use a \ref vx_size parameter. */ + VX_ARRAY_ATTRIBUTE_ITEMSIZE = VX_ATTRIBUTE_BASE(VX_ID_KHRONOS, VX_TYPE_ARRAY) + 0x3, +}; + +/*! \brief The meta format object attributes. + * \ingroup group_user_kernels + */ +enum vx_meta_format_attribute_e { + /*! \brief Configures a delta rectangle during kernel output parameter validation. Use a \ref vx_delta_rectangle_t. */ + VX_META_FORMAT_ATTRIBUTE_DELTA_RECTANGLE = VX_ATTRIBUTE_BASE(VX_ID_KHRONOS, VX_TYPE_META_FORMAT) + 0x0, +}; + +/*! \brief The channel enumerations for channel extractions. + * \see vxChannelExtractNode + * \see vxuChannelExtract + * \see VX_KERNEL_CHANNEL_EXTRACT + * \ingroup group_basic_features + */ +enum vx_channel_e { + /*! \brief Used by formats with unknown channel types. */ + VX_CHANNEL_0 = VX_ENUM_BASE(VX_ID_KHRONOS, VX_ENUM_CHANNEL) + 0x0, + /*! \brief Used by formats with unknown channel types. */ + VX_CHANNEL_1 = VX_ENUM_BASE(VX_ID_KHRONOS, VX_ENUM_CHANNEL) + 0x1, + /*! \brief Used by formats with unknown channel types. */ + VX_CHANNEL_2 = VX_ENUM_BASE(VX_ID_KHRONOS, VX_ENUM_CHANNEL) + 0x2, + /*! \brief Used by formats with unknown channel types. */ + VX_CHANNEL_3 = VX_ENUM_BASE(VX_ID_KHRONOS, VX_ENUM_CHANNEL) + 0x3, + + /*! \brief Use to extract the RED channel, no matter the byte or packing order. */ + VX_CHANNEL_R = VX_ENUM_BASE(VX_ID_KHRONOS, VX_ENUM_CHANNEL) + 0x10, + /*! \brief Use to extract the GREEN channel, no matter the byte or packing order. */ + VX_CHANNEL_G = VX_ENUM_BASE(VX_ID_KHRONOS, VX_ENUM_CHANNEL) + 0x11, + /*! \brief Use to extract the BLUE channel, no matter the byte or packing order. */ + VX_CHANNEL_B = VX_ENUM_BASE(VX_ID_KHRONOS, VX_ENUM_CHANNEL) + 0x12, + /*! \brief Use to extract the ALPHA channel, no matter the byte or packing order. */ + VX_CHANNEL_A = VX_ENUM_BASE(VX_ID_KHRONOS, VX_ENUM_CHANNEL) + 0x13, + /*! \brief Use to extract the LUMA channel, no matter the byte or packing order. */ + VX_CHANNEL_Y = VX_ENUM_BASE(VX_ID_KHRONOS, VX_ENUM_CHANNEL) + 0x14, + /*! \brief Use to extract the Cb/U channel, no matter the byte or packing order. */ + VX_CHANNEL_U = VX_ENUM_BASE(VX_ID_KHRONOS, VX_ENUM_CHANNEL) + 0x15, + /*! \brief Use to extract the Cr/V/Value channel, no matter the byte or packing order. */ + VX_CHANNEL_V = VX_ENUM_BASE(VX_ID_KHRONOS, VX_ENUM_CHANNEL) + 0x16, +}; + +/*! \brief An enumeration of memory import types. + * \ingroup group_context + */ +enum vx_import_type_e { + /*! \brief For memory allocated through OpenVX, this is the import type. */ + VX_IMPORT_TYPE_NONE = VX_ENUM_BASE(VX_ID_KHRONOS, VX_ENUM_IMPORT_MEM) + 0x0, + + /*! \brief The default memory type to import from the Host. */ + VX_IMPORT_TYPE_HOST = VX_ENUM_BASE(VX_ID_KHRONOS, VX_ENUM_IMPORT_MEM) + 0x1, +}; + +/*! \brief The image reconstruction filters supported by image resampling operations. + * + * The edge of a pixel is interpreted as being aligned to the edge of the image. + * The value for an output pixel is evaluated at the center of that pixel. + * + * This means, for example, that an even enlargement of a factor of two in nearest-neighbor + * interpolation will replicate every source pixel into a 2x2 quad in the destination, and that + * an even shrink by a factor of two in bilinear interpolation will create each destination pixel + * by average a 2x2 quad of source pixels. + * + * Samples that cross the boundary of the source image have values determined by the border + * mode - see \ref vx_border_mode_e and \ref VX_NODE_ATTRIBUTE_BORDER_MODE. + * \see vxuScaleImage + * \see vxScaleImageNode + * \see VX_KERNEL_SCALE_IMAGE + * \see vxuWarpAffine + * \see vxWarpAffineNode + * \see VX_KERNEL_WARP_AFFINE + * \see vxuWarpPerspective + * \see vxWarpPerspectiveNode + * \see VX_KERNEL_WARP_PERSPECTIVE + * \ingroup group_basic_features + */ +enum vx_interpolation_type_e { + /*! \brief Output values are defined to match the source pixel whose center is nearest to the sample position. */ + VX_INTERPOLATION_TYPE_NEAREST_NEIGHBOR = VX_ENUM_BASE(VX_ID_KHRONOS, VX_ENUM_INTERPOLATION) + 0x0, + /*! \brief Output values are defined by bilinear interpolation between the pixels whose centers are closest + * to the sample position, weighted linearly by the distance of the sample from the pixel centers. */ + VX_INTERPOLATION_TYPE_BILINEAR = VX_ENUM_BASE(VX_ID_KHRONOS, VX_ENUM_INTERPOLATION) + 0x1, + /*! \brief Output values are determined by averaging the source pixels whose areas fall under the + * area of the destination pixel, projected onto the source image. */ + VX_INTERPOLATION_TYPE_AREA = VX_ENUM_BASE(VX_ID_KHRONOS, VX_ENUM_INTERPOLATION) + 0x2, +}; + +/*! \brief The image color space list used by the \ref VX_IMAGE_ATTRIBUTE_SPACE attribute of a \ref vx_image. + * \ingroup group_image + */ +enum vx_color_space_e { + /*! \brief Use to indicate that no color space is used. */ + VX_COLOR_SPACE_NONE = VX_ENUM_BASE(VX_ID_KHRONOS, VX_ENUM_COLOR_SPACE) + 0x0, + /*! \brief Use to indicate that the BT.601 coefficients and SMPTE C primaries are used for conversions. */ + VX_COLOR_SPACE_BT601_525 = VX_ENUM_BASE(VX_ID_KHRONOS, VX_ENUM_COLOR_SPACE) + 0x1, + /*! \brief Use to indicate that the BT.601 coefficients and BTU primaries are used for conversions. */ + VX_COLOR_SPACE_BT601_625 = VX_ENUM_BASE(VX_ID_KHRONOS, VX_ENUM_COLOR_SPACE) + 0x2, + /*! \brief Use to indicate that the BT.709 coefficients are used for conversions. */ + VX_COLOR_SPACE_BT709 = VX_ENUM_BASE(VX_ID_KHRONOS, VX_ENUM_COLOR_SPACE) + 0x3, + + /*! \brief All images in VX are by default BT.709 */ + VX_COLOR_SPACE_DEFAULT = VX_COLOR_SPACE_BT709, +}; + +/*! \brief The image channel range list used by the \ref VX_IMAGE_ATTRIBUTE_RANGE attribute of a \ref vx_image. + * \ingroup group_image + */ +enum vx_channel_range_e { + /*! \brief Full range of the unit of the channel */ + VX_CHANNEL_RANGE_FULL = VX_ENUM_BASE(VX_ID_KHRONOS, VX_ENUM_COLOR_RANGE) + 0x0, + /*! \brief Restricted range of the unit of the channel based on the space given */ + VX_CHANNEL_RANGE_RESTRICTED = VX_ENUM_BASE(VX_ID_KHRONOS, VX_ENUM_COLOR_RANGE) + 0x1, +}; + +/*! \brief The parameter state type. + * \ingroup group_parameter + */ +enum vx_parameter_state_e { + /*! \brief Default. The parameter must be supplied. If not set, during + * Verify, an error is returned. + */ + VX_PARAMETER_STATE_REQUIRED = VX_ENUM_BASE(VX_ID_KHRONOS, VX_ENUM_PARAMETER_STATE) + 0x0, + /*! \brief The parameter may be unspecified. The kernel takes care not + * to deference optional parameters until it is certain they are valid. + */ + VX_PARAMETER_STATE_OPTIONAL = VX_ENUM_BASE(VX_ID_KHRONOS, VX_ENUM_PARAMETER_STATE) + 0x1, +}; + +/*! \brief The border mode list. + * \ingroup group_borders + */ +enum vx_border_mode_e { + /*! \brief No defined border mode behavior is given. */ + VX_BORDER_MODE_UNDEFINED = VX_ENUM_BASE(VX_ID_KHRONOS, VX_ENUM_BORDER_MODE) + 0x0, + /*! \brief For nodes that support this behavior, a constant value is + * \e filled-in when accessing out-of-bounds pixels. + */ + VX_BORDER_MODE_CONSTANT = VX_ENUM_BASE(VX_ID_KHRONOS, VX_ENUM_BORDER_MODE) + 0x1, + /*! \brief For nodes that support this behavior, a replication of the nearest + * edge pixels value is given for out-of-bounds pixels. + */ + VX_BORDER_MODE_REPLICATE = VX_ENUM_BASE(VX_ID_KHRONOS, VX_ENUM_BORDER_MODE) + 0x2, +}; + +/*! \brief The termination criteria list. + * \see group_vision_function_opticalflowpyrlk + * \ingroup group_context + */ +enum vx_termination_criteria_e { + /*! \brief Indicates a termination after a set number of iterations. */ + VX_TERM_CRITERIA_ITERATIONS = VX_ENUM_BASE(VX_ID_KHRONOS, VX_ENUM_TERM_CRITERIA) + 0x0, + /*! \brief Indicates a termination after matching against the value of eplison provided to the function. */ + VX_TERM_CRITERIA_EPSILON = VX_ENUM_BASE(VX_ID_KHRONOS, VX_ENUM_TERM_CRITERIA) + 0x1, + /*! \brief Indicates that both an iterations and eplison method are employed. Whichever one matches first + * causes the termination. + */ + VX_TERM_CRITERIA_BOTH = VX_ENUM_BASE(VX_ID_KHRONOS, VX_ENUM_TERM_CRITERIA) + 0x2, +}; + +/*! \brief A normalization type. + * \see group_vision_function_canny + * \ingroup group_vision_function_canny + */ +enum vx_norm_type_e { + /*! \brief The L1 normalization. */ + VX_NORM_L1 = VX_ENUM_BASE(VX_ID_KHRONOS, VX_ENUM_NORM_TYPE) + 0x0, + /*! \brief The L2 normalization. */ + VX_NORM_L2 = VX_ENUM_BASE(VX_ID_KHRONOS, VX_ENUM_NORM_TYPE) + 0x1, +}; + +/*! \brief The delay attribute list. + * \ingroup group_delay + */ +enum vx_delay_attribute_e { + /*! \brief The type of reference contained in the delay. Use a \ref vx_enum parameter. */ + VX_DELAY_ATTRIBUTE_TYPE = VX_ATTRIBUTE_BASE(VX_ID_KHRONOS, VX_TYPE_DELAY) + 0x0, + /*! \brief The number of items in the delay. Use a \ref vx_size parameter.*/ + VX_DELAY_ATTRIBUTE_SLOTS = VX_ATTRIBUTE_BASE(VX_ID_KHRONOS, VX_TYPE_DELAY) + 0x1, +}; + +/*! \brief The memory accessor hint flags. + * These enumeration values are used to indicate desired \e system behavior, + * not the \b User intent. For example: these can be interpretted as hints to the + * system about cache operations or marshalling operations. + * \ingroup group_context + */ +enum vx_accessor_e { + /*! \brief The memory shall be treated by the system as if it were read-only. + * If the User writes to this memory, the results are implementation defined. + */ + VX_READ_ONLY = VX_ENUM_BASE(VX_ID_KHRONOS, VX_ENUM_ACCESSOR) + 0x1, + /*! \brief The memory shall be treated by the system as if it were write-only. + * If the User reads from this memory, the results are implementation defined. + */ + VX_WRITE_ONLY = VX_ENUM_BASE(VX_ID_KHRONOS, VX_ENUM_ACCESSOR) + 0x2, + /*! \brief The memory shall be treated by the system as if it were readable and writeable. + */ + VX_READ_AND_WRITE = VX_ENUM_BASE(VX_ID_KHRONOS, VX_ENUM_ACCESSOR) + 0x3, +}; + +/*! \brief The Round Policy Enumeration. + * \ingroup group_context + */ +enum vx_round_policy_e { + /*! \brief When scaling, this truncates the least significant values that are lost in operations. */ + VX_ROUND_POLICY_TO_ZERO = VX_ENUM_BASE(VX_ID_KHRONOS, VX_ENUM_ROUND_POLICY) + 0x1, + /*! \brief When scaling, this rounds to nearest even output value. */ + VX_ROUND_POLICY_TO_NEAREST_EVEN = VX_ENUM_BASE(VX_ID_KHRONOS, VX_ENUM_ROUND_POLICY) + 0x2, +}; + +/*! + * \brief The entry point into modules loaded by \ref vxLoadKernels. + * \param [in] context The handle to the implementation context. + * \note The symbol exported from the user module must be vxPublishKernels in extern C format. + * \ingroup group_user_kernels + */ +typedef vx_status (VX_API_CALL *vx_publish_kernels_f)(vx_context context); + +/*! + * \brief The pointer to the Host side kernel. + * \param [in] node The handle to the node that contains this kernel. + * \param [in] parameters The array of parameter references. + * \param [in] num The number of parameters. + * \ingroup group_user_kernels + */ +typedef vx_status (VX_CALLBACK *vx_kernel_f)(vx_node node, const vx_reference *parameters, vx_uint32 num); + +/*! + * \brief The pointer to the kernel initializer. If the host code requires a call + * to initialize data once all the parameters have been validated, this function is called + * if not NULL. + * \param [in] node The handle to the node that contains this kernel. + * \param [in] parameters The array of parameter references. + * \param [in] num The number of parameters. + * \ingroup group_user_kernels + */ +typedef vx_status (VX_CALLBACK *vx_kernel_initialize_f)(vx_node node, const vx_reference *parameters, vx_uint32 num); + +/*! + * \brief The pointer to the kernel deinitializer. If the host code requires a call + * to deinitialize data during a node garbage collection, this function is called + * if not NULL. + * \param [in] node The handle to the node that contains this kernel. + * \param [in] parameters The array of parameter references. + * \param [in] num The number of parameters. + * \ingroup group_user_kernels + */ +typedef vx_status (VX_CALLBACK *vx_kernel_deinitialize_f)(vx_node node, const vx_reference *parameters, vx_uint32 num); + +/*! + * \brief The user-defined kernel node input parameter validation function. + * \note This function is called once for each VX_INPUT or VX_BIDIRECTIONAL + * parameter index. + * \param [in] node The handle to the node that is being validated. + * \param [in] index The index of the parameter being validated. + * \return An error code describing the validation status on this + * parameter. + * \retval VX_ERROR_INVALID_FORMAT The parameter format was incorrect. + * \retval VX_ERROR_INVALID_VALUE The value of the parameter was incorrect. + * \retval VX_ERROR_INVALID_DIMENSION The dimensionality of the parameter was incorrect. + * \retval VX_ERROR_INVALID_PARAMETERS The index was out of bounds. + * \ingroup group_user_kernels + */ +typedef vx_status (VX_CALLBACK *vx_kernel_input_validate_f)(vx_node node, vx_uint32 index); + +/*! + * \brief The user-defined kernel node output parameter validation function. The function only + * needs to fill in the meta data structure. + * \note This function is called once for each VX_OUTPUT parameter index. + * \param [in] node The handle to the node that is being validated. + * \param [in] index The index of the parameter being validated. + * \param [in] ptr A pointer to a pre-allocated structure that the system holds. + * The validation function fills in the correct type, format, and dimensionality for + * the system to use either to create memory or to check against existing memory. + * \return An error code describing the validation status on this + * parameter. + * \retval VX_ERROR_INVALID_PARAMETERS The index is out of bounds. + * \ingroup group_user_kernels + */ +typedef vx_status (VX_CALLBACK *vx_kernel_output_validate_f)(vx_node node, vx_uint32 index, vx_meta_format meta); + +#if defined(_WIN32) || defined(UNDER_CE) +#if defined(_WIN64) +/*! Use to aid in debugging values in OpenVX. + * \ingroup group_basic_features + */ +#define VX_FMT_REF "%I64u" +/*! Use to aid in debugging values in OpenVX. + * \ingroup group_basic_features + */ +#define VX_FMT_SIZE "%I64u" +#else +/*! Use to aid in debugging values in OpenVX. + * \ingroup group_basic_features + */ +#define VX_FMT_REF "%lu" +/*! Use to aid in debugging values in OpenVX. + * \ingroup group_basic_features + */ +#define VX_FMT_SIZE "%lu" +#endif +#else +/*! Use to aid in debugging values in OpenVX. + * \ingroup group_basic_features + */ +#define VX_FMT_REF "%p" +/*! Use to aid in debugging values in OpenVX. + * \ingroup group_basic_features + */ +#define VX_FMT_SIZE "%zu" +#endif +/*! Use to indicate the 1:1 ratio in Q22.10 format. + * \ingroup group_basic_features + */ +#define VX_SCALE_UNITY (1024u) + +/*! + * \brief The addressing image patch structure is used by the Host only + * to address pixels in an image patch. The fields of the structure are defined as: + * \arg dim - The dimensions of the image in logical pixel units in the x & y direction. + * \arg stride - The physical byte distance from a logical pixel to the next + * logically adjacent pixel in the positive x or y direction. + * \arg scale - The relationship of scaling from the primary plane (typically + * the zero indexed plane) to this plane. An integer down-scaling factor of \f$ f \f$ shall be + * set to a value equal to \f$ scale = \frac{unity}{f} \f$ and an integer up-scaling factor of \f$ f \f$ + * shall be set to a value of \f$ scale = unity * f \f$. \f$ unity \f$ is defined as \ref VX_SCALE_UNITY. + * \arg step - The step is the number of logical pixel units to skip to + * arrive at the next physically unique pixel. For example, on a plane that is + * half-scaled in a dimension, the step in that dimension is 2 to indicate that + * every other pixel in that dimension is an alias. This is useful in situations + * where iteration over unique pixels is required, such as in serializing + * or de-serializing the image patch information. + * \see \ref vxAccessImagePatch + * \ingroup group_image + * \include vx_imagepatch.c + */ +typedef struct _vx_imagepatch_addressing_t { + vx_uint32 dim_x; /*!< \brief Width of patch in X dimension in pixels. */ + vx_uint32 dim_y; /*!< \brief Height of patch in Y dimension in pixels. */ + vx_int32 stride_x; /*!< \brief Stride in X dimension in bytes. */ + vx_int32 stride_y; /*!< \brief Stride in Y dimension in bytes. */ + vx_uint32 scale_x; /*!< \brief Scale of X dimension. For sub-sampled planes this is the scaling factor of the dimension of the plane in relation to the zero plane. Use \ref VX_SCALE_UNITY in the numerator. */ + vx_uint32 scale_y; /*!< \brief Scale of Y dimension. For sub-sampled planes this is the scaling factor of the dimension of the plane in relation to the zero plane. Use \ref VX_SCALE_UNITY in the numerator. */ + vx_uint32 step_x; /*!< \brief Step of X dimension in pixels. */ + vx_uint32 step_y; /*!< \brief Step of Y dimension in pixels. */ +} vx_imagepatch_addressing_t; + +/*! \brief Use to initialize a \ref vx_imagepatch_addressing_t structure on the stack. + * \ingroup group_image + */ +#define VX_IMAGEPATCH_ADDR_INIT {0u, 0u, 0, 0, 0u, 0u, 0u, 0u} + +/*! \brief The performance measurement structure. + * \ingroup group_performance + */ +typedef struct _vx_perf_t { + vx_uint64 tmp; /*!< \brief Holds the last measurement. */ + vx_uint64 beg; /*!< \brief Holds the first measurement in a set. */ + vx_uint64 end; /*!< \brief Holds the last measurement in a set. */ + vx_uint64 sum; /*!< \brief Holds the summation of durations. */ + vx_uint64 avg; /*!< \brief Holds the average of the durations. */ + vx_uint64 min; /*!< \brief Holds the minimum of the durations. */ + vx_uint64 num; /*!< \brief Holds the number of measurements. */ + vx_uint64 max; /*!< \brief Holds the maximum of the durations. */ +} vx_perf_t; + +/*! \brief Initializes a \ref vx_perf_t on the stack. + * \ingroup group performance + */ +#define VX_PERF_INIT {0ul, 0ul, 0ul, 0ul, 0ul, 0ul} + +/*! \brief The Kernel Information Structure. This is returned by the Context + * to indicate which kernels are available in the OpenVX implementation. + * \ingroup group_kernel + */ +typedef struct _vx_kernel_info_t { + /*! \brief The kernel enumeration value from \ref vx_kernel_e (or an + * extension thereof). + * \see vxGetKernelByEnum + */ + vx_enum enumeration; + + /*! \brief The kernel name in dotted hierarchical format. + * e.g. "org.khronos.openvx.sobel3x3" + * \see vxGetKernelByName + */ + vx_char name[VX_MAX_KERNEL_NAME]; +} vx_kernel_info_t; + +/*! \brief Use to indicate a half-scale pyramid. + * \ingroup group_pyramid + */ +#define VX_SCALE_PYRAMID_HALF (0.5f) + +/*! \brief Use to indicate a ORB scaled pyramid whose scaling factor is \f$ \frac{1}{\root 4 \of {2}} \f$. + * \ingroup group_pyramid + */ +#define VX_SCALE_PYRAMID_ORB ((vx_float32)0.8408964f) + +/*! \brief Use with the enumeration \ref VX_NODE_ATTRIBUTE_BORDER_MODE to set the + * border mode behavior of a node that supports borders. + * \ingroup group_borders + */ +typedef struct _vx_border_mode_t { + /*! \brief See \ref vx_border_mode_e. */ + vx_enum mode; + /*! \brief For the mode \ref VX_BORDER_MODE_CONSTANT, this value is + * filled into each pixel. If there are sub-channels in the pixel then this + * value is divided up accordingly. + */ + vx_uint32 constant_value; +} vx_border_mode_t; + +/*! \brief The keypoint data structure. + * \ingroup group_basic_features + */ +typedef struct _vx_keypoint_t { + vx_int32 x; /*!< \brief The x coordinate. */ + vx_int32 y; /*!< \brief The y coordinate. */ + vx_float32 strength; /*!< \brief The strength of the keypoint. Its definition is specific to the corner detector. */ + vx_float32 scale; /*!< \brief Initialized to 0 by corner detectors. */ + vx_float32 orientation; /*!< \brief Initialized to 0 by corner detectors. */ + vx_int32 tracking_status; /*!< \brief A zero indicates a lost point. Initialized to 1 by corner detectors. */ + vx_float32 error; /*!< \brief A tracking method specific error. Initialized to 0 by corner detectors. */ +} vx_keypoint_t; + +/*! \brief The rectangle data structure that is shared with the users. + * \ingroup group_basic_features + */ +typedef struct _vx_rectangle_t { + vx_uint32 start_x; /*!< \brief The Start X coordinate. */ + vx_uint32 start_y; /*!< \brief The Start Y coordinate. */ + vx_uint32 end_x; /*!< \brief The End X coordinate. */ + vx_uint32 end_y; /*!< \brief The End Y coordinate. */ +} vx_rectangle_t; + +/*! \brief The changes in dimensions of the rectangle between input and output + * images in an output parameter validator. Used in conjunction with + * \ref VX_META_FORMAT_ATTRIBUTE_DELTA_RECTANGLE and + * \ref vxSetMetaFormatAttribute. + * \see vx_kernel_output_validate_f + * \see vx_meta_format + * \ingroup group_basic_features + */ +typedef struct _vx_delta_rectangle_t { + vx_int32 delta_start_x; /*!< \brief The change in the start x. */ + vx_int32 delta_start_y; /*!< \brief The change in the start y. */ + vx_int32 delta_end_x; /*!< \brief The change in the end x. */ + vx_int32 delta_end_y; /*!< \brief The change in the end y. */ +} vx_delta_rectangle_t; + +/*! \brief The 2D Coordinates structure. + * \ingroup group_basic_features + */ +typedef struct _vx_coordinates2d_t { + vx_uint32 x; /*!< \brief The X coordinate. */ + vx_uint32 y; /*!< \brief The Y coordinate. */ +} vx_coordinates2d_t; + +/*! \brief The 3D Coordinates structure. + * \ingroup group_basic_features + */ +typedef struct _vx_coordinates3d_t { + vx_uint32 x; /*!< \brief The X coordinate. */ + vx_uint32 y; /*!< \brief The Y coordinate. */ + vx_uint32 z; /*!< \brief The Z coordinate. */ +} vx_coordinates3d_t; + +/*! \brief The log callback function. + * \ingroup group_log + */ +typedef void (VX_CALLBACK *vx_log_callback_f)(vx_context context, + vx_reference ref, + vx_status status, + const vx_char string[]); + +#endif diff --git a/vx_ext_cv/include/VX/vx_vendors.h b/vx_ext_cv/include/VX/vx_vendors.h new file mode 100644 index 0000000..0dcbdeb --- /dev/null +++ b/vx_ext_cv/include/VX/vx_vendors.h @@ -0,0 +1,93 @@ +/* +Copyright (c) 2015 Advanced Micro Devices, Inc. All rights reserved. + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. +*/ + + +/* + * Copyright (c) 2012-2015 The Khronos Group Inc. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and/or associated documentation files (the + * "Materials"), to deal in the Materials without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Materials, and to + * permit persons to whom the Materials are furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Materials. + * + * THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY,\todo FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY + * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS. + */ + +#ifndef _OPENVX_VENDORS_H_ +#define _OPENVX_VENDORS_H_ + +/*! + * \file + * \brief The Vendor ID list for OpenVX. + */ + +/*! \brief The Vendor ID of the Implementation. As new vendors submit their + * implementations, this enumeration will grow. + * \ingroup group_basic_features + */ +enum vx_vendor_id_e { + VX_ID_KHRONOS = 0x000, /*!< \brief The Khronos Group */ + VX_ID_TI = 0x001, /*!< \brief Texas Instruments, Inc. */ + VX_ID_QUALCOMM = 0x002, /*!< \brief Qualcomm, Inc. */ + VX_ID_NVIDIA = 0x003, /*!< \brief NVIDIA Corporation */ + VX_ID_ARM = 0x004, /*!< \brief ARM Ltd. */ + VX_ID_BDTI = 0x005, /*!< \brief Berkley Design Technology, Inc. */ + VX_ID_RENESAS = 0x006, /*!< \brief Renasas Electronics */ + VX_ID_VIVANTE = 0x007, /*!< \brief Vivante Corporation */ + VX_ID_XILINX = 0x008, /*!< \brief Xilinx Inc. */ + VX_ID_AXIS = 0x009, /*!< \brief Axis Communications */ + VX_ID_MOVIDIUS = 0x00A, /*!< \brief Movidius Ltd. */ + VX_ID_SAMSUNG = 0x00B, /*!< \brief Samsung Electronics */ + VX_ID_FREESCALE = 0x00C, /*!< \brief Freescale Semiconductor */ + VX_ID_AMD = 0x00D, /*!< \brief Advanced Micro Devices */ + VX_ID_BROADCOM = 0x00E, /*!< \brief Broadcom Corporation */ + VX_ID_INTEL = 0x00F, /*!< \brief Intel Corporation */ + VX_ID_MARVELL = 0x010, /*!< \brief Marvell Technology Group Ltd. */ + VX_ID_MEDIATEK = 0x011, /*!< \brief MediaTek, Inc. */ + VX_ID_ST = 0x012, /*!< \brief STMicroelectronics */ + VX_ID_CEVA = 0x013, /*!< \brief CEVA DSP */ + VX_ID_ITSEEZ = 0x014, /*!< \brief Itseez, Inc. */ + VX_ID_IMAGINATION=0x015, /*!< \brief Imagination Technologies */ + VX_ID_COGNIVUE = 0x016, /*!< \brief CogniVue Corporation */ + VX_ID_VIDEANTIS = 0x017, /*!< \brief Videantis */ + VX_ID_SYNOPSYS = 0x018, /*!< \brief Synopsys */ + /* Add new vendor code above this line */ + + VX_ID_MAX = 0xFFF, + /*! \brief For use by all Kernel authors until they can obtain an assigned ID. */ + VX_ID_DEFAULT = VX_ID_MAX, +}; + +#endif + diff --git a/vx_ext_cv/include/VX/vxu.h b/vx_ext_cv/include/VX/vxu.h new file mode 100644 index 0000000..27963f1 --- /dev/null +++ b/vx_ext_cv/include/VX/vxu.h @@ -0,0 +1,614 @@ +/* +Copyright (c) 2015 Advanced Micro Devices, Inc. All rights reserved. + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. +*/ + + +/* + * Copyright (c) 2012-2015 The Khronos Group Inc. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and/or associated documentation files (the + * "Materials"), to deal in the Materials without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Materials, and to + * permit persons to whom the Materials are furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Materials. + * + * THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY + * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS. + */ + +#ifndef _OPENVX_UTILITY_H_ +#define _OPENVX_UTILITY_H_ + +/*! + * \file + * \brief The OpenVX Utility Library. + */ + +#ifdef __cplusplus +extern "C" { +#endif + +/*! \brief [Immediate] Invokes an immediate Color Conversion. + * \param [in] context The reference to the overall context. + * \param [in] input The input image. + * \param [out] output The output image. + * \ingroup group_vision_function_colorconvert + * \return A \ref vx_status_e enumeration. + * \retval VX_SUCCESS Success + * \retval * An error occurred. See \ref vx_status_e. + */ +VX_API_ENTRY vx_status VX_API_CALL vxuColorConvert(vx_context context, vx_image input, vx_image output); + +/*! \brief [Immediate] Invokes an immediate Channel Extract. + * \param [in] context The reference to the overall context. + * \param [in] input The input image. Must be one of the defined \ref vx_df_image_e multiplanar formats. + * \param [in] channel The \ref vx_channel_e enumeration to extract. + * \param [out] output The output image. Must be \ref VX_DF_IMAGE_U8. + * \ingroup group_vision_function_channelextract + * \return A \ref vx_status_e enumeration. + * \retval VX_SUCCESS Success + * \retval * An error occurred. See \ref vx_status_e. + */ +VX_API_ENTRY vx_status VX_API_CALL vxuChannelExtract(vx_context context, vx_image input, vx_enum channel, vx_image output); + +/*! \brief [Immediate] Invokes an immediate Channel Combine. + * \param [in] context The reference to the overall context. + * \param [in] plane0 The plane that forms channel 0. Must be \ref VX_DF_IMAGE_U8. + * \param [in] plane1 The plane that forms channel 1. Must be \ref VX_DF_IMAGE_U8. + * \param [in] plane2 [optional] The plane that forms channel 2. Must be \ref VX_DF_IMAGE_U8. + * \param [in] plane3 [optional] The plane that forms channel 3. Must be \ref VX_DF_IMAGE_U8. + * \param [out] output The output image. + * \ingroup group_vision_function_channelcombine + * \return A \ref vx_status_e enumeration. + * \retval VX_SUCCESS Success + * \retval * An error occurred. See \ref vx_status_e. + */ +VX_API_ENTRY vx_status VX_API_CALL vxuChannelCombine(vx_context context, vx_image plane0, vx_image plane1, vx_image plane2, vx_image plane3, vx_image output); + +/*! \brief [Immediate] Invokes an immediate Sobel 3x3. + * \param [in] context The reference to the overall context. + * \param [in] input The input image in \ref VX_DF_IMAGE_U8 format. + * \param [out] output_x [optional] The output gradient in the x direction in \ref VX_DF_IMAGE_S16. + * \param [out] output_y [optional] The output gradient in the y direction in \ref VX_DF_IMAGE_S16. + * \ingroup group_vision_function_sobel3x3 + * \return A \ref vx_status_e enumeration. + * \retval VX_SUCCESS Success + * \retval * An error occurred. See \ref vx_status_e. + */ +VX_API_ENTRY vx_status VX_API_CALL vxuSobel3x3(vx_context context, vx_image input, vx_image output_x, vx_image output_y); + +/*! \brief [Immediate] Invokes an immediate Magnitude. + * \param [in] context The reference to the overall context. + * \param [in] grad_x The input x image. This must be in \ref VX_DF_IMAGE_S16 format. + * \param [in] grad_y The input y image. This must be in \ref VX_DF_IMAGE_S16 format. + * \param [out] output The magnitude image. This will be in \ref VX_DF_IMAGE_S16 format. + * \ingroup group_vision_function_magnitude + * \return A \ref vx_status_e enumeration. + * \retval VX_SUCCESS Success + * \retval * An error occurred. See \ref vx_status_e. + */ +VX_API_ENTRY vx_status VX_API_CALL vxuMagnitude(vx_context context, vx_image grad_x, vx_image grad_y, vx_image output); + +/*! \brief [Immediate] Invokes an immediate Phase. + * \param [in] context The reference to the overall context. + * \param [in] grad_x The input x image. This must be in \ref VX_DF_IMAGE_S16 format. + * \param [in] grad_y The input y image. This must be in \ref VX_DF_IMAGE_S16 format. + * \param [out] output The phase image. This will be in \ref VX_DF_IMAGE_U8 format. + * \ingroup group_vision_function_phase + * \return A \ref vx_status_e enumeration. + * \retval VX_SUCCESS Success + * \retval * An error occurred. See \ref vx_status_e. + */ +VX_API_ENTRY vx_status VX_API_CALL vxuPhase(vx_context context, vx_image grad_x, vx_image grad_y, vx_image output); + +/*! \brief [Immediate] Scales an input image to an output image. + * \param [in] context The reference to the overall context. + * \param [in] src The source image of type \ref VX_DF_IMAGE_U8. + * \param [out] dst The destintation image of type \ref VX_DF_IMAGE_U8. + * \param [in] type The interpolation type. \see vx_interpolation_type_e. + * \ingroup group_vision_function_scale_image + * \return A \ref vx_status_e enumeration. + * \retval VX_SUCCESS Success + * \retval * An error occurred. See \ref vx_status_e. + */ +VX_API_ENTRY vx_status VX_API_CALL vxuScaleImage(vx_context context, vx_image src, vx_image dst, vx_enum type); + +/*! \brief [Immediate] Processes the image through the LUT. + * \param [in] context The reference to the overall context. + * \param [in] input The input image in \ref VX_DF_IMAGE_U8 + * \param [in] lut The LUT which is of type VX_TYPE_UINT8 + * \param [out] output The output image of type \ref VX_DF_IMAGE_U8 + * \ingroup group_vision_function_lut + * \return A \ref vx_status_e enumeration. + * \retval VX_SUCCESS Success + * \retval * An error occurred. See \ref vx_status_e. + */ +VX_API_ENTRY vx_status VX_API_CALL vxuTableLookup(vx_context context, vx_image input, vx_lut lut, vx_image output); + +/*! \brief [Immediate] Generates a distribution from an image. + * \param [in] context The reference to the overall context. + * \param [in] input The input image in \ref VX_DF_IMAGE_U8 + * \param [out] distribution The output distribution. + * \ingroup group_vision_function_histogram + * \return A \ref vx_status_e enumeration. + * \retval VX_SUCCESS Success + * \retval * An error occurred. See \ref vx_status_e. + */ +VX_API_ENTRY vx_status VX_API_CALL vxuHistogram(vx_context context, vx_image input, vx_distribution distribution); + +/*! \brief [Immediate] Equalizes the Histogram of a grayscale image. + * \param [in] context The reference to the overall context. + * \param [in] input The grayscale input image in \ref VX_DF_IMAGE_U8 + * \param [out] output The grayscale output image of type \ref VX_DF_IMAGE_U8 with equalized brightness and contrast. + * \ingroup group_vision_function_equalize_hist + * \return A \ref vx_status_e enumeration. + * \retval VX_SUCCESS Success + * \retval * An error occurred. See \ref vx_status_e. + */ +VX_API_ENTRY vx_status VX_API_CALL vxuEqualizeHist(vx_context context, vx_image input, vx_image output); + +/*! \brief [Immediate] Computes the absolute difference between two images. + * \param [in] context The reference to the overall context. + * \param [in] in1 An input image in \ref VX_DF_IMAGE_U8 or \ref VX_DF_IMAGE_S16 format. + * \param [in] in2 An input image in \ref VX_DF_IMAGE_U8 or \ref VX_DF_IMAGE_S16 format. + * \param [out] out The output image in \ref VX_DF_IMAGE_U8 or \ref VX_DF_IMAGE_S16 format. + * \ingroup group_vision_function_absdiff + * \return A \ref vx_status_e enumeration. + * \retval VX_SUCCESS Success + * \retval * An error occurred. See \ref vx_status_e. + */ +VX_API_ENTRY vx_status VX_API_CALL vxuAbsDiff(vx_context context, vx_image in1, vx_image in2, vx_image out); + +/*! \brief [Immediate] Computes the mean value and standard deviation. + * \param [in] context The reference to the overall context. + * \param [in] input The input image. \ref VX_DF_IMAGE_U8 is supported. + * \param [out] mean The average pixel value. + * \param [out] stddev The standard deviation of the pixel values. + * \ingroup group_vision_function_meanstddev + * \return A \ref vx_status_e enumeration. + * \retval VX_SUCCESS Success + * \retval * An error occurred. See \ref vx_status_e. + */ +VX_API_ENTRY vx_status VX_API_CALL vxuMeanStdDev(vx_context context, vx_image input, vx_float32 *mean, vx_float32 *stddev); + +/*! \brief [Immediate] Threshold's an input image and produces a \ref VX_DF_IMAGE_U8 * boolean image. + * \param [in] context The reference to the overall context. + * \param [in] input The input image. \ref VX_DF_IMAGE_U8 is supported. + * \param [in] thresh The thresholding object that defines the parameters of + * the operation. + * \param [out] output The output Boolean image. Values are either 0 or 255. + * \ingroup group_vision_function_threshold + * \return A \ref vx_status_e enumeration. + * \retval VX_SUCCESS Success + * \retval * An error occurred. See \ref vx_status_e. + */ +VX_API_ENTRY vx_status VX_API_CALL vxuThreshold(vx_context context, vx_image input, vx_threshold thresh, vx_image output); + +/*! \brief [Immediate] Computes the integral image of the input. + * \param [in] context The reference to the overall context. + * \param [in] input The input image in \ref VX_DF_IMAGE_U8 format. + * \param [out] output The output image in \ref VX_DF_IMAGE_U32 format. + * \ingroup group_vision_function_integral_image + * \return A \ref vx_status_e enumeration. + * \retval VX_SUCCESS Success + * \retval * An error occurred. See \ref vx_status_e. + */ +VX_API_ENTRY vx_status VX_API_CALL vxuIntegralImage(vx_context context, vx_image input, vx_image output); + +/*! \brief [Immediate] Erodes an image by a 3x3 window. + * \param [in] context The reference to the overall context. + * \param [in] input The input image in \ref VX_DF_IMAGE_U8 format. + * \param [out] output The output image in \ref VX_DF_IMAGE_U8 format. + * \ingroup group_vision_function_erode_image + * \return A \ref vx_status_e enumeration. + * \retval VX_SUCCESS Success + * \retval * An error occurred. See \ref vx_status_e. + */ +VX_API_ENTRY vx_status VX_API_CALL vxuErode3x3(vx_context context, vx_image input, vx_image output); + +/*! \brief [Immediate] Dilates an image by a 3x3 window. + * \param [in] context The reference to the overall context. + * \param [in] input The input image in \ref VX_DF_IMAGE_U8 format. + * \param [out] output The output image in \ref VX_DF_IMAGE_U8 format. + * \ingroup group_vision_function_dilate_image + * \return A \ref vx_status_e enumeration. + * \retval VX_SUCCESS Success + * \retval * An error occurred. See \ref vx_status_e. + */ +VX_API_ENTRY vx_status VX_API_CALL vxuDilate3x3(vx_context context, vx_image input, vx_image output); + +/*! \brief [Immediate] Computes a median filter on the image by a 3x3 window. + * \param [in] context The reference to the overall context. + * \param [in] input The input image in \ref VX_DF_IMAGE_U8 format. + * \param [out] output The output image in \ref VX_DF_IMAGE_U8 format. + * \ingroup group_vision_function_median_image + * \return A \ref vx_status_e enumeration. + * \retval VX_SUCCESS Success + * \retval * An error occurred. See \ref vx_status_e. + */ +VX_API_ENTRY vx_status VX_API_CALL vxuMedian3x3(vx_context context, vx_image input, vx_image output); + +/*! \brief [Immediate] Computes a box filter on the image by a 3x3 window. + * \param [in] context The reference to the overall context. + * \param [in] input The input image in \ref VX_DF_IMAGE_U8 format. + * \param [out] output The output image in \ref VX_DF_IMAGE_U8 format. + * \ingroup group_vision_function_box_image + * \return A \ref vx_status_e enumeration. + * \retval VX_SUCCESS Success + * \retval * An error occurred. See \ref vx_status_e. + */ +VX_API_ENTRY vx_status VX_API_CALL vxuBox3x3(vx_context context, vx_image input, vx_image output); + +/*! \brief [Immediate] Computes a gaussian filter on the image by a 3x3 window. + * \param [in] context The reference to the overall context. + * \param [in] input The input image in \ref VX_DF_IMAGE_U8 format. + * \param [out] output The output image in \ref VX_DF_IMAGE_U8 format. + * \ingroup group_vision_function_gaussian_image + * \return A \ref vx_status_e enumeration. + * \retval VX_SUCCESS Success + * \retval * An error occurred. See \ref vx_status_e. + */ +VX_API_ENTRY vx_status VX_API_CALL vxuGaussian3x3(vx_context context, vx_image input, vx_image output); + +/*! \brief [Immediate] Computes a convolution on the input image with the supplied + * matrix. + * \param [in] context The reference to the overall context. + * \param [in] input The input image in \ref VX_DF_IMAGE_U8 format. + * \param [in] matrix The convolution matrix. + * \param [out] output The output image in \ref VX_DF_IMAGE_U8 or \ref VX_DF_IMAGE_S16 format. + * \ingroup group_vision_function_custom_convolution + * \return A \ref vx_status_e enumeration. + * \retval VX_SUCCESS Success + * \retval * An error occurred. See \ref vx_status_e. + */ +VX_API_ENTRY vx_status VX_API_CALL vxuConvolve(vx_context context, vx_image input, vx_convolution matrix, vx_image output); + +/*! \brief [Immediate] Computes a Gaussian pyramid from an input image. + * \param [in] context The reference to the overall context. + * \param [in] input The input image in \ref VX_DF_IMAGE_U8 + * \param [out] gaussian The Gaussian pyramid with \ref VX_DF_IMAGE_U8 to construct. + * \ingroup group_vision_function_gaussian_pyramid + * \return A \ref vx_status_e enumeration. + * \retval VX_SUCCESS Success + * \retval * An error occurred. See \ref vx_status_e. + */ +VX_API_ENTRY vx_status VX_API_CALL vxuGaussianPyramid(vx_context context, vx_image input, vx_pyramid gaussian); + +/*! \brief [Immediate] Computes an accumulation. + * \param [in] context The reference to the overall context. + * \param [in] input The input \ref VX_DF_IMAGE_U8 image. + * \param [in,out] accum The accumulation image in \ref VX_DF_IMAGE_S16 + * \ingroup group_vision_function_accumulate + * \return A \ref vx_status_e enumeration. + * \retval VX_SUCCESS Success + * \retval * An error occurred. See \ref vx_status_e. + */ +VX_API_ENTRY vx_status VX_API_CALL vxuAccumulateImage(vx_context context, vx_image input, vx_image accum); + +/*! \brief [Immediate] Computes a weighted accumulation. + * \param [in] context The reference to the overall context. + * \param [in] input The input \ref VX_DF_IMAGE_U8 image. + * \param [in] scale A \ref VX_TYPE_FLOAT32 type, the input value with the range \f$ 0.0 \le \alpha \le 1.0 \f$. + * \param [in,out] accum The \ref VX_DF_IMAGE_U8 accumulation image. + * \ingroup group_vision_function_accumulate_weighted + * \return A \ref vx_status_e enumeration. + * \retval VX_SUCCESS Success + * \retval * An error occurred. See \ref vx_status_e. + */ +VX_API_ENTRY vx_status VX_API_CALL vxuAccumulateWeightedImage(vx_context context, vx_image input, vx_scalar scale, vx_image accum); + +/*! \brief [Immediate] Computes a squared accumulation. + * \param [in] context The reference to the overall context. + * \param [in] input The input \ref VX_DF_IMAGE_U8 image. + * \param [in] shift A \ref VX_TYPE_UINT32 type, the input value with the range \f$ 0 \le shift \le 15 \f$. + * \param [in,out] accum The accumulation image in \ref VX_DF_IMAGE_S16 + * \ingroup group_vision_function_accumulate_square + * \return A \ref vx_status_e enumeration. + * \retval VX_SUCCESS Success + * \retval * An error occurred. See \ref vx_status_e. + */ +VX_API_ENTRY vx_status VX_API_CALL vxuAccumulateSquareImage(vx_context context, vx_image input, vx_scalar shift, vx_image accum); + +/*! \brief [Immediate] Computes the minimum and maximum values of the image. + * \param [in] context The reference to the overall context. + * \param [in] input The input image in \ref VX_DF_IMAGE_U8 or \ref VX_DF_IMAGE_S16 format. + * \param [out] minVal The minimum value in the image. + * \param [out] maxVal The maximum value in the image. + * \param [out] minLoc The minimum locations (optional). If the input image has several minimums, the kernel will return all of them). + * \param [out] maxLoc The maximum locations (optional). If the input image has several maximums, the kernel will return all of them). + * \param [out] minCount The total number of detected minimums in image (optional). + * \param [out] maxCount The total number of detected maximums in image (optional). + * \ingroup group_vision_function_minmaxloc + * \return A \ref vx_status_e enumeration. + * \retval VX_SUCCESS Success + * \retval * An error occurred. See \ref vx_status_e. + */ +VX_API_ENTRY vx_status VX_API_CALL vxuMinMaxLoc(vx_context context, vx_image input, + vx_scalar minVal, vx_scalar maxVal, + vx_array minLoc, vx_array maxLoc, + vx_scalar minCount, vx_scalar maxCount); + +/*! \brief [Immediate] Converts the input images bit-depth into the output image. + * \param [in] context The reference to the overall context. + * \param [in] input The input image. + * \param [out] output The output image. + * \param [in] policy A \ref vx_convert_policy_e enumeration. + * \param [in] shift The shift value. + * \ingroup group_vision_function_convertdepth + * \return A \ref vx_status_e enumeration. + * \retval VX_SUCCESS Success + * \retval * An error occurred. See \ref vx_status_e.. + */ +VX_API_ENTRY vx_status VX_API_CALL vxuConvertDepth(vx_context context, vx_image input, vx_image output, vx_enum policy, vx_int32 shift); + +/*! \brief [Immediate] Computes Canny Edges on the input image into the output image. + * \param [in] context The reference to the overall context. + * \param [in] input The input \ref VX_DF_IMAGE_U8 image. + * \param [in] hyst The double threshold for hysteresis. + * \param [in] gradient_size The size of the Sobel filter window, must support at least 3, 5 and 7. + * \param [in] norm_type A flag indicating the norm used to compute the gradient, VX_NORM_L1 or VX_NORM_L2. + * \param [out] output The output image in \ref VX_DF_IMAGE_U8 format. + * \ingroup group_vision_function_canny + * \return A \ref vx_status_e enumeration. + * \retval VX_SUCCESS Success + * \retval * An error occurred. See \ref vx_status_e. + */ +VX_API_ENTRY vx_status VX_API_CALL vxuCannyEdgeDetector(vx_context context, vx_image input, vx_threshold hyst, + vx_int32 gradient_size, vx_enum norm_type, + vx_image output); + +/*! \brief [Immediate] Performs a Gaussian Blur on an image then half-scales it. + * \param [in] context The reference to the overall context. + * \param [in] input The input \ref VX_DF_IMAGE_U8 image. + * \param [out] output The output \ref VX_DF_IMAGE_U8 image. + * \param [in] kernel_size The input size of the Gaussian filter. Supported values are 3 and 5. + * \ingroup group_vision_function_scale_image + * \return A \ref vx_status_e enumeration. + * \retval VX_SUCCESS Success + * \retval * An error occurred. See \ref vx_status_e. + */ +VX_API_ENTRY vx_status VX_API_CALL vxuHalfScaleGaussian(vx_context context, vx_image input, vx_image output, vx_int32 kernel_size); + +/*! \brief [Immediate] Computes the bitwise and between two images. + * \param [in] context The reference to the overall context. + * \param [in] in1 A \ref VX_DF_IMAGE_U8 input image + * \param [in] in2 A \ref VX_DF_IMAGE_U8 input image + * \param [out] out The \ref VX_DF_IMAGE_U8 output image. + * \ingroup group_vision_function_and + * \return A \ref vx_status_e enumeration. + * \retval VX_SUCCESS Success + * \retval * An error occurred. See \ref vx_status_e. + */ +VX_API_ENTRY vx_status VX_API_CALL vxuAnd(vx_context context, vx_image in1, vx_image in2, vx_image out); + +/*! \brief [Immediate] Computes the bitwise inclusive-or between two images. + * \param [in] context The reference to the overall context. + * \param [in] in1 A \ref VX_DF_IMAGE_U8 input image + * \param [in] in2 A \ref VX_DF_IMAGE_U8 input image + * \param [out] out The \ref VX_DF_IMAGE_U8 output image. + * \ingroup group_vision_function_or + * \return A \ref vx_status_e enumeration. + * \retval VX_SUCCESS Success + * \retval * An error occurred. See \ref vx_status_e. + */ +VX_API_ENTRY vx_status VX_API_CALL vxuOr(vx_context context, vx_image in1, vx_image in2, vx_image out); + +/*! \brief [Immediate] Computes the bitwise exclusive-or between two images. + * \param [in] context The reference to the overall context. + * \param [in] in1 A \ref VX_DF_IMAGE_U8 input image + * \param [in] in2 A \ref VX_DF_IMAGE_U8 input image + * \param [out] out The \ref VX_DF_IMAGE_U8 output image. + * \ingroup group_vision_function_xor + * \return A \ref vx_status_e enumeration. + * \retval VX_SUCCESS Success + * \retval * An error occurred. See \ref vx_status_e. + */ +VX_API_ENTRY vx_status VX_API_CALL vxuXor(vx_context context, vx_image in1, vx_image in2, vx_image out); + +/*! \brief [Immediate] Computes the bitwise not of an image. + * \param [in] context The reference to the overall context. + * \param [in] input The \ref VX_DF_IMAGE_U8 input image + * \param [out] output The \ref VX_DF_IMAGE_U8 output image. + * \ingroup group_vision_function_not + * \return A \ref vx_status_e enumeration. + * \retval VX_SUCCESS Success + * \retval * An error occurred. See \ref vx_status_e. + */ +VX_API_ENTRY vx_status VX_API_CALL vxuNot(vx_context context, vx_image input, vx_image output); + +/*! \brief [Immediate] Performs elementwise multiplications on pixel values in the input images and a scale. + * \param [in] context The reference to the overall context. + * \param [in] in1 A \ref VX_DF_IMAGE_U8 or \ref VX_DF_IMAGE_S16 input image. + * \param [in] in2 A \ref VX_DF_IMAGE_U8 or \ref VX_DF_IMAGE_S16 input image. + * \param [in] scale The scale value. + * \param [in] overflow_policy A \ref vx_convert_policy_e enumeration. + * \param [in] rounding_policy A \ref vx_round_policy_e enumeration. + * \param [out] out The output image in \ref VX_DF_IMAGE_U8 or \ref VX_DF_IMAGE_S16 format. + * \ingroup group_vision_function_mult + * \return A \ref vx_status_e enumeration. + * \retval VX_SUCCESS Success + * \retval * An error occurred. See \ref vx_status_e. + */ +VX_API_ENTRY vx_status VX_API_CALL vxuMultiply(vx_context context, vx_image in1, vx_image in2, vx_float32 scale, vx_enum overflow_policy, vx_enum rounding_policy, vx_image out); + +/*! \brief [Immediate] Performs arithmetic addition on pixel values in the input images. + * \param [in] context The reference to the overall context. + * \param [in] in1 A \ref VX_DF_IMAGE_U8 or \ref VX_DF_IMAGE_S16 input image. + * \param [in] in2 A \ref VX_DF_IMAGE_U8 or \ref VX_DF_IMAGE_S16 input image. + * \param [in] policy A \ref vx_convert_policy_e enumeration. + * \param [out] out The output image in \ref VX_DF_IMAGE_U8 or \ref VX_DF_IMAGE_S16 format. + * \ingroup group_vision_function_add + * \return A \ref vx_status_e enumeration. + * \retval VX_SUCCESS Success + * \retval * An error occurred. See \ref vx_status_e. + */ +VX_API_ENTRY vx_status VX_API_CALL vxuAdd(vx_context context, vx_image in1, vx_image in2, vx_enum policy, vx_image out); + +/*! \brief [Immediate] Performs arithmetic subtraction on pixel values in the input images. + * \param [in] context The reference to the overall context. + * \param [in] in1 A \ref VX_DF_IMAGE_U8 or \ref VX_DF_IMAGE_S16 input image, the minuend. + * \param [in] in2 A \ref VX_DF_IMAGE_U8 or \ref VX_DF_IMAGE_S16 input image, the subtrahend. + * \param [in] policy A \ref vx_convert_policy_e enumeration. + * \param [out] out The output image in \ref VX_DF_IMAGE_U8 or \ref VX_DF_IMAGE_S16 format. + * \ingroup group_vision_function_sub + * \return A \ref vx_status_e enumeration. + * \retval VX_SUCCESS Success + * \retval * An error occurred. See \ref vx_status_e. + */ +VX_API_ENTRY vx_status VX_API_CALL vxuSubtract(vx_context context, vx_image in1, vx_image in2, vx_enum policy, vx_image out); + +/*! \brief [Immediate] Performs an Affine warp on an image. + * \param [in] context The reference to the overall context. + * \param [in] input The input \ref VX_DF_IMAGE_U8 image. + * \param [in] matrix The affine matrix. Must be 2x3 of type \ref VX_TYPE_FLOAT32. + * \param [in] type The interpolation type from \ref vx_interpolation_type_e. + * \ref VX_INTERPOLATION_TYPE_AREA is not supported. + * \param [out] output The output \ref VX_DF_IMAGE_U8 image. + * \ingroup group_vision_function_warp_affine + * \return A \ref vx_status_e enumeration. + * \retval VX_SUCCESS Success + * \retval * An error occurred. See \ref vx_status_e. + */ +VX_API_ENTRY vx_status VX_API_CALL vxuWarpAffine(vx_context context, vx_image input, vx_matrix matrix, vx_enum type, vx_image output); + +/*! \brief [Immediate] Performs an Perspective warp on an image. + * \param [in] context The reference to the overall context. + * \param [in] input The input \ref VX_DF_IMAGE_U8 image. + * \param [in] matrix The perspective matrix. Must be 3x3 of type \ref VX_TYPE_FLOAT32. + * \param [in] type The interpolation type from \ref vx_interpolation_type_e. + * \ref VX_INTERPOLATION_TYPE_AREA is not supported. + * \param [out] output The output \ref VX_DF_IMAGE_U8 image. + * \ingroup group_vision_function_warp_perspective + * \return A \ref vx_status_e enumeration. + * \retval VX_SUCCESS Success + * \retval * An error occurred. See \ref vx_status_e. + */ +VX_API_ENTRY vx_status VX_API_CALL vxuWarpPerspective(vx_context context, vx_image input, vx_matrix matrix, vx_enum type, vx_image output); + +/*! \brief [Immediate] Computes the Harris Corners over an image and produces the array of scored points. + * \param [in] context The reference to the overall context. + * \param [in] input The input \ref VX_DF_IMAGE_U8 image. + * \param [in] strength_thresh The \ref VX_TYPE_FLOAT32 minimum threshold which to eliminate Harris Corner scores (computed using the normalized Sobel kernel). + * \param [in] min_distance The \ref VX_TYPE_FLOAT32 radial Euclidean distance for non-maximum suppression. + * \param [in] sensitivity The \ref VX_TYPE_FLOAT32 scalar sensitivity threshold \f$ k \f$ from the Harris-Stephens equation. + * \param [in] gradient_size The gradient window size to use on the input. The + * implementation must support at least 3, 5, and 7. + * \param [in] block_size The block window size used to compute the harris corner score. + * The implementation must support at least 3, 5, and 7. + * \param [out] corners The array of \ref VX_TYPE_KEYPOINT structs. + * \param [out] num_corners The total number of detected corners in image (optional). Use a \ref VX_TYPE_SIZE scalar + * \ingroup group_vision_function_harris + * \return A \ref vx_status_e enumeration. + * \retval VX_SUCCESS Success + * \retval * An error occurred. See \ref vx_status_e. + */ +VX_API_ENTRY vx_status VX_API_CALL vxuHarrisCorners(vx_context context, + vx_image input, + vx_scalar strength_thresh, + vx_scalar min_distance, + vx_scalar sensitivity, + vx_int32 gradient_size, + vx_int32 block_size, + vx_array corners, + vx_scalar num_corners); + + +/*! \brief [Immediate] Computes corners on an image using FAST algorithm and produces the array of feature points. + * \param [in] context The reference to the overall context. + * \param [in] input The input \ref VX_DF_IMAGE_U8 image. + * \param [in] strength_thresh Threshold on difference between intensity of the central pixel and pixels on Bresenham's circle of radius 3 (\ref VX_TYPE_FLOAT32 scalar) + * \param [in] nonmax_suppression If true, non-maximum suppression is applied to + * detected corners before being places in the \ref vx_array of \ref VX_TYPE_KEYPOINT structs. + * \param [out] corners Output corner \ref vx_array of \ref VX_TYPE_KEYPOINT. + * \param [out] num_corners The total number of detected corners in image (optional). Use a \ref VX_TYPE_SIZE scalar. + * \ingroup group_vision_function_fast + * \return A \ref vx_status_e enumeration. + * \retval VX_SUCCESS Success + * \retval * An error occurred. See \ref vx_status_e. + */ +VX_API_ENTRY vx_status VX_API_CALL vxuFastCorners(vx_context context, vx_image input, vx_scalar strength_thresh, vx_bool nonmax_suppression, vx_array corners, vx_scalar num_corners); + +/*! \brief [Immediate] Computes an optical flow on two images. + * \param [in] context The reference to the overall context. + * \param [in] old_images Input of first (old) image pyramid + * \param [in] new_images Input of destination (new) image pyramid + * \param [in] old_points an array of key points in a vx_array of \ref VX_TYPE_KEYPOINT those key points are defined at + * the old_images high resolution pyramid + * \param [in] new_points_estimates an array of estimation on what is the output key points in a \ref vx_array of + * \ref VX_TYPE_KEYPOINT those keypoints are defined at the new_images high resolution pyramid + * \param [out] new_points an output array of key points in a \ref vx_array of \ref VX_TYPE_KEYPOINT those key points are + * defined at the new_images high resolution pyramid + * \param [in] termination termination can be \ref VX_TERM_CRITERIA_ITERATIONS or \ref VX_TERM_CRITERIA_EPSILON or + * \ref VX_TERM_CRITERIA_BOTH + * \param [in] epsilon is the \ref vx_float32 error for terminating the algorithm + * \param [in] num_iterations is the number of iterations. Use a \ref VX_TYPE_UINT32 scalar. + * \param [in] use_initial_estimate Can be set to either \ref vx_false_e or \ref vx_true_e. + * \param [in] window_dimension The size of the window on which to perform the algorithm. See + * \ref VX_CONTEXT_ATTRIBUTE_OPTICAL_FLOW_WINDOW_MAXIMUM_DIMENSION + * + * \ingroup group_vision_function_opticalflowpyrlk + * \return A \ref vx_status_e enumeration. + * \retval VX_SUCCESS Success + * \retval * An error occurred. See \ref vx_status_e. + */ +VX_API_ENTRY vx_status VX_API_CALL vxuOpticalFlowPyrLK(vx_context context, + vx_pyramid old_images, + vx_pyramid new_images, + vx_array old_points, + vx_array new_points_estimates, + vx_array new_points, + vx_enum termination, + vx_scalar epsilon, + vx_scalar num_iterations, + vx_scalar use_initial_estimate, + vx_size window_dimension); + +/*! \brief [Immediate] Remaps an output image from an input image. + * \param [in] context The reference to the overall context. + * \param [in] input The input \ref VX_DF_IMAGE_U8 image. + * \param [in] table The remap table object. + * \param [in] policy The interpolation policy from \ref vx_interpolation_type_e. + * \ref VX_INTERPOLATION_TYPE_AREA is not supported. + * \param [out] output The output \ref VX_DF_IMAGE_U8 image. + * \return A \ref vx_status_e enumeration. + * \ingroup group_vision_function_remap + */ +VX_API_ENTRY vx_status VX_API_CALL vxuRemap(vx_context context, + vx_image input, + vx_remap table, + vx_enum policy, + vx_image output); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/vx_ext_cv/publishkernels.cpp b/vx_ext_cv/publishkernels.cpp new file mode 100644 index 0000000..5f9aa62 --- /dev/null +++ b/vx_ext_cv/publishkernels.cpp @@ -0,0 +1,124 @@ +/* +Copyright (c) 2015 Advanced Micro Devices, Inc. All rights reserved. + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. +*/ + + +#include"publishkernels.h" +#include"OpenCV_VX_Functions.h" + +/********************************************************************** + PUBLIC FUNCTION for OpenVX/OpenCV user defined functions + **********************************************************************/ +extern "C" SHARED_PUBLIC vx_status VX_API_CALL vxPublishKernels(vx_context context) +{ + vx_status status = VX_SUCCESS; + + STATUS_ERROR_CHECK(get_kernels_to_publish()); + STATUS_ERROR_CHECK(Kernel_List->PUBLISH(context)); + + return status; +} + +/************************************************************************************************************ +Add All Kernels to the Kernel List +*************************************************************************************************************/ +vx_status get_kernels_to_publish() +{ + vx_status status = VX_SUCCESS; + + Kernel_List = new Kernellist(MAX_KERNELS); + + STATUS_ERROR_CHECK(ADD_KERENEL(CV_absdiff_Register)); + STATUS_ERROR_CHECK(ADD_KERENEL(CV_adaptiveThreshold_Register)); + STATUS_ERROR_CHECK(ADD_KERENEL(CV_add_Register)); + STATUS_ERROR_CHECK(ADD_KERENEL(CV_AddWeighted_Register)); + STATUS_ERROR_CHECK(ADD_KERENEL(CV_bilateralFilter_Register)); + STATUS_ERROR_CHECK(ADD_KERENEL(CV_bitwise_and_Register)); + STATUS_ERROR_CHECK(ADD_KERENEL(CV_bitwise_not_Register)); + STATUS_ERROR_CHECK(ADD_KERENEL(CV_bitwise_or_Register)); + STATUS_ERROR_CHECK(ADD_KERENEL(CV_bitwise_xor_Register)); + STATUS_ERROR_CHECK(ADD_KERENEL(CV_blur_Register)); + STATUS_ERROR_CHECK(ADD_KERENEL(CV_Boxfilter_Register)); + STATUS_ERROR_CHECK(ADD_KERENEL(CV_brisk_compute_Register)); + STATUS_ERROR_CHECK(ADD_KERENEL(CV_brisk_detect_Register)); + STATUS_ERROR_CHECK(ADD_KERENEL(CV_buildOpticalFlowPyramid_Register)); + STATUS_ERROR_CHECK(ADD_KERENEL(CV_buildPyramid_Register)); + STATUS_ERROR_CHECK(ADD_KERENEL(CV_Canny_Register)); + STATUS_ERROR_CHECK(ADD_KERENEL(CV_compare_Register)); + STATUS_ERROR_CHECK(ADD_KERENEL(CV_convertScaleAbs_Register)); + STATUS_ERROR_CHECK(ADD_KERENEL(CV_cornerHarris_Register)); + STATUS_ERROR_CHECK(ADD_KERENEL(CV_cornerMinEigenVal_Register)); + STATUS_ERROR_CHECK(ADD_KERENEL(CV_countNonZero_Register)); + STATUS_ERROR_CHECK(ADD_KERENEL(CV_cvtColor_Register)); + STATUS_ERROR_CHECK(ADD_KERENEL(CV_dilate_Register)); + STATUS_ERROR_CHECK(ADD_KERENEL(CV_distanceTransform_Register)); + STATUS_ERROR_CHECK(ADD_KERENEL(CV_divide_Register)); + STATUS_ERROR_CHECK(ADD_KERENEL(CV_erode_Register)); + STATUS_ERROR_CHECK(ADD_KERENEL(CV_FAST_detector_Register)); + STATUS_ERROR_CHECK(ADD_KERENEL(CV_fastNlMeansDenoising_Register)); + STATUS_ERROR_CHECK(ADD_KERENEL(CV_fastNlMeansDenoisingColored_Register)); + STATUS_ERROR_CHECK(ADD_KERENEL(CV_filter2D_Register)); + STATUS_ERROR_CHECK(ADD_KERENEL(CV_flip_Register)); + STATUS_ERROR_CHECK(ADD_KERENEL(CV_Gaussianblur_Register)); + STATUS_ERROR_CHECK(ADD_KERENEL(CV_good_features_to_track_Register)); + STATUS_ERROR_CHECK(ADD_KERENEL(CV_integral_Register)); + STATUS_ERROR_CHECK(ADD_KERENEL(CV_Laplacian_Register)); + STATUS_ERROR_CHECK(ADD_KERENEL(CV_MedianBlur_Register)); + STATUS_ERROR_CHECK(ADD_KERENEL(CV_morphologyEx_Register)); + STATUS_ERROR_CHECK(ADD_KERENEL(CV_MSER_detect_Register)); + STATUS_ERROR_CHECK(ADD_KERENEL(CV_multiply_Register)); + STATUS_ERROR_CHECK(ADD_KERENEL(CV_norm_Register)); + STATUS_ERROR_CHECK(ADD_KERENEL(CV_ORB_compute_Register)); + STATUS_ERROR_CHECK(ADD_KERENEL(CV_ORB_detect_Register)); + STATUS_ERROR_CHECK(ADD_KERENEL(CV_pyrdown_Register)); + STATUS_ERROR_CHECK(ADD_KERENEL(CV_pyrup_Register)); + STATUS_ERROR_CHECK(ADD_KERENEL(CV_resize_Register)); + STATUS_ERROR_CHECK(ADD_KERENEL(CV_Scharr_Register)); + STATUS_ERROR_CHECK(ADD_KERENEL(CV_sepFilter2D_Register)); + STATUS_ERROR_CHECK(ADD_KERENEL(CV_simple_blob_detect_Register)); + STATUS_ERROR_CHECK(ADD_KERENEL(CV_simple_blob_detect_initialize_Register)); + STATUS_ERROR_CHECK(ADD_KERENEL(CV_Sobel_Register)); + STATUS_ERROR_CHECK(ADD_KERENEL(CV_subtract_Register)); + STATUS_ERROR_CHECK(ADD_KERENEL(CV_threshold_Register)); + STATUS_ERROR_CHECK(ADD_KERENEL(CV_transpose_Register)); + STATUS_ERROR_CHECK(ADD_KERENEL(CV_warpAffine_Register)); + STATUS_ERROR_CHECK(ADD_KERENEL(CV_warpPerspective_Register)); + +#if USE_OPENCV_CONTRIB + STATUS_ERROR_CHECK(ADD_KERENEL(CV_SIFT_compute_Register)); + STATUS_ERROR_CHECK(ADD_KERENEL(CV_SIFT_detect_Register)); + STATUS_ERROR_CHECK(ADD_KERENEL(CV_star_detect_Register)); + STATUS_ERROR_CHECK(ADD_KERENEL(CV_SURF_compute_Register)); + STATUS_ERROR_CHECK(ADD_KERENEL(CV_SURF_detect_Register)); +#endif + + return status; +} + +/************************************************************************************************************ +Add Kernels to the Kernel List +*************************************************************************************************************/ +vx_status ADD_KERENEL(std::function func) +{ + vx_status status = VX_SUCCESS; + STATUS_ERROR_CHECK(Kernel_List->ADD(func)); + return status; +} \ No newline at end of file diff --git a/vx_ext_cv/publishkernels.h b/vx_ext_cv/publishkernels.h new file mode 100644 index 0000000..c8de3ab --- /dev/null +++ b/vx_ext_cv/publishkernels.h @@ -0,0 +1,186 @@ +/* +Copyright (c) 2015 Advanced Micro Devices, Inc. All rights reserved. + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. +*/ + + +#ifndef _PUBLISH_KERNELS_H_ +#define _PUBLISH_KERNELS_H_ + +#if _WIN32 +#define SHARED_PUBLIC __declspec(dllexport) +#else +#define SHARED_PUBLIC __attribute__ ((visibility ("default"))) +#endif + +#include +#include "vx_ext_cv.h" +#include"OpenCV_Tunnel.h" + +#ifndef USE_OPENCV_CONTRIB +#define USE_OPENCV_CONTRIB 0 +#endif + +extern "C" SHARED_PUBLIC vx_status VX_API_CALL vxPublishKernels(vx_context context); +vx_status ADD_KERENEL(std::function); +vx_status get_kernels_to_publish(); + +vx_status CV_absdiff_Register(vx_context); +vx_status CV_adaptiveThreshold_Register(vx_context); +vx_status CV_add_Register(vx_context); +vx_status CV_AddWeighted_Register(vx_context); +vx_status CV_bilateralFilter_Register(vx_context); +vx_status CV_bitwise_and_Register(vx_context); +vx_status CV_bitwise_not_Register(vx_context); +vx_status CV_bitwise_or_Register(vx_context); +vx_status CV_bitwise_xor_Register(vx_context); +vx_status CV_blur_Register(vx_context); +vx_status CV_Boxfilter_Register(vx_context); +vx_status CV_brisk_compute_Register(vx_context); +vx_status CV_brisk_detect_Register(vx_context); +vx_status CV_buildOpticalFlowPyramid_Register(vx_context); +vx_status CV_buildPyramid_Register(vx_context); +vx_status CV_Canny_Register(vx_context); +vx_status CV_compare_Register(vx_context); +vx_status CV_convertScaleAbs_Register(vx_context); +vx_status CV_cornerHarris_Register(vx_context); +vx_status CV_cornerMinEigenVal_Register(vx_context); +vx_status CV_countNonZero_Register(vx_context); +vx_status CV_cvtColor_Register(vx_context); +vx_status CV_dilate_Register(vx_context); +vx_status CV_distanceTransform_Register(vx_context); +vx_status CV_divide_Register(vx_context); +vx_status CV_erode_Register(vx_context); +vx_status CV_FAST_detector_Register(vx_context); +vx_status CV_fastNlMeansDenoising_Register(vx_context); +vx_status CV_fastNlMeansDenoisingColored_Register(vx_context); +vx_status CV_filter2D_Register(vx_context); +vx_status CV_flip_Register(vx_context); +vx_status CV_Gaussianblur_Register(vx_context); +vx_status CV_good_features_to_track_Register(vx_context); +vx_status CV_integral_Register(vx_context); +vx_status CV_Laplacian_Register(vx_context); +vx_status CV_MedianBlur_Register(vx_context); +vx_status CV_morphologyEx_Register(vx_context); +vx_status CV_MSER_detect_Register(vx_context); +vx_status CV_multiply_Register(vx_context); +vx_status CV_norm_Register(vx_context); +vx_status CV_ORB_compute_Register(vx_context); +vx_status CV_ORB_detect_Register(vx_context); +vx_status CV_pyrdown_Register(vx_context); +vx_status CV_pyrup_Register(vx_context); +vx_status CV_resize_Register(vx_context); +vx_status CV_Scharr_Register(vx_context); +vx_status CV_sepFilter2D_Register(vx_context); +vx_status CV_simple_blob_detect_Register(vx_context); +vx_status CV_simple_blob_detect_initialize_Register(vx_context); +vx_status CV_Sobel_Register(vx_context); +vx_status CV_subtract_Register(vx_context); +vx_status CV_threshold_Register(vx_context); +vx_status CV_transpose_Register(vx_context); +vx_status CV_warpAffine_Register(vx_context); +vx_status CV_warpPerspective_Register(vx_context); + +#if USE_OPENCV_CONTRIB +vx_status CV_SIFT_compute_Register(vx_context); +vx_status CV_SIFT_detect_Register(vx_context); +vx_status CV_star_detect_Register(vx_context); +vx_status CV_SURF_compute_Register(vx_context); +vx_status CV_SURF_detect_Register(vx_context); +#endif + + + +//Filters +#define VX_KERNEL_EXT_CV_Medianblur_NAME "org.opencv.medianblur" +#define VX_KERNEL_EXT_CV_Boxfilter_NAME "org.opencv.boxfilter" +#define VX_KERNEL_EXT_CV_Gaussianblur_NAME "org.opencv.gaussianblur" +#define VX_KERNEL_EXT_CV_Blur_NAME "org.opencv.blur" +#define VX_KERNEL_EXT_CV_BilateralFilter_NAME "org.opencv.bilateralfilter" +#define VX_KERNEL_EXT_CV_FILTER2D_NAME "org.opencv.filter2d" +#define VX_KERNEL_EXT_CV_SEPFILTER2D_NAME "org.opencv.sepfilter2d" + +//Corner Detectors +#define VX_KERNEL_EXT_CV_FAST_Detector_NAME "org.opencv.fast" +#define VX_KERNEL_EXT_CV_GoodFeature_Detector_NAME "org.opencv.good_features_to_track" + +//Non-Free Freature Detectors +#define VX_KERNEL_EXT_CV_SIFT_DETECT_NAME "org.opencv.sift_detect" +#define VX_KERNEL_EXT_CV_SURF_DETECT_NAME "org.opencv.surf_detect" +#define VX_KERNEL_EXT_CV_SIFT_Compute_NAME "org.opencv.sift_compute" +#define VX_KERNEL_EXT_CV_SURF_Compute_NAME "org.opencv.surf_compute" +#define VX_KERNEL_EXT_CV_STAR_FEATURE_Detector_NAME "org.opencv.star_detect" + +//Feature Detectors +#define VX_KERNEL_EXT_CV_BRISK_Detector_NAME "org.opencv.brisk_detect" +#define VX_KERNEL_EXT_CV_MSER_Detector_NAME "org.opencv.mser_detect" +#define VX_KERNEL_EXT_CV_ORB_Detector_NAME "org.opencv.orb_detect" +#define VX_KERNEL_EXT_CV_SIMPLE_BLOB_Detector_NAME "org.opencv.simple_blob_detect" +#define VX_KERNEL_EXT_CV_SIMPLE_BLOB_Detector_Init_NAME "org.opencv.simple_blob_detect_initialize" + +//Feature Descriptors or Compute Nodes +#define VX_KERNEL_EXT_CV_BRISK_Compute_NAME "org.opencv.brisk_compute" +#define VX_KERNEL_EXT_CV_ORB_Compute_NAME "org.opencv.ORB_compute" + +//Other OpenCV Tunneled Nodes +#define VX_KERNEL_EXT_CV_SOBEL_NAME "org.opencv.sobel" +#define VX_KERNEL_EXT_CV_SCHARR_NAME "org.opencv.scharr" +#define VX_KERNEL_EXT_CV_CANNY_NAME "org.opencv.canny" +#define VX_KERNEL_EXT_CV_LAPLACIAN_NAME "org.opencv.laplacian" +#define VX_KERNEL_EXT_CV_MORPHOLOGYEX_NAME "org.opencv.morphologyex" +#define VX_KERNEL_EXT_CV_MULTIPLY_NAME "org.opencv.multiply" +#define VX_KERNEL_EXT_CV_DIVIDE_NAME "org.opencv.divide" +#define VX_KERNEL_EXT_CV_ADD_NAME "org.opencv.add" +#define VX_KERNEL_EXT_CV_SUBTRACT_NAME "org.opencv.subtract" +#define VX_KERNEL_EXT_CV_BITWISE_AND_NAME "org.opencv.bitwise_and" +#define VX_KERNEL_EXT_CV_BITWISE_NOT_NAME "org.opencv.bitwise_not" +#define VX_KERNEL_EXT_CV_BITWISE_OR_NAME "org.opencv.bitwise_or" +#define VX_KERNEL_EXT_CV_BITWISE_XOR_NAME "org.opencv.bitwise_xor" +#define VX_KERNEL_EXT_CV_CONVERT_SCALE_ABS_NAME "org.opencv.convertscaleabs" +#define VX_KERNEL_EXT_CV_ADD_WEIGHTED_NAME "org.opencv.addweighted" +#define VX_KERNEL_EXT_CV_FLIP_NAME "org.opencv.flip" +#define VX_KERNEL_EXT_CV_TRANSPOSE_NAME "org.opencv.transpose" +#define VX_KERNEL_EXT_CV_ABSDIFF_NAME "org.opencv.absdiff" +#define VX_KERNEL_EXT_CV_COMPARE_NAME "org.opencv.compare" +#define VX_KERNEL_EXT_CV_RESIZE_NAME "org.opencv.resize" +#define VX_KERNEL_EXT_CV_ADAPTIVE_THRESHOLD_NAME "org.opencv.adaptivethreshold" +#define VX_KERNEL_EXT_CV_DISTANCE_TRANSFORM_NAME "org.opencv.distancetransform" +#define VX_KERNEL_EXT_CV_CVTCOLOR_NAME "org.opencv.cvtcolor" +#define VX_KERNEL_EXT_CV_THRESHOLD_NAME "org.opencv.threshold" +#define VX_KERNEL_EXT_CV_fastNlMeansDenoising_NAME "org.opencv.fastnlmeansdenoising" +#define VX_KERNEL_EXT_CV_fastNlMeansDenoisingColored_NAME "org.opencv.fastnlmeansdenoisingcolored" +#define VX_KERNEL_EXT_CV_BUILD_OPTICAL_FLOW_PYRAMID_NAME "org.opencv.buildopticalflowpyramid" +#define VX_KERNEL_EXT_CV_BUILDPYRAMID_NAME "org.opencv.buildpyramid" +#define VX_KERNEL_EXT_CV_pyrUp_NAME "org.opencv.pyrup" +#define VX_KERNEL_EXT_CV_pyrDown_NAME "org.opencv.pyrdown" +#define VX_KERNEL_EXT_CV_DILATE_NAME "org.opencv.dilate" +#define VX_KERNEL_EXT_CV_ERODE_NAME "org.opencv.erode" +#define VX_KERNEL_EXT_CV_WARPAFFINE_NAME "org.opencv.warpaffine" +#define VX_KERNEL_EXT_CV_WARPPERSPECTIVE_NAME "org.opencv.warpperspective" +#define VX_KERNEL_EXT_CV_CORNERHARRIS_NAME "org.opencv.cornerharris" +#define VX_KERNEL_EXT_CV_cornerMinEigenVal_NAME "org.opencv.cornermineigenval" +#define VX_KERNEL_EXT_CV_integral_NAME "org.opencv.integral" +#define VX_KERNEL_EXT_CV_countNonZero_NAME "org.opencv.countnonzero" +#define VX_KERNEL_EXT_CV_norm_NAME "org.opencv.norm" + + + +#endif //_AMDVX_EXT__PUBLISH_KERNELS_H_ + diff --git a/vx_ext_cv/vx_ext_cv.h b/vx_ext_cv/vx_ext_cv.h new file mode 100644 index 0000000..d9b6de1 --- /dev/null +++ b/vx_ext_cv/vx_ext_cv.h @@ -0,0 +1,361 @@ +/* +Copyright (c) 2015 Advanced Micro Devices, Inc. All rights reserved. + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. +*/ + + +/* + * Copyright (c) 2014 Advanced Micro Devices, Inc. All rights reserved. + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Materials. + * + * THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY + * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS. + */ + +#ifndef _VX_EXT_AMD_CV_H_ +#define _VX_EXT_AMD_CV_H_ + +#ifdef __cplusplus +extern "C" { +#endif + + /*! \brief The AMD extension library for OpenCV */ +#define VX_LIBRARY_EXT_CV 1 + + /*! + * \brief The list of available vision kernels in the OpenCV extension library. + */ + enum vx_kernel_ext_amd_cv_e + { + + /*! + * \brief The OpenCV blur function kernel. Kernel name is "org.opencv.blur". + */ + VX_KERNEL_EXT_CV_BLUR = VX_KERNEL_BASE(VX_ID_AMD, VX_LIBRARY_EXT_CV) + 0x100, + + /*! + * \brief The OpenCV medianBlur function kernel. Kernel name is "org.opencv.medianblur". + */ + VX_KERNEL_EXT_CV_MEDIAN_BLUR = VX_KERNEL_BASE(VX_ID_AMD, VX_LIBRARY_EXT_CV) + 0x101, + + /*! + * \brief The OpenCV GaussianBlur function kernel. Kernel name is "org.opencv.gaussianblur". + */ + VX_KERNEL_EXT_CV_GAUSSIAN_BLUR = VX_KERNEL_BASE(VX_ID_AMD, VX_LIBRARY_EXT_CV) + 0x102, + + /*! + * \brief The OpenCV boxFilter function kernel. Kernel name is "org.opencv.boxfilter". + */ + VX_KERNEL_EXT_CV_BOXFILTER = VX_KERNEL_BASE(VX_ID_AMD, VX_LIBRARY_EXT_CV) + 0x103, + + /*! + * \brief The OpenCV BilateralFilter function kernel. Kernel name is "org.opencv.bilateralfilter". + */ + VX_KERNEL_EXT_CV_BILATERAL_FILTER = VX_KERNEL_BASE(VX_ID_AMD, VX_LIBRARY_EXT_CV) + 0x104, + + /*! + * \brief The OpenCV Flip function kernel. Kernel name is "org.opencv.flip". + */ + VX_KERNEL_EXT_CV_FLIP = VX_KERNEL_BASE(VX_ID_AMD, VX_LIBRARY_EXT_CV) + 0x37, + + /*! + * \brief The OpenCV transpose function kernel. Kernel name is "org.opencv.transpose". + */ + VX_KERNEL_EXT_CV_TRANSPOSE = VX_KERNEL_BASE(VX_ID_AMD, VX_LIBRARY_EXT_CV) + 0x39, + + /*! + * \brief The OpenCV absdiff function kernel. Kernel name is "org.opencv.absdiff". + */ + VX_KERNEL_EXT_CV_ABSDIFF = VX_KERNEL_BASE(VX_ID_AMD, VX_LIBRARY_EXT_CV) + 0x40, + + /*! + * \brief The OpenCV add function kernel. Kernel name is "org.opencv.add". + */ + VX_KERNEL_EXT_CV_ADD = VX_KERNEL_BASE(VX_ID_AMD, VX_LIBRARY_EXT_CV) + 0x41, + + /*! + * \brief The OpenCV bitwise_and function kernel. Kernel name is "org.opencv.bitwise_and". + */ + VX_KERNEL_EXT_CV_BITWISE_AND = VX_KERNEL_BASE(VX_ID_AMD, VX_LIBRARY_EXT_CV) + 0x42, + + /*! + * \brief The OpenCV bitwise_not function kernel. Kernel name is "org.opencv.flip". + */ + VX_KERNEL_EXT_CV_BITWISE_NOT = VX_KERNEL_BASE(VX_ID_AMD, VX_LIBRARY_EXT_CV) + 0x43, + + /*! + * \brief The OpenCV bitwise_or function kernel. Kernel name is "org.opencv.bitwise_or". + */ + VX_KERNEL_EXT_CV_BITWISE_OR = VX_KERNEL_BASE(VX_ID_AMD, VX_LIBRARY_EXT_CV) + 0x44, + + /*! + * \brief The OpenCV bitwise_xor function kernel. Kernel name is "org.opencv.bitwise_xor". + */ + VX_KERNEL_EXT_CV_BITWISE_XOR = VX_KERNEL_BASE(VX_ID_AMD, VX_LIBRARY_EXT_CV) + 0x45, + + /*! + * \brief The OpenCV subtract function kernel. Kernel name is "org.opencv.subtract". + */ + VX_KERNEL_EXT_CV_SUBTRACT = VX_KERNEL_BASE(VX_ID_AMD, VX_LIBRARY_EXT_CV) + 0x46, + + /*! + * \brief The OpenCV compare function kernel. Kernel name is "org.opencv.compare". + */ + VX_KERNEL_EXT_CV_COMPARE = VX_KERNEL_BASE(VX_ID_AMD, VX_LIBRARY_EXT_CV) + 0x47, + + /*! + * \brief The OpenCV SOBEL function kernel. Kernel name is "org.opencv.sobel". + */ + VX_KERNEL_EXT_CV_SOBEL = VX_KERNEL_BASE(VX_ID_AMD, VX_LIBRARY_EXT_CV) + 0x30, + + /*! + * \brief The OpenCV CONVERTSCALEABS function kernel. Kernel name is "org.opencv.convertscaleabs". + */ + VX_KERNEL_EXT_CV_CONVERTSCALEABS = VX_KERNEL_BASE(VX_ID_AMD, VX_LIBRARY_EXT_CV) + 0x31, + + /*! + * \brief The OpenCV ADDWEIGHTED function kernel. Kernel name is "org.opencv.addweighted". + */ + VX_KERNEL_EXT_CV_ADDWEIGHTED = VX_KERNEL_BASE(VX_ID_AMD, VX_LIBRARY_EXT_CV) + 0x32, + + /*! + * \brief The OpenCV CANNY function kernel. Kernel name is "org.opencv.canny". + */ + VX_KERNEL_EXT_CV_CANNY = VX_KERNEL_BASE(VX_ID_AMD, VX_LIBRARY_EXT_CV) + 0x33, + + /*! + * \brief The OpenCV LAPLACIAN function kernel. Kernel name is "org.opencv.laplacian". + */ + VX_KERNEL_EXT_CV_LAPLACIAN = VX_KERNEL_BASE(VX_ID_AMD, VX_LIBRARY_EXT_CV) + 0x34, + + /*! + * \brief The OpenCV MORPHOLOGYEX function kernel. Kernel name is "org.opencv.morphologyex". + */ + VX_KERNEL_EXT_CV_MORPHOLOGYEX = VX_KERNEL_BASE(VX_ID_AMD, VX_LIBRARY_EXT_CV) + 0x35, + + /*! + * \brief The OpenCV SCHARR function kernel. Kernel name is "org.opencv.scharr". + */ + VX_KERNEL_EXT_CV_SCHARR = VX_KERNEL_BASE(VX_ID_AMD, VX_LIBRARY_EXT_CV) + 0x36, + + /*! + * \brief The OpenCV FAST feature detector function kernel. Kernel name is "org.opencv.fast". + */ + VX_KERNEL_EXT_CV_FAST = VX_KERNEL_BASE(VX_ID_AMD, VX_LIBRARY_EXT_CV) + 0x12, + + /*! + * \brief The OpenCV GoodFeaturesToTrack (GFTT) detector function kernel. Kernel name is "org.opencv.good_features_to_track". + */ + VX_KERNEL_EXT_CV_GOOD_FEATURE_TO_TRACK = VX_KERNEL_BASE(VX_ID_AMD, VX_LIBRARY_EXT_CV) + 0x13, + + /*! + * \brief The OpenCV SIFT detector function kernel.Kernel name is "org.opencv.sift_detect". + */ + VX_KERNEL_EXT_CV_SIFT_DETECT = VX_KERNEL_BASE(VX_ID_AMD, VX_LIBRARY_EXT_CV) + 0x10, + + /*! + * \brief The OpenCV SURF detector function kernel. Kernel name is "org.opencv.surf_detect". + */ + VX_KERNEL_EXT_CV_SURF_DETECT = VX_KERNEL_BASE(VX_ID_AMD, VX_LIBRARY_EXT_CV) + 0x11, + + /*! + * \brief The OpenCV BRISK detector function kernel. Kernel name is "org.opencv.brisk_detect". + */ + VX_KERNEL_EXT_CV_BRISK_DETECT = VX_KERNEL_BASE(VX_ID_AMD, VX_LIBRARY_EXT_CV) + 0x14, + + /*! + * \brief The OpenCV MSER feature detector function kernel. Kernel name is "org.opencv.mser_detect". + */ + VX_KERNEL_EXT_CV_MSER_DETECT = VX_KERNEL_BASE(VX_ID_AMD, VX_LIBRARY_EXT_CV) + 0x16, + + /*! + * \brief The OpenCV ORB detector function kernel. Kernel name is "org.opencv.orb_detect". + */ + VX_KERNEL_EXT_CV_ORB_DETECT = VX_KERNEL_BASE(VX_ID_AMD, VX_LIBRARY_EXT_CV) + 0x17, + + /*! + * \brief The OpenCV Simple Blob detector function kernel. Kernel name is "org.opencv.simple_blob_detect". + */ + VX_KERNEL_EXT_CV_SIMPLE_BLOB_DETECT = VX_KERNEL_BASE(VX_ID_AMD, VX_LIBRARY_EXT_CV) + 0x18, + + /*! + * \brief The OpenCV simple_blob_detector_initialize function kernel. Kernel name is "org.opencv.simple_blob_detector_initialize". + */ + VX_KERNEL_EXT_CV_SIMPLE_BLOB_DETECT_INITIALIZE = VX_KERNEL_BASE(VX_ID_AMD, VX_LIBRARY_EXT_CV) + 0x19, + + /*! + * \brief The OpenCV STAR feature detector function kernel. Kernel name is "org.opencv.star_detect". + */ + VX_KERNEL_EXT_CV_STAR_FEATURE_DETECT = VX_KERNEL_BASE(VX_ID_AMD, VX_LIBRARY_EXT_CV) + 0x20, + + /*! + * \brief The OpenCV SIFT descriptor function kernel. Kernel name is "org.opencv.sift_compute". + */ + VX_KERNEL_EXT_CV_SIFT_COMPUTE = VX_KERNEL_BASE(VX_ID_AMD, VX_LIBRARY_EXT_CV) + 0x21, + + /*! + * \brief The OpenCV SURF descriptor function kernel. Kernel name is "org.opencv.surf_compute". + */ + VX_KERNEL_EXT_CV_SURF_COMPUTE = VX_KERNEL_BASE(VX_ID_AMD, VX_LIBRARY_EXT_CV) + 0x22, + + /*! + * \brief The OpenCV BRISK descriptor function kernel. Kernel name is "org.opencv.brisk_compute". + */ + VX_KERNEL_EXT_CV_BRISK_COMPUTE = VX_KERNEL_BASE(VX_ID_AMD, VX_LIBRARY_EXT_CV) + 0x23, + + /*! + * \brief The OpenCV ORB descriptor function kernel. Kernel name is "org.opencv.orb_compute". + */ + VX_KERNEL_EXT_CV_ORB_COMPUTE = VX_KERNEL_BASE(VX_ID_AMD, VX_LIBRARY_EXT_CV) + 0x24, + + /*! + * \brief The OpenCV MULTIPLY function kernel. Kernel name is "org.opencv.multiply". + */ + VX_KERNEL_EXT_CV_MULTIPLY = VX_KERNEL_BASE(VX_ID_AMD, VX_LIBRARY_EXT_CV) + 0x51, + + /*! + * \brief The OpenCV Divide function kernel. Kernel name is "org.opencv.divide". + */ + VX_KERNEL_EXT_CV_DIVIDE = VX_KERNEL_BASE(VX_ID_AMD, VX_LIBRARY_EXT_CV) + 0x52, + + /*! + * \brief The OpenCV ADAPTIVETHRESHOLD function kernel. Kernel name is "org.opencv.adaptivethreshold". + */ + VX_KERNEL_EXT_CV_ADAPTIVETHRESHOLD = VX_KERNEL_BASE(VX_ID_AMD, VX_LIBRARY_EXT_CV) + 0x53, + + /*! + * \brief The OpenCV DISTANCETRANSFORM function kernel. Kernel name is "org.opencv.distancetransform". + */ + VX_KERNEL_EXT_CV_DISTANCETRANSFORM = VX_KERNEL_BASE(VX_ID_AMD, VX_LIBRARY_EXT_CV) + 0x54, + + /*! + * \brief The OpenCV cvtcolor function kernel. Kernel name is "org.opencv.cvtcolor". + */ + VX_KERNEL_EXT_CV_CVTCOLOR = VX_KERNEL_BASE(VX_ID_AMD, VX_LIBRARY_EXT_CV) + 0x55, + + /*! + * \brief The OpenCV Threshold function kernel. Kernel name is "org.opencv.threshold". + */ + VX_KERNEL_EXT_CV_THRESHOLD = VX_KERNEL_BASE(VX_ID_AMD, VX_LIBRARY_EXT_CV) + 0x56, + + /*! + * \brief The OpenCV fastNlMeansDenoising function kernel. Kernel name is "org.opencv.fastnlmeansdenoising". + */ + VX_KERNEL_EXT_CV_FAST_NL_MEANS_DENOISING = VX_KERNEL_BASE(VX_ID_AMD, VX_LIBRARY_EXT_CV) + 0x57, + + /*! + * \brief The OpenCV fastNlMeansDenoising Colored function kernel. Kernel name is "org.opencv.fastnlmeansdenoisingcolored". + */ + VX_KERNEL_EXT_CV_FAST_NL_MEANS_DENOISING_COLORED = VX_KERNEL_BASE(VX_ID_AMD, VX_LIBRARY_EXT_CV) + 0x58, + + /*! + * \brief The OpenCV pyrup function kernel. Kernel name is "org.opencv.pyrup". + */ + VX_KERNEL_EXT_CV_PYRUP = VX_KERNEL_BASE(VX_ID_AMD, VX_LIBRARY_EXT_CV) + 0x59, + + /*! + * \brief The OpenCV pyrdown function kernel. Kernel name is "org.opencv.pyrdown". + */ + VX_KERNEL_EXT_CV_PYRDOWN = VX_KERNEL_BASE(VX_ID_AMD, VX_LIBRARY_EXT_CV) + 0x60, + + /*! + * \brief The OpenCV filter2D function kernel. Kernel name is "org.opencv.filter2D". + */ + VX_KERNEL_EXT_CV_FILTER_2D = VX_KERNEL_BASE(VX_ID_AMD, VX_LIBRARY_EXT_CV) + 0x61, + + /*! + * \brief The OpenCV sepFilter2D function kernel. Kernel name is "org.opencv.sepFilter2D". + */ + VX_KERNEL_EXT_CV_SEPFILTER_2D = VX_KERNEL_BASE(VX_ID_AMD, VX_LIBRARY_EXT_CV) + 0x62, + + /*! + * \brief The OpenCV dilate function kernel. Kernel name is "org.opencv.dilate". + */ + VX_KERNEL_EXT_CV_DILATE = VX_KERNEL_BASE(VX_ID_AMD, VX_LIBRARY_EXT_CV) + 0x63, + + /*! + * \brief The OpenCV erode function kernel. Kernel name is "org.opencv.erode". + */ + VX_KERNEL_EXT_CV_ERODE = VX_KERNEL_BASE(VX_ID_AMD, VX_LIBRARY_EXT_CV) + 0x64, + + /*! + * \brief The OpenCV warpAffine function kernel. Kernel name is "org.opencv.warpAffine". + */ + VX_KERNEL_EXT_CV_WARP_AFFINE = VX_KERNEL_BASE(VX_ID_AMD, VX_LIBRARY_EXT_CV) + 0x65, + + /*! + * \brief The OpenCV warpPerspective function kernel. Kernel name is "org.opencv.warpPerspective". + */ + VX_KERNEL_EXT_CV_WARP_PERSPECTIVE = VX_KERNEL_BASE(VX_ID_AMD, VX_LIBRARY_EXT_CV) + 0x66, + + /*! + * \brief The OpenCV resize function kernel. Kernel name is "org.opencv.resize". + */ + VX_KERNEL_EXT_CV_RESIZE = VX_KERNEL_BASE(VX_ID_AMD, VX_LIBRARY_EXT_CV) + 0x67, + + /*! + * \brief The OpenCV buildPyramid function kernel. Kernel name is "org.opencv.buildPyramid". + */ + VX_KERNEL_EXT_CV_BUILD_PYRAMID = VX_KERNEL_BASE(VX_ID_AMD, VX_LIBRARY_EXT_CV) + 0x68, + + /*! + * \brief The OpenCV Flip function kernel. Kernel name is "org.opencv.Flip". + */ + VX_KERNEL_EXT_CV_BUILD_OPTICAL_FLOW_PYRAMID = VX_KERNEL_BASE(VX_ID_AMD, VX_LIBRARY_EXT_CV) + 0x69, + + /*! + * \brief The OpenCV integral function kernel. Kernel name is "org.opencv.integral". + */ + VX_KERNEL_EXT_CV_INTEGRAL = VX_KERNEL_BASE(VX_ID_AMD, VX_LIBRARY_EXT_CV) + 0x70, + + /*! + * \brief The OpenCV countNonZero function kernel. Kernel name is "org.opencv.countnonzero". + */ + VX_KERNEL_EXT_CV_COUNT_NON_ZERO = VX_KERNEL_BASE(VX_ID_AMD, VX_LIBRARY_EXT_CV) + 0x71, + + /*! + * \brief The OpenCV norm function kernel. Kernel name is "org.opencv.norm". + */ + VX_KERNEL_EXT_CV_NORM = VX_KERNEL_BASE(VX_ID_AMD, VX_LIBRARY_EXT_CV) + 0x72, + + /*! + * \brief The OpenCV CORNERHARRIS function kernel. Kernel name is "org.opencv.cornerharris". + */ + VX_KERNEL_EXT_CV_CORNERHARRIS = VX_KERNEL_BASE(VX_ID_AMD, VX_LIBRARY_EXT_CV) + 0x201, + + /*! + * \brief The OpenCV cornerMinEigenVal function kernel. Kernel name is "org.opencv.cornermineigenVal". + */ + VX_KERNEL_EXT_CV_CORNER_MIN_EIGEN_VAL = VX_KERNEL_BASE(VX_ID_AMD, VX_LIBRARY_EXT_CV) + 0x202, + + }; + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/vx_ext_cv/vx_ext_cv.sln b/vx_ext_cv/vx_ext_cv.sln new file mode 100644 index 0000000..6ef0f7d --- /dev/null +++ b/vx_ext_cv/vx_ext_cv.sln @@ -0,0 +1,22 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio 2013 +VisualStudioVersion = 12.0.31101.0 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "vx_ext_cv", "vx_ext_cv.vcxproj", "{C5F3ED68-728A-4610-A37F-89323A93DD81}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|x64 = Debug|x64 + Release|x64 = Release|x64 + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {C5F3ED68-728A-4610-A37F-89323A93DD81}.Debug|x64.ActiveCfg = Debug|x64 + {C5F3ED68-728A-4610-A37F-89323A93DD81}.Debug|x64.Build.0 = Debug|x64 + {C5F3ED68-728A-4610-A37F-89323A93DD81}.Release|x64.ActiveCfg = Release|x64 + {C5F3ED68-728A-4610-A37F-89323A93DD81}.Release|x64.Build.0 = Release|x64 + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection +EndGlobal diff --git a/vx_ext_cv/vx_ext_cv.vcxproj b/vx_ext_cv/vx_ext_cv.vcxproj new file mode 100644 index 0000000..115642e --- /dev/null +++ b/vx_ext_cv/vx_ext_cv.vcxproj @@ -0,0 +1,158 @@ + + + + + Debug + x64 + + + Release + x64 + + + + {C5F3ED68-728A-4610-A37F-89323A93DD81} + vx_ext_cv + + + + DynamicLibrary + true + v120 + MultiByte + + + DynamicLibrary + false + v120 + true + MultiByte + + + + + + + + + + + + + + + Level3 + Disabled + true + include;$(OpenCV_DIR)\include;$(opencv_contrib_dir)\include + MultiThreadedDebug + _WINDLL;%(PreprocessorDefinitions) + + + true + ..\..\amdovx-core\x64\Debug;$(AMDOVX_DIR)\x64\Debug;$(OpenCV_DIR)\x64\vc12\staticlib + openvx.lib;IlmImfd.lib;ippicvmt.lib;zlibd.lib;libwebpd.lib;libjpegd.lib;libtiffd.lib;libpngd.lib;libjasperd.lib;vfw32.lib;opencv_calib3d300d.lib;opencv_core300d.lib;opencv_features2d300d.lib;opencv_flann300d.lib;opencv_hal300d.lib;opencv_highgui300d.lib;opencv_imgcodecs300d.lib;opencv_imgproc300d.lib;opencv_ml300d.lib;opencv_objdetect300d.lib;opencv_photo300d.lib;opencv_shape300d.lib;opencv_stitching300d.lib;opencv_superres300d.lib;opencv_ts300d.lib;opencv_video300d.lib;opencv_videoio300d.lib;opencv_videostab300d.lib;kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib + + + + + + + Level3 + MaxSpeed + true + true + true + include;$(OpenCV_DIR)\include;$(opencv_contrib_dir)\include + MultiThreaded + _WINDLL;%(PreprocessorDefinitions) + + + true + true + true + ..\..\amdovx-core\x64\Release;$(AMDOVX_DIR)\x64\Release;$(OpenCV_DIR)\x64\vc12\staticlib + openvx.lib;IlmImf.lib;ippicvmt.lib;zlib.lib;libwebp.lib;libjpeg.lib;libtiff.lib;libpng.lib;libjasper.lib;vfw32.lib;opencv_calib3d300.lib;opencv_core300.lib;opencv_features2d300.lib;opencv_flann300.lib;opencv_hal300.lib;opencv_highgui300.lib;opencv_imgcodecs300.lib;opencv_imgproc300.lib;opencv_ml300.lib;opencv_objdetect300.lib;opencv_photo300.lib;opencv_shape300.lib;opencv_stitching300.lib;opencv_superres300.lib;opencv_ts300.lib;opencv_video300.lib;opencv_videoio300.lib;opencv_videostab300.lib;kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib; + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/vx_ext_cv/vx_ext_cv.vcxproj.filters b/vx_ext_cv/vx_ext_cv.vcxproj.filters new file mode 100644 index 0000000..09c006a --- /dev/null +++ b/vx_ext_cv/vx_ext_cv.vcxproj.filters @@ -0,0 +1,243 @@ + + + + + {4FC737F1-C7A5-4376-A066-2A32D752A2FF} + cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx + + + {93995380-89BD-4b04-88EB-625FBE52EBFB} + h;hh;hpp;hxx;hm;inl;inc;xsd + + + {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} + rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms + + + {b1b82705-135d-43d0-b61a-4d8e24837075} + + + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + + + Header Files + + + Header Files\VX + + + Header Files\VX + + + Header Files\VX + + + Header Files\VX + + + Header Files\VX + + + Header Files\VX + + + Header Files\VX + + + Header Files + + + Header Files + + + Header Files + + + \ No newline at end of file