├── .github ├── dependabot.yml └── workflows │ └── docs-build-deploy.yml ├── .gitignore ├── CMakeLists.txt ├── CODE_OF_CONDUCT.md ├── CONTRIBUTING.md ├── CONTRIBUTORS.md ├── LICENSE ├── README.md ├── cmake ├── Modules │ ├── FindComputeCpp.cmake │ ├── common.cmake │ ├── doxygen.cmake │ ├── examples.cmake │ ├── testgen.cmake │ └── tests.cmake └── toolchains │ ├── arm-gcc-poky.cmake │ └── gcc-generic.cmake ├── data ├── tsukuba_l.png └── tsukuba_r.png ├── doc └── Doxyfile.in ├── examples ├── anisotropic_diffusion.cpp ├── bayer_filter.cpp ├── depth_map_from_2_images.cpp ├── edge_detector.cpp ├── greyscale.cpp ├── harris.cpp ├── hello_world.cpp ├── optical_flow_LK.cpp ├── pyramid.cpp ├── rgb2hsv.cpp ├── simple_conv.cpp └── threshold.cpp ├── include ├── framework │ ├── device │ │ ├── device.hpp │ │ └── sycl │ │ │ ├── device.hpp │ │ │ ├── extract_accessors.hpp │ │ │ └── sycl_device.hpp │ ├── evaluator │ │ ├── eval_assign │ │ │ ├── eval_assign.hpp │ │ │ └── eval_assign_partial.hpp │ │ ├── eval_expression │ │ │ ├── eval_expr_assign.hpp │ │ │ ├── eval_expr_leaf_node.hpp │ │ │ ├── eval_expr_r_binary.hpp │ │ │ ├── eval_expr_r_unary.hpp │ │ │ ├── eval_expr_reduction.hpp │ │ │ ├── eval_expr_stn_filt.hpp │ │ │ ├── eval_expr_stn_no_filt.hpp │ │ │ └── eval_expression.hpp │ │ ├── evaluator.hpp │ │ └── load_pattern │ │ │ └── square_pattern.hpp │ ├── executor │ │ ├── executor.hpp │ │ ├── executor_subexpr_if_needed.hpp │ │ └── policy │ │ │ ├── fuse.hpp │ │ │ └── nofuse.hpp │ ├── expr_convertor │ │ ├── expr_convertor.hpp │ │ ├── leaf_count.hpp │ │ ├── local_mem_count.hpp │ │ ├── local_output.hpp │ │ ├── make_place_holder_expr.hpp │ │ └── place_holder_leaf_node.hpp │ ├── expr_tree │ │ ├── complex_ops │ │ │ ├── complex_ops.hpp │ │ │ ├── pyramid_mem.hpp │ │ │ ├── pyramid_with_auto_mem_gen.hpp │ │ │ └── pyramid_with_auto_mem_sep.hpp │ │ ├── expr_tree.hpp │ │ ├── neighbour_ops │ │ │ ├── neighbour_ops.hpp │ │ │ ├── reduction.hpp │ │ │ ├── stencil_no_filter.hpp │ │ │ └── stencil_with_filter.hpp │ │ └── point_ops │ │ │ ├── assign.hpp │ │ │ ├── leaf_node.hpp │ │ │ ├── parallel_copy.hpp │ │ │ ├── point_ops.hpp │ │ │ ├── resizable_binary.hpp │ │ │ └── resizable_unary.hpp │ ├── forward_declarations.hpp │ ├── framework.hpp │ ├── memory │ │ ├── mem_const.hpp │ │ ├── mem_prop.hpp │ │ ├── mem_virtual.hpp │ │ ├── mem_vision.hpp │ │ ├── memory.hpp │ │ └── memory_access │ │ │ ├── mem_coordinate.hpp │ │ │ ├── mem_neighbour.hpp │ │ │ └── memory_access.hpp │ └── tools │ │ ├── convert.hpp │ │ ├── static_if.hpp │ │ ├── time.hpp │ │ ├── tools.hpp │ │ ├── tuple.hpp │ │ └── type_dereferencer.hpp ├── operators │ ├── OP_Broadcast.hpp │ ├── OP_ScaleChannel.hpp │ ├── convert │ │ ├── OP_BGRToRGB.hpp │ │ ├── OP_F32C3ToU8C3.hpp │ │ ├── OP_HSVToRGB.hpp │ │ ├── OP_HSVToU8C3.hpp │ │ ├── OP_RGBToBGR.hpp │ │ ├── OP_RGBToGREY.hpp │ │ ├── OP_RGBToHSV.hpp │ │ ├── OP_U8C3ToF32C3.hpp │ │ └── ops_convert.hpp │ ├── convolution │ │ ├── OP_Filter2D.hpp │ │ ├── OP_GaussianBlur3x3.hpp │ │ ├── OP_SepFilter.hpp │ │ ├── OP_SepGauss3x3.hpp │ │ └── ops_conv.hpp │ ├── downsampling │ │ ├── OP_DownsampleAverage.hpp │ │ ├── OP_DownsampleClosest.hpp │ │ └── ops_downsampling.hpp │ ├── experimental │ │ ├── OP_AbsSub.hpp │ │ ├── OP_Add.hpp │ │ ├── OP_AniDiff.hpp │ │ ├── OP_Div.hpp │ │ ├── OP_FloatToF32C3.hpp │ │ ├── OP_Median.hpp │ │ ├── OP_Merge2Chns.hpp │ │ ├── OP_Mul.hpp │ │ ├── OP_PowerOf2.hpp │ │ ├── OP_Scale.hpp │ │ ├── OP_Sub.hpp │ │ ├── OP_Thresh.hpp │ │ └── experimental.hpp │ ├── opencvinterop.hpp │ └── ops.hpp ├── pixel │ └── pixel.hpp └── visioncpp.hpp └── tests ├── include └── common.hpp └── operators ├── OP_BGRToRGB └── OP_BGRToRGB.hpp ├── OP_CVBGRToGRAY └── OP_CVBGRToGRAY.hpp ├── OP_CVBGRToRGB └── OP_CVBGRToRGB.hpp ├── OP_Filter2D └── OP_Filter2D.hpp ├── OP_GaussianBlur3x3 └── OP_GaussianBlur3x3.hpp ├── OP_SepFilterCol3x3 └── OP_SepFilterCol3x3.hpp ├── OP_UnsignedBGRToFloatRGB └── OP_UnsignedBGRToFloatRGB.hpp ├── cc-gen.py └── cc.template /.github/dependabot.yml: -------------------------------------------------------------------------------- 1 | version: 2 2 | updates: 3 | - package-ecosystem: "github-actions" 4 | directory: "/" 5 | schedule: 6 | interval: daily 7 | -------------------------------------------------------------------------------- /.github/workflows/docs-build-deploy.yml: -------------------------------------------------------------------------------- 1 | 2 | name: Docs Build/Deploy 3 | 4 | # Controls when the action will run. 5 | on: 6 | # Triggers the workflow on push events but only for the master branch 7 | push: 8 | branches: [ master ] 9 | 10 | # Allows you to run this workflow manually from the Actions tab 11 | workflow_dispatch: 12 | 13 | # A workflow run is made up of one or more jobs that can run sequentially or in parallel 14 | jobs: 15 | # This workflow contains a single job called "build-and-deploy" 16 | build-and-deploy: 17 | # The type of runner that the job will run on 18 | runs-on: ubuntu-latest 19 | 20 | # Steps represent a sequence of tasks that will be executed as part of the job 21 | steps: 22 | # Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it 23 | - uses: actions/checkout@v4 24 | 25 | - name: Pre-requisites 26 | run: | 27 | sudo apt install doxygen 28 | sudo apt install graphviz 29 | 30 | # Build the docs 31 | - name: Build Docs 32 | run: | 33 | mkdir build 34 | cd build 35 | cmake -DVISIONCPP_DOC_ONLY=TRUE .. 36 | make doc 37 | 38 | #Checks that the build created some files 39 | - name: Check Build 40 | id: check_build 41 | uses: andstor/file-existence-action@v3 42 | with: 43 | files: "build/html/visioncpp_8hpp.html" 44 | 45 | # Deploys the docs to the gh-pages branch 46 | - name: Deploy Docs 47 | if: steps.check_build.outputs.files_exists == 'true' 48 | uses: JamesIves/github-pages-deploy-action@v4.6.0 49 | with: 50 | branch: gh-pages 51 | folder: build/html 52 | git-config-name: "Github Actions" 53 | git-config-email: "noreply@github.com" 54 | commit-message: | 55 | ""Deploy docs to GH Pages Build: ${{github.run_number}}" -m "Commit: ${{github.sha}}"" -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | /build/ 2 | .DS_Store 3 | -------------------------------------------------------------------------------- /CMakeLists.txt: -------------------------------------------------------------------------------- 1 | #Minimum CMake version 2 | cmake_minimum_required(VERSION 3.2) 3 | 4 | if(NOT CMAKE_BUILD_TYPE) 5 | set(CMAKE_BUILD_TYPE "Release" CACHE STRING 6 | "Choose the type of build, options are: Debug Release 7 | RelWithDebInfo MinSizeRel." 8 | FORCE) 9 | endif(NOT CMAKE_BUILD_TYPE) 10 | 11 | if(${CMAKE_BUILD_TYPE} STREQUAL "Release") 12 | set(PASS_TO_DEVICE_COMPILER ${CMAKE_CXX_FLAGS_RELEASE}) 13 | elseif(${CMAKE_BUILD_TYPE} STREQUAL "Debug") 14 | set(PASS_TO_DEVICE_COMPILER ${CMAKE_CXX_FLAGS_DEBUG}) 15 | elseif(${CMAKE_BUILD_TYPE} STREQUAL "RelWithDebInfo") 16 | set(PASS_TO_DEVICE_COMPILER ${CMAKE_CXX_FLAGS_RELWITHDEBINFO}) 17 | elseif(${CMAKE_BUILD_TYPE} STREQUAL "MinSizeRel") 18 | set(PASS_TO_DEVICE_COMPILER ${CMAKE_CXX_FLAGS_MINSIZEREL}) 19 | else() 20 | message(ERROR " Unknown value for CMAKE_BUILD_TYPE: ${CMAKE_BUILD_TYPE}") 21 | endif() 22 | 23 | list(APPEND CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake/Modules) 24 | 25 | find_package(PythonInterp 3.2 REQUIRED) 26 | message(STATUS "PYTHON_EXECUTABLE = ${PYTHON_EXECUTABLE}") 27 | 28 | #setup the minimum required cxx version 29 | set(CMAKE_CXX_STANDARD 11) 30 | set(CMAKE_CXX_STANDARD_REQUIRED ON) 31 | 32 | #find pthread 33 | find_package(Threads REQUIRED) 34 | 35 | if(NOT VISIONCPP_DOC_ONLY) 36 | find_package(ComputeCpp REQUIRED) 37 | #internal dep 38 | include(testgen) 39 | #projects 40 | include(tests) 41 | include(examples) 42 | endif() 43 | 44 | #docs 45 | include(doxygen) 46 | -------------------------------------------------------------------------------- /CODE_OF_CONDUCT.md: -------------------------------------------------------------------------------- 1 | # Contributor Covenant Code of Conduct 2 | 3 | ## Our Pledge 4 | 5 | In the interest of fostering an open and welcoming environment, we as 6 | contributors and maintainers pledge to making participation in our project and 7 | our community a harassment-free experience for everyone, regardless of age, body 8 | size, disability, ethnicity, sex characteristics, gender identity and expression, 9 | level of experience, education, socio-economic status, nationality, personal 10 | appearance, race, religion, or sexual identity and orientation. 11 | 12 | ## Our Standards 13 | 14 | Examples of behavior that contributes to creating a positive environment 15 | include: 16 | 17 | * Using welcoming and inclusive language 18 | * Being respectful of differing viewpoints and experiences 19 | * Gracefully accepting constructive criticism 20 | * Focusing on what is best for the community 21 | * Showing empathy towards other community members 22 | 23 | Examples of unacceptable behavior by participants include: 24 | 25 | * The use of sexualized language or imagery and unwelcome sexual attention or 26 | advances 27 | * Trolling, insulting/derogatory comments, and personal or political attacks 28 | * Public or private harassment 29 | * Publishing others' private information, such as a physical or electronic 30 | address, without explicit permission 31 | * Other conduct which could reasonably be considered inappropriate in a 32 | professional setting 33 | 34 | ## Our Responsibilities 35 | 36 | Project maintainers are responsible for clarifying the standards of acceptable 37 | behavior and are expected to take appropriate and fair corrective action in 38 | response to any instances of unacceptable behavior. 39 | 40 | Project maintainers have the right and responsibility to remove, edit, or 41 | reject comments, commits, code, wiki edits, issues, and other contributions 42 | that are not aligned to this Code of Conduct, or to ban temporarily or 43 | permanently any contributor for other behaviors that they deem inappropriate, 44 | threatening, offensive, or harmful. 45 | 46 | ## Scope 47 | 48 | This Code of Conduct applies within all project spaces, and it also applies when 49 | an individual is representing the project or its community in public spaces. 50 | Examples of representing a project or community include using an official 51 | project e-mail address, posting via an official social media account, or acting 52 | as an appointed representative at an online or offline event. Representation of 53 | a project may be further defined and clarified by project maintainers. 54 | 55 | ## Enforcement 56 | 57 | Instances of abusive, harassing, or otherwise unacceptable behavior may be 58 | reported by contacting the project team at [sycl@codeplay.com](mailto:sycl@codeplay.com). All 59 | complaints will be reviewed and investigated and will result in a response that 60 | is deemed necessary and appropriate to the circumstances. The project team is 61 | obligated to maintain confidentiality with regard to the reporter of an incident. 62 | Further details of specific enforcement policies may be posted separately. 63 | 64 | Project maintainers who do not follow or enforce the Code of Conduct in good 65 | faith may face temporary or permanent repercussions as determined by other 66 | members of the project's leadership. 67 | 68 | ## Attribution 69 | 70 | This Code of Conduct is adapted from the [Contributor Covenant](https://www.contributor-covenant.org/), version 1.4, 71 | available at https://www.contributor-covenant.org/version/1/4/code-of-conduct.html 72 | 73 | --- 74 | 75 | If there are any issues or suggestions relating to the current set of rules, you can reach us at [sycl@codeplay.com](mailto:sycl@codeplay.com). 76 | 77 | -------------------------------------------------------------------------------- /CONTRIBUTORS.md: -------------------------------------------------------------------------------- 1 | ``` 2 | The file is a list of people responsible for code in particular sections 3 | of VisionCpp including patch reviews and PR approval. 4 | 5 | The below list is sorted by surname. The fields are: 6 | name (N), email (E), description (D), affiliation (A). 7 | 8 | N: Cummins, Chris 9 | A: PhD student at The University of Edinburgh. 10 | E: visioncpp@codeplay.com 11 | D: design and main developer of contrib/python 12 | 13 | N: Dolinsky, Uwe 14 | A: Codeplay Software Ltd. 15 | E: visioncpp@codeplay.com 16 | D: Design, coding guidance, core reviewer 17 | 18 | N: Goli, Mehdi 19 | A: Codeplay Software Ltd. 20 | E: visioncpp@codeplay.com 21 | D: Designer and main developer of visioncpp/include 22 | 23 | N: Iwanski, Luke 24 | A: Codeplay Software Ltd. 25 | E: visioncpp@codeplay.com 26 | D: Team lead 27 | 28 | N: Lomuller, Victor 29 | A: Codeplay Software Ltd. 30 | E: visioncpp@codeplay.com 31 | D: Code reviewer 32 | 33 | N: Richards, Andrew 34 | A: Codeplay Software Ltd. 35 | E: visioncpp@codeplay.com 36 | D: The idea, designer 37 | 38 | N: Potter, Ralph 39 | A: Codeplay Software Ltd. 40 | E: visioncpp@codeplay.com 41 | D: The idea, designer 42 | 43 | N: Sheeny, Marcel 44 | A: Codeplay Software Ltd. 45 | E: visioncpp@codeplay.com 46 | D: Developer of examples 47 | ``` 48 | -------------------------------------------------------------------------------- /cmake/Modules/common.cmake: -------------------------------------------------------------------------------- 1 | find_package(OpenCV REQUIRED) 2 | find_package(GTest REQUIRED) 3 | 4 | include_directories( 5 | ${GTEST_INCLUDE_DIRS} 6 | ${OpenCV_INCLUDE_DIRS} 7 | ${PROJECT_SOURCE_DIR}/include 8 | ) 9 | 10 | link_directories(${GTEST_LIBRARIES}) 11 | 12 | link_libraries( 13 | #opencv libs 14 | ${OpenCV_LIBS} 15 | #gtest libs 16 | ${GTEST_BOTH_LIBRARIES} 17 | ) 18 | -------------------------------------------------------------------------------- /cmake/Modules/doxygen.cmake: -------------------------------------------------------------------------------- 1 | # add a target to generate API documentation with Doxygen 2 | find_package(Doxygen) 3 | if(DOXYGEN_FOUND) 4 | configure_file(${CMAKE_CURRENT_SOURCE_DIR}/doc/Doxyfile.in ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile @ONLY) 5 | add_custom_target(doc 6 | ${DOXYGEN_EXECUTABLE} ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile 7 | WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} 8 | COMMENT "Generating API documentation with Doxygen" VERBATIM 9 | ) 10 | endif(DOXYGEN_FOUND) 11 | -------------------------------------------------------------------------------- /cmake/Modules/examples.cmake: -------------------------------------------------------------------------------- 1 | # include common configs 2 | include(common) 3 | 4 | project(visioncpp-Examples CXX) 5 | set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin/example) 6 | 7 | file(GLOB_RECURSE _srcs ${PROJECT_SOURCE_DIR}/examples/*.cpp) 8 | # for each cc example in folder 9 | foreach(_src ${_srcs}) 10 | 11 | # take folder path 12 | get_filename_component(path ${_src} PATH) 13 | 14 | # take name of file 15 | get_filename_component(filename ${_src} NAME_WE) 16 | 17 | set(inc_dir_device "") 18 | get_property(inc_dirs DIRECTORY PROPERTY INCLUDE_DIRECTORIES) 19 | foreach(inc_dir_element ${inc_dirs}) 20 | set(inc_dir_device ${inc_dir_device} -I${inc_dir_element}) 21 | endforeach() 22 | 23 | # add executable that depends on the generated file 24 | add_executable(example_${filename} ${_src}) 25 | # link the pthreads library to the executable 26 | target_link_libraries(example_${filename} 27 | PRIVATE Threads::Threads) 28 | # link sycl with the executable 29 | add_sycl_to_target( 30 | TARGET example_${filename} 31 | SOURCES ${_src}) 32 | 33 | endforeach(_src ${_srcs}) 34 | -------------------------------------------------------------------------------- /cmake/Modules/testgen.cmake: -------------------------------------------------------------------------------- 1 | project(testgen CXX) 2 | 3 | execute_process( 4 | COMMAND ${PYTHON_EXECUTABLE} ${PROJECT_SOURCE_DIR}/tests/operators/cc-gen.py --builddir ${CMAKE_BINARY_DIR} --testdir ${PROJECT_SOURCE_DIR}/tests/operators 5 | WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}/tests/operators/ 6 | RESULT_VARIABLE result 7 | OUTPUT_VARIABLE ver 8 | ) 9 | 10 | if(${result}) 11 | message(FATAL_ERROR "${PYTHON_EXECUTABLE} cc-gen.py failed to generate tests.") 12 | else() 13 | message(STATUS "${PYTHON_EXECUTABLE} cc-gen.py generated tests.") 14 | endif() 15 | -------------------------------------------------------------------------------- /cmake/Modules/tests.cmake: -------------------------------------------------------------------------------- 1 | # include common configs 2 | include(common) 3 | 4 | project(visioncpp-Tests CXX) 5 | set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin/test) 6 | enable_testing() 7 | 8 | add_custom_target(testgen COMMAND cd ${PROJECT_SOURCE_DIR}/tests/operators && ${PYTHON_EXECUTABLE} cc-gen.py) 9 | 10 | file(GLOB_RECURSE _srcs 11 | ${CMAKE_BINARY_DIR}/autogen/*/*.cpp 12 | ) 13 | # for each cc test in folder 14 | foreach(_src ${_srcs}) 15 | 16 | # take folder path 17 | get_filename_component(path ${_src} PATH) 18 | 19 | # take name of file 20 | get_filename_component(filename ${_src} NAME_WE) 21 | 22 | set(inc_dir_device "") 23 | get_property(inc_dirs DIRECTORY PROPERTY INCLUDE_DIRECTORIES) 24 | foreach(inc_dir_element ${inc_dirs}) 25 | set(inc_dir_device ${inc_dir_device} -I${inc_dir_element}) 26 | endforeach() 27 | 28 | # add executable that depends on the generated file 29 | add_executable(${filename} ${_src}) 30 | # link the pthreads library to the executable 31 | target_link_libraries(${filename} 32 | PRIVATE Threads::Threads) 33 | # link sycl with the executable 34 | add_sycl_to_target( 35 | TARGET ${filename} 36 | SOURCES ${_src}) 37 | 38 | add_test(NAME ${filename} COMMAND ${CMAKE_CURRENT_BINARY_DIR}/bin/test/${filename}) 39 | endforeach(_src ${test_SRC}) 40 | -------------------------------------------------------------------------------- /cmake/toolchains/arm-gcc-poky.cmake: -------------------------------------------------------------------------------- 1 | set(CMAKE_SYSTEM_NAME Linux) 2 | set(CMAKE_SYSTEM_PROCESSOR ARM64) 3 | set(SDK_POKY_ROOT $ENV{SDK_POKY_ROOT}) 4 | 5 | if(NOT SDK_POKY_ROOT) 6 | message(FATAL_ERROR 7 | "Please set SDK_POKY_ROOT in the environment when crosscompiling.") 8 | endif() 9 | 10 | set(SDK_TARGET_TRIPLE aarch64-poky-linux) 11 | set(SDK_TOOLCHAIN_DIR ${SDK_POKY_ROOT}/x86_64-pokysdk-linux) 12 | set(SDK_SYSROOT_DIR ${SDK_POKY_ROOT}/aarch64-poky-linux) 13 | # Adding this as the GCC toolchain makes compute++ not find headers 14 | set(SDK_DONT_USE_TOOLCHAIN ON) 15 | 16 | set(CMAKE_C_COMPILER "${SDK_TOOLCHAIN_DIR}/usr/bin/${SDK_TARGET_TRIPLE}/${SDK_TARGET_TRIPLE}-gcc" CACHE PATH "gcc") 17 | set(CMAKE_CXX_COMPILER "${SDK_TOOLCHAIN_DIR}/usr/bin/${SDK_TARGET_TRIPLE}/${SDK_TARGET_TRIPLE}-g++" CACHE PATH "g++") 18 | set(CMAKE_AR "${SDK_TOOLCHAIN_DIR}/usr/bin/${SDK_TARGET_TRIPLE}/${SDK_TARGET_TRIPLE}-ar" CACHE PATH "archive") 19 | set(CMAKE_LINKER "${SDK_TOOLCHAIN_DIR}/usr/bin/${SDK_TARGET_TRIPLE}/${SDK_TARGET_TRIPLE}-ld" CACHE PATH "linker") 20 | set(CMAKE_NM "${SDK_TOOLCHAIN_DIR}/usr/bin/${SDK_TARGET_TRIPLE}/${SDK_TARGET_TRIPLE}-nm" CACHE PATH "nm") 21 | set(CMAKE_OBJCOPY "${SDK_TOOLCHAIN_DIR}/usr/bin/${SDK_TARGET_TRIPLE}/${SDK_TARGET_TRIPLE}-objcopy" CACHE PATH "objcopy") 22 | set(CMAKE_OBJDUMP "${SDK_TOOLCHAIN_DIR}/usr/bin/${SDK_TARGET_TRIPLE}/${SDK_TARGET_TRIPLE}-objdump" CACHE PATH "objdump") 23 | set(CMAKE_STRIP "${SDK_TOOLCHAIN_DIR}/usr/bin/${SDK_TARGET_TRIPLE}/${SDK_TARGET_TRIPLE}-strip" CACHE PATH "strip") 24 | set(CMAKE_RANLIB "${SDK_TOOLCHAIN_DIR}/usr/bin/${SDK_TARGET_TRIPLE}/${SDK_TARGET_TRIPLE}-ranlib" CACHE PATH "ranlib") 25 | 26 | set(CMAKE_FIND_ROOT_PATH ${SDK_SYSROOT_DIR}) 27 | set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER) 28 | 29 | set(CMAKE_SYSROOT "${SDK_SYSROOT_DIR}") 30 | 31 | set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -D__aarch64__ --sysroot=${SDK_SYSROOT_DIR}" CACHE INTERNAL "") 32 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -D__aarch64__ --sysroot=${SDK_SYSROOT_DIR}" CACHE INTERNAL "") 33 | 34 | set(CMAKE_CXX_LINK_EXECUTABLE " -o " CACHE INTERNAL "") 35 | -------------------------------------------------------------------------------- /cmake/toolchains/gcc-generic.cmake: -------------------------------------------------------------------------------- 1 | set(CMAKE_SYSTEM_NAME Linux) 2 | set(SDK_SYSROOT_DIR $ENV{SDK_SYSROOT_DIR}) 3 | set(SDK_TOOLCHAIN_DIR $ENV{SDK_TOOLCHAIN_DIR}) 4 | set(SDK_TARGET_TRIPLE $ENV{SDK_TARGET_TRIPLE}) 5 | 6 | if(NOT SDK_SYSROOT_DIR OR 7 | NOT SDK_TOOLCHAIN_DIR OR 8 | NOT SDK_TARGET_TRIPLE 9 | ) 10 | message(FATAL_ERROR 11 | "Please set all of SDK_TARGET_TRIPLE, SDK_SYSROOT_DIR and " 12 | "SDK_TOOLCHAIN_DIR in the environment when crosscompiling.") 13 | endif() 14 | 15 | set(CMAKE_SYSROOT ${SDK_SYSROOT_DIR}) 16 | set(CMAKE_C_COMPILER ${SDK_TOOLCHAIN_DIR}/bin/${SDK_TARGET_TRIPLE}-gcc) 17 | set(CMAKE_CXX_COMPILER ${SDK_TOOLCHAIN_DIR}/bin/${SDK_TARGET_TRIPLE}-g++) 18 | set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY NEVER) 19 | -------------------------------------------------------------------------------- /data/tsukuba_l.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/codeplaysoftware/visioncpp/ce31d1d3070d14463564737cedac6693d791f37f/data/tsukuba_l.png -------------------------------------------------------------------------------- /data/tsukuba_r.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/codeplaysoftware/visioncpp/ce31d1d3070d14463564737cedac6693d791f37f/data/tsukuba_r.png -------------------------------------------------------------------------------- /examples/greyscale.cpp: -------------------------------------------------------------------------------- 1 | // This file is part of VisionCpp, a lightweight C++ template library 2 | // for computer vision and image processing. 3 | // 4 | // Copyright (C) 2016 Codeplay Software Limited. All Rights Reserved. 5 | // 6 | // Contact: visioncpp@codeplay.com 7 | // 8 | // Licensed under the Apache License, Version 2.0 (the "License"); 9 | // you may not use this file except in compliance with the License. 10 | // You may obtain a copy of the License at 11 | // 12 | // http://www.apache.org/licenses/LICENSE-2.0 13 | // 14 | // Unless required by applicable law or agreed to in writing, software 15 | // distributed under the License is distributed on an "AS IS" BASIS, 16 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | // See the License for the specific language governing permissions and 18 | // limitations under the License. 19 | 20 | /// \file greyscale.cc 21 | /// 22 | /// -------Example-------- 23 | /// GreyScale 24 | /// 25 | /// \brief this example capture the camera image and convert to grey scale 26 | /// 27 | 28 | // include OpenCV for camera display 29 | #include 30 | // include VisionCpp 31 | #include 32 | 33 | int main(int argc, char** argv) { 34 | // open video or camera 35 | cv::VideoCapture cap; 36 | 37 | if (argc == 1) { 38 | cap.open(0); 39 | std::cout << "To use video" << std::endl; 40 | std::cout << "example>: ./example path/to/video.avi" << std::endl; 41 | } else if (argc > 1) { 42 | cap.open(argv[1]); 43 | } 44 | 45 | // check if we succeeded 46 | if (!cap.isOpened()) { 47 | std::cout << "Opening Camera/Video Failed." << std::endl; 48 | return -1; 49 | } 50 | 51 | constexpr size_t COLS = 640; 52 | constexpr size_t ROWS = 480; 53 | 54 | // where VisionCpp will run. 55 | auto dev = visioncpp::make_device(); 57 | 58 | // create a container for pipe output 59 | std::shared_ptr img_cv( 60 | new unsigned char[COLS * ROWS], 61 | [](unsigned char* dataMem) { delete[] dataMem; }); 62 | 63 | // create opencv mat 64 | cv::Mat frame; 65 | 66 | // point the img_cv to the Mat structure created for displaying purposes 67 | cv::Mat output(ROWS, COLS, CV_8UC1, img_cv.get()); 68 | 69 | for (;;) { 70 | // read frame 71 | cap.read(frame); 72 | 73 | // check if image was loaded 74 | if (!frame.data) { 75 | break; 76 | } 77 | 78 | // resize image to the desirable size 79 | cv::resize(frame, frame, cv::Size(COLS, ROWS), 0, 0, cv::INTER_CUBIC); 80 | 81 | // create input node 82 | auto data = 83 | visioncpp::terminal(frame.data); 85 | // create output node 86 | auto data_out = 87 | visioncpp::terminal(img_cv.get()); 89 | 90 | // unsigned char BGR to float RGB storage conversion 91 | auto node = visioncpp::point_operation(data); 92 | // convert RGB to GREY 93 | auto node2 = visioncpp::point_operation(node); 94 | // GREY is stored as a float so we need to do [0.0f, 1.0f] to [0, 255] 95 | // conversion 96 | auto node3 = visioncpp::point_operation(node2); 97 | 98 | // assign operation 99 | auto pipe = visioncpp::assign(data_out, node3); 100 | 101 | // execute the pipe 102 | visioncpp::execute(pipe, dev); 103 | 104 | // show image 105 | cv::imshow("Reference Image", frame); 106 | cv::imshow("Greyscale", output); 107 | 108 | // esc? 109 | if (cv::waitKey(30) >= 0) break; 110 | } 111 | 112 | // release video/camera 113 | cap.release(); 114 | 115 | return 0; 116 | } 117 | -------------------------------------------------------------------------------- /examples/hello_world.cpp: -------------------------------------------------------------------------------- 1 | // This file is part of VisionCpp, a lightweight C++ template library 2 | // for computer vision and image processing. 3 | // 4 | // Copyright (C) 2016 Codeplay Software Limited. All Rights Reserved. 5 | // 6 | // Contact: visioncpp@codeplay.com 7 | // 8 | // Licensed under the Apache License, Version 2.0 (the "License"); 9 | // you may not use this file except in compliance with the License. 10 | // You may obtain a copy of the License at 11 | // 12 | // http://www.apache.org/licenses/LICENSE-2.0 13 | // 14 | // Unless required by applicable law or agreed to in writing, software 15 | // distributed under the License is distributed on an "AS IS" BASIS, 16 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | // See the License for the specific language governing permissions and 18 | // limitations under the License. 19 | 20 | /// \file hello_world.cc 21 | /// 22 | /// -------Example-------- 23 | /// Hello World 24 | /// 25 | /// \brief this example converts RGB pixel to Grey 26 | /// 27 | 28 | // include VisionCpp library 29 | #include 30 | 31 | /// \brief This functor performs conversion from [0, 255] to [0.0f, 1.0f] 32 | struct MyNormaliseFunctor { 33 | /// \param in - three channel unsigned char 34 | /// \return F32C3 - three channel float 35 | visioncpp::pixel::F32C3 operator()(visioncpp::pixel::U8C3 in) { 36 | const float FLOAT_TO_BYTE = 255.0f; 37 | const float BYTE_TO_FLOAT = 1.0f / FLOAT_TO_BYTE; 38 | return visioncpp::pixel::F32C3(static_cast(in[0] * BYTE_TO_FLOAT), 39 | static_cast(in[1] * BYTE_TO_FLOAT), 40 | static_cast(in[2] * BYTE_TO_FLOAT)); 41 | } 42 | }; 43 | 44 | /// \brief This functor performs RGB to grey convertion following rule: 45 | /// GREY <- 0.299f * R + 0,587f * G + 0.114 * B 46 | struct MyGreyFunctor { 47 | /// \param in - RGB pixel. 48 | /// \returns float - greyscale value. 49 | float operator()(visioncpp::pixel::F32C3 in) { 50 | return 0.299f * in[0] + 0.587f * in[1] + 0.114f * in[2]; 51 | } 52 | }; 53 | 54 | int main(int argc, char **argv) { 55 | if (argc < 4) { 56 | std::cout << "You need to provide 3 uchar values" << std::endl; 57 | std::cout << "example>: ./example_hello_world 100 13 145" << std::endl; 58 | return -1; 59 | } 60 | 61 | // where VisionCpp will run. 62 | auto dev = visioncpp::make_device(); 64 | 65 | // an image pixel to be converted to grey 66 | std::shared_ptr in_rgb(new unsigned char[3]); 67 | in_rgb.get()[0] = atoi(argv[1]); 68 | in_rgb.get()[1] = atoi(argv[2]); 69 | in_rgb.get()[2] = atoi(argv[3]); 70 | 71 | // create a host container for output data 72 | std::shared_ptr out_grey(new float[1]); 73 | 74 | // definition of the VisionCpp pipe: 75 | { 76 | // put expression tree in a curly braces in order to define the scope for 77 | // the expression 78 | // create terminal nodes - a leaf node in the expression tree. 79 | // terminal struct takes 4 arguments 80 | // 1st template parameter specifies the data U8 (unsigned char) C3 (three 81 | // channels) 82 | // 2nd number of columns in the storage 83 | // 3rd number of rows in the storage 84 | // 4th underlying storage type - currently only Buffer2D supported 85 | auto data = 86 | visioncpp::terminal(in_rgb.get()); 88 | auto data_out = 89 | visioncpp::terminal(out_grey.get()); 91 | 92 | // converting unsigned char value to normalised float value 93 | auto node = visioncpp::point_operation(data); 94 | // float RGB to float Grey conversion 95 | auto node2 = visioncpp::point_operation(node); 96 | // converting float value for the grey to the unsigned char 97 | // assign operation that writes output of the pipe to output terminal node 98 | auto pipe = visioncpp::assign(data_out, node2); 99 | 100 | // execute the pipe defined pipe 101 | // 1st template parameter defines if VisionCpp back-end fuses the expression 102 | // 2nd & 3rd shared memory sizes ( column, row ) 103 | // 4th & 5th local work group size ( column , row ) 104 | visioncpp::execute(pipe, dev); 105 | } // destroy the expression tree to bring the data back to host 106 | 107 | printf("RGB: %u %u %u \nGrey: %f \n", in_rgb.get()[0], in_rgb.get()[1], 108 | in_rgb.get()[2], out_grey.get()[0]); 109 | } 110 | -------------------------------------------------------------------------------- /examples/rgb2hsv.cpp: -------------------------------------------------------------------------------- 1 | // This file is part of VisionCpp, a lightweight C++ template library 2 | // for computer vision and image processing. 3 | // 4 | // Copyright (C) 2016 Codeplay Software Limited. All Rights Reserved. 5 | // 6 | // Contact: visioncpp@codeplay.com 7 | // 8 | // Licensed under the Apache License, Version 2.0 (the "License"); 9 | // you may not use this file except in compliance with the License. 10 | // You may obtain a copy of the License at 11 | // 12 | // http://www.apache.org/licenses/LICENSE-2.0 13 | // 14 | // Unless required by applicable law or agreed to in writing, software 15 | // distributed under the License is distributed on an "AS IS" BASIS, 16 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | // See the License for the specific language governing permissions and 18 | // limitations under the License. 19 | 20 | /// \file rgb2hsv.cc 21 | /// 22 | /// -------Example-------- 23 | /// RGB -> HSV 24 | /// \brief this example convert an RGB pixel to HSV 25 | 26 | // include VisionCpp 27 | #include 28 | 29 | int main(int argc, char *argv[]) { 30 | if (argc < 4) { 31 | std::cout << "You need to provide 3 uchar values" << std::endl; 32 | std::cout << "example>: ./example_rgb2hsv 100 13 145" << std::endl; 33 | return -1; 34 | } 35 | 36 | // where VisionCpp will run. 37 | auto dev = visioncpp::make_device(); 39 | 40 | // create a host container for input data 41 | std::shared_ptr in_rgb( 42 | new unsigned char[3], [](unsigned char *dataMem) { delete[] dataMem; }); 43 | 44 | in_rgb.get()[0] = atoi(argv[1]); 45 | in_rgb.get()[1] = atoi(argv[2]); 46 | in_rgb.get()[2] = atoi(argv[3]); 47 | 48 | // create a host container for output data 49 | std::shared_ptr out_hsv( 50 | new unsigned char[3], [](unsigned char *dataMem) { delete[] dataMem; }); 51 | 52 | // exiting this scope will sync data 53 | { 54 | // definition of the VisionCpp pipeline: 55 | 56 | // create terminal nodes - a leaf node ( data node ) of the expression tree. 57 | // terminal struct takes 4 arguments 58 | // 1st template parameter specifies the data U8 (unsigned char) C3 (three 59 | // channels) 60 | // 2nd: the number of columns in the storage 61 | // 3rd: the number of rows in the storage 62 | // 4th: the underlying storage type - currently only Buffer2D supported 63 | auto data = 64 | visioncpp::terminal(in_rgb.get()); 66 | auto data_out = 67 | visioncpp::terminal(out_hsv.get()); 69 | 70 | // unsigned char -> float RGB storage conversion 71 | auto node = visioncpp::point_operation(data); 72 | // float RGB to float HSV conversion 73 | auto node2 = visioncpp::point_operation(node); 74 | // helper node that allows display of HSV 75 | // for unsigned char: V <- 255*V, S <- 255*S, H <- H/2 ( to fit in range of 76 | // 0..255 ) 77 | auto node3 = visioncpp::point_operation(node2); 78 | 79 | // assign operation that writes output of the pipe to output terminal node 80 | auto pipe = visioncpp::assign(data_out, node3); 81 | // execute the pipeline 82 | // 1st template parameter defines if VisionCpp back-end fuses the expression 83 | // 2nd & 3rd shared memory sizes ( column, row ) 84 | // 4th & 5th local work group size ( column , row ) 85 | visioncpp::execute(pipe, dev); 86 | } 87 | 88 | printf("RGB: %u %u %u \nHSV: %u %u %u \n", in_rgb.get()[0], in_rgb.get()[1], 89 | in_rgb.get()[2], out_hsv.get()[0], out_hsv.get()[1], out_hsv.get()[2]); 90 | 91 | return 0; 92 | } 93 | -------------------------------------------------------------------------------- /examples/simple_conv.cpp: -------------------------------------------------------------------------------- 1 | // This file is part of VisionCpp, a lightweight C++ template library 2 | // for computer vision and image processing. 3 | // 4 | // Copyright (C) 2016 Codeplay Software Limited. All Rights Reserved. 5 | // 6 | // Contact: visioncpp@codeplay.com 7 | // 8 | // Licensed under the Apache License, Version 2.0 (the "License"); 9 | // you may not use this file except in compliance with the License. 10 | // You may obtain a copy of the License at 11 | // 12 | // http://www.apache.org/licenses/LICENSE-2.0 13 | // 14 | // Unless required by applicable law or agreed to in writing, software 15 | // distributed under the License is distributed on an "AS IS" BASIS, 16 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | // See the License for the specific language governing permissions and 18 | // limitations under the License. 19 | 20 | /// \file simple_conv.cc 21 | /// 22 | /// ---------Example--------- 23 | /// Simple Convolution 24 | /// 25 | /// \brief This example implements a simple separable convolution using mean 26 | /// filter 27 | /// 28 | 29 | #ifdef NOT_COMPATIBLE_WITH_COMPUTECPP_050 30 | 31 | // include OpenCV for camera display 32 | #include 33 | 34 | // include VisionCpp 35 | #include 36 | 37 | // main program 38 | int main(int argc, char** argv) { 39 | // open video or camera 40 | cv::VideoCapture cap; 41 | 42 | if (argc == 1) { 43 | cap.open(0); 44 | std::cout << "To use video" << std::endl; 45 | std::cout << "example>: ./example path/to/video.avi" << std::endl; 46 | } else if (argc > 1) { 47 | cap.open(argv[1]); 48 | } 49 | 50 | // check if we succeeded 51 | if (!cap.isOpened()) { 52 | std::cout << "Opening Camera/Video Failed." << std::endl; 53 | return -1; 54 | } 55 | 56 | // set fixed resolution on the camera 57 | constexpr size_t COLS = 640; 58 | constexpr size_t ROWS = 480; 59 | 60 | // where VisionCpp will run? 61 | auto dev = visioncpp::make_device(); 63 | std::shared_ptr vc_buffer( 64 | new unsigned char[COLS * ROWS * 3], 65 | [](unsigned char* dataMem) { delete[] dataMem; }); 66 | 67 | // creating a 1x9 filter mean filter 68 | float filter_array[9] = {1.0f / 9.0f, 1.0f / 9.0f, 1.0f / 9.0f, 69 | 1.0f / 9.0f, 1.0f / 9.0f, 1.0f / 9.0f, 70 | 1.0f / 9.0f, 1.0f / 9.0f, 1.0f / 9.0f}; 71 | // create opencv mat 72 | cv::Mat frame; 73 | cv::Mat output; 74 | 75 | for (;;) { 76 | // read frame 77 | cap.read(frame); 78 | 79 | // check if image was loaded 80 | if (!frame.data) { 81 | break; 82 | } 83 | 84 | // resize image to the desirable size 85 | cv::resize(frame, frame, cv::Size(COLS, ROWS), 0, 0, cv::INTER_CUBIC); 86 | 87 | // column-wise filter for separable convolution 88 | auto filter_col = 89 | visioncpp::terminal(filter_array); 91 | // row wise filter for separable convolution 92 | auto filter_row = 93 | visioncpp::terminal(filter_array); 95 | // wrap OpenCV frame data in our leaf node 96 | auto data = 97 | visioncpp::terminal(frame.data); 99 | auto data_out = 100 | visioncpp::terminal(vc_buffer.get()); 102 | 103 | auto node2 = visioncpp::neighbour_operation( 104 | data, filter_col); 105 | auto node3 = visioncpp::neighbour_operation( 106 | node2, filter_row); 107 | 108 | // writing back to Mat 109 | auto k = visioncpp::assign(data_out, node3); 110 | 111 | // execute the pipe 112 | visioncpp::execute(k, dev); 113 | 114 | // show image 115 | output = cv::Mat(ROWS, COLS, CV_8UC3, vc_buffer.get()); 116 | cv::imshow("Reference Image", frame); 117 | cv::imshow("Mean Filter Convolution", output); 118 | 119 | // loop 120 | if (cv::waitKey(30) >= 0) break; 121 | } 122 | 123 | // release video/camera 124 | cap.release(); 125 | 126 | return 0; 127 | } 128 | 129 | #endif 130 | -------------------------------------------------------------------------------- /examples/threshold.cpp: -------------------------------------------------------------------------------- 1 | // This file is part of VisionCPP, a lightweight C++ template library 2 | // for computer vision and image processing. 3 | // 4 | // Copyright (C) 2016 Codeplay Software Limited. All Rights Reserved. 5 | // 6 | // Contact: visioncpp@codeplay.com 7 | // 8 | // Licensed under the Apache License, Version 2.0 (the "License"); 9 | // you may not use this file except in compliance with the License. 10 | // You may obtain a copy of the License at 11 | // 12 | // http://www.apache.org/licenses/LICENSE-2.0 13 | // 14 | // Unless required by applicable law or agreed to in writing, software 15 | // distributed under the License is distributed on an "AS IS" BASIS, 16 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | // See the License for the specific language governing permissions and 18 | // limitations under the License. 19 | 20 | /// \file threhsold.cc 21 | /// 22 | /// ---------Example--------- 23 | /// Threshold 24 | /// 25 | /// \brief This example implements a binary threshold 26 | /// 27 | /// \param threshold - threshold value whose range is [0..1] 28 | /// 29 | 30 | // include OpenCV for camera display 31 | #include 32 | 33 | // include VisionCpp 34 | #include 35 | 36 | // main program 37 | int main(int argc, char **argv) { 38 | // open video or camera 39 | cv::VideoCapture cap; 40 | 41 | if (argc == 1) { 42 | cap.open(0); 43 | std::cout << "To use video" << std::endl; 44 | std::cout << "example>: ./example path/to/video.avi" << std::endl; 45 | } else if (argc > 1) { 46 | cap.open(argv[1]); 47 | } 48 | 49 | // check if we succeeded 50 | if (!cap.isOpened()) { 51 | std::cout << "Opening Camera/Video Failed." << std::endl; 52 | return -1; 53 | } 54 | 55 | // selecting device using sycl as backend 56 | auto dev = visioncpp::make_device(); 58 | 59 | // defining size constants 60 | constexpr size_t COLS = 640; 61 | constexpr size_t ROWS = 480; 62 | 63 | // initializing output pointer 64 | std::shared_ptr output(new uchar[COLS * ROWS], 65 | [](uchar *dataMem) { delete[] dataMem; }); 66 | 67 | // initializing input and output image 68 | cv::Mat input; 69 | cv::Mat outImage(ROWS, COLS, CV_8UC1, output.get()); 70 | 71 | // threshold parameter 72 | constexpr float threshold{0.5f}; 73 | 74 | for (;;) { 75 | // Starting building the tree (use {} during the creation of the tree) 76 | { 77 | // read frame 78 | cap.read(input); 79 | 80 | // check if image was loaded 81 | if (!input.data) { 82 | break; 83 | } 84 | 85 | // resize image to the desirable size 86 | cv::resize(input, input, cv::Size(COLS, ROWS), 0, 0, cv::INTER_CUBIC); 87 | 88 | auto in_node = 89 | visioncpp::terminal(input.data); 91 | auto out_node = 92 | visioncpp::terminal(output.get()); 94 | 95 | // convert to Float 96 | auto frgb = 97 | visioncpp::point_operation(in_node); 98 | 99 | // convert to grey 100 | auto fgrey = visioncpp::point_operation(frgb); 101 | 102 | // apply the threshold 103 | auto thresh_node = 104 | visioncpp::terminal( 105 | static_cast(threshold)); 106 | auto thresh = 107 | visioncpp::point_operation(fgrey, thresh_node); 108 | 109 | // scale threshold to display 110 | auto scale_node = 111 | visioncpp::terminal( 112 | static_cast(255.0f)); 113 | auto urgb = 114 | visioncpp::point_operation(thresh, scale_node); 115 | 116 | // assign to the host memory 117 | auto k = visioncpp::assign(out_node, urgb); 118 | 119 | // execute 120 | visioncpp::execute(k, dev); 121 | } 122 | 123 | // display results 124 | cv::imshow("Reference Image", input); 125 | cv::imshow("Threshold", outImage); 126 | 127 | // wait for key to finalize program 128 | if (cv::waitKey(1) >= 0) break; 129 | } 130 | 131 | // release video/camera 132 | cap.release(); 133 | 134 | return 0; 135 | } 136 | -------------------------------------------------------------------------------- /include/framework/device/device.hpp: -------------------------------------------------------------------------------- 1 | // This file is part of VisionCpp, a lightweight C++ template library 2 | // for computer vision and image processing. 3 | // 4 | // Copyright (C) 2016 Codeplay Software Limited. All Rights Reserved. 5 | // 6 | // Contact: visioncpp@codeplay.com 7 | // 8 | // Licensed under the Apache License, Version 2.0 (the "License"); 9 | // you may not use this file except in compliance with the License. 10 | // You may obtain a copy of the License at 11 | // 12 | // http://www.apache.org/licenses/LICENSE-2.0 13 | // 14 | // Unless required by applicable law or agreed to in writing, software 15 | // distributed under the License is distributed on an "AS IS" BASIS, 16 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | // See the License for the specific language governing permissions and 18 | // limitations under the License. 19 | 20 | /// \file device/device.hpp 21 | /// \brief include headers for adding different devices. Currently we only 22 | /// support sycl backend 23 | 24 | #ifndef VISIONCPP_INCLUDE_FRAMEWORK_DEVICE_DEVICE_HPP_ 25 | #define VISIONCPP_INCLUDE_FRAMEWORK_DEVICE_DEVICE_HPP_ 26 | #include "sycl/device.hpp" 27 | #endif // VISIONCPP_INCLUDE_FRAMEWORK_DEVICE_DEVICE_HPP_ 28 | -------------------------------------------------------------------------------- /include/framework/device/sycl/device.hpp: -------------------------------------------------------------------------------- 1 | // This file is part of VisionCpp, a lightweight C++ template library 2 | // for compute vision and image processing. 3 | // 4 | // Copyright (C) 2016 Codeplay Software Limited. All Rights Reserved. 5 | // 6 | // Contact: visioncpp@codeplay.com 7 | // 8 | // Licensed under the Apache License, Version 2.0 (the "License"); 9 | // you may not use this file except in compliance with the License. 10 | // You may obtain a copy of the License at 11 | // 12 | // http://www.apache.org/licenses/LICENSE-2.0 13 | // 14 | // Unless required by applicable law or agreed to in writing, software 15 | // distributed under the License is distributed on an "AS IS" BASIS, 16 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | // See the License for the specific language governing permissions and 18 | // limitations under the License. 19 | 20 | /// \file sycl/device.hpp 21 | /// \brief This file contains the include headers for sycl devices 22 | #pragma once 23 | 24 | namespace visioncpp { 25 | namespace internal { 26 | /// \struct DeviceSelector 27 | /// \brief this class is used to define different types of device for sycl 28 | template 29 | struct DeviceSelector; 30 | 31 | /// \brief specialisation of the device_selector for sycl when the device type 32 | /// is cpu 33 | template <> 34 | struct DeviceSelector { 35 | using Type = cl::sycl::cpu_selector; 36 | }; 37 | /// \brief specialisation of the device_selector for sycl when the device type 38 | /// is gpu 39 | template <> 40 | struct DeviceSelector { 41 | using Type = cl::sycl::gpu_selector; 42 | }; 43 | /// \brief specialisation of the device_selector for sycl when the device type 44 | /// is host 45 | template <> 46 | struct DeviceSelector { 47 | using Type = cl::sycl::host_selector; 48 | }; 49 | } // end internal 50 | } // end visioncpp 51 | #include "extract_accessors.hpp" 52 | #include "sycl_device.hpp" 53 | -------------------------------------------------------------------------------- /include/framework/device/sycl/sycl_device.hpp: -------------------------------------------------------------------------------- 1 | // This file is part of VisionCpp, a lightweight C++ template library 2 | // for computer vision and image processing. 3 | // 4 | // Copyright (C) 2016 Codeplay Software Limited. All Rights Reserved. 5 | // 6 | // Contact: visioncpp@codeplay.com 7 | // 8 | // Licensed under the Apache License, Version 2.0 (the "License"); 9 | // you may not use this file except in compliance with the License. 10 | // You may obtain a copy of the License at 11 | // 12 | // http://www.apache.org/licenses/LICENSE-2.0 13 | // 14 | // Unless required by applicable law or agreed to in writing, software 15 | // distributed under the License is distributed on an "AS IS" BASIS, 16 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | // See the License for the specific language governing permissions and 18 | // limitations under the License. 19 | 20 | /// \file sycl_device.hpp 21 | /// \brief This fill contains features related to sycl devices. 22 | 23 | #ifndef VISIONCPP_INCLUDE_FRAMEWORK_DEVICE_SYCL_DEVICE_HPP_ 24 | #define VISIONCPP_INCLUDE_FRAMEWORK_DEVICE_SYCL_DEVICE_HPP_ 25 | 26 | namespace visioncpp { 27 | namespace internal { 28 | 29 | /// \brief specialisation Device_ for sycl 30 | /// \tparam device type supported by sycl 31 | template 32 | class Device_ { 33 | using QueueType = cl::sycl::queue; 34 | using DevType = typename DeviceSelector::Type; 35 | 36 | private: 37 | mutable QueueType dev; 38 | 39 | public: 40 | Device_() 41 | : dev(QueueType(DevType(), [=](cl::sycl::exception_list l) { 42 | for (const auto &e : l) { 43 | try { 44 | std::rethrow_exception(e); 45 | } catch (cl::sycl::exception e) { 46 | std::cout << e.what() << std::endl; 47 | } 48 | } 49 | })) {} 50 | template 52 | void execute(Expr &expr) const { 53 | /// generating the short class name for the AMD gpu 54 | constexpr size_t TotalLeaves = LeafCount::Count; 55 | /// replacing the the leaf node in the expression tree with a placeholder 56 | /// number 57 | using placeHolderExprType = 58 | typename MakePlaceHolderExprHelper::Type; 60 | 61 | /// submitting the lambda expression to the sycl queue. 62 | dev.submit([&](cl::sycl::handler &cgh) { 63 | 64 | /// creating global accessors on all input output buffers 65 | auto global_accessor_tuple = extract_accessors(cgh, expr); 66 | /// create the tuple of local output accessor 67 | auto device_only_accessor_tuple = 68 | create_local_accessors(cgh); 69 | /// starting point of local tuples 70 | constexpr size_t Output_offset = 71 | tools::tuple::size(global_accessor_tuple); 72 | /// merge it with all the other existing tuples 73 | auto device_tuple = tools::tuple::append(global_accessor_tuple, 74 | device_only_accessor_tuple); 75 | /// submitting the kernel lambda to the parallel 76 | 77 | cgh.parallel_for( 78 | cl::sycl::nd_range( 79 | visioncpp::internal::get_range(RGT, CGT), 80 | visioncpp::internal::get_range(RLT, CLT)), 81 | [=](cl::sycl::nd_item itemID) { 82 | /// creating the index access for each thread 83 | auto cOffset = visioncpp::internal::memLocation(itemID); 84 | 85 | /// creating the eval expression for evaluating the expression 86 | /// tree. The output now moved to the front so the Output_offset 87 | /// should be reduced by one. 88 | eval(cOffset, 89 | device_tuple); 90 | }); 91 | }); 92 | dev.throw_asynchronous(); 93 | } 94 | }; 95 | } // namespace internal 96 | } // namespace visioncpp 97 | #endif // VISIONCPP_INCLUDE_FRAMEWORK_DEVICE_SYCL_DEVICE_HPP_ 98 | -------------------------------------------------------------------------------- /include/framework/evaluator/eval_assign/eval_assign.hpp: -------------------------------------------------------------------------------- 1 | // This file is part of VisionCpp, a lightweight C++ template library 2 | // for computer vision and image processing. 3 | // 4 | // Copyright (C) 2016 Codeplay Software Limited. All Rights Reserved. 5 | // 6 | // Contact: visioncpp@codeplay.com 7 | // 8 | // Licensed under the Apache License, Version 2.0 (the "License"); 9 | // you may not use this file except in compliance with the License. 10 | // You may obtain a copy of the License at 11 | // 12 | // http://www.apache.org/licenses/LICENSE-2.0 13 | // 14 | // Unless required by applicable law or agreed to in writing, software 15 | // distributed under the License is distributed on an "AS IS" BASIS, 16 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | // See the License for the specific language governing permissions and 18 | // limitations under the License. 19 | 20 | /// \file eval_assign.hpp 21 | /// \brief This file contains the specialisation of the Evaluator struct for 22 | /// assign when it is a root struct 23 | 24 | #ifndef VISIONCPP_INCLUDE_FRAMEWORK_EVALUATOR_EVAL_ASSIGN_EVAL_ASSIGN_HPP_ 25 | #define VISIONCPP_INCLUDE_FRAMEWORK_EVALUATOR_EVAL_ASSIGN_EVAL_ASSIGN_HPP_ 26 | 27 | namespace visioncpp { 28 | namespace internal { 29 | /// \brief Partial specialisation of the Evaluator when the expression is an 30 | /// internal::Assign expression and the internal::ops_category is 31 | /// GlobalNeighbourOP. 32 | template 35 | struct Evaluator, 37 | Loc, Params...> { 38 | static inline void eval(Loc &cOffset, 39 | const tools::tuple::Tuple &t) { 40 | EvalExpr::template eval_global_neighbour< 41 | true, Offset, OutputIndex, LC, LR>(cOffset, t); 42 | } 43 | }; 44 | 45 | /// \brief Partial specialisation of the Evaluator when the expression is an 46 | /// internal::Assign expression and the internal::ops_category is NeighbourOP. 47 | template 50 | struct Evaluator, Loc, 52 | Params...> { 53 | static inline void eval(Loc &cOffset, 54 | const tools::tuple::Tuple &t) { 55 | EvalExpr::template eval_neighbour< 56 | true, 0, 0, 0, 0, Offset, OutputIndex, LC, LR>(cOffset, t); 57 | } 58 | }; 59 | 60 | /// \brief Partial specialisation of the Evaluator when the expression is an 61 | /// internal::Assign expression and the internal::ops_category is PointOP. 62 | template 65 | struct Evaluator, Loc, 67 | Params...> { 68 | using Expr = internal::Assign; 69 | static inline void eval(Loc &cOffset, 70 | const tools::tuple::Tuple &t) { 71 | using RHS_Eval_Expr = EvalExpr; 72 | using LHS_Eval_Expr = EvalExpr; 73 | 74 | using ElementType = 75 | typename MemoryTrait(t))>::Type; 77 | for (int i = 0; i < LC; i += cOffset.cLRng) 78 | if (cOffset.g_c + i < Expr::Type::Cols) 79 | for (int j = 0; j < LR; j += cOffset.rLRng) 80 | if (cOffset.g_r + j < Expr::Type::Rows) { 81 | cOffset.pointOp_gc = cOffset.g_c + i; 82 | cOffset.pointOp_gr = cOffset.g_r + j; 83 | *(LHS_Eval_Expr::get_accessor(t).get_pointer() + 84 | calculate_index(cOffset.g_c + i, cOffset.g_r + j, 85 | Expr::Type::Cols, Expr::Type::Rows)) = 86 | tools::convert( 87 | RHS_Eval_Expr::eval_point(cOffset, t)); 88 | } 89 | } 90 | }; 91 | } // namespace internal 92 | } // namespace visioncpp 93 | #endif // VISIONCPP_INCLUDE_FRAMEWORK_EVALUATOR_EVAL_ASSIGN_EVAL_ASSIGN_HPP_ 94 | -------------------------------------------------------------------------------- /include/framework/evaluator/eval_expression/eval_expr_leaf_node.hpp: -------------------------------------------------------------------------------- 1 | // This file is part of VisionCpp, a lightweight C++ template library 2 | // for computer vision and image processing. 3 | // 4 | // Copyright (C) 2016 Codeplay Software Limited. All Rights Reserved. 5 | // 6 | // Contact: visioncpp@codeplay.com 7 | // 8 | // Licensed under the Apache License, Version 2.0 (the "License"); 9 | // you may not use this file except in compliance with the License. 10 | // You may obtain a copy of the License at 11 | // 12 | // http://www.apache.org/licenses/LICENSE-2.0 13 | // 14 | // Unless required by applicable law or agreed to in writing, software 15 | // distributed under the License is distributed on an "AS IS" BASIS, 16 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | // See the License for the specific language governing permissions and 18 | // limitations under the License. 19 | 20 | /// \file eval_expr_leaf_node.hpp 21 | /// \brief This file contains the specialisation of the EvalExpr 22 | /// for LeafNode. 23 | 24 | #ifndef VISIONCPP_INCLUDE_FRAMEWORK_EVALUATOR_EVAL_EXPRESSION_EVAL_EXPR_LEAF_NODE_HPP_ 25 | #define VISIONCPP_INCLUDE_FRAMEWORK_EVALUATOR_EVAL_EXPRESSION_EVAL_EXPR_LEAF_NODE_HPP_ 26 | 27 | namespace visioncpp { 28 | namespace internal { 29 | /// \brief Partial specialisation of the EvalExpr when the expression is 30 | /// an LeafNode expression and the internal::ops_category is NeighbourOP. 31 | template 33 | struct EvalExpr, LVL>, Loc, 34 | Params...> { 35 | using Expr = LeafNode, LVL>; 36 | 37 | static auto get_accessor(const tools::tuple::Tuple &t) 38 | -> decltype(tools::tuple::get(t)) { 39 | return tools::tuple::get(t); 40 | } 41 | /// \brief evaluate function when the internal::ops_category is PointOP. 42 | static inline auto 43 | eval_point(Loc &cOffset, const tools::tuple::Tuple &t) -> decltype( 44 | tools::tuple::get(t) 45 | .get_pointer()[cOffset.pointOp_gc + (Cols * cOffset.pointOp_gr)]) { 46 | return tools::tuple::get(t).get_pointer()[calculate_index( 47 | cOffset.pointOp_gc, cOffset.pointOp_gr, Cols, Rows)]; 48 | } 49 | /// \brief evaluate function when the internal::ops_category is NeighbourOP. 50 | template 53 | static inline auto eval_neighbour(Loc &cOffset, 54 | const tools::tuple::Tuple &t) 55 | -> decltype( 56 | tools::tuple::get::ID, Memory_Type, 58 | Trait(t))>::Type>::scope>::Index>(t)) { 60 | fill_local_neighbour< 61 | Halo_Top, Halo_Left, Halo_Butt, Halo_Right, 62 | Index_Finder::ID, 63 | Memory_Type, Sc>::Index, 64 | LC, LR, Expr>(cOffset, t); 65 | return tools::tuple::get< 66 | Index_Finder::ID, 67 | Memory_Type, Sc>::Index>(t); 68 | } 69 | /// \brief evaluate function when the internal::ops_category is 70 | /// GlobalNeighbour; 71 | template 72 | static inline auto 73 | eval_global_neighbour(Loc &, const tools::tuple::Tuple &t) 74 | -> decltype(tools::tuple::get(t)) { 75 | return tools::tuple::get(t); 76 | } 77 | }; 78 | } // namespace internal 79 | } // namespace visioncpp 80 | #endif // VISIONCPP_INCLUDE_FRAMEWORK_EVALUATOR_EVAL_EXPRESSION_EVAL_EXPR_LEAF_NODE_HPP_ 81 | -------------------------------------------------------------------------------- /include/framework/evaluator/eval_expression/eval_expr_r_binary.hpp: -------------------------------------------------------------------------------- 1 | // This file is part of VisionCpp, a lightweight C++ template library 2 | // for computer vision and image processing. 3 | // 4 | // Copyright (C) 2016 Codeplay Software Limited. All Rights Reserved. 5 | // 6 | // Contact: visioncpp@codeplay.com 7 | // 8 | // Licensed under the Apache License, Version 2.0 (the "License"); 9 | // you may not use this file except in compliance with the License. 10 | // You may obtain a copy of the License at 11 | // 12 | // http://www.apache.org/licenses/LICENSE-2.0 13 | // 14 | // Unless required by applicable law or agreed to in writing, software 15 | // distributed under the License is distributed on an "AS IS" BASIS, 16 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | // See the License for the specific language governing permissions and 18 | // limitations under the License. 19 | 20 | /// \file eval_expr_r_binary.hpp 21 | /// \brief This file contains the specialisation of the EvalExpr 22 | /// for RBiOP( pointwise Binary operation node). 23 | 24 | #ifndef VISIONCPP_INCLUDE_FRAMEWORK_EVALUATOR_EVAL_EXPRESSION_EVAL_EXPR_R_BINARY_HPP_ 25 | #define VISIONCPP_INCLUDE_FRAMEWORK_EVALUATOR_EVAL_EXPRESSION_EVAL_EXPR_R_BINARY_HPP_ 26 | 27 | namespace visioncpp { 28 | namespace internal { 29 | /// \brief Partial specialisation of the EvalExpr when the expression is 30 | /// an RBiOP(binary operation) expression. 31 | template 33 | struct EvalExpr, Loc, 34 | Params...> { 35 | /// \brief evaluate function when the internal::ops_category is PointOP. 36 | static typename BI_OP::OutType 37 | eval_point(Loc &cOffset, const tools::tuple::Tuple &t) { 38 | auto lhs_acc = EvalExpr::eval_point(cOffset, t); 39 | auto rhs_acc = EvalExpr::eval_point(cOffset, t); 40 | return 41 | typename BI_OP::OP()(tools::convert(lhs_acc), 42 | tools::convert(rhs_acc)); 43 | } 44 | /// \brief evaluate function when the internal::ops_category is NeighbourOP. 45 | template 48 | static auto eval_neighbour(Loc &cOffset, 49 | const tools::tuple::Tuple &t) 50 | -> decltype( 51 | tools::tuple::get::ID>( 52 | t)) { 53 | constexpr size_t OutOffset = OutputLocation::ID; 54 | constexpr bool isLocal = 55 | Trait(t))>::Type>::scope == scope::Local; 57 | static constexpr size_t RHSCount = 58 | LocalMemCount::Count; 59 | 60 | auto lhs_acc = EvalExpr::template eval_neighbour< 61 | false, Halo_Top, Halo_Left, Halo_Butt, Halo_Right, 62 | Offset, Index - 1 - RHSCount, LC, LR>(cOffset, t) 63 | .get_pointer(); 64 | auto rhs_acc = EvalExpr::template eval_neighbour< 65 | false, Halo_Top, Halo_Left, Halo_Butt, Halo_Right, 66 | Offset, Index - 1, LC, LR>(cOffset, t) 67 | .get_pointer(); 68 | // eval the RBiOP 69 | for (int i = 0; i < LC; i += cOffset.cLRng) { 70 | if (get_compare(cOffset.l_c, i, cOffset.g_c)) { 71 | for (int j = 0; j < LR; j += cOffset.rLRng) { 72 | if (get_compare(cOffset.l_r, j, cOffset.g_r)) { 73 | size_t child_index = 74 | calculate_index(cOffset.l_c + i, cOffset.l_r + j, LC, LR); 75 | *(tools::tuple::get(t).get_pointer() + 76 | calculate_index(id_val(cOffset.l_c, cOffset.g_c) + i, 77 | id_val(cOffset.l_r, cOffset.g_r) + j, 78 | id_val(LC, Cols), 79 | id_val(LR, Rows))) = 80 | tools::convert(t))>::Type>( 82 | typename BI_OP::OP()(*(lhs_acc + child_index), 83 | rhs_acc[child_index])); 84 | } 85 | } 86 | } 87 | } 88 | 89 | // here you need to put a local barrier 90 | cOffset.barrier(); 91 | // return the valid neighbour area for your parent 92 | return tools::tuple::get(t); 93 | } 94 | }; 95 | } // namespace internal 96 | } // namespace visioncpp 97 | #endif // VISIONCPP_INCLUDE_FRAMEWORK_EVALUATOR_EVAL_EXPRESSION_EVAL_EXPR_R_BINARY_HPP_ 98 | -------------------------------------------------------------------------------- /include/framework/evaluator/eval_expression/eval_expr_r_unary.hpp: -------------------------------------------------------------------------------- 1 | // This file is part of VisionCpp, a lightweight C++ template library 2 | // for computer vision and image processing. 3 | // 4 | // Copyright (C) 2016 Codeplay Software Limited. All Rights Reserved. 5 | // 6 | // Contact: visioncpp@codeplay.com 7 | // 8 | // Licensed under the Apache License, Version 2.0 (the "License"); 9 | // you may not use this file except in compliance with the License. 10 | // You may obtain a copy of the License at 11 | // 12 | // http://www.apache.org/licenses/LICENSE-2.0 13 | // 14 | // Unless required by applicable law or agreed to in writing, software 15 | // distributed under the License is distributed on an "AS IS" BASIS, 16 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | // See the License for the specific language governing permissions and 18 | // limitations under the License. 19 | 20 | /// \file eval_expr_r_unary.hpp 21 | /// \brief This file contains the specialisation of the EvalExpr 22 | /// for RUnOP( pointwise Unary operation node). 23 | 24 | #ifndef VISIONCPP_INCLUDE_FRAMEWORK_EVALUATOR_EVAL_EXPRESSION_EVAL_EXPR_R_UNARY_HPP_ 25 | #define VISIONCPP_INCLUDE_FRAMEWORK_EVALUATOR_EVAL_EXPRESSION_EVAL_EXPR_R_UNARY_HPP_ 26 | 27 | namespace visioncpp { 28 | namespace internal { 29 | /// \brief Partial specialisation of the EvalExpr when the expression is 30 | /// an RUnOP(unary operation) expression. 31 | template 33 | struct EvalExpr, Loc, Params...> { 34 | /// \brief evaluate function when the internal::ops_category is PointOP. 35 | static typename UN_OP::OutType 36 | eval_point(Loc &cOffset, const tools::tuple::Tuple &t) { 37 | auto nested_acc = EvalExpr::eval_point(cOffset, t); 38 | return typename UN_OP::OP()( 39 | tools::convert(nested_acc)); 40 | } 41 | /// \brief evaluate function when the internal::ops_category is NeighbourOP. 42 | template 45 | static auto eval_neighbour(Loc &cOffset, 46 | const tools::tuple::Tuple &t) 47 | -> decltype( 48 | tools::tuple::get::ID>( 49 | t)) { 50 | constexpr size_t OutOffset = OutputLocation::ID; 51 | constexpr bool isLocal = 52 | Trait(t))>::Type>::scope == scope::Local; 54 | auto nested_acc = EvalExpr::template eval_neighbour< 55 | false, Halo_Top, Halo_Left, Halo_Butt, Halo_Right, 56 | Offset, Index - 1, LC, LR>(cOffset, t) 57 | .get_pointer(); 58 | for (int i = 0; i < LC; i += cOffset.cLRng) { 59 | if (get_compare(cOffset.l_c, i, cOffset.g_c)) { 60 | for (int j = 0; j < LR; j += cOffset.rLRng) { 61 | if (get_compare(cOffset.l_r, j, cOffset.g_r)) { 62 | *(tools::tuple::get(t).get_pointer() + 63 | calculate_index(id_val(cOffset.l_c, cOffset.g_c) + i, 64 | id_val(cOffset.l_r, cOffset.g_r) + j, 65 | id_val(LC, Cols), 66 | id_val(LR, Rows))) = 67 | tools::convert(t))>::Type>( 69 | typename UN_OP::OP()( 70 | *(nested_acc + calculate_index(cOffset.l_c + i, 71 | cOffset.l_r + j, LC, 72 | LR)))); 73 | } 74 | } 75 | } 76 | } 77 | 78 | // here you need to put a local barrier 79 | cOffset.barrier(); 80 | // return the the valid neighbour area for parent 81 | return tools::tuple::get(t); 82 | } 83 | }; 84 | } // namespace internal 85 | } // namespace visioncpp 86 | #endif // VISIONCPP_INCLUDE_FRAMEWORK_EVALUATOR_EVAL_EXPRESSION_EVAL_EXPR_R_UNARY_HPP_ 87 | -------------------------------------------------------------------------------- /include/framework/evaluator/eval_expression/eval_expr_stn_filt.hpp: -------------------------------------------------------------------------------- 1 | // This file is part of VisionCpp, a lightweight C++ template library 2 | // for computer vision and image processing. 3 | // 4 | // Copyright (C) 2016 Codeplay Software Limited. All Rights Reserved. 5 | // 6 | // Contact: visioncpp@codeplay.com 7 | // 8 | // Licensed under the Apache License, Version 2.0 (the "License"); 9 | // you may not use this file except in compliance with the License. 10 | // You may obtain a copy of the License at 11 | // 12 | // http://www.apache.org/licenses/LICENSE-2.0 13 | // 14 | // Unless required by applicable law or agreed to in writing, software 15 | // distributed under the License is distributed on an "AS IS" BASIS, 16 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | // See the License for the specific language governing permissions and 18 | // limitations under the License. 19 | 20 | /// \file eval_expr_stn_filt.hpp 21 | /// \brief This file contains the specialisation of the EvalExpr 22 | /// for StnFilt( stencil node with filter ). 23 | 24 | #ifndef VISIONCPP_INCLUDE_FRAMEWORK_EVALUATOR_EVAL_EXPRESSION_EVAL_EXPR_STN_FILT_HPP_ 25 | #define VISIONCPP_INCLUDE_FRAMEWORK_EVALUATOR_EVAL_EXPRESSION_EVAL_EXPR_STN_FILT_HPP_ 26 | 27 | namespace visioncpp { 28 | namespace internal { 29 | /// \brief Partial specialisation of the EvalExpr when the expression is 30 | /// an StnFilt(stencil with filter operation) expression. 31 | template 34 | struct EvalExpr, 36 | Loc, Params...> { 37 | /// \brief evaluate function when the internal::ops_category is NeighbourOP. 38 | template 41 | static auto eval_neighbour(Loc &cOffset, 42 | const tools::tuple::Tuple &t) 43 | -> decltype( 44 | tools::tuple::get::ID>( 45 | t)) { 46 | constexpr size_t OutOffset = OutputLocation::ID; 47 | constexpr bool isLocal = 48 | Trait(t))>::Type>::scope == scope::Local; 50 | // lhs expression shared mem 51 | static constexpr size_t RHSCount = 52 | LocalMemCount::Count; 53 | auto lhs_acc = 54 | EvalExpr::template eval_neighbour< 55 | false, Halo_Top + Halo_T, Halo_Left + Halo_L, Halo_Butt + Halo_B, 56 | Halo_Right + Halo_R, Offset, Index - 1 - RHSCount, 57 | LC + Halo_L + Halo_R, LR + Halo_T + Halo_B>(cOffset, t) 58 | .get_pointer(); 59 | // rhs expression shared mem 60 | auto rhs_acc = EvalExpr::template eval_neighbour< 61 | false, Halo_Top, Halo_Left, Halo_Butt, Halo_Right, 62 | Offset, Index - 1, LC, LR>(cOffset, t) 63 | .get_pointer(); 64 | 65 | auto neighbour = LocalNeighbour( 66 | lhs_acc, LC + Halo_L + Halo_R, LR + Halo_T + Halo_B); 67 | // filter for StnFilt 68 | auto filter = ConstNeighbour( 69 | rhs_acc, RHS::Type::Cols, RHS::Type::Rows); 70 | for (int i = 0; i < LC; i += cOffset.cLRng) { 71 | if (get_compare(cOffset.l_c, i, cOffset.g_c)) { 72 | for (int j = 0; j < LR; j += cOffset.rLRng) { 73 | if (get_compare(cOffset.l_r, j, cOffset.g_r)) { 74 | neighbour.set_offset(cOffset.l_c + Halo_L + i, 75 | cOffset.l_r + Halo_T + j); 76 | *(tools::tuple::get(t).get_pointer() + 77 | calculate_index(id_val(cOffset.l_c, cOffset.g_c) + i, 78 | id_val(cOffset.l_r, cOffset.g_r) + j, 79 | id_val(LC, Cols), 80 | id_val(LR, Rows))) = 81 | tools::convert(t))>::Type>( 83 | typename C_OP::OP()(neighbour, filter)); 84 | } 85 | } 86 | } 87 | } 88 | // here you need to put a local barrier 89 | cOffset.barrier(); 90 | 91 | // return the valid neighbour area for your parent 92 | return tools::tuple::get(t); 93 | } 94 | }; 95 | } // namespace internal 96 | } // namespace visioncpp 97 | #endif // VISIONCPP_INCLUDE_FRAMEWORK_EVALUATOR_EVAL_EXPRESSION_EVAL_EXPR_STN_FILT_HPP_ 98 | -------------------------------------------------------------------------------- /include/framework/evaluator/eval_expression/eval_expr_stn_no_filt.hpp: -------------------------------------------------------------------------------- 1 | // This file is part of VisionCpp, a lightweight C++ template library 2 | // for computer vision and image processing. 3 | // 4 | // Copyright (C) 2016 Codeplay Software Limited. All Rights Reserved. 5 | // 6 | // Contact: visioncpp@codeplay.com 7 | // 8 | // Licensed under the Apache License, Version 2.0 (the "License"); 9 | // you may not use this file except in compliance with the License. 10 | // You may obtain a copy of the License at 11 | // 12 | // http://www.apache.org/licenses/LICENSE-2.0 13 | // 14 | // Unless required by applicable law or agreed to in writing, software 15 | // distributed under the License is distributed on an "AS IS" BASIS, 16 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | // See the License for the specific language governing permissions and 18 | // limitations under the License. 19 | 20 | /// \file eval_expr_stn_no_filt.hpp 21 | /// \brief This file contains the specialisation of the EvalExpr 22 | /// for StnFilt( stencil node without filter). 23 | 24 | #ifndef VISIONCPP_INCLUDE_FRAMEWORK_EVALUATOR_EVAL_EXPRESSION_EVAL_EXPR_STN_NO_FILT_HPP_ 25 | #define VISIONCPP_INCLUDE_FRAMEWORK_EVALUATOR_EVAL_EXPRESSION_EVAL_EXPR_STN_NO_FILT_HPP_ 26 | 27 | namespace visioncpp { 28 | namespace internal { 29 | /// \brief Partial specialisation of the EvalExpr when the expression is 30 | /// an StnNoFilt(stencil without filter operation) expression. 31 | template 34 | struct EvalExpr, 36 | Loc, Params...> { 37 | /// \brief evaluate function when the internal::ops_category is NeighbourOP. 38 | template 41 | static auto eval_neighbour(Loc &cOffset, 42 | const tools::tuple::Tuple &t) 43 | -> decltype( 44 | tools::tuple::get::ID>( 45 | t)) { 46 | constexpr size_t OutOffset = OutputLocation::ID; 47 | constexpr bool isLocal = 48 | Trait(t))>::Type>::scope == scope::Local; 50 | // lhs expression shared mem 51 | auto nested_acc = 52 | EvalExpr::template eval_neighbour< 53 | false, Halo_Top + Halo_T, Halo_Left + Halo_L, Halo_Butt + Halo_B, 54 | Halo_Right + Halo_R, Offset, Index - 1, LC + Halo_L + Halo_R, 55 | LR + Halo_T + Halo_B>(cOffset, t) 56 | .get_pointer(); 57 | 58 | auto neighbour = LocalNeighbour( 59 | nested_acc, LC + Halo_L + Halo_R, LR + Halo_T + Halo_B); 60 | for (int i = 0; i < LC; i += cOffset.cLRng) { 61 | if (get_compare(cOffset.l_c, i, cOffset.g_c)) { 62 | for (int j = 0; j < LR; j += cOffset.rLRng) { 63 | if (get_compare(cOffset.l_r, j, cOffset.g_r)) { 64 | neighbour.set_offset(cOffset.l_c + Halo_L + i, 65 | cOffset.l_r + Halo_T + j); 66 | *(tools::tuple::get(t).get_pointer() + 67 | calculate_index(id_val(cOffset.l_c, cOffset.g_c) + i, 68 | id_val(cOffset.l_r, cOffset.g_r) + j, 69 | id_val(LC, Cols), 70 | id_val(LR, Rows))) = 71 | tools::convert(t))>::Type>( 73 | typename C_OP::OP()(neighbour)); 74 | } 75 | } 76 | } 77 | } 78 | // here you need to put a local barrier 79 | cOffset.barrier(); 80 | // return the valid neighbour area for your parent 81 | return tools::tuple::get(t); 82 | } 83 | // eval Global -no global 84 | }; 85 | } // namespace internal 86 | } // namespace visioncpp 87 | #endif // VISIONCPP_INCLUDE_FRAMEWORK_EVALUATOR_EVAL_EXPRESSION_EVAL_EXPR_STN_NO_FILT_HPP_ 88 | -------------------------------------------------------------------------------- /include/framework/evaluator/eval_expression/eval_expression.hpp: -------------------------------------------------------------------------------- 1 | // This file is part of VisionCpp, a lightweight C++ template library 2 | // for computer vision and image processing. 3 | // 4 | // Copyright (C) 2016 Codeplay Software Limited. All Rights Reserved. 5 | // 6 | // Contact: visioncpp@codeplay.com 7 | // 8 | // Licensed under the Apache License, Version 2.0 (the "License"); 9 | // you may not use this file except in compliance with the License. 10 | // You may obtain a copy of the License at 11 | // 12 | // http://www.apache.org/licenses/LICENSE-2.0 13 | // 14 | // Unless required by applicable law or agreed to in writing, software 15 | // distributed under the License is distributed on an "AS IS" BASIS, 16 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | // See the License for the specific language governing permissions and 18 | // limitations under the License. 19 | 20 | /// \file eval_expression.hpp 21 | /// \brief This file contains a collection of headers that required for 22 | /// eval_expression 23 | 24 | #ifndef VISIONCPP_INCLUDE_FRAMEWORK_EVALUATOR_EVAL_EXPRESSION_EVAL_EXPRESSION_HPP_ 25 | #define VISIONCPP_INCLUDE_FRAMEWORK_EVALUATOR_EVAL_EXPRESSION_EVAL_EXPRESSION_HPP_ 26 | 27 | #include "eval_expr_assign.hpp" 28 | #include "eval_expr_leaf_node.hpp" 29 | #include "eval_expr_r_binary.hpp" 30 | #include "eval_expr_r_unary.hpp" 31 | #include "eval_expr_reduction.hpp" 32 | #include "eval_expr_stn_filt.hpp" 33 | #include "eval_expr_stn_no_filt.hpp" 34 | #endif // VISIONCPP_INCLUDE_FRAMEWORK_EVALUATOR_EVAL_EXPRESSION_EVAL_EXPRESSION_HPP_ -------------------------------------------------------------------------------- /include/framework/evaluator/load_pattern/square_pattern.hpp: -------------------------------------------------------------------------------- 1 | // This file is part of VisionCpp, a lightweight C++ template library 2 | // for computer vision and image processing. 3 | // 4 | // Copyright (C) 2016 Codeplay Software Limited. All Rights Reserved. 5 | // 6 | // Contact: visioncpp@codeplay.com 7 | // 8 | // Licensed under the Apache License, Version 2.0 (the "License"); 9 | // you may not use this file except in compliance with the License. 10 | // You may obtain a copy of the License at 11 | // 12 | // http://www.apache.org/licenses/LICENSE-2.0 13 | // 14 | // Unless required by applicable law or agreed to in writing, software 15 | // distributed under the License is distributed on an "AS IS" BASIS, 16 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | // See the License for the specific language governing permissions and 18 | // limitations under the License. 19 | 20 | /// \file square_pattern.hpp 21 | /// \brief this file contains the partial specialisation of the Fill for 22 | /// LeafNode 23 | 24 | #ifndef VISIONCPP_INCLUDE_FRAMEWORK_EVALUATOR_LOAD_PATTERN_SQUARE_PATTERN_HPP_ 25 | #define VISIONCPP_INCLUDE_FRAMEWORK_EVALUATOR_LOAD_PATTERN_SQUARE_PATTERN_HPP_ 26 | 27 | namespace visioncpp { 28 | namespace internal { 29 | /// \brief Partial specialisation of the Fill when the LeafNode contains the 30 | /// const variable. In this case we load nothing in to the shared memory as 31 | /// there is no shared memory for const variable and the const variable directly 32 | /// copied to the device and accessed by each thread. 33 | template 35 | struct Fill, LVL>, 36 | Loc, Params...> { 37 | template 39 | static void fill_neighbour(Loc &cOffset, 40 | const tools::tuple::Tuple &t) { 41 | // no need to do anything the memory is read only 42 | } 43 | }; 44 | /// \brief Partial specialisation of the Fill when the LeafNode contains a sycl 45 | /// buffer created on constant memory. In this case we load nothing in to the 46 | /// shared memory as there is no shared memory created for a buffer on a device 47 | /// constant memory. Such a buffer is directly accessed on the device by each 48 | /// thread. 49 | template 51 | struct Fill< 52 | LeafNode, LVL>, 53 | Loc, Params...> { 54 | template 56 | static void fill_neighbour(Loc &cOffset, 57 | const tools::tuple::Tuple &t) {} 58 | }; 59 | /// \brief Partial specialisation of the Fill when the LeafNode contains the 60 | /// sycl buffer on the global memory. In this case each work group loads a 61 | /// rectangle block of (LR,LC) in to their dedicated local memory. 62 | template 64 | struct Fill, LVL>, Loc, 65 | Params...> { 66 | template 68 | static void fill_neighbour(Loc &cOffset, 69 | const tools::tuple::Tuple &t) { 70 | static_assert(Cols > 0 && LC > 0, "Cols must be greater than 0"); 71 | static_assert(Rows > 0 && LR > 0, "Rows must be greater than 0"); 72 | // calculation begins from here for unary op 73 | for (int i = 0; i < LC; i += cOffset.cLRng) { 74 | if ((cOffset.l_c + i < LC)) { 75 | size_t val_c = get_global_range(cOffset.g_c + i); 76 | for (size_t j = 0; j < LR; j += cOffset.rLRng) { 77 | size_t val_r = get_global_range(cOffset.g_r + j); 78 | if ((cOffset.l_r + j < LR)) { 79 | tools::tuple::get(t) 80 | .get_pointer()[(cOffset.l_c + i) + (LC * (cOffset.l_r + j))] = 81 | tools::convert(t))>::Type>( 83 | *(tools::tuple::get(t).get_pointer() + 84 | calculate_index(val_c, val_r, Cols, Rows))); 85 | /// FIXME: image cannot be accessed by pointer 86 | } 87 | } 88 | } 89 | } 90 | // here you need to put local barrier 91 | cOffset.barrier(); 92 | } 93 | }; 94 | 95 | // template deduction for Fill struct. 96 | template 99 | static void fill_local_neighbour(Loc &cOffset, 100 | const tools::tuple::Tuple &t) { 101 | Fill::template fill_neighbour< 102 | Halo_Top, Halo_Left, Halo_Butt, Halo_Right, Offset, LC, LR>(cOffset, t); 103 | } 104 | } // namespace internal 105 | } // namespace visioncpp 106 | #endif // VISIONCPP_INCLUDE_FRAMEWORK_EVALUATOR_LOAD_PATTERN_SQUARE_PATTERN_HPP_ 107 | -------------------------------------------------------------------------------- /include/framework/executor/policy/fuse.hpp: -------------------------------------------------------------------------------- 1 | // This file is part of VisionCpp, a lightweight C++ template library 2 | // for computer vision and image processing. 3 | // 4 | // Copyright (C) 2016 Codeplay Software Limited. All Rights Reserved. 5 | // 6 | // Contact: visioncpp@codeplay.com 7 | // 8 | // Licensed under the Apache License, Version 2.0 (the "License"); 9 | // you may not use this file except in compliance with the License. 10 | // You may obtain a copy of the License at 11 | // 12 | // http://www.apache.org/licenses/LICENSE-2.0 13 | // 14 | // Unless required by applicable law or agreed to in writing, software 15 | // distributed under the License is distributed on an "AS IS" BASIS, 16 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | // See the License for the specific language governing permissions and 18 | // limitations under the License. 19 | 20 | /// \file fuse.hpp 21 | /// \brief This file contains the specialisation of the FuseExpr for terminal and 22 | /// non-terminal nodes. 23 | 24 | #ifndef VISIONCPP_INCLUDE_FRAMEWORK_EXECUTOR_POLICY_FUSE_HPP_ 25 | #define VISIONCPP_INCLUDE_FRAMEWORK_EXECUTOR_POLICY_FUSE_HPP_ 26 | 27 | namespace visioncpp { 28 | namespace internal { 29 | /// \brief the FuseExpr when the expression type is not a terminal node 30 | /// (leafNode). 31 | template 32 | struct FuseExpr { 33 | /// \brief the fuse function for executing the given expr. 34 | /// \param expr : the expression passed to be executed on the device 35 | /// \param dev : the selected device for executing the expression 36 | /// return void 37 | static void fuse(Expr &expr, const DeviceT &dev) { 38 | /// LRT is the workgroup size row and is checked with LR. LR is based 39 | /// on LRIn. LCT is the workgroup size column checked with LC. LC is based 40 | /// on LCIn. The local memory size and the work group size is calculated at 41 | /// compile time. 42 | constexpr size_t LR = 43 | tools::IfConst<(Expr::RThread > LRIn), LRIn, Expr::RThread>::Value; 44 | constexpr size_t LC = 45 | tools::IfConst<(Expr::CThread > LCIn), LCIn, Expr::CThread>::Value; 46 | 47 | constexpr int rLThread = 48 | tools::IfConst<(Expr::RThread > LRT), LRT, Expr::RThread>::Value; 49 | 50 | constexpr int cLThread = 51 | tools::IfConst<(Expr::CThread > LCT), LCT, Expr::CThread>::Value; 52 | 53 | constexpr size_t rGThreads = 54 | (tools::IfConst<(Expr::RThread % LR == 0), (Expr::RThread / LR), 55 | ((Expr::RThread / LR) + 1)>::Value) * 56 | rLThread; 57 | 58 | constexpr size_t cGThreads = 59 | (tools::IfConst<(Expr::CThread % LC == 0), (Expr::CThread / LC), 60 | ((Expr::CThread / LC) + 1)>::Value) * 61 | cLThread; 62 | dev.template execute( 63 | expr); 64 | } 65 | }; 66 | /// \brief specialisation of Fuse struct when the Expr is a terminal node 67 | /// (leafNode) 68 | template 70 | struct FuseExpr, DeviceT> { 71 | /// when the node is a terminal node (leafNode) we do nothing as there is no 72 | /// need to run any expression 73 | static void fuse(LeafNode &expr, const DeviceT &dev) {} 74 | }; 75 | 76 | /// function fuse 77 | /// \brief fuse function to generate a device kernel and execute. 78 | /// template parameters: 79 | /// \tparam LC: suggested column size for the local memory 80 | /// \tparam LR: suggested row size for the local memory 81 | /// \tparam LRT: suggested workgroup row size 82 | /// \tparam LCT: suggested workgroup column size 83 | /// \tparam Expr: the expression type 84 | /// function parameters: 85 | /// \param expr: the input expression 86 | /// \param dev : the selected device for executing the expression 87 | template 89 | inline void fuse(Expr expr, const DeviceT &dev) { 90 | FuseExpr::fuse(expr, dev); 91 | }; 92 | } // internal 93 | } // visioncpp 94 | #endif // VISIONCPP_INCLUDE_FRAMEWORK_EXECUTOR_POLICY_FUSE_HPP_ 95 | -------------------------------------------------------------------------------- /include/framework/expr_convertor/expr_convertor.hpp: -------------------------------------------------------------------------------- 1 | // This file is part of VisionCpp, a lightweight C++ template library 2 | // for computer vision and image processing. 3 | // 4 | // Copyright (C) 2016 Codeplay Software Limited. All Rights Reserved. 5 | // 6 | // Contact: visioncpp@codeplay.com 7 | // 8 | // Licensed under the Apache License, Version 2.0 (the "License"); 9 | // you may not use this file except in compliance with the License. 10 | // You may obtain a copy of the License at 11 | // 12 | // http://www.apache.org/licenses/LICENSE-2.0 13 | // 14 | // Unless required by applicable law or agreed to in writing, software 15 | // distributed under the License is distributed on an "AS IS" BASIS, 16 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | // See the License for the specific language governing permissions and 18 | // limitations under the License. 19 | 20 | /// \file expr_convertor.hpp 21 | /// \brief this is used to replace the leaf node with a PlaceHolder node. 22 | 23 | #ifndef VISIONCPP_INCLUDE_FRAMEWORK_EXPR_CONVERTOR_EXPR_CONVERTOR_HPP_ 24 | #define VISIONCPP_INCLUDE_FRAMEWORK_EXPR_CONVERTOR_EXPR_CONVERTOR_HPP_ 25 | 26 | namespace visioncpp { 27 | namespace internal { 28 | /// \struct PlaceHolder 29 | /// \brief PlaceHolder is used to replace the Vision Memory in the LeafNode 30 | /// containing sycl buffer. PlaceHolder contains the order of the leaf node in 31 | /// the expression tree. 32 | /// template parameters: 33 | /// \tparam Memory_Type: represents the type of the memory 34 | /// \tparam N: represents the order of the visionMemory in the LeafNode 35 | /// \tparam C: contains the column size of the visionMemory 36 | /// \tparam R: contains the row size of the visionMemory 37 | template 38 | struct PlaceHolder { 39 | static constexpr size_t I = N; 40 | static constexpr size_t Cols = C; 41 | static constexpr size_t Rows = R; 42 | static constexpr size_t LeafType = Memory_Type; 43 | using Type = PlaceHolder; 44 | using OutType = Type; 45 | static constexpr size_t Scope = Sc; 46 | }; 47 | 48 | /// \brief LocalOutput:Local output is used for neighbour operation in order to 49 | /// create a local memory for the output of non-terminal nodes in the expression 50 | /// tree when the NeighbourOP is used. 51 | template 52 | struct LocalOutput; 53 | 54 | /// \brief is used to count the total number of leafNode in the expression tree. 55 | template 56 | struct LeafCount; 57 | /// \brief is used to count the total number of local memory for the 58 | /// subxpression. 59 | template 60 | struct LocalMemCount; 61 | 62 | // template 63 | // struct PlaceHolder; 64 | /// \brief it is used to create the PlaceHolder expression. The PlaceHolder 65 | /// expression is a copy of expression type where the visionMemory of the 66 | /// leaf node has been replaced with PlaceHolder. 67 | template 68 | struct MakePlaceHolderExprHelper; 69 | 70 | } // internal 71 | } // visioncpp 72 | // Static Operation Over Type 73 | #include "leaf_count.hpp" 74 | #include "local_mem_count.hpp" 75 | #include "local_output.hpp" 76 | #include "make_place_holder_expr.hpp" 77 | #include "place_holder_leaf_node.hpp" 78 | #endif // VISIONCPP_INCLUDE_FRAMEWORK_EXPR_CONVERTOR_EXPR_CONVERTOR_HPP_ 79 | -------------------------------------------------------------------------------- /include/framework/expr_convertor/leaf_count.hpp: -------------------------------------------------------------------------------- 1 | // This file is part of VisionCpp, a lightweight C++ template library 2 | // for computer vision and image processing. 3 | // 4 | // Copyright (C) 2016 Codeplay Software Limited. All Rights Reserved. 5 | // 6 | // Contact: visioncpp@codeplay.com 7 | // 8 | // Licensed under the Apache License, Version 2.0 (the "License"); 9 | // you may not use this file except in compliance with the License. 10 | // You may obtain a copy of the License at 11 | // 12 | // http://www.apache.org/licenses/LICENSE-2.0 13 | // 14 | // Unless required by applicable law or agreed to in writing, software 15 | // distributed under the License is distributed on an "AS IS" BASIS, 16 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | // See the License for the specific language governing permissions and 18 | // limitations under the License. 19 | 20 | /// \file leaf_count.hpp 21 | /// \brief LeafCount used to counting terminal nodes. The total number of 22 | /// leaf nodes is used by MakePlaceHolderExprHelper to statically find the order 23 | /// of the leaf node in a expression tree. 24 | 25 | #ifndef VISIONCPP_INCLUDE_FRAMEWORK_EXPR_CONVERTOR_LEAF_COUNT_HPP_ 26 | #define VISIONCPP_INCLUDE_FRAMEWORK_EXPR_CONVERTOR_LEAF_COUNT_HPP_ 27 | 28 | namespace visioncpp { 29 | namespace internal { 30 | /// \brief specialisation of LeafCount when the node is a LeafNode 31 | /// template parameters: 32 | /// \param RHS is the visionMemory 33 | /// \param LVL shows the level of the node in the expression tree 34 | template 35 | struct LeafCount> { 36 | static constexpr size_t Count = 1; 37 | }; 38 | 39 | /// \brief specialisation of LeafCount when the node has one child 40 | /// template parameters: 41 | /// \param RHS is the right-hand side expression of the node 42 | /// \param LVL shows the level of the node in the expression tree 43 | template 44 | struct LeafCount { 45 | static constexpr size_t Count = 46 | 0 + LeafCount::Count; 47 | }; 48 | /// \brief specialisation of LeafCount when the node has two children 49 | /// template parameters: 50 | /// \param LHS is the left-hand side expression in the node 51 | /// \param RHS is the right-hand side expression in the node 52 | /// \param LVL shows the level of the node in the expression tree 53 | template 54 | struct LeafCount { 55 | static constexpr size_t Count = 56 | 0 + LeafCount::Count + 57 | LeafCount::Count; 58 | }; 59 | } // internal 60 | } // visioncpp 61 | #endif // VISIONCPP_INCLUDE_FRAMEWORK_EXPR_CONVERTOR_LEAF_COUNT_HPP_ -------------------------------------------------------------------------------- /include/framework/expr_convertor/local_mem_count.hpp: -------------------------------------------------------------------------------- 1 | // This file is part of VisionCpp, a lightweight C++ template library 2 | // for computer vision and image processing. 3 | // 4 | // Copyright (C) 2016 Codeplay Software Limited. All Rights Reserved. 5 | // 6 | // Contact: visioncpp@codeplay.com 7 | // 8 | // Licensed under the Apache License, Version 2.0 (the "License"); 9 | // you may not use this file except in compliance with the License. 10 | // You may obtain a copy of the License at 11 | // 12 | // http://www.apache.org/licenses/LICENSE-2.0 13 | // 14 | // Unless required by applicable law or agreed to in writing, software 15 | // distributed under the License is distributed on an "AS IS" BASIS, 16 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | // See the License for the specific language governing permissions and 18 | // limitations under the License. 19 | 20 | /// \file local_mem_count.hpp 21 | /// \brief LocalmemCount used to counting terminal nodes. The total number of 22 | /// leaf nodes is used by MakePlaceHolderExprHelper to statically find the order 23 | /// of the leaf node in a expression tree. 24 | 25 | #ifndef VISIONCPP_INCLUDE_FRAMEWORK_EXPR_CONVERTOR_LOCAL_MEM_COUNT_HPP_ 26 | #define VISIONCPP_INCLUDE_FRAMEWORK_EXPR_CONVERTOR_LOCAL_MEM_COUNT_HPP_ 27 | 28 | namespace visioncpp { 29 | namespace internal { 30 | /// \brief Partial specialisation of the LocalmemCount when the LeafNode contains 31 | /// the const variable. In this case there is no shared memory for const 32 | /// variable and the const variable is directly copied to the device and accessed 33 | /// by each thread. 34 | template 35 | struct LocalMemCount< 36 | expr_category::Unary, 37 | LeafNode, 38 | LVL>> { 39 | static constexpr size_t Count = 0; 40 | }; 41 | /// \brief Partial specialisation of the LocalmemCount when the LeafNode contains 42 | /// a sycl buffer created on constant memory. There is no shared memory created 43 | /// for a buffer on a device constant memory. Such a buffer is directly accessed 44 | /// on the device by each thread. 45 | template 46 | struct LocalMemCount< 47 | expr_category::Unary, 48 | LeafNode, LVL>> { 49 | static constexpr size_t Count = 0; 50 | }; 51 | 52 | /// \brief specialisation of LocalmemCount when the node is a LeafNode 53 | /// template parameters: 54 | /// \param RHS is the visionMemory 55 | /// \param LVL shows the level of the node in the expression tree 56 | template 57 | struct LocalMemCount> { 58 | static constexpr size_t Count = 1; 59 | }; 60 | 61 | /// template parameters: 62 | /// \brief specialisation of LocalmemCount when the node has one child 63 | /// \param RHS is the right-hand side expression of the node 64 | /// \param LVL shows the level of the node in the expression tree 65 | template 66 | struct LocalMemCount { 67 | static constexpr size_t Count = 68 | 1 + 69 | LocalMemCount::Count; 70 | }; 71 | /// \brief specialisation of LocalmemCount when the node has two children 72 | /// template parameters: 73 | /// \param LHS is the left-hand side expression in the node 74 | /// \param RHS is the right-hand side expression in the node 75 | /// \param LVL shows the level of the node in the expression tree 76 | template 77 | struct LocalMemCount { 78 | static constexpr size_t Count = 79 | 1 + 80 | LocalMemCount::Count + 81 | LocalMemCount::Count; 82 | }; 83 | 84 | /// \brief Specialisation of ExtractAccessor class where the expression node is 85 | /// Assign 86 | template 88 | struct LocalMemCount> { 90 | static constexpr size_t Count = 91 | 0 + LocalMemCount::Count; 92 | }; 93 | 94 | /// \brief Specialisation of ExtractAccessor class where the expression node is 95 | /// is ParallelCopy (partial assign) 96 | template 99 | struct LocalMemCount< 100 | expr_category::Binary, 101 | ParallelCopy> { 103 | static constexpr size_t Count = 104 | 0 + LocalMemCount::Count; 105 | }; 106 | 107 | } // internal 108 | } // visioncpp 109 | #endif // VISIONCPP_INCLUDE_FRAMEWORK_EXPR_CONVERTOR_LOCAL_MEM_COUNT_HPP_ 110 | -------------------------------------------------------------------------------- /include/framework/expr_convertor/make_place_holder_expr.hpp: -------------------------------------------------------------------------------- 1 | // This file is part of VisionCpp, a lightweight C++ template library 2 | // for computer vision and image processing. 3 | // 4 | // Copyright (C) 2016 Codeplay Software Limited. All Rights Reserved. 5 | // 6 | // Contact: visioncpp@codeplay.com 7 | // 8 | // Licensed under the Apache License, Version 2.0 (the "License"); 9 | // you may not use this file except in compliance with the License. 10 | // You may obtain a copy of the License at 11 | // 12 | // http://www.apache.org/licenses/LICENSE-2.0 13 | // 14 | // Unless required by applicable law or agreed to in writing, software 15 | // distributed under the License is distributed on an "AS IS" BASIS, 16 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | // See the License for the specific language governing permissions and 18 | // limitations under the License. 19 | 20 | /// \file make_place_holder_expr.hpp 21 | /// \brief PlaceHolder expression helper is used to create an expression in 22 | /// which the leafNodes of visionMemories has been replaced by leafNodes of 23 | /// PlaceHolders. 24 | 25 | #ifndef VISIONCPP_INCLUDE_FRAMEWORK_EXPR_CONVERTOR_MAKE_PLACE_HOLDER_EXPR_HPP_ 26 | #define VISIONCPP_INCLUDE_FRAMEWORK_EXPR_CONVERTOR_MAKE_PLACE_HOLDER_EXPR_HPP_ 27 | 28 | namespace visioncpp { 29 | namespace internal { 30 | /// \brief specialisation of MakePlaceHolderExprHelper where the node is 31 | /// leaf node. 32 | template 33 | struct MakePlaceHolderExprHelper, N> { 35 | using Type = 36 | LeafNode, 37 | LVL>; 38 | }; 39 | /// \brief specialisation of MakePlaceHolderExprHelper where the operation of 40 | /// the node is unary (the node has one child). 41 | template 42 | struct MakePlaceHolderExprHelper { 43 | using RHSPlaceHolderType = 44 | typename MakePlaceHolderExprHelper::Type; 46 | using Type = typename Expr::template ExprExchange; 47 | }; 48 | /// \brief specialisation of MakePlaceHolderExprHelper where the operation of 49 | /// the node is binary (the node has two children). 50 | template 51 | struct MakePlaceHolderExprHelper { 52 | static constexpr size_t RHSLeafCount = 53 | LeafCount::Count; 54 | 55 | using LHSPlaceHolderType = 56 | typename MakePlaceHolderExprHelper::Type; 59 | using RHSPlaceHolderType = 60 | typename MakePlaceHolderExprHelper::Type; 62 | 63 | using Type = typename Expr::template ExprExchange; 65 | }; 66 | } // internal 67 | } // visioncpp 68 | #endif // VISIONCPP_INCLUDE_FRAMEWORK_EXPR_CONVERTOR_MAKE_PLACE_HOLDER_EXPR_HPP_ -------------------------------------------------------------------------------- /include/framework/expr_convertor/place_holder_leaf_node.hpp: -------------------------------------------------------------------------------- 1 | // This file is part of VisionCpp, a lightweight C++ template library 2 | // for computer vision and image processing. 3 | // 4 | // Copyright (C) 2016 Codeplay Software Limited. All Rights Reserved. 5 | // 6 | // Contact: visioncpp@codeplay.com 7 | // 8 | // Licensed under the Apache License, Version 2.0 (the "License"); 9 | // you may not use this file except in compliance with the License. 10 | // You may obtain a copy of the License at 11 | // 12 | // http://www.apache.org/licenses/LICENSE-2.0 13 | // 14 | // Unless required by applicable law or agreed to in writing, software 15 | // distributed under the License is distributed on an "AS IS" BASIS, 16 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | // See the License for the specific language governing permissions and 18 | // limitations under the License. 19 | 20 | /// \file place_holder_leaf_node.hpp 21 | /// \brief This file contains different specialisations leafNodes for different 22 | /// types of memory. 23 | 24 | #ifndef VISIONCPP_INCLUDE_FRAMEWORK_EXPR_CONVERTOR_PLACE_HOLDER_LEAF_NODE_HPP_ 25 | #define VISIONCPP_INCLUDE_FRAMEWORK_EXPR_CONVERTOR_PLACE_HOLDER_LEAF_NODE_HPP_ 26 | 27 | namespace visioncpp { 28 | namespace internal { 29 | /// The specialisation of LeafNode for the PlaceHolder. It is used to store the 30 | /// information of visionMemory. 31 | /// template parameters: 32 | /// \param Memory_Type : determines the type of the memory {Buffer2D, Buffer1D, 33 | /// Host, Image} 34 | /// \param N: is the position of the leafNode in the expression tree 35 | /// \param C is the column size of the visionMemory 36 | /// \param R is the row size of the visionMemory 37 | /// \param LVL represents the level of the node in the expression tree. 38 | template 40 | struct LeafNode, LVL> { 41 | static constexpr bool PointOp = true; 42 | static constexpr size_t LeafType = Memory_Type; 43 | using RHSExpr = PlaceHolder; 44 | using Type = typename RHSExpr::Type; 45 | using OutType = typename RHSExpr::OutType; 46 | static constexpr size_t RThread = Type::Rows; 47 | static constexpr size_t CThread = Type::Cols; 48 | static constexpr size_t ND_Category = internal::expr_category::Unary; 49 | static constexpr size_t Level = N; 50 | static constexpr bool SubExpressionEvaluationNeeded = false; 51 | static constexpr size_t Operation_type = internal::ops_category::PointOP; 52 | using Sub_expression_Type = 53 | LeafNode, LVL>; 54 | template 56 | Sub_expression_Type inline sub_expression_evaluation(const DeviceT &); 57 | }; 58 | } // internal 59 | } // visioncpp 60 | #endif // VISIONCPP_INCLUDE_FRAMEWORK_EXPR_CONVERTOR_PLACE_HOLDER_LEAF_NODE_HPP_ 61 | -------------------------------------------------------------------------------- /include/framework/expr_tree/expr_tree.hpp: -------------------------------------------------------------------------------- 1 | // This file is part of VisionCpp, a lightweight C++ template library 2 | // for computer vision and image processing. 3 | // 4 | // Copyright (C) 2016 Codeplay Software Limited. All Rights Reserved. 5 | // 6 | // Contact: visioncpp@codeplay.com 7 | // 8 | // Licensed under the Apache License, Version 2.0 (the "License"); 9 | // you may not use this file except in compliance with the License. 10 | // You may obtain a copy of the License at 11 | // 12 | // http://www.apache.org/licenses/LICENSE-2.0 13 | // 14 | // Unless required by applicable law or agreed to in writing, software 15 | // distributed under the License is distributed on an "AS IS" BASIS, 16 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | // See the License for the specific language governing permissions and 18 | // limitations under the License. 19 | 20 | /// \file expr_tree.hpp 21 | /// \brief This file contains the forward declarations and all the necessary 22 | /// include headers for the construction of static expression trees. 23 | 24 | #ifndef VISIONCPP_INCLUDE_FRAMEWORK_EXPR_TREE_EXPR_TREE_HPP_ 25 | #define VISIONCPP_INCLUDE_FRAMEWORK_EXPR_TREE_EXPR_TREE_HPP_ 26 | 27 | namespace visioncpp { 28 | namespace internal { 29 | /// \struct GlobalUnaryOp 30 | /// \brief This class is used to encapsulate the global unary functor and the 31 | /// types of each operand in this functor. The functor passed to this struct 32 | /// applies global neighbour. This struct is used for global neighbour operation 33 | /// template parameters: 34 | /// \tparam USROP : the user/built-in functor 35 | /// \tparam InTp the input type for that unary functor 36 | template 37 | struct GlobalUnaryOp { 38 | using OP = USROP; 39 | using InType = InTp; 40 | visioncpp::internal::GlobalNeighbour x; 41 | using OutType = decltype(OP()(x)); 42 | static constexpr size_t Operation_type = 43 | internal::ops_category::GlobalNeighbourOP; 44 | }; 45 | /// \struct LocalUnaryOp 46 | /// \brief This class is used to encapsulate the local unary functor and the 47 | /// types of each operand in this functor. The functor passed to this struct 48 | /// applies local neighbour. This struct is used for local neighbour operation 49 | /// template parameters: 50 | /// \tparam USROP : the user/built-in functor 51 | /// \tparam InTp the input type for that unary functor 52 | template 53 | struct LocalUnaryOp { 54 | using OP = USROP; 55 | using InType = InTp; 56 | visioncpp::internal::LocalNeighbour x; 57 | using OutType = decltype(OP()(x)); 58 | static constexpr size_t Operation_type = internal::ops_category::NeighbourOP; 59 | }; 60 | /// \struct LocalBinaryOp 61 | /// \brief This class is used to encapsulate the local binary functor and the 62 | /// types of each operand in this functor. The functor passed to this struct 63 | /// applies local neighbour. This struct is used for local neighbour operation. 64 | /// template parameters: 65 | /// \tparam USROP : the user/built-in functor 66 | /// \tparam InTp1 the left hand side input type for the binary functor 67 | /// \tparam InTp2 the right hand side input type for the binary functor 68 | template 69 | struct LocalBinaryOp { 70 | using OP = USROP; 71 | using InType1 = InTp1; 72 | using InType2 = InTp2; 73 | visioncpp::internal::LocalNeighbour x; 74 | visioncpp::internal::ConstNeighbour y; 75 | using OutType = decltype(OP()(x, y)); 76 | static constexpr size_t Operation_type = internal::ops_category::NeighbourOP; 77 | }; 78 | /// \struct PixelUnaryOp 79 | /// \brief This class is used to encapsulate the unary point operation functor 80 | /// and the types of each operand in this functor. The functor passed to this 81 | /// struct applies point operation. This struct is used for point operation. 82 | /// template parameters: 83 | /// \tparam USROP : the user/built-in functor 84 | /// \tparam InTp the right-hand side input type for the unary functor 85 | template 86 | struct PixelUnaryOp { 87 | using OP = USROP; 88 | using InType = InTp; 89 | InType x; 90 | using OutType = decltype(OP()(x)); 91 | }; 92 | /// \struct PixelBinaryOp 93 | /// \brief This class is used to encapsulate the binary point operation functor 94 | /// and the types of each operand in this functor. The functor passed to this 95 | /// struct applies point operation. This struct is used for point operation. 96 | /// template parameters: 97 | /// \tparam USROP : the user/built-in functor 98 | /// \tparam InTp1 the left-hand side input type for the binary functor 99 | /// \tparam InTp2 the right-hand side input type for the binary functor 100 | template 101 | struct PixelBinaryOp { 102 | using OP = USROP; 103 | using InType1 = InTp1; 104 | using InType2 = InTp2; 105 | InType1 x; 106 | InType2 y; 107 | using OutType = decltype(OP()(x, y)); 108 | }; 109 | 110 | } // internal 111 | } // visioncpp 112 | // Expression Tree headers 113 | #include "neighbour_ops/neighbour_ops.hpp" 114 | #include "point_ops/point_ops.hpp" 115 | // here it should be 116 | #include "complex_ops/complex_ops.hpp" 117 | #endif // VISIONCPP_INCLUDE_FRAMEWORK_EXPR_TREE_EXPR_TREE_HPP_ 118 | -------------------------------------------------------------------------------- /include/framework/expr_tree/neighbour_ops/neighbour_ops.hpp: -------------------------------------------------------------------------------- 1 | // This file is part of VisionCpp, a lightweight C++ template library 2 | // for computer vision and image processing. 3 | // 4 | // Copyright (C) 2016 Codeplay Software Limited. All Rights Reserved. 5 | // 6 | // Contact: visioncpp@codeplay.com 7 | // 8 | // Licensed under the Apache License, Version 2.0 (the "License"); 9 | // you may not use this file except in compliance with the License. 10 | // You may obtain a copy of the License at 11 | // 12 | // http://www.apache.org/licenses/LICENSE-2.0 13 | // 14 | // Unless required by applicable law or agreed to in writing, software 15 | // distributed under the License is distributed on an "AS IS" BASIS, 16 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | // See the License for the specific language governing permissions and 18 | // limitations under the License. 19 | 20 | /// \file neighbour_ops.hpp 21 | /// \brief This file contains a set of includes used to construct neighbour 22 | /// nodes in expression tree 23 | 24 | #ifndef VISIONCPP_INCLUDE_FRAMEWORK_EXPR_TREE_NEIGHBOUR_OPS_NEIGHBOUR_OPS_HPP_ 25 | #define VISIONCPP_INCLUDE_FRAMEWORK_EXPR_TREE_NEIGHBOUR_OPS_NEIGHBOUR_OPS_HPP_ 26 | 27 | #include "reduction.hpp" 28 | #include "stencil_no_filter.hpp" 29 | #include "stencil_with_filter.hpp" 30 | #endif // VISIONCPP_INCLUDE_FRAMEWORK_EXPR_TREE_NEIGHBOUR_OPS_NEIGHBOUR_OPS_HPP_ 31 | -------------------------------------------------------------------------------- /include/framework/expr_tree/point_ops/point_ops.hpp: -------------------------------------------------------------------------------- 1 | // This file is part of VisionCpp, a lightweight C++ template library 2 | // for computer vision and image processing. 3 | // 4 | // Copyright (C) 2016 Codeplay Software Limited. All Rights Reserved. 5 | // 6 | // Contact: visioncpp@codeplay.com 7 | // 8 | // Licensed under the Apache License, Version 2.0 (the "License"); 9 | // you may not use this file except in compliance with the License. 10 | // You may obtain a copy of the License at 11 | // 12 | // http://www.apache.org/licenses/LICENSE-2.0 13 | // 14 | // Unless required by applicable law or agreed to in writing, software 15 | // distributed under the License is distributed on an "AS IS" BASIS, 16 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | // See the License for the specific language governing permissions and 18 | // limitations under the License. 19 | 20 | /// \file point_ops.hpp 21 | /// \brief This files contains a set of include headers for point operation node 22 | /// in the expression tree 23 | 24 | #ifndef VISIONCPP_INCLUDE_FRAMEWORK_EXPR_TREE_POINT_OPS_POINT_OPS_HPP_ 25 | #define VISIONCPP_INCLUDE_FRAMEWORK_EXPR_TREE_POINT_OPS_POINT_OPS_HPP_ 26 | 27 | #include "assign.hpp" 28 | #include "leaf_node.hpp" 29 | #include "parallel_copy.hpp" 30 | #include "resizable_binary.hpp" 31 | #include "resizable_unary.hpp" 32 | #endif // VISIONCPP_INCLUDE_FRAMEWORK_EXPR_TREE_POINT_OPS_POINT_OPS_HPP_ -------------------------------------------------------------------------------- /include/framework/framework.hpp: -------------------------------------------------------------------------------- 1 | // This file is part of VisionCpp, a lightweight C++ template library 2 | // for computer vision and image processing. 3 | // 4 | // Copyright (C) 2016 Codeplay Software Limited. All Rights Reserved. 5 | // 6 | // Contact: visioncpp@codeplay.com 7 | // 8 | // Licensed under the Apache License, Version 2.0 (the "License"); 9 | // you may not use this file except in compliance with the License. 10 | // You may obtain a copy of the License at 11 | // 12 | // http://www.apache.org/licenses/LICENSE-2.0 13 | // 14 | // Unless required by applicable law or agreed to in writing, software 15 | // distributed under the License is distributed on an "AS IS" BASIS, 16 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | // See the License for the specific language governing permissions and 18 | // limitations under the License. 19 | 20 | /// \file framework.hpp 21 | /// \brief Collection of VisionCpp framework headers. 22 | 23 | #ifndef VISIONCPP_INCLUDE_FRAMEWORK_FRAMEWORK_HPP_ 24 | #define VISIONCPP_INCLUDE_FRAMEWORK_FRAMEWORK_HPP_ 25 | 26 | // including all the claas name required by the framework 27 | #include "forward_declarations.hpp" 28 | 29 | // include tools headers 30 | #include "tools/tools.hpp" 31 | 32 | // include memory headers 33 | #include "memory/memory.hpp" 34 | 35 | // expression with placeholder leafnode includes 36 | #include "expr_convertor/expr_convertor.hpp" 37 | 38 | // Expression Tree headers 39 | #include "expr_tree/expr_tree.hpp" 40 | 41 | // Evaluation tree headers 42 | #include "evaluator/evaluator.hpp" 43 | 44 | // Executor Policies 45 | #include "executor/executor.hpp" 46 | 47 | // devices used to execute the code 48 | #include "device/device.hpp" 49 | #endif // VISIONCPP_INCLUDE_FRAMEWORK_FRAMEWORK_HPP_ 50 | -------------------------------------------------------------------------------- /include/framework/memory/mem_const.hpp: -------------------------------------------------------------------------------- 1 | // This file is part of VisionCpp, a lightweight C++ template library 2 | // for computer vision and image processing. 3 | // 4 | // Copyright (C) 2016 Codeplay Software Limited. All Rights Reserved. 5 | // 6 | // Contact: visioncpp@codeplay.com 7 | // 8 | // Licensed under the Apache License, Version 2.0 (the "License"); 9 | // you may not use this file except in compliance with the License. 10 | // You may obtain a copy of the License at 11 | // 12 | // http://www.apache.org/licenses/LICENSE-2.0 13 | // 14 | // Unless required by applicable law or agreed to in writing, software 15 | // distributed under the License is distributed on an "AS IS" BASIS, 16 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | // See the License for the specific language governing permissions and 18 | // limitations under the License. 19 | 20 | /// \file mem_const.hpp 21 | /// \brief specialisations of SyclMem type when we are passing constant variable 22 | /// to the device. In this case we are not using syclbuffer which can be stored 23 | /// on device memory. we have created struct supporting c++ standard layout. 24 | /// Therefore, the constant variable can be detectable by sycl compiler on the 25 | /// device side and each thread can have a copy of it on the private memory. 26 | 27 | #ifndef VISIONCPP_INCLUDE_FRAMEWORK_MEMORY_MEM_CONST_HPP_ 28 | #define VISIONCPP_INCLUDE_FRAMEWORK_MEMORY_MEM_CONST_HPP_ 29 | 30 | namespace visioncpp { 31 | namespace internal { 32 | /// \struct ConstMemory 33 | /// \brief represents a c++ standard layout for detecting constant variable on 34 | /// the device. 35 | /// template parameters: 36 | /// \tparam T: the type of the constant variable 37 | template 38 | struct ConstMemory { 39 | ConstMemory(T r) : r(r) {} 40 | template 41 | ConstMemory(T r, T2 &x) 42 | : ConstMemory(r) {} 43 | using value_type = T; 44 | const T r; 45 | const value_type &operator[](cl::sycl::nd_item<2> itemID) const { return r; } 46 | const value_type &operator[](cl::sycl::nd_item<1> itemID) const { return r; } 47 | const value_type &operator[](cl::sycl::id<2> itemID) const { return r; } 48 | const value_type &operator[](int itemID) const { return r; } 49 | const value_type &operator[](size_t itemID) const { return r; } 50 | /// this function is used to mimic the getpointer function used by evaluator 51 | /// expression, in order to access a ConstMemory Node. 52 | /// \return ConstMemory 53 | const ConstMemory &get_pointer() const { return *this; } 54 | }; 55 | } // internal 56 | } // visioncpp 57 | #endif // VISIONCPP_INCLUDE_FRAMEWORK_MEMORY_MEM_CONST_HPP_ -------------------------------------------------------------------------------- /include/framework/memory/mem_prop.hpp: -------------------------------------------------------------------------------- 1 | // This file is part of VisionCpp, a lightweight C++ template library 2 | // for computer vision and image processing. 3 | // 4 | // Copyright (C) 2016 Codeplay Software Limited. All Rights Reserved. 5 | // 6 | // Contact: visioncpp@codeplay.com 7 | // 8 | // Licensed under the Apache License, Version 2.0 (the "License"); 9 | // you may not use this file except in compliance with the License. 10 | // You may obtain a copy of the License at 11 | // 12 | // http://www.apache.org/licenses/LICENSE-2.0 13 | // 14 | // Unless required by applicable law or agreed to in writing, software 15 | // distributed under the License is distributed on an "AS IS" BASIS, 16 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | // See the License for the specific language governing permissions and 18 | // limitations under the License. 19 | 20 | /// \file mem_prop.hpp 21 | /// \brief Series of pixel convert functions. 22 | 23 | #ifndef VISIONCPP_INCLUDE_FRAMEWORK_MEMORY_MEM_PROP_HPP_ 24 | #define VISIONCPP_INCLUDE_FRAMEWORK_MEMORY_MEM_PROP_HPP_ 25 | 26 | namespace visioncpp { 27 | namespace internal { 28 | 29 | /// \brief This file is used to detect the ChannelType ElementCategory {basic or 30 | /// struct}, and the channel size of a row input data 31 | template 32 | struct MemoryProperties { 33 | static constexpr size_t ElementCategory = element_category::Struct; 34 | using ChannelType = typename ElementTp::data_type; 35 | static constexpr size_t ChannelSize = ElementTp::elements; 36 | }; 37 | 38 | /// \brief Specialisation of the MemoryProperties when the output is unsigned 39 | /// char 40 | template <> 41 | struct MemoryProperties { 42 | static constexpr size_t ElementCategory = element_category::Basic; 43 | using ChannelType = unsigned char; 44 | static constexpr size_t ChannelSize = 1; 45 | }; 46 | 47 | /// \brief Specialisation of the MemoryProperties when the output is char 48 | template <> 49 | struct MemoryProperties { 50 | static constexpr size_t ElementCategory = element_category::Basic; 51 | using ChannelType = char; 52 | static constexpr size_t ChannelSize = 1; 53 | }; 54 | 55 | /// \brief Specialisation of the MemoryProperties when the output is unsigned 56 | /// short 57 | template <> 58 | struct MemoryProperties { 59 | static constexpr size_t ElementCategory = element_category::Basic; 60 | using ChannelType = unsigned short; 61 | static constexpr size_t ChannelSize = 1; 62 | }; 63 | 64 | /// \brief Specialisation of the MemoryProperties when the output is short 65 | template <> 66 | struct MemoryProperties { 67 | static constexpr size_t ElementCategory = element_category::Basic; 68 | using ChannelType = short; 69 | static constexpr size_t ChannelSize = 1; 70 | }; 71 | 72 | /// \brief Specialisation of the MemoryProperties when the output is unsigned 73 | /// int 74 | template <> 75 | struct MemoryProperties { 76 | static constexpr size_t ElementCategory = element_category::Basic; 77 | using ChannelType = unsigned int; 78 | static constexpr size_t ChannelSize = 1; 79 | }; 80 | 81 | /// \brief Specialisation of the MemoryProperties when the output is int 82 | template <> 83 | struct MemoryProperties { 84 | static constexpr size_t ElementCategory = element_category::Basic; 85 | using ChannelType = int; 86 | static constexpr size_t ChannelSize = 1; 87 | }; 88 | 89 | /// \brief Specialisation of the MemoryProperties when the output is float 90 | template <> 91 | struct MemoryProperties { 92 | static constexpr size_t ElementCategory = element_category::Basic; 93 | using ChannelType = float; 94 | static constexpr size_t ChannelSize = 1; 95 | }; 96 | } // internal 97 | } // visioncpp 98 | #endif // VISIONCPP_INCLUDE_FRAMEWORK_MEMORY_MEM_PROP_HPP_ 99 | -------------------------------------------------------------------------------- /include/framework/memory/memory_access/mem_coordinate.hpp: -------------------------------------------------------------------------------- 1 | // This file is part of VisionCpp, a lightweight C++ template library 2 | // for computer vision and image processing. 3 | // 4 | // Copyright (C) 2016 Codeplay Software Limited. All Rights Reserved. 5 | // 6 | // Contact: visioncpp@codeplay.com 7 | // 8 | // Licensed under the Apache License, Version 2.0 (the "License"); 9 | // you may not use this file except in compliance with the License. 10 | // You may obtain a copy of the License at 11 | // 12 | // http://www.apache.org/licenses/LICENSE-2.0 13 | // 14 | // Unless required by applicable law or agreed to in writing, software 15 | // distributed under the License is distributed on an "AS IS" BASIS, 16 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | // See the License for the specific language governing permissions and 18 | // limitations under the License. 19 | 20 | /// \file mem_coordinate.hpp 21 | /// \brief This files contains the Coordinate struct which is used to specify 22 | /// local/global offset for local/global access to the local/global memory for 23 | /// each thread on the device. 24 | 25 | #ifndef VISIONCPP_INCLUDE_FRAMEWORK_MEMORY_MEMORY_ACCESS_MEM_COORDINATE_HPP_ 26 | #define VISIONCPP_INCLUDE_FRAMEWORK_MEMORY_MEMORY_ACCESS_MEM_COORDINATE_HPP_ 27 | 28 | // these two must be switched for row-major 29 | namespace visioncpp { 30 | namespace internal { 31 | /// \brief Color / Row-major option 32 | namespace mem_dim { 33 | /// \brief when the sycl change the dim this should be applied and work 34 | /// ColDim=1 and RowDim==0; 35 | static constexpr size_t ColDim = 0; 36 | static constexpr size_t RowDim = 1; 37 | }; 38 | /// \struct Coordinate 39 | /// \brief Coordinate is used to specify 40 | /// local/global offset for local/global access to the local/global memory for 41 | /// each thread on the device. 42 | /// template parameters: 43 | /// \tparam LC The column size for local memory 44 | /// \tparam LR The Row size for the local memory 45 | /// \tparam ItemID provided by sycl 46 | template 47 | struct Coordinate { 48 | Coordinate(ItemID itemID) 49 | : itemID(itemID), 50 | cLRng(itemID.get_local_range()[mem_dim::ColDim]), 51 | rLRng(itemID.get_local_range()[mem_dim::RowDim]), 52 | pointOp_gc(0), 53 | pointOp_gr(0), 54 | g_c(itemID.get_local_id(mem_dim::ColDim) + 55 | (itemID.get_group(mem_dim::ColDim) * ((LC / cLRng) * cLRng))), 56 | g_r(itemID.get_local_id(mem_dim::RowDim) + 57 | itemID.get_group(mem_dim::RowDim) * ((LR / rLRng) * rLRng)), 58 | l_c(itemID.get_local_id(mem_dim::ColDim)), 59 | l_r(itemID.get_local_id(mem_dim::RowDim)) {} 60 | 61 | /// function barrier is used to call sycl local barrier for local threads 62 | /// \return void 63 | inline void barrier() { 64 | itemID.barrier(cl::sycl::access::fence_space::local_space); 65 | } 66 | // function global_barrier is used to call sycl local barrier for global 67 | // threads 68 | /// \return void 69 | inline void global_barrier() { 70 | itemID.barrier(cl::sycl::access::fence_space::global_space); 71 | } 72 | 73 | ItemID itemID; 74 | size_t cLRng; 75 | size_t rLRng; 76 | size_t pointOp_gc; 77 | size_t pointOp_gr; 78 | size_t g_c; 79 | size_t g_r; 80 | size_t l_c; 81 | size_t l_r; 82 | }; 83 | /// deduction function for Coordinate 84 | template 85 | Coordinate memLocation(ItemID itemID) { 86 | return Coordinate(itemID); 87 | } 88 | } // internal 89 | } // visioncpp 90 | #endif // VISIONCPP_INCLUDE_FRAMEWORK_MEMORY_MEMORY_ACCESS_MEM_COORDINATE_HPP_ 91 | -------------------------------------------------------------------------------- /include/framework/tools/static_if.hpp: -------------------------------------------------------------------------------- 1 | // This file is part of VisionCpp, a lightweight C++ template library 2 | // for computer vision and image processing. 3 | // 4 | // Copyright (C) 2016 Codeplay Software Limited. All Rights Reserved. 5 | // 6 | // Contact: visioncpp@codeplay.com 7 | // 8 | // Licensed under the Apache License, Version 2.0 (the "License"); 9 | // you may not use this file except in compliance with the License. 10 | // You may obtain a copy of the License at 11 | // 12 | // http://www.apache.org/licenses/LICENSE-2.0 13 | // 14 | // Unless required by applicable law or agreed to in writing, software 15 | // distributed under the License is distributed on an "AS IS" BASIS, 16 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | // See the License for the specific language governing permissions and 18 | // limitations under the License. 19 | 20 | /// \file static_if.hpp 21 | /// \brief This file provides a set of static_if functions used at to calculate 22 | /// the result of if statement at compile time 23 | 24 | #ifndef VISIONCPP_INCLUDE_FRAMEWORK_TOOLS_STATIC_IF_HPP_ 25 | #define VISIONCPP_INCLUDE_FRAMEWORK_TOOLS_STATIC_IF_HPP_ 26 | 27 | namespace visioncpp { 28 | namespace internal { 29 | namespace tools { 30 | /// \struct IfNode 31 | /// \brief This struct is used to determine whether or not an expression node is 32 | /// a leafNode 33 | /// template parameters 34 | /// \tparam T is the type of the expression tree 35 | template 36 | struct IfNode { 37 | static constexpr bool Is_LeafNode = false; 38 | }; 39 | /// \brief specialisation of the IfNode when the node is leafNode 40 | template 41 | struct IfNode> { 42 | static constexpr bool Is_LeafNode = true; 43 | }; 44 | 45 | /// \struct StaticIf 46 | /// \brief It is used to select either of the input type based the Conds 47 | /// template parameters 48 | /// \tparam Conds : determines the condition 49 | /// \tparam T1 : first input type 50 | /// \tparam T2 : second input type 51 | template 52 | struct StaticIf { 53 | using Type = T1; 54 | using LostType = T2; 55 | }; 56 | /// \brief specialisation of the StaticIf when the condition is false 57 | template 58 | struct StaticIf { 59 | using Type = T2; 60 | using LostType = T1; 61 | }; 62 | /// \struct StaticIf 63 | /// \brief It is used to select either of the template constant variable based 64 | /// the Conds 65 | /// template parameters 66 | /// \tparam Conds : determines the condition 67 | /// \tparam X : first constant variable 68 | /// \tparam Y : second constant type 69 | template 70 | struct IfConst { 71 | static constexpr size_t Value = X; 72 | }; 73 | /// specialisation of the IfConst when the condition is false 74 | template 75 | struct IfConst { 76 | static constexpr size_t Value = Y; 77 | }; 78 | 79 | } // tools 80 | } // internal 81 | } // visioncpp 82 | #endif // VISIONCPP_INCLUDE_FRAMEWORK_TOOLS_STATIC_IF_HPP_ 83 | -------------------------------------------------------------------------------- /include/framework/tools/time.hpp: -------------------------------------------------------------------------------- 1 | // This file is part of VisionCpp, a lightweight C++ template library 2 | // for computer vision and image processing. 3 | // 4 | // Copyright (C) 2016 Codeplay Software Limited. All Rights Reserved. 5 | // 6 | // Contact: visioncpp@codeplay.com 7 | // 8 | // Licensed under the Apache License, Version 2.0 (the "License"); 9 | // you may not use this file except in compliance with the License. 10 | // You may obtain a copy of the License at 11 | // 12 | // http://www.apache.org/licenses/LICENSE-2.0 13 | // 14 | // Unless required by applicable law or agreed to in writing, software 15 | // distributed under the License is distributed on an "AS IS" BASIS, 16 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | // See the License for the specific language governing permissions and 18 | // limitations under the License. 19 | 20 | /// \file time.hpp 21 | /// \brief Basic time operations 22 | 23 | #ifndef VISIONCPP_INCLUDE_FRAMEWORK_TOOLS_TIME_HPP_ 24 | #define VISIONCPP_INCLUDE_FRAMEWORK_TOOLS_TIME_HPP_ 25 | 26 | #include 27 | 28 | namespace visioncpp { 29 | namespace internal { 30 | namespace tools { 31 | /// function get_elapse_time 32 | /// \brief it is used to calculate the time period in second. 33 | /// template parameters 34 | /// \tparam T : the type of the time from chrono 35 | /// function parameters 36 | /// \param begin : start of the time 37 | /// \param end : end of the time 38 | /// returns a double 39 | template 40 | double get_elapse_time(T begin, T end) { 41 | return std::chrono::duration( 42 | end - begin).count(); 43 | }; 44 | /// function get_current_time 45 | /// \brief getting the current time from the system using chrono 46 | /// \return std::chrono::high_resolution_clock::time_point 47 | std::chrono::high_resolution_clock::time_point get_current_time() { 48 | return std::chrono::high_resolution_clock::now(); 49 | } 50 | } // tools 51 | } // internal 52 | } // visioncpp 53 | #endif // VISIONCPP_INCLUDE_FRAMEWORK_TOOLS_TIME_HPP_ 54 | -------------------------------------------------------------------------------- /include/framework/tools/tools.hpp: -------------------------------------------------------------------------------- 1 | // This file is part of VisionCpp, a lightweight C++ template library 2 | // for computer vision and image processing. 3 | // 4 | // Copyright (C) 2016 Codeplay Software Limited. All Rights Reserved. 5 | // 6 | // Contact: visioncpp@codeplay.com 7 | // 8 | // Licensed under the Apache License, Version 2.0 (the "License"); 9 | // you may not use this file except in compliance with the License. 10 | // You may obtain a copy of the License at 11 | // 12 | // http://www.apache.org/licenses/LICENSE-2.0 13 | // 14 | // Unless required by applicable law or agreed to in writing, software 15 | // distributed under the License is distributed on an "AS IS" BASIS, 16 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | // See the License for the specific language governing permissions and 18 | // limitations under the License. 19 | 20 | /// \file tools.hpp 21 | /// \brief Collection of tools headers 22 | 23 | #ifndef VISIONCPP_INCLUDE_FRAMEWORK_TOOLS_TOOLS_HPP_ 24 | #define VISIONCPP_INCLUDE_FRAMEWORK_TOOLS_TOOLS_HPP_ 25 | 26 | // Tuple struct 27 | #include "convert.hpp" 28 | #include "static_if.hpp" 29 | #include "time.hpp" 30 | #include "tuple.hpp" 31 | #include "type_dereferencer.hpp" 32 | #endif // VISIONCPP_INCLUDE_FRAMEWORK_TOOLS_TOOLS_HPP_ 33 | -------------------------------------------------------------------------------- /include/framework/tools/type_dereferencer.hpp: -------------------------------------------------------------------------------- 1 | // This file is part of VisionCpp, a lightweight C++ template library 2 | // for computer vision and image processing. 3 | // 4 | // Copyright (C) 2016 Codeplay Software Limited. All Rights Reserved. 5 | // 6 | // Contact: visioncpp@codeplay.com 7 | // 8 | // Licensed under the Apache License, Version 2.0 (the "License"); 9 | // you may not use this file except in compliance with the License. 10 | // You may obtain a copy of the License at 11 | // 12 | // http://www.apache.org/licenses/LICENSE-2.0 13 | // 14 | // Unless required by applicable law or agreed to in writing, software 15 | // distributed under the License is distributed on an "AS IS" BASIS, 16 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | // See the License for the specific language governing permissions and 18 | // limitations under the License. 19 | 20 | /// \file type_dereferencer.hpp 21 | /// \brief These methods are used to remove all the & const and * from a type. 22 | 23 | #ifndef VISIONCPP_INCLUDE_FRAMEWORK_TOOLS_TYPE_DEREFERENCER_HPP_ 24 | #define VISIONCPP_INCLUDE_FRAMEWORK_TOOLS_TYPE_DEREFERENCER_HPP_ 25 | 26 | namespace visioncpp { 27 | namespace internal { 28 | namespace tools { 29 | /// \struct RemoveAll 30 | /// \brief These methods are used to remove all the & const and * from a type. 31 | /// template parameters 32 | /// \tparam T : the type we are interested in 33 | template 34 | struct RemoveAll { 35 | typedef T Type; 36 | }; 37 | /// specialisation of RemoveAll when the type contains & 38 | template 39 | struct RemoveAll { 40 | typedef typename RemoveAll::Type Type; 41 | }; 42 | /// specialisation of RemoveAll when the type contains * 43 | template 44 | struct RemoveAll { 45 | typedef typename RemoveAll::Type Type; 46 | }; 47 | /// specialisation of RemoveAll when the type contains const 48 | template 49 | struct RemoveAll { 50 | typedef typename RemoveAll::Type Type; 51 | }; 52 | 53 | /// specialisation of RemoveAll when the type contains const and & 54 | template 55 | struct RemoveAll { 56 | typedef typename RemoveAll::Type Type; 57 | }; 58 | /// specialisation of RemoveAll when the type contains volatile 59 | template 60 | struct RemoveAll { 61 | typedef typename RemoveAll::Type Type; 62 | }; 63 | /// specialisation of RemoveAll when the type contains const volatile 64 | template 65 | struct RemoveAll { 66 | typedef typename RemoveAll::Type Type; 67 | }; 68 | /// specialisation of RemoveAll when the type contains const and * 69 | template 70 | struct RemoveAll { 71 | typedef typename RemoveAll::Type Type; 72 | }; 73 | } // tools 74 | } // internal 75 | } // visioncpp 76 | #endif // VISIONCPP_INCLUDE_FRAMEWORK_TOOLS_TYPE_DEREFERENCER_HPP_ 77 | -------------------------------------------------------------------------------- /include/operators/OP_Broadcast.hpp: -------------------------------------------------------------------------------- 1 | // This file is part of VisionCpp, a lightweight C++ template library 2 | // for computer vision and image processing. 3 | // 4 | // Copyright (C) 2016 Codeplay Software Limited. All Rights Reserved. 5 | // 6 | // Contact: visioncpp@codeplay.com 7 | // 8 | // Licensed under the Apache License, Version 2.0 (the "License"); 9 | // you may not use this file except in compliance with the License. 10 | // You may obtain a copy of the License at 11 | // 12 | // http://www.apache.org/licenses/LICENSE-2.0 13 | // 14 | // Unless required by applicable law or agreed to in writing, software 15 | // distributed under the License is distributed on an "AS IS" BASIS, 16 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | // See the License for the specific language governing permissions and 18 | // limitations under the License. 19 | 20 | /// \file OP_Broadcast.hpp 21 | /// \brief This file contains a struct to set pixel to the value passed in. 22 | 23 | namespace visioncpp { 24 | /// \struct OP_Broadcast 25 | /// \brief This functor sets the pixel to the value passed in. 26 | struct OP_Broadcast { 27 | /// \param val 28 | /// \return SCALAR 29 | template 30 | SCALAR operator()(SCALAR val) { 31 | return val; 32 | } 33 | }; 34 | } 35 | -------------------------------------------------------------------------------- /include/operators/OP_ScaleChannel.hpp: -------------------------------------------------------------------------------- 1 | // This file is part of VisionCpp, a lightweight C++ template library 2 | // for computer vision and image processing. 3 | // 4 | // Copyright (C) 2016 Codeplay Software Limited. All Rights Reserved. 5 | // 6 | // Contact: visioncpp@codeplay.com 7 | // 8 | // Licensed under the Apache License, Version 2.0 (the "License"); 9 | // you may not use this file except in compliance with the License. 10 | // You may obtain a copy of the License at 11 | // 12 | // http://www.apache.org/licenses/LICENSE-2.0 13 | // 14 | // Unless required by applicable law or agreed to in writing, software 15 | // distributed under the License is distributed on an "AS IS" BASIS, 16 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | // See the License for the specific language governing permissions and 18 | // limitations under the License. 19 | 20 | /// \file OP_ScaleChannel.hpp 21 | /// \brief This files contains structs that change different channels by factor 22 | /// passed via float f. 23 | 24 | namespace visioncpp { 25 | /// \struct OP_ScaleChannelZero 26 | /// \brief This custom functor changes 0 channel by factor passed via float f. 27 | struct OP_ScaleChannelZero { 28 | /// \param lhs - Pixel in HSV color space 29 | /// \param f - S channel multiplier 30 | /// \return F32C3 - Altered HSV color space pixel 31 | visioncpp::pixel::F32C3 operator()(visioncpp::pixel::F32C3 lhs, float f) { 32 | lhs[0] *= f; 33 | return lhs; 34 | } 35 | }; 36 | 37 | /// \struct OP_ScaleChannelOne 38 | /// \brief This custom functor changes 1 channel by factor passed via float f. 39 | struct OP_ScaleChannelOne { 40 | /// \param lhs - Pixel in HSV color space 41 | /// \param f - S channel multiplier 42 | /// \return F32C3 - Altered HSV color space pixel 43 | visioncpp::pixel::F32C3 operator()(visioncpp::pixel::F32C3 lhs, float f) { 44 | lhs[1] *= f; 45 | return lhs; 46 | } 47 | }; 48 | 49 | /// \struct OP_ScaleChannelTwo 50 | /// \brief This custom functor changes 2 channel by factor passed via float f. 51 | struct OP_ScaleChannelTwo { 52 | /// \param lhs - Pixel in HSV color space 53 | /// \param f - S channel multiplier 54 | /// \return F32C3 - Altered HSV color space pixel 55 | visioncpp::pixel::F32C3 operator()(visioncpp::pixel::F32C3 lhs, float f) { 56 | lhs[2] *= f; 57 | return lhs; 58 | } 59 | }; 60 | } 61 | -------------------------------------------------------------------------------- /include/operators/convert/OP_BGRToRGB.hpp: -------------------------------------------------------------------------------- 1 | // This file is part of VisionCpp, a lightweight C++ template library 2 | // for computer vision and image processing. 3 | // 4 | // Copyright (C) 2016 Codeplay Software Limited. All Rights Reserved. 5 | // 6 | // Contact: visioncpp@codeplay.com 7 | // 8 | // Licensed under the Apache License, Version 2.0 (the "License"); 9 | // you may not use this file except in compliance with the License. 10 | // You may obtain a copy of the License at 11 | // 12 | // http://www.apache.org/licenses/LICENSE-2.0 13 | // 14 | // Unless required by applicable law or agreed to in writing, software 15 | // distributed under the License is distributed on an "AS IS" BASIS, 16 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | // See the License for the specific language governing permissions and 18 | // limitations under the License. 19 | 20 | /// \file OP_BGRToRGB.hpp 21 | /// \brief it converts BGR pixel to RGB pixel 22 | 23 | namespace visioncpp { 24 | /// \brief This functor reorders channels BGR to RGB 25 | struct OP_BGRToRGB { 26 | /// \brief functor that reorders channels, e.g. HSV becomes VSH 27 | /// \param in - three channel unsigned char 28 | /// \return U8C3 - three channel unsigned char 29 | visioncpp::pixel::U8C3 operator()(visioncpp::pixel::U8C3 in) { 30 | return visioncpp::pixel::U8C3(static_cast(in[2]), 31 | static_cast(in[1]), 32 | static_cast(in[0])); 33 | } 34 | }; 35 | } 36 | -------------------------------------------------------------------------------- /include/operators/convert/OP_F32C3ToU8C3.hpp: -------------------------------------------------------------------------------- 1 | // This file is part of VisionCpp, a lightweight C++ template library 2 | // for computer vision and image processing. 3 | // 4 | // Copyright (C) 2016 Codeplay Software Limited. All Rights Reserved. 5 | // 6 | // Contact: visioncpp@codeplay.com 7 | // 8 | // Licensed under the Apache License, Version 2.0 (the "License"); 9 | // you may not use this file except in compliance with the License. 10 | // You may obtain a copy of the License at 11 | // 12 | // http://www.apache.org/licenses/LICENSE-2.0 13 | // 14 | // Unless required by applicable law or agreed to in writing, software 15 | // distributed under the License is distributed on an "AS IS" BASIS, 16 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | // See the License for the specific language governing permissions and 18 | // limitations under the License. 19 | 20 | /// \file OP_F32C3ToU8C3.hpp 21 | /// \brief it converts F32C3 pixel to U8C3 pixel 22 | 23 | namespace visioncpp { 24 | /// \brief This functor performs conversion from [0.0f, 1.0f] to [0, 255] 25 | struct OP_F32C3ToU8C3 { 26 | /// \param in - three-channel float 27 | /// \return U8C3 - three-channel unsigned char 28 | visioncpp::pixel::U8C3 operator()(visioncpp::pixel::F32C3 in) { 29 | const float FLOAT_TO_BYTE = 255.0f; 30 | return visioncpp::pixel::U8C3( 31 | static_cast(in[0] * FLOAT_TO_BYTE), 32 | static_cast(in[1] * FLOAT_TO_BYTE), 33 | static_cast(in[2] * FLOAT_TO_BYTE)); 34 | } 35 | }; 36 | } 37 | -------------------------------------------------------------------------------- /include/operators/convert/OP_HSVToRGB.hpp: -------------------------------------------------------------------------------- 1 | // This file is part of VisionCpp, a lightweight C++ template library 2 | // for computer vision and image processing. 3 | // 4 | // Copyright (C) 2016 Codeplay Software Limited. All Rights Reserved. 5 | // 6 | // Contact: visioncpp@codeplay.com 7 | // 8 | // Licensed under the Apache License, Version 2.0 (the "License"); 9 | // you may not use this file except in compliance with the License. 10 | // You may obtain a copy of the License at 11 | // 12 | // http://www.apache.org/licenses/LICENSE-2.0 13 | // 14 | // Unless required by applicable law or agreed to in writing, software 15 | // distributed under the License is distributed on an "AS IS" BASIS, 16 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | // See the License for the specific language governing permissions and 18 | // limitations under the License. 19 | 20 | /// \file OP_HSVToRGB.hpp 21 | /// \brief it converts HSV pixel to RGB pixel 22 | 23 | namespace visioncpp { 24 | /// \brief functor converts HSV(H:[0.0f, 360.f], S:[0.0f, 1.0f] V: [0.0f, 1.0f]) 25 | /// to color RGB(R:[0.0f, 1.0f], G:[0.0f, 1.0f], B:[0.0f, 1.0f]) 26 | struct OP_HSVToRGB { 27 | /// \param inHSV 28 | /// \return RGB 29 | visioncpp::pixel::F32C3 operator()(visioncpp::pixel::F32C3 inHSV) { 30 | float fR = 0.0f, fG = 0.0f, fB = 0.0f; 31 | float fH = inHSV[0]; // H component 32 | float fS = inHSV[1]; // S component 33 | float fV = inHSV[2]; // V component 34 | 35 | // Convert from HSV to RGB, using float ranges 0.0 to 1.0 36 | int iI = 0; 37 | float fI = 0.0f, fF = 0.0f, p = 0.0f, q = 0.0f, t = 0.0f; 38 | 39 | if (fS == 0.0f) { 40 | // achromatic (grey) 41 | fR = fG = fB = fV; 42 | } else { 43 | // If Hue == 1.0, then wrap it around the circle to 0.0 44 | if (fH >= 1.0f) fH = 0.0f; 45 | 46 | fH *= 6.0f; // sector 0 to 5 47 | fI = cl::sycl::floor(fH); // integer part of h (0,1,2,3,4,5 or 6) 48 | iI = static_cast(fH); // " " " " 49 | fF = fH - fI; // factorial part of h (0 to 1) 50 | 51 | p = fV * (1.0f - fS); 52 | q = fV * (1.0f - fS * fF); 53 | t = fV * (1.0f - fS * (1.0f - fF)); 54 | 55 | switch (iI) { 56 | case 0: 57 | fR = fV; 58 | fG = t; 59 | fB = p; 60 | break; 61 | case 1: 62 | fR = q; 63 | fG = fV; 64 | fB = p; 65 | break; 66 | case 2: 67 | fR = p; 68 | fG = fV; 69 | fB = t; 70 | break; 71 | case 3: 72 | fR = p; 73 | fG = q; 74 | fB = fV; 75 | break; 76 | case 4: 77 | fR = t; 78 | fG = p; 79 | fB = fV; 80 | break; 81 | default: // case 5 (or 6): 82 | fR = fV; 83 | fG = p; 84 | fB = q; 85 | break; 86 | } 87 | } 88 | 89 | return visioncpp::pixel::F32C3(fR, fG, fB); 90 | } 91 | }; 92 | } 93 | -------------------------------------------------------------------------------- /include/operators/convert/OP_HSVToU8C3.hpp: -------------------------------------------------------------------------------- 1 | // This file is part of VisionCpp, a lightweight C++ template library 2 | // for computer vision and image processing. 3 | // 4 | // Copyright (C) 2016 Codeplay Software Limited. All Rights Reserved. 5 | // 6 | // Contact: visioncpp@codeplay.com 7 | // 8 | // Licensed under the Apache License, Version 2.0 (the "License"); 9 | // you may not use this file except in compliance with the License. 10 | // You may obtain a copy of the License at 11 | // 12 | // http://www.apache.org/licenses/LICENSE-2.0 13 | // 14 | // Unless required by applicable law or agreed to in writing, software 15 | // distributed under the License is distributed on an "AS IS" BASIS, 16 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | // See the License for the specific language governing permissions and 18 | // limitations under the License. 19 | 20 | /// \file OP_HSVToU8C3.hpp 21 | /// \brief it converts HSV pixel to U8C3 pixel 22 | 23 | namespace visioncpp { 24 | /// \brief This functor allows displaying HSV. 25 | /// the formula followed for unsigned char: 255S, 255V, 128H 26 | struct OP_HSVToU8C3 { 27 | /// \param in 28 | /// \return U8C3 29 | visioncpp::pixel::U8C3 operator()(visioncpp::pixel::F32C3 in) { 30 | const float FLOAT_TO_BYTE = 255.0f; 31 | 32 | // Convert from floats to 8-bit integers 33 | // let follow OpenCV convention of 34 | // V <- 255V, S <- 255S, H <- H/2(to fit 0 to 255) 35 | float bH = (float)(in[0] * 180.0f); 36 | float bS = (float)(in[1] * FLOAT_TO_BYTE); 37 | float bV = (float)(in[2] * FLOAT_TO_BYTE); 38 | 39 | return visioncpp::pixel::U8C3(static_cast(bH), 40 | static_cast(bS), 41 | static_cast(bV)); 42 | } 43 | }; 44 | } 45 | -------------------------------------------------------------------------------- /include/operators/convert/OP_RGBToBGR.hpp: -------------------------------------------------------------------------------- 1 | // This file is part of VisionCpp, a lightweight C++ template library 2 | // for computer vision and image processing. 3 | // 4 | // Copyright (C) 2016 Codeplay Software Limited. All Rights Reserved. 5 | // 6 | // Contact: visioncpp@codeplay.com 7 | // 8 | // Licensed under the Apache License, Version 2.0 (the "License"); 9 | // you may not use this file except in compliance with the License. 10 | // You may obtain a copy of the License at 11 | // 12 | // http://www.apache.org/licenses/LICENSE-2.0 13 | // 14 | // Unless required by applicable law or agreed to in writing, software 15 | // distributed under the License is distributed on an "AS IS" BASIS, 16 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | // See the License for the specific language governing permissions and 18 | // limitations under the License. 19 | 20 | /// \file OP_RGBToBGR.hpp 21 | /// \brief it converts RGB pixel to BGR pixel 22 | 23 | namespace visioncpp { 24 | /// \brief This functor reorders channels BGR to RGB 25 | struct OP_RGBToBGR { 26 | /// \param in - three-channel unsigned char 27 | /// \return U8C3 - three-channel unsigned char 28 | visioncpp::pixel::U8C3 operator()(visioncpp::pixel::U8C3 in) { 29 | return visioncpp::pixel::U8C3(static_cast(in[2]), 30 | static_cast(in[1]), 31 | static_cast(in[0])); 32 | } 33 | }; 34 | } 35 | -------------------------------------------------------------------------------- /include/operators/convert/OP_RGBToGREY.hpp: -------------------------------------------------------------------------------- 1 | // This file is part of VisionCpp, a lightweight C++ template library 2 | // for computer vision and image processing. 3 | // 4 | // Copyright (C) 2016 Codeplay Software Limited. All Rights Reserved. 5 | // 6 | // Contact: visioncpp@codeplay.com 7 | // 8 | // Licensed under the Apache License, Version 2.0 (the "License"); 9 | // you may not use this file except in compliance with the License. 10 | // You may obtain a copy of the License at 11 | // 12 | // http://www.apache.org/licenses/LICENSE-2.0 13 | // 14 | // Unless required by applicable law or agreed to in writing, software 15 | // distributed under the License is distributed on an "AS IS" BASIS, 16 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | // See the License for the specific language governing permissions and 18 | // limitations under the License. 19 | 20 | /// \file OP_RGBToGREY.hpp 21 | /// \brief it converts RGB pixel to Grey pixel 22 | 23 | namespace visioncpp { 24 | /// \brief This functor performs RGB to GREY convertion following rule: 25 | /// GREY <- 0.299f * R + 0,587f * G + 0.114 * B 26 | struct OP_RGBToGREY { 27 | /// \param in - RGB pixel. 28 | /// \returns float - greyscale value. 29 | float operator()(visioncpp::pixel::F32C3 in) { 30 | // because it is saved cv in our rgb format then b stored in r 31 | // and r stored in b. 32 | // luminance , the most accurate one 33 | return 0.299f * in[0] + 0.587f * in[1] + 0.114f * in[2]; 34 | } 35 | }; 36 | } 37 | -------------------------------------------------------------------------------- /include/operators/convert/OP_RGBToHSV.hpp: -------------------------------------------------------------------------------- 1 | // This file is part of VisionCpp, a lightweight C++ template library 2 | // for computer vision and image processing. 3 | // 4 | // Copyright (C) 2016 Codeplay Software Limited. All Rights Reserved. 5 | // 6 | // Contact: visioncpp@codeplay.com 7 | // 8 | // Licensed under the Apache License, Version 2.0 (the "License"); 9 | // you may not use this file except in compliance with the License. 10 | // You may obtain a copy of the License at 11 | // 12 | // http://www.apache.org/licenses/LICENSE-2.0 13 | // 14 | // Unless required by applicable law or agreed to in writing, software 15 | // distributed under the License is distributed on an "AS IS" BASIS, 16 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | // See the License for the specific language governing permissions and 18 | // limitations under the License. 19 | 20 | /// \file OP_RGBToHSV.hpp 21 | /// \brief it converts RGB pixel to HSV pixel 22 | 23 | namespace visioncpp { 24 | /// \brief Functor converts RGB ( R: 0.0f..1.0f, G: 0.0f..1.0f, B: 0.0f..1.0f) 25 | /// to HSV ( H: 0.0f..360.f, S: 0.0f..1.0f V: 0.0f..1.0f ) color space 26 | struct OP_RGBToHSV { 27 | /// \param inRGB 28 | /// \return F32C3 29 | visioncpp::pixel::F32C3 operator()(visioncpp::pixel::F32C3 inRGB) { 30 | // Convert from RGB to HSV, using float ranges 0.0 to 1.0. 31 | float fR = inRGB[0], fG = inRGB[1], fB = inRGB[2]; 32 | float fH = 0.0f, fS = 0.0f, fV = 0.0f; 33 | 34 | float fDelta; 35 | float fMin, fMax; 36 | // Get the min and max, but use integer comparisons for slight speedup. 37 | if (inRGB[2] < inRGB[1]) { 38 | if (inRGB[2] < inRGB[0]) { 39 | fMin = fB; 40 | if (inRGB[0] > inRGB[1]) { 41 | fMax = fR; 42 | } else { 43 | fMax = fG; 44 | } 45 | } else { 46 | fMin = fR; 47 | fMax = fG; 48 | } 49 | } else { 50 | if (inRGB[1] < inRGB[0]) { 51 | fMin = fG; 52 | if (inRGB[2] > inRGB[0]) { 53 | fMax = fB; 54 | } else { 55 | fMax = fR; 56 | } 57 | } else { 58 | fMin = fR; 59 | fMax = fB; 60 | } 61 | } 62 | fDelta = fMax - fMin; 63 | fV = fMax; // Value (Brightness). 64 | if (fMax != 0.0f) { // Make sure it's not pure black. 65 | fS = fDelta / fMax; // Saturation. 66 | float ANGLE_TO_UNIT = 67 | 1.0f / 68 | (6.0f * fDelta); // Make the Hues between 0.0 to 1.0 instead of 6.0 69 | if (fDelta == 0.0f) { 70 | fH = 0.0f; // undefined hue 71 | } else if (fMax == inRGB[0]) { // between yellow and magenta. 72 | fH = (fG - fB) * ANGLE_TO_UNIT; 73 | } else if (fMax == inRGB[1]) { // between cyan and yellow. 74 | fH = (2.0f / 6.0f) + (fB - fR) * ANGLE_TO_UNIT; 75 | } else { // between magenta and cyan. 76 | fH = (4.0f / 6.0f) + (fR - fG) * ANGLE_TO_UNIT; 77 | } 78 | // Wrap outlier Hues around the circle. 79 | if (fH < 0.0f) fH += 1.0f; 80 | if (fH >= 1.0f) fH -= 1.0f; 81 | } else { 82 | // color is pure Black. 83 | fS = 0.0f; 84 | fH = 0.0f; // undefined hue 85 | } 86 | return visioncpp::pixel::F32C3(fH, fS, fV); 87 | } 88 | }; 89 | } 90 | -------------------------------------------------------------------------------- /include/operators/convert/OP_U8C3ToF32C3.hpp: -------------------------------------------------------------------------------- 1 | // This file is part of VisionCpp, a lightweight C++ template library 2 | // for computer vision and image processing. 3 | // 4 | // Copyright (C) 2016 Codeplay Software Limited. All Rights Reserved. 5 | // 6 | // Contact: visioncpp@codeplay.com 7 | // 8 | // Licensed under the Apache License, Version 2.0 (the "License"); 9 | // you may not use this file except in compliance with the License. 10 | // You may obtain a copy of the License at 11 | // 12 | // http://www.apache.org/licenses/LICENSE-2.0 13 | // 14 | // Unless required by applicable law or agreed to in writing, software 15 | // distributed under the License is distributed on an "AS IS" BASIS, 16 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | // See the License for the specific language governing permissions and 18 | // limitations under the License. 19 | 20 | /// \file OP_U8C3ToF32C3.hpp 21 | /// \brief it converts U8C3 pixel to F32C3 pixel 22 | 23 | namespace visioncpp { 24 | /// \brief This functor performs conversion from [0, 255] to [0.0f, 1.0f] 25 | struct OP_U8C3ToF32C3 { 26 | /// \param in - three-channel unsigned char 27 | /// \return F32C3 - three-channel float 28 | visioncpp::pixel::F32C3 operator()(visioncpp::pixel::U8C3 in) { 29 | const float FLOAT_TO_BYTE = 255.0f; 30 | const float BYTE_TO_FLOAT = 1.0f / FLOAT_TO_BYTE; 31 | return visioncpp::pixel::F32C3(static_cast(in[0] * BYTE_TO_FLOAT), 32 | static_cast(in[1] * BYTE_TO_FLOAT), 33 | static_cast(in[2] * BYTE_TO_FLOAT)); 34 | } 35 | }; 36 | } 37 | -------------------------------------------------------------------------------- /include/operators/convert/ops_convert.hpp: -------------------------------------------------------------------------------- 1 | // This file is part of VisionCpp, a lightweight C++ template library 2 | // for computer vision and image processing. 3 | // 4 | // Copyright (C) 2016 Codeplay Software Limited. All Rights Reserved. 5 | // 6 | // Contact: visioncpp@codeplay.com 7 | // 8 | // Licensed under the Apache License, Version 2.0 (the "License"); 9 | // you may not use this file except in compliance with the License. 10 | // You may obtain a copy of the License at 11 | // 12 | // http://www.apache.org/licenses/LICENSE-2.0 13 | // 14 | // Unless required by applicable law or agreed to in writing, software 15 | // distributed under the License is distributed on an "AS IS" BASIS, 16 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | // See the License for the specific language governing permissions and 18 | // limitations under the License. 19 | 20 | /// \file ops_convert.hpp 21 | /// \brief This header gathers all conversion operations. 22 | 23 | #ifndef VISIONCPP_INCLUDE_OPERATORS_CONVERT_OPS_CONVERT_HPP_ 24 | #define VISIONCPP_INCLUDE_OPERATORS_CONVERT_OPS_CONVERT_HPP_ 25 | 26 | #include "OP_BGRToRGB.hpp" 27 | #include "OP_F32C3ToU8C3.hpp" 28 | #include "OP_HSVToRGB.hpp" 29 | #include "OP_HSVToU8C3.hpp" 30 | #include "OP_RGBToBGR.hpp" 31 | #include "OP_RGBToGREY.hpp" 32 | #include "OP_RGBToHSV.hpp" 33 | #include "OP_U8C3ToF32C3.hpp" 34 | #endif // VISIONCPP_INCLUDE_OPERATORS_CONVERT_OPS_CONVERT_HPP_ -------------------------------------------------------------------------------- /include/operators/convolution/OP_Filter2D.hpp: -------------------------------------------------------------------------------- 1 | // This file is part of VisionCpp, a lightweight C++ template library 2 | // for computer vision and image processing. 3 | // 4 | // Copyright (C) 2016 Codeplay Software Limited. All Rights Reserved. 5 | // 6 | // Contact: visioncpp@codeplay.com 7 | // 8 | // Licensed under the Apache License, Version 2.0 (the "License"); 9 | // you may not use this file except in compliance with the License. 10 | // You may obtain a copy of the License at 11 | // 12 | // http://www.apache.org/licenses/LICENSE-2.0 13 | // 14 | // Unless required by applicable law or agreed to in writing, software 15 | // distributed under the License is distributed on an "AS IS" BASIS, 16 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | // See the License for the specific language governing permissions and 18 | // limitations under the License. 19 | 20 | /// \file OP_Filter2D.hpp 21 | /// \brief This file apply the general convolution 22 | 23 | namespace visioncpp { 24 | /// \struct OP_Filter2D 25 | /// \brief Applying the general convolution for 3 channel Image. 26 | /// If the number of channel is different in your case feel free to write your 27 | /// own. 28 | struct OP_Filter2D { 29 | /// \param nbr 30 | /// \param fltr 31 | /// \return NeighbourT::PixelType 32 | template 33 | typename NeighbourT::PixelType operator()(NeighbourT& nbr, FilterT& fltr) { 34 | int i, i2, j, j2; 35 | int hs_c = (fltr.cols / 2); 36 | int hs_r = (fltr.rows / 2); 37 | typename NeighbourT::PixelType out{}; 38 | for (i2 = -hs_c, i = 0; i2 <= hs_c; i2++, i++) 39 | for (j2 = -hs_r, j = 0; j2 <= hs_r; j2++, j++) 40 | out += nbr.at(nbr.I_c + i2, nbr.I_r + j2) * fltr.at(i, j); 41 | return out; 42 | } 43 | }; 44 | 45 | /// \struct OP_Filter2D_One 46 | /// \brief Applying the general convolution for 1 channel Image. 47 | /// If the number of channel is different in your case feel free to write your 48 | /// own. 49 | struct OP_Filter2D_One { 50 | /// \param nbr 51 | /// \param fltr 52 | /// \return float 53 | template 54 | float operator()(NeighbourT& nbr, FilterT& fltr) { 55 | int i, i2, j, j2; 56 | int hs_c = (fltr.cols / 2); 57 | int hs_r = (fltr.rows / 2); 58 | float out = 0; 59 | for (i2 = -hs_c, i = 0; i2 <= hs_c; i2++, i++) 60 | for (j2 = -hs_r, j = 0; j2 <= hs_r; j2++, j++) 61 | out += (nbr.at(nbr.I_c + i2, nbr.I_r + j2) * fltr.at(i, j)); 62 | return out; 63 | } 64 | }; 65 | } 66 | -------------------------------------------------------------------------------- /include/operators/convolution/OP_GaussianBlur3x3.hpp: -------------------------------------------------------------------------------- 1 | // This file is part of VisionCpp, a lightweight C++ template library 2 | // for computer vision and image processing. 3 | // 4 | // Copyright (C) 2016 Codeplay Software Limited. All Rights Reserved. 5 | // 6 | // Contact: visioncpp@codeplay.com 7 | // 8 | // Licensed under the Apache License, Version 2.0 (the "License"); 9 | // you may not use this file except in compliance with the License. 10 | // You may obtain a copy of the License at 11 | // 12 | // http://www.apache.org/licenses/LICENSE-2.0 13 | // 14 | // Unless required by applicable law or agreed to in writing, software 15 | // distributed under the License is distributed on an "AS IS" BASIS, 16 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | // See the License for the specific language governing permissions and 18 | // limitations under the License. 19 | 20 | /// \file OP_GaussianBlur3x3.hpp 21 | /// \brief this file apply the Gaussian blur 3x3 22 | 23 | namespace visioncpp { 24 | /// \struct OP_GaussianBlur3x3 25 | /// \brief applying the Gaussian blur 3x3 26 | struct OP_GaussianBlur3x3 { 27 | /// \param nbr 28 | /// \return PIXEL 29 | template 30 | typename NeighbourT::PixelType operator()(NeighbourT &nbr) { 31 | auto out = nbr.at(nbr.I_c - 1, nbr.I_r - 1) * 1.0f / 16.0f; 32 | out += nbr.at(nbr.I_c - 1, nbr.I_r + 1) * 1.0f / 16.0f; 33 | out += nbr.at(nbr.I_c + 1, nbr.I_r - 1) * 1.0f / 16.0f; 34 | out += nbr.at(nbr.I_c + 1, nbr.I_r + 1) * 1.0f / 16.0f; 35 | out += nbr.at(nbr.I_c, nbr.I_r - 1) * 2.0f / 16.0f; 36 | out += nbr.at(nbr.I_c - 1, nbr.I_r) * 2.0f / 16.0f; 37 | out += nbr.at(nbr.I_c, nbr.I_r + 1) * 2.0f / 16.0f; 38 | out += nbr.at(nbr.I_c + 1, nbr.I_r) * 2.0f / 16.0f; 39 | out += nbr.at(nbr.I_c, nbr.I_r) * 4.0f / 16.0f; 40 | return out; 41 | } 42 | }; 43 | } 44 | -------------------------------------------------------------------------------- /include/operators/convolution/OP_SepFilter.hpp: -------------------------------------------------------------------------------- 1 | // This file is part of VisionCpp, a lightweight C++ template library 2 | // for computer vision and image processing. 3 | // 4 | // Copyright (C) 2016 Codeplay Software Limited. All Rights Reserved. 5 | // 6 | // Contact: visioncpp@codeplay.com 7 | // 8 | // Licensed under the Apache License, Version 2.0 (the "License"); 9 | // you may not use this file except in compliance with the License. 10 | // You may obtain a copy of the License at 11 | // 12 | // http://www.apache.org/licenses/LICENSE-2.0 13 | // 14 | // Unless required by applicable law or agreed to in writing, software 15 | // distributed under the License is distributed on an "AS IS" BASIS, 16 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | // See the License for the specific language governing permissions and 18 | // limitations under the License. 19 | 20 | /// \file OP_SepFilter.hpp 21 | /// \brief This file applies Separable filter convolution 22 | 23 | namespace visioncpp { 24 | /// \struct OP_SepFilterRow 25 | /// \brief Separable filter for rows. 26 | /// If the number of channel is different in your case feel free to write your 27 | /// own. 28 | struct OP_SepFilterRow { 29 | /// \param nbr - where NeighbourT is pixel type 30 | /// \param fltr - filter array 31 | /// \return NeighbourT::PixelType 32 | template 33 | typename NeighbourT::PixelType operator()(NeighbourT& nbr, FilterT& fltr) { 34 | int i, i2; 35 | int hs_r = (fltr.rows / 2); 36 | auto out = nbr.at(nbr.I_c, nbr.I_r - 1) * fltr.at(0, 0); 37 | for (i2 = -hs_r + 1, i = 1; i2 <= hs_r; i2++, i++) { 38 | out += nbr.at(nbr.I_c, nbr.I_r + i2) * fltr.at(0, i); 39 | } 40 | return out; 41 | } 42 | }; 43 | 44 | /// \struct OP_SepFilterCol 45 | /// \brief Separable filter for cols. 46 | struct OP_SepFilterCol { 47 | /// \param nbr - where NeighbourT is pixel type 48 | /// \param fltr - filter array 49 | /// \return NeighbourT::PixelType 50 | template 51 | typename NeighbourT::PixelType operator()(NeighbourT& nbr, FilterT& fltr) { 52 | int i, i2; 53 | int hs_c = (fltr.cols / 2); 54 | auto out = nbr.at(nbr.I_c - 1, nbr.I_r) * fltr.at(0, 0); 55 | for (i2 = -hs_c + 1, i = 1; i2 <= hs_c; i2++, i++) { 56 | out += nbr.at(nbr.I_c + i2, nbr.I_r) * fltr.at(i, 0); 57 | } 58 | return out; 59 | } 60 | }; 61 | } 62 | -------------------------------------------------------------------------------- /include/operators/convolution/OP_SepGauss3x3.hpp: -------------------------------------------------------------------------------- 1 | // This file is part of VisionCpp, a lightweight C++ template library 2 | // for computer vision and image processing. 3 | // 4 | // Copyright (C) 2016 Codeplay Software Limited. All Rights Reserved. 5 | // 6 | // Contact: visioncpp@codeplay.com 7 | // 8 | // Licensed under the Apache License, Version 2.0 (the "License"); 9 | // you may not use this file except in compliance with the License. 10 | // You may obtain a copy of the License at 11 | // 12 | // http://www.apache.org/licenses/LICENSE-2.0 13 | // 14 | // Unless required by applicable law or agreed to in writing, software 15 | // distributed under the License is distributed on an "AS IS" BASIS, 16 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | // See the License for the specific language governing permissions and 18 | // limitations under the License. 19 | 20 | /// \file OP_SepGauss3x3.hpp 21 | /// \brief Separable Gaussian filter for 3x3 filter size 22 | 23 | namespace visioncpp { 24 | /// \struct OP_SepGaussRow3 25 | /// \brief Separable filter for rows. 26 | /// If the number of channel is different in your case feel free to write your 27 | /// own. 28 | struct OP_SepGaussRow3 { 29 | /// \param nbr - Where PIXEL is pixel type 30 | /// \return PIXEL 31 | template 32 | typename NeighbourT::PixelType operator()(NeighbourT &nbr) { 33 | auto out = nbr.at(nbr.I_c, nbr.I_r - 1) * 1.0f / 4.0f; 34 | out += nbr.at(nbr.I_c, nbr.I_r) * 2.0f / 4.0f; 35 | out += nbr.at(nbr.I_c, nbr.I_r + 1) * 1.0f / 4.0f; 36 | return out; 37 | } 38 | }; 39 | 40 | /// \struct OP_SepGaussCol3 41 | /// \brief Separable filter for cols. 42 | struct OP_SepGaussCol3 { 43 | /// \param nbr - Where PIXEL is pixel type 44 | /// \return PIXEL 45 | template 46 | typename NeighbourT::PixelType operator()(NeighbourT &nbr) { 47 | auto out = nbr.at(nbr.I_c - 1, nbr.I_r) * 1.0f / 3.0f; 48 | out += nbr.at(nbr.I_c, nbr.I_r) * 1.0f / 3.0f; 49 | out += nbr.at(nbr.I_c + 1, nbr.I_r) * 1.0f / 3.0f; 50 | return out; 51 | } 52 | }; 53 | } 54 | -------------------------------------------------------------------------------- /include/operators/convolution/ops_conv.hpp: -------------------------------------------------------------------------------- 1 | // This file is part of VisionCpp, a lightweight C++ template library 2 | // for computer vision and image processing. 3 | // 4 | // Copyright (C) 2016 Codeplay Software Limited. All Rights Reserved. 5 | // 6 | // Contact: visioncpp@codeplay.com 7 | // 8 | // Licensed under the Apache License, Version 2.0 (the "License"); 9 | // you may not use this file except in compliance with the License. 10 | // You may obtain a copy of the License at 11 | // 12 | // http://www.apache.org/licenses/LICENSE-2.0 13 | // 14 | // Unless required by applicable law or agreed to in writing, software 15 | // distributed under the License is distributed on an "AS IS" BASIS, 16 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | // See the License for the specific language governing permissions and 18 | // limitations under the License. 19 | 20 | /// \file ops_conv.hpp 21 | /// \brief This header gathers all convolution operations. 22 | 23 | #ifndef VISIONCPP_INCLUDE_OPERATORS_CONVOLUTION_OPS_CONV_HPP_ 24 | #define VISIONCPP_INCLUDE_OPERATORS_CONVOLUTION_OPS_CONV_HPP_ 25 | 26 | #include "OP_Filter2D.hpp" 27 | #include "OP_GaussianBlur3x3.hpp" 28 | #include "OP_SepFilter.hpp" 29 | #include "OP_SepGauss3x3.hpp" 30 | #endif // VISIONCPP_INCLUDE_OPERATORS_CONVOLUTION_OPS_CONV_HPP_ -------------------------------------------------------------------------------- /include/operators/downsampling/OP_DownsampleAverage.hpp: -------------------------------------------------------------------------------- 1 | // This file is part of VisionCpp, a lightweight C++ template library 2 | // for computer vision and image processing. 3 | // 4 | // Copyright (C) 2016 Codeplay Software Limited. All Rights Reserved. 5 | // 6 | // Contact: visioncpp@codeplay.com 7 | // 8 | // Licensed under the Apache License, Version 2.0 (the "License"); 9 | // you may not use this file except in compliance with the License. 10 | // You may obtain a copy of the License at 11 | // 12 | // http://www.apache.org/licenses/LICENSE-2.0 13 | // 14 | // Unless required by applicable law or agreed to in writing, software 15 | // distributed under the License is distributed on an "AS IS" BASIS, 16 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | // See the License for the specific language governing permissions and 18 | // limitations under the License. 19 | 20 | /// \file OP_DownsampleAverage.hpp 21 | /// \brief This file contains the downsampling filter using average technique 22 | 23 | namespace visioncpp { 24 | /// \struct OP_DownsampleAverage 25 | /// \brief Downsampling filter using average technique 26 | /// Other filters could be added for different numbers of channels. 27 | struct OP_DownsampleAverage { 28 | /// \param rdn 29 | /// \return PIXEL 30 | template 31 | typename NeighbourT::PixelType operator()(NeighbourT &rdn) { 32 | auto out = rdn.at(2 * rdn.I_c, 2 * rdn.I_r) + 33 | rdn.at(2 * rdn.I_c + 1, 2 * rdn.I_r + 1) / 2.0f; 34 | return out; 35 | } 36 | }; 37 | } 38 | -------------------------------------------------------------------------------- /include/operators/downsampling/OP_DownsampleClosest.hpp: -------------------------------------------------------------------------------- 1 | // This file is part of VisionCpp, a lightweight C++ template library 2 | // for computer vision and image processing. 3 | // 4 | // Copyright (C) 2016 Codeplay Software Limited. All Rights Reserved. 5 | // 6 | // Contact: visioncpp@codeplay.com 7 | // 8 | // Licensed under the Apache License, Version 2.0 (the "License"); 9 | // you may not use this file except in compliance with the License. 10 | // You may obtain a copy of the License at 11 | // 12 | // http://www.apache.org/licenses/LICENSE-2.0 13 | // 14 | // Unless required by applicable law or agreed to in writing, software 15 | // distributed under the License is distributed on an "AS IS" BASIS, 16 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | // See the License for the specific language governing permissions and 18 | // limitations under the License. 19 | 20 | /// \file OP_DownsampleClosest.hpp 21 | /// \brief This files contains downsampling filter using closest technique 22 | /// If the number of channel is different in your case feel free to write your 23 | /// own. 24 | 25 | namespace visioncpp { 26 | /// \struct OP_DownsampleClosest 27 | /// \brief Downsampling filter using closest technique 28 | struct OP_DownsampleClosest { 29 | /// \param rdn 30 | /// \return PIXEL 31 | template 32 | typename NeighbourT::PixelType operator()(NeighbourT &rdn) { 33 | return rdn.at(2 * rdn.I_c, 2 * rdn.I_r); 34 | } 35 | }; 36 | } 37 | -------------------------------------------------------------------------------- /include/operators/downsampling/ops_downsampling.hpp: -------------------------------------------------------------------------------- 1 | // This file is part of VisionCpp, a lightweight C++ template library 2 | // for computer vision and image processing. 3 | // 4 | // Copyright (C) 2016 Codeplay Software Limited. All Rights Reserved. 5 | // 6 | // Contact: visioncpp@codeplay.com 7 | // 8 | // Licensed under the Apache License, Version 2.0 (the "License"); 9 | // you may not use this file except in compliance with the License. 10 | // You may obtain a copy of the License at 11 | // 12 | // http://www.apache.org/licenses/LICENSE-2.0 13 | // 14 | // Unless required by applicable law or agreed to in writing, software 15 | // distributed under the License is distributed on an "AS IS" BASIS, 16 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | // See the License for the specific language governing permissions and 18 | // limitations under the License. 19 | 20 | /// \file ops_downsampling.hpp 21 | /// \brief This header gathers all downsampling operations. 22 | 23 | #ifndef VISIONCPP_INCLUDE_OPERATORS_DOWNSAMPLING_OPS_DOWNSAMPLING_HPP_ 24 | #define VISIONCPP_INCLUDE_OPERATORS_DOWNSAMPLING_OPS_DOWNSAMPLING_HPP_ 25 | 26 | #include "OP_DownsampleAverage.hpp" 27 | #include "OP_DownsampleClosest.hpp" 28 | #endif // VISIONCPP_INCLUDE_OPERATORS_DOWNSAMPLING_OPS_DOWNSAMPLING_HPP_ -------------------------------------------------------------------------------- /include/operators/experimental/OP_AbsSub.hpp: -------------------------------------------------------------------------------- 1 | // This file is part of VisionCPP, a lightweight C++ template library 2 | // for computer vision and image processing. 3 | // 4 | // Copyright (C) 2016 Codeplay Software Limited. All Rights Reserved. 5 | // 6 | // Contact: visioncpp@codeplay.com 7 | // 8 | // Licensed under the Apache License, Version 2.0 (the "License"); 9 | // you may not use this file except in compliance with the License. 10 | // You may obtain a copy of the License at 11 | // 12 | // http://www.apache.org/licenses/LICENSE-2.0 13 | // 14 | // Unless required by applicable law or agreed to in writing, software 15 | // distributed under the License is distributed on an "AS IS" BASIS, 16 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | // See the License for the specific language governing permissions and 18 | // limitations under the License. 19 | 20 | /// \file OP_AbsSub.hpp 21 | /// \brief It gets the absolute difference between 2 images 22 | 23 | namespace visioncpp { 24 | /// \brief this functor uses the sycl::fabs to return the difference 25 | struct OP_AbsSub { 26 | /// \brief this functor uses the sycl::fabs to return the difference 27 | /// \param t1 - First image 28 | /// \param t2 - Second image 29 | /// \return float - Return the difference (t1 - t2) 30 | template 31 | auto operator()(T1 t1, T2 t2) -> decltype(t1 - t2) { 32 | return cl::sycl::fabs(t1 - t2); 33 | } 34 | }; 35 | } 36 | -------------------------------------------------------------------------------- /include/operators/experimental/OP_Add.hpp: -------------------------------------------------------------------------------- 1 | // This file is part of VisionCPP, a lightweight C++ template library 2 | // for computer vision and image processing. 3 | // 4 | // Copyright (C) 2016 Codeplay Software Limited. All Rights Reserved. 5 | // 6 | // Contact: visioncpp@codeplay.com 7 | // 8 | // Licensed under the Apache License, Version 2.0 (the "License"); 9 | // you may not use this file except in compliance with the License. 10 | // You may obtain a copy of the License at 11 | // 12 | // http://www.apache.org/licenses/LICENSE-2.0 13 | // 14 | // Unless required by applicable law or agreed to in writing, software 15 | // distributed under the License is distributed on an "AS IS" BASIS, 16 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | // See the License for the specific language governing permissions and 18 | // limitations under the License. 19 | 20 | /// \file OP_Add.hpp 21 | /// \brief It adds the values pixel by pixel of two images 22 | 23 | namespace visioncpp { 24 | /// \brief This functor adds two pixels 25 | struct OP_Add { 26 | /// \brief This functor adds two pixels 27 | /// \param t1 - First image 28 | /// \param t2 - Second image 29 | /// \return float - Return the sum 30 | template 31 | auto operator()(T1 t1, T2 t2) -> decltype(t1 + t2) { 32 | return t1 + t2; 33 | } 34 | }; 35 | } 36 | -------------------------------------------------------------------------------- /include/operators/experimental/OP_AniDiff.hpp: -------------------------------------------------------------------------------- 1 | // This file is part of VisionCPP, a lightweight C++ template library 2 | // for computer vision and image processing. 3 | // 4 | // Copyright (C) 2016 Codeplay Software Limited. All Rights Reserved. 5 | // 6 | // Contact: visioncpp@codeplay.com 7 | // 8 | // Licensed under the Apache License, Version 2.0 (the "License"); 9 | // you may not use this file except in compliance with the License. 10 | // You may obtain a copy of the License at 11 | // 12 | // http://www.apache.org/licenses/LICENSE-2.0 13 | // 14 | // Unless required by applicable law or agreed to in writing, software 15 | // distributed under the License is distributed on an "AS IS" BASIS, 16 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | // See the License for the specific language governing permissions and 18 | // limitations under the License. 19 | 20 | /// \file OP_AniDiff.hpp 21 | /// \brief It applies a simplified version of the anisotropic diffusion 22 | 23 | namespace visioncpp { 24 | /// \brief This functor applies anisotropic diffusion for one channel 25 | struct OP_AniDiff_Grey { 26 | /// \brief This functor applies a simplified version of the anisotropic 27 | /// diffusion for one channel 28 | /// \param nbr - An image with one channel 29 | /// \return float - Return the anisotropic diffusion in one channel 30 | template 31 | float operator()(T nbr) { 32 | float out = 0; 33 | float sum_w = 0; 34 | 35 | for (int i = -1; i <= 1; i++) { 36 | for (int j = -1; j <= 1; j++) { 37 | float w = 38 | exp((-30.0f) * cl::sycl::fabs(nbr.at(nbr.I_c, nbr.I_r) - 39 | nbr.at(nbr.I_c + i, nbr.I_r + j))); 40 | sum_w += w; 41 | out += w * nbr.at(nbr.I_c + i, nbr.I_r + j); 42 | } 43 | } 44 | return out / sum_w; 45 | } 46 | }; 47 | 48 | /// \brief This functor applies anisotropic diffusion for 3 channels 49 | struct OP_AniDiff { 50 | /// \brief This functor applies a simplified version of the anisotropic 51 | /// diffusion for 3 channels 52 | /// \param nbr - An image with three channels 53 | /// \return float - Returns the anisotropic diffusion in 3 channels 54 | template 55 | typename T::PixelType operator()(T nbr) { 56 | using Type = typename T::PixelType::data_type; 57 | 58 | cl::sycl::float4 out(0, 0, 0, 0); 59 | cl::sycl::float4 sum_w(0, 0, 0, 0); 60 | 61 | for (int i = -1; i <= 1; i++) { 62 | for (int j = -1; j <= 1; j++) { 63 | cl::sycl::float4 p1(nbr.at(nbr.I_c, nbr.I_r)[0], 64 | nbr.at(nbr.I_c, nbr.I_r)[1], 65 | nbr.at(nbr.I_c, nbr.I_r)[2], 0); 66 | cl::sycl::float4 p2(nbr.at(nbr.I_c + i, nbr.I_r + j)[0], 67 | nbr.at(nbr.I_c + i, nbr.I_r + j)[1], 68 | nbr.at(nbr.I_c + i, nbr.I_r + j)[2], 0); 69 | cl::sycl::float4 w = exp((-30.0f) * cl::sycl::fabs(p1 - p2)); 70 | sum_w += w; 71 | out += w * p2; 72 | } 73 | } 74 | out = out / sum_w; 75 | return typename T::PixelType(static_cast(out.x()), 76 | static_cast(out.y()), 77 | static_cast(out.z())); 78 | } 79 | }; 80 | } 81 | -------------------------------------------------------------------------------- /include/operators/experimental/OP_Div.hpp: -------------------------------------------------------------------------------- 1 | // This file is part of VisionCPP, a lightweight C++ template library 2 | // for computer vision and image processing. 3 | // 4 | // Copyright (C) 2016 Codeplay Software Limited. All Rights Reserved. 5 | // 6 | // Contact: visioncpp@codeplay.com 7 | // 8 | // Licensed under the Apache License, Version 2.0 (the "License"); 9 | // you may not use this file except in compliance with the License. 10 | // You may obtain a copy of the License at 11 | // 12 | // http://www.apache.org/licenses/LICENSE-2.0 13 | // 14 | // Unless required by applicable law or agreed to in writing, software 15 | // distributed under the License is distributed on an "AS IS" BASIS, 16 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | // See the License for the specific language governing permissions and 18 | // limitations under the License. 19 | 20 | /// \file OP_Div.hpp 21 | /// \brief It divides two matrices element-wise 22 | 23 | namespace visioncpp { 24 | /// \brief This functor divides two matrices element-wise 25 | struct OP_Div { 26 | /// \brief This functor divides two matrices element-wise 27 | /// \param t1 - Matrix1 28 | /// \param t2 - Matrix2 29 | /// \return T - Division ( t1 / t2 ) 30 | template 31 | auto operator()(T1 t1, T2 t2) -> decltype(t1 / t2) { 32 | return t1 / t2; 33 | } 34 | }; 35 | } 36 | -------------------------------------------------------------------------------- /include/operators/experimental/OP_FloatToF32C3.hpp: -------------------------------------------------------------------------------- 1 | // This file is part of VisionCPP, a lightweight C++ template library 2 | // for computer vision and image processing. 3 | // 4 | // Copyright (C) 2016 Codeplay Software Limited. All Rights Reserved. 5 | // 6 | // Contact: visioncpp@codeplay.com 7 | // 8 | // Licensed under the Apache License, Version 2.0 (the "License"); 9 | // you may not use this file except in compliance with the License. 10 | // You may obtain a copy of the License at 11 | // 12 | // http://www.apache.org/licenses/LICENSE-2.0 13 | // 14 | // Unless required by applicable law or agreed to in writing, software 15 | // distributed under the License is distributed on an "AS IS" BASIS, 16 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | // See the License for the specific language governing permissions and 18 | // limitations under the License. 19 | 20 | /// \file OP_FloatToF32C3.hpp 21 | /// \brief Converts from uchar to float and float to uchar 22 | 23 | namespace visioncpp { 24 | 25 | /// \brief It replicates one channel to 3 channels 26 | struct OP_FloatToF32C3 { 27 | /// \brief It replicates one channel to 3 channels 28 | /// \param t - Float of 1 channel 29 | /// \return F32C3 - Float of 3 channels 30 | visioncpp::pixel::F32C3 operator()(float t) { 31 | return visioncpp::pixel::F32C3(t, t, t); 32 | } 33 | }; 34 | 35 | /// \brief It converts float to uchar converting [0.0f, 1.0f] to [0, 255] 36 | struct OP_FloatToU8C1 { 37 | /// \brief It converts float to uchar converting [0.0f, 1.0f] to [0, 255] 38 | /// \param t - float of 1 channel 39 | /// \return U8C1 - uchar of 1 channel 40 | visioncpp::pixel::U8C1 operator()(float t) { 41 | return visioncpp::pixel::U8C1(static_cast(t * 255)); 42 | } 43 | }; 44 | 45 | /// \brief It converts uchar to float converting range [0, 255] to [0.0f, 1.0f] 46 | struct OP_U8C1ToFloat { 47 | /// \brief It converts uchar to float converting range [0, 255] to [0.0f, 1.0f] 48 | /// \param t - uchar of 1 channel 49 | /// \return float - float of 1 channels 50 | float operator()(visioncpp::pixel::U8C1 t) { 51 | return static_cast(t[0]) / 255.0f; 52 | } 53 | }; 54 | 55 | /// \brief It converts float to uchar 56 | struct OP_FloatToUChar { 57 | /// \brief It converts float to uchar 58 | /// \param t - float of 1 channel 59 | /// \return F32C3 - uchar of 1 channel 60 | unsigned char operator()(float t) { 61 | return (static_cast(t * 255)); 62 | } 63 | }; 64 | } 65 | -------------------------------------------------------------------------------- /include/operators/experimental/OP_Median.hpp: -------------------------------------------------------------------------------- 1 | // This file is part of VisionCPP, a lightweight C++ template library 2 | // for computer vision and image processing. 3 | // 4 | // Copyright (C) 2016 Codeplay Software Limited. All Rights Reserved. 5 | // 6 | // Contact: visioncpp@codeplay.com 7 | // 8 | // Licensed under the Apache License, Version 2.0 (the "License"); 9 | // you may not use this file except in compliance with the License. 10 | // You may obtain a copy of the License at 11 | // 12 | // http://www.apache.org/licenses/LICENSE-2.0 13 | // 14 | // Unless required by applicable law or agreed to in writing, software 15 | // distributed under the License is distributed on an "AS IS" BASIS, 16 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | // See the License for the specific language governing permissions and 18 | // limitations under the License. 19 | 20 | /// \file OP_Median.hpp 21 | /// \brief It applies the median filter in an image. It gets the median value 22 | /// of a neighbour after sorted 23 | 24 | namespace visioncpp { 25 | /// \brief User defined functionality for the kernel 26 | namespace custom { 27 | template 28 | void bubbleSort(T &a, int N) { 29 | bool swapp = true; 30 | while (swapp) { 31 | swapp = false; 32 | for (size_t i = 0; i < N - 1; i++) { 33 | if (a[i] > a[i + 1]) { 34 | a[i] += a[i + 1]; 35 | a[i + 1] = a[i] - a[i + 1]; 36 | a[i] -= a[i + 1]; 37 | swapp = true; 38 | } 39 | } 40 | } 41 | } 42 | } 43 | 44 | /// \brief This functor implements a median filter 45 | struct OP_Median { 46 | /// \brief This functor implements median filter 47 | /// \param nbr - Input image 48 | /// \return float - Returns the image with median filter applied 49 | template 50 | T operator()(T nbr) { 51 | int size = 5; 52 | int bound = size / 2; 53 | float v[25]; 54 | int k = 0; 55 | for (int i = -bound; i <= bound; i++) { 56 | for (int j = -bound; j <= bound; j++) { 57 | v[k++] = nbr.at(nbr.I_c + i, nbr.I_r + j); 58 | } 59 | } 60 | custom::bubbleSort(v, size * size); 61 | return v[size * size / 2]; 62 | } 63 | }; 64 | } 65 | -------------------------------------------------------------------------------- /include/operators/experimental/OP_Merge2Chns.hpp: -------------------------------------------------------------------------------- 1 | // This file is part of VisionCPP, a lightweight C++ template library 2 | // for computer vision and image processing. 3 | // 4 | // Copyright (C) 2016 Codeplay Software Limited. All Rights Reserved. 5 | // 6 | // Contact: visioncpp@codeplay.com 7 | // 8 | // Licensed under the Apache License, Version 2.0 (the "License"); 9 | // you may not use this file except in compliance with the License. 10 | // You may obtain a copy of the License at 11 | // 12 | // http://www.apache.org/licenses/LICENSE-2.0 13 | // 14 | // Unless required by applicable law or agreed to in writing, software 15 | // distributed under the License is distributed on an "AS IS" BASIS, 16 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | // See the License for the specific language governing permissions and 18 | // limitations under the License. 19 | 20 | /// \file OP_Merge2Chns.hpp 21 | /// \brief It merges 2 matrices of one channels into one matrix of 2 channels 22 | 23 | namespace visioncpp { 24 | /// \brief This functor merges 2 matrices into one matrix of 2 channels 25 | struct OP_Merge2Chns { 26 | /// \brief Merge 2 matrices into one matrix onf 2 channels 27 | /// \param t1 - One channel float 28 | /// \param t2 - One channel float 29 | /// \return F32C2 - 2 channels float 30 | template 31 | visioncpp::pixel::F32C2 operator()(T1 t1, T2 t2) { 32 | return visioncpp::pixel::F32C2(t1, t2); 33 | } 34 | }; 35 | } 36 | -------------------------------------------------------------------------------- /include/operators/experimental/OP_Mul.hpp: -------------------------------------------------------------------------------- 1 | // This file is part of VisionCPP, a lightweight C++ template library 2 | // for computer vision and image processing. 3 | // 4 | // Copyright (C) 2016 Codeplay Software Limited. All Rights Reserved. 5 | // 6 | // Contact: visioncpp@codeplay.com 7 | // 8 | // Licensed under the Apache License, Version 2.0 (the "License"); 9 | // you may not use this file except in compliance with the License. 10 | // You may obtain a copy of the License at 11 | // 12 | // http://www.apache.org/licenses/LICENSE-2.0 13 | // 14 | // Unless required by applicable law or agreed to in writing, software 15 | // distributed under the License is distributed on an "AS IS" BASIS, 16 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | // See the License for the specific language governing permissions and 18 | // limitations under the License. 19 | 20 | /// \file OP_Mul.hpp 21 | /// \brief Element-wise matrix multiplication 22 | 23 | namespace visioncpp { 24 | /// \struct OP_Mul 25 | /// \brief This functor implements an element-wise matrix multiplication 26 | struct OP_Mul { 27 | /// \brief this functor implements an element-wise matrix multiplication 28 | /// \param t1 - first image 29 | /// \param t2 - second image 30 | /// \return float - return multiplication of them t1 * t2 31 | template 32 | auto operator()(T1 t1, T2 t2) -> decltype(t1* t2) { 33 | return t1 * t2; 34 | } 35 | }; 36 | } 37 | -------------------------------------------------------------------------------- /include/operators/experimental/OP_PowerOf2.hpp: -------------------------------------------------------------------------------- 1 | // This file is part of VisionCPP, a lightweight C++ template library 2 | // for computer vision and image processing. 3 | // 4 | // Copyright (C) 2016 Codeplay Software Limited. All Rights Reserved. 5 | // 6 | // Contact: visioncpp@codeplay.com 7 | // 8 | // Licensed under the Apache License, Version 2.0 (the "License"); 9 | // you may not use this file except in compliance with the License. 10 | // You may obtain a copy of the License at 11 | // 12 | // http://www.apache.org/licenses/LICENSE-2.0 13 | // 14 | // Unless required by applicable law or agreed to in writing, software 15 | // distributed under the License is distributed on an "AS IS" BASIS, 16 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | // See the License for the specific language governing permissions and 18 | // limitations under the License. 19 | 20 | /// \file OP_PowerOf2.hpp 21 | /// \brief It calculates the power of 2 of a matrix 22 | 23 | namespace visioncpp { 24 | /// \struct OP_PowerOf2 25 | /// \brief This functor implements the power of 2 of one matrix 26 | struct OP_PowerOf2 { 27 | /// \brief It calculates the power of 2 ( t^2 ) 28 | /// \param t - Float matrix 29 | /// \return float - Return the power of 2 ( t^2 ) 30 | template 31 | auto operator()(T t) -> decltype(t* t) { 32 | return t * t; 33 | } 34 | }; 35 | } 36 | -------------------------------------------------------------------------------- /include/operators/experimental/OP_Scale.hpp: -------------------------------------------------------------------------------- 1 | // This file is part of VisionCPP, a lightweight C++ template library 2 | // for computer vision and image processing. 3 | // 4 | // Copyright (C) 2016 Codeplay Software Limited. All Rights Reserved. 5 | // 6 | // Contact: visioncpp@codeplay.com 7 | // 8 | // Licensed under the Apache License, Version 2.0 (the "License"); 9 | // you may not use this file except in compliance with the License. 10 | // You may obtain a copy of the License at 11 | // 12 | // http://www.apache.org/licenses/LICENSE-2.0 13 | // 14 | // Unless required by applicable law or agreed to in writing, software 15 | // distributed under the License is distributed on an "AS IS" BASIS, 16 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | // See the License for the specific language governing permissions and 18 | // limitations under the License. 19 | 20 | /// \file OP_Scale.hpp 21 | /// \brief It scales the pixel value of an image by a factor 22 | 23 | namespace visioncpp { 24 | /// \struct OP_Scale 25 | /// \brief Scales the pixel value of an image by a factor 26 | struct OP_Scale { 27 | /// \brief Scales each pixel of an image by a factor 28 | /// \param t1 - Image of one channel 29 | /// \param f - Scale factor 30 | /// \return T1 - Returns the scaled image of time of the input image 31 | template 32 | T1 operator()(T1 t1, T2 f) { 33 | return t1 * f; 34 | } 35 | }; 36 | } 37 | -------------------------------------------------------------------------------- /include/operators/experimental/OP_Sub.hpp: -------------------------------------------------------------------------------- 1 | // This file is part of VisionCPP, a lightweight C++ template library 2 | // for computer vision and image processing. 3 | // 4 | // Copyright (C) 2016 Codeplay Software Limited. All Rights Reserved. 5 | // 6 | // Contact: visioncpp@codeplay.com 7 | // 8 | // Licensed under the Apache License, Version 2.0 (the "License"); 9 | // you may not use this file except in compliance with the License. 10 | // You may obtain a copy of the License at 11 | // 12 | // http://www.apache.org/licenses/LICENSE-2.0 13 | // 14 | // Unless required by applicable law or agreed to in writing, software 15 | // distributed under the License is distributed on an "AS IS" BASIS, 16 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | // See the License for the specific language governing permissions and 18 | // limitations under the License. 19 | 20 | /// \file OP_Sub.hpp 21 | /// \brief It calculates the difference between 2 images 22 | 23 | namespace visioncpp { 24 | /// \struct OP_Sub 25 | /// \brief This functor subtracts 2 images 26 | struct OP_Sub { 27 | /// \brief This functor subtracts 2 images 28 | /// \param t1 - First image 29 | /// \param t2 - Second image 30 | /// \return float - Return the difference (t1 - t2) 31 | template 32 | float operator()(T1 t1, T2 t2) { 33 | return t1 - t2; 34 | } 35 | }; 36 | } 37 | -------------------------------------------------------------------------------- /include/operators/experimental/OP_Thresh.hpp: -------------------------------------------------------------------------------- 1 | // This file is part of VisionCPP, a lightweight C++ template library 2 | // for computer vision and image processing. 3 | // 4 | // Copyright (C) 2016 Codeplay Software Limited. All Rights Reserved. 5 | // 6 | // Contact: visioncpp@codeplay.com 7 | // 8 | // Licensed under the Apache License, Version 2.0 (the "License"); 9 | // you may not use this file except in compliance with the License. 10 | // You may obtain a copy of the License at 11 | // 12 | // http://www.apache.org/licenses/LICENSE-2.0 13 | // 14 | // Unless required by applicable law or agreed to in writing, software 15 | // distributed under the License is distributed on an "AS IS" BASIS, 16 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | // See the License for the specific language governing permissions and 18 | // limitations under the License. 19 | 20 | /// \file OP_Thresh.hpp 21 | /// \brief it applies a threshold operation in the image 22 | 23 | namespace visioncpp { 24 | /// \struct OP_Thresh 25 | /// \brief Implements a binary threshold 26 | struct OP_Thresh { 27 | /// \brief This functor implements a binary threshold 28 | /// \param t1 - Image 29 | /// \param thresh - float threshold value 30 | /// \return U8C1 - Returns a binary image (1 if greater than threshold, 0 31 | /// otherwise) 32 | template 33 | visioncpp::pixel::U8C1 operator()(T1 t1, T2 thresh) { 34 | return t1 > thresh ? 1 : 0; 35 | } 36 | }; 37 | } 38 | -------------------------------------------------------------------------------- /include/operators/experimental/experimental.hpp: -------------------------------------------------------------------------------- 1 | // This file is part of VisionCPP, a lightweight C++ template library 2 | // for computer vision and image processing. 3 | // 4 | // Copyright (C) 2016 Codeplay Software Limited. All Rights Reserved. 5 | // 6 | // Contact: visioncpp@codeplay.com 7 | // 8 | // Licensed under the Apache License, Version 2.0 (the "License"); 9 | // you may not use this file except in compliance with the License. 10 | // You may obtain a copy of the License at 11 | // 12 | // http://www.apache.org/licenses/LICENSE-2.0 13 | // 14 | // Unless required by applicable law or agreed to in writing, software 15 | // distributed under the License is distributed on an "AS IS" BASIS, 16 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | // See the License for the specific language governing permissions and 18 | // limitations under the License. 19 | 20 | /// \file experimental.hpp 21 | /// \brief This header gathers all experimental operations. 22 | 23 | #ifndef VISIONCPP_INCLUDE_OPERATORS_EXPERIMENTAL_EXPERIMENTAL_HPP_ 24 | #define VISIONCPP_INCLUDE_OPERATORS_EXPERIMENTAL_EXPERIMENTAL_HPP_ 25 | 26 | #include "OP_AbsSub.hpp" 27 | #include "OP_Add.hpp" 28 | #include "OP_AniDiff.hpp" 29 | #include "OP_Div.hpp" 30 | #include "OP_FloatToF32C3.hpp" 31 | #include "OP_Median.hpp" 32 | #include "OP_Merge2Chns.hpp" 33 | #include "OP_Mul.hpp" 34 | #include "OP_PowerOf2.hpp" 35 | #include "OP_Scale.hpp" 36 | #include "OP_Sub.hpp" 37 | #include "OP_Thresh.hpp" 38 | #endif // VISIONCPP_INCLUDE_OPERATORS_EXPERIMENTAL_EXPERIMENTAL_HPP_ 39 | -------------------------------------------------------------------------------- /include/operators/opencvinterop.hpp: -------------------------------------------------------------------------------- 1 | // This file is part of VisionCpp, a lightweight C++ template library 2 | // for computer vision and image processing. 3 | // 4 | // Copyright (C) 2016 Codeplay Software Limited. All Rights Reserved. 5 | // 6 | // Contact: visioncpp@codeplay.com 7 | // 8 | // Licensed under the Apache License, Version 2.0 (the "License"); 9 | // you may not use this file except in compliance with the License. 10 | // You may obtain a copy of the License at 11 | // 12 | // http://www.apache.org/licenses/LICENSE-2.0 13 | // 14 | // Unless required by applicable law or agreed to in writing, software 15 | // distributed under the License is distributed on an "AS IS" BASIS, 16 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | // See the License for the specific language governing permissions and 18 | // limitations under the License. 19 | 20 | /// \file opencvinterop.hpp 21 | /// \brief This header gathers all interoperability with OpenCV operations. 22 | 23 | namespace visioncpp { 24 | /// \struct OP_CVBGRToRGB 25 | /// \brief This node is a utility node that does a conversion from cv::Mat ( 26 | /// unsigned char storage; channel order BGR ) to float with order of RGB 27 | /// normalise from opencv format to VisionCpp internal format [0, 255] to 28 | /// [0.0f, 1.0f] 29 | struct OP_CVBGRToRGB { 30 | /// \param in 31 | /// \return F32C3 32 | visioncpp::pixel::F32C3 operator()(visioncpp::pixel::U8C3 in) { 33 | visioncpp::pixel::F32C3 out(static_cast(in[2] / 255.0f), 34 | static_cast(in[1] / 255.0f), 35 | static_cast(in[0] / 255.0f)); 36 | return out; 37 | } 38 | }; 39 | 40 | /// \struct OP_RGBToCVBGR 41 | /// \brief This node is a utility node that does a conversion from float with 42 | /// order of RGB to cv::Mat ( unsigned char storage; channel order BGR ) 43 | /// denormalise from VisionCpp base format ( \ref F32C3 ) to opencv 8UC3 44 | /// (three channel unsigned char) 45 | struct OP_RGBToCVBGR { 46 | /// \param in 47 | /// \return U8C3 48 | visioncpp::pixel::U8C3 operator()(visioncpp::pixel::F32C3 in) { 49 | visioncpp::pixel::U8C3 out(static_cast(in[2] * 255.0f), 50 | static_cast(in[1] * 255.0f), 51 | static_cast(in[0] * 255.0f)); 52 | return out; 53 | } 54 | }; 55 | 56 | /// \struct OP_GREYToCVBGR 57 | /// \brief float between [0.0f, 1.0f] to [0, 255] 58 | /// One channel GREY ( float ) is going to be converted to one channel cv::Mat 59 | struct OP_GREYToCVBGR { 60 | /// \param in 61 | /// \return U8C1 62 | unsigned char operator()(float in) { 63 | return static_cast(in * 255); 64 | } 65 | }; 66 | } 67 | -------------------------------------------------------------------------------- /include/operators/ops.hpp: -------------------------------------------------------------------------------- 1 | // This file is part of VisionCpp, a lightweight C++ template library 2 | // for computer vision and image processing. 3 | // 4 | // Copyright (C) 2016 Codeplay Software Limited. All Rights Reserved. 5 | // 6 | // Contact: visioncpp@codeplay.com 7 | // 8 | // Licensed under the Apache License, Version 2.0 (the "License"); 9 | // you may not use this file except in compliance with the License. 10 | // You may obtain a copy of the License at 11 | // 12 | // http://www.apache.org/licenses/LICENSE-2.0 13 | // 14 | // Unless required by applicable law or agreed to in writing, software 15 | // distributed under the License is distributed on an "AS IS" BASIS, 16 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | // See the License for the specific language governing permissions and 18 | // limitations under the License. 19 | 20 | /// \file ops.hpp 21 | /// \brief This header gathers all operations available in VisionCpp. 22 | 23 | #ifndef VISIONCPP_INCLUDE_OPERATORS_OPS_HPP_ 24 | #define VISIONCPP_INCLUDE_OPERATORS_OPS_HPP_ 25 | 26 | // supported operators - covered by a testcase 27 | #include "convert/ops_convert.hpp" 28 | #include "convolution/ops_conv.hpp" 29 | #include "downsampling/ops_downsampling.hpp" 30 | // interop with openCV 31 | #include "opencvinterop.hpp" 32 | 33 | #include "OP_Broadcast.hpp" 34 | #include "OP_ScaleChannel.hpp" 35 | 36 | #include "experimental/experimental.hpp" 37 | #endif // VISIONCPP_INCLUDE_OPERATORS_OPS_HPP_ -------------------------------------------------------------------------------- /include/visioncpp.hpp: -------------------------------------------------------------------------------- 1 | // This file is part of VisionCpp, a lightweight C++ template library 2 | // for computer vision and image processing. 3 | // 4 | // Copyright (C) 2016 Codeplay Software Limited. All Rights Reserved. 5 | // 6 | // Contact: visioncpp@codeplay.com 7 | // 8 | // Licensed under the Apache License, Version 2.0 (the "License"); 9 | // you may not use this file except in compliance with the License. 10 | // You may obtain a copy of the License at 11 | // 12 | // http://www.apache.org/licenses/LICENSE-2.0 13 | // 14 | // Unless required by applicable law or agreed to in writing, software 15 | // distributed under the License is distributed on an "AS IS" BASIS, 16 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | // See the License for the specific language governing permissions and 18 | // limitations under the License. 19 | 20 | /// \file visioncpp.hpp 21 | /// \brief This file is collection of headers that makes VisionCpp library 22 | 23 | #ifndef VISIONCPP_INCLUDE_VISIONCPP_HPP_ 24 | #define VISIONCPP_INCLUDE_VISIONCPP_HPP_ 25 | 26 | #include 27 | 28 | /// Include SYCL header 29 | #include 30 | 31 | // include VisionCpp type definitions 32 | #include "pixel/pixel.hpp" 33 | 34 | // include framework operators 35 | #include "operators/ops.hpp" 36 | 37 | // include framework headers 38 | #include "framework/framework.hpp" 39 | 40 | #endif // VISIONCPP_INCLUDE_VISIONCPP_HPP_ -------------------------------------------------------------------------------- /tests/include/common.hpp: -------------------------------------------------------------------------------- 1 | // This file is part of VisionCpp, a lightweight C++ template library 2 | // for computer vision and image processing. 3 | // 4 | // Copyright (C) 2016 Codeplay Software Limited. All Rights Reserved. 5 | // 6 | // Contact: visioncpp@codeplay.com 7 | // 8 | // Licensed under the Apache License, Version 2.0 (the "License"); 9 | // you may not use this file except in compliance with the License. 10 | // You may obtain a copy of the License at 11 | // 12 | // http://www.apache.org/licenses/LICENSE-2.0 13 | // 14 | // Unless required by applicable law or agreed to in writing, software 15 | // distributed under the License is distributed on an "AS IS" BASIS, 16 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | // See the License for the specific language governing permissions and 18 | // limitations under the License. 19 | 20 | #ifndef VISIONCPP_TESTS_INCLUDE_COMMON_HPP_ 21 | #define VISIONCPP_TESTS_INCLUDE_COMMON_HPP_ 22 | 23 | // opencv dep 24 | // make sure that opencv is installed on the testing machine 25 | #include 26 | #include 27 | #include 28 | #include 29 | #include 30 | #include 31 | 32 | // used to generate test names 33 | #define GLUE_HELPER(x, y) x##_##y 34 | #define GLUE(x, y) GLUE_HELPER(x, y) 35 | #define REAL_STRINGIZE(x) #x 36 | #define STRINGIZE(x) REAL_STRINGIZE(x) 37 | 38 | // verification function that takes OpenCVs Mat as a reference and 39 | // and shared pointer that points to host storage with output from VisionCpps 40 | // pipe. 41 | template 42 | void verify(const cv::Mat &ref, std::shared_ptr img) { 43 | // opencv channels 44 | int cv_cn = ref.channels(); 45 | 46 | uint8_t *pixelPtr = (uint8_t *)ref.data; 47 | 48 | for (int i = 0; i < ref.rows; i++) { 49 | for (int j = 0; j < ref.cols; j++) { 50 | for (int c = 0; c < cv_cn; c++) { 51 | auto expected = (float)(pixelPtr[i * ref.cols * cv_cn + j * cv_cn + c]); 52 | auto tested = (float)(img.get()[i * ref.cols * cv_cn + j * cv_cn + c]); 53 | ASSERT_NEAR(expected, tested, 6) 54 | << "\nrow: " << i << " col: " << j << " channel: " << c 55 | << " expected: " << expected << " tested: " << tested; 56 | } 57 | } 58 | } 59 | } 60 | 61 | // singleton that is used for generating a data for tests 62 | // create 256 textures that are 256x256 with all possible combinations of pixel 63 | // values for unsigned char storage. 64 | namespace common { 65 | namespace singleton { 66 | struct DataSet { 67 | std::vector> m_data; 68 | static const size_t m_width = 256; 69 | static const size_t m_height = 256; 70 | static const size_t m_depth = 256; 71 | 72 | public: 73 | static DataSet &Instance() { 74 | static DataSet m_dataset; 75 | return m_dataset; 76 | } 77 | 78 | DataSet(DataSet const &) = delete; 79 | DataSet(DataSet &&) = delete; 80 | DataSet &operator=(DataSet const &) = delete; 81 | DataSet &operator=(DataSet &&) = delete; 82 | 83 | protected: 84 | DataSet() { 85 | for (size_t b = 0; b < m_depth; b++) { 86 | int i = 0; 87 | auto element = std::shared_ptr( 88 | new unsigned char[m_width * m_height * 3]); 89 | for (size_t g = 0; g < m_height; g++) { 90 | for (size_t r = 0; r < m_width; r++) { 91 | element.get()[i] = b; 92 | element.get()[i + 1] = g; 93 | element.get()[i + 2] = r; 94 | i += 3; 95 | } 96 | } 97 | m_data.push_back(element); 98 | } 99 | } 100 | 101 | ~DataSet() {} 102 | }; 103 | 104 | } // singleton 105 | 106 | // utility function that creates 2D Node based on singleton data 107 | auto getBuffer2D(size_t i) -> decltype(visioncpp::terminal< 108 | visioncpp::pixel::U8C3, common::singleton::DataSet::m_width, 109 | common::singleton::DataSet::m_height, visioncpp::memory_type::Buffer2D>( 110 | common::singleton::DataSet::Instance().m_data[i].get())) { 111 | return visioncpp::terminal< 112 | visioncpp::pixel::U8C3, common::singleton::DataSet::m_width, 113 | common::singleton::DataSet::m_height, visioncpp::memory_type::Buffer2D>( 114 | common::singleton::DataSet::Instance().m_data[i].get()); 115 | } 116 | 117 | } // internal 118 | 119 | #endif // VISIONCPP_TESTS_INCLUDE_COMMON_HPP_ 120 | -------------------------------------------------------------------------------- /tests/operators/OP_BGRToRGB/OP_BGRToRGB.hpp: -------------------------------------------------------------------------------- 1 | // This file is part of VisionCpp, a lightweight C++ template library 2 | // for computer vision and image processing. 3 | // 4 | // Copyright (C) 2016 Codeplay Software Limited. All Rights Reserved. 5 | // 6 | // Contact: visioncpp@codeplay.com 7 | // 8 | // Licensed under the Apache License, Version 2.0 (the "License"); 9 | // you may not use this file except in compliance with the License. 10 | // You may obtain a copy of the License at 11 | // 12 | // http://www.apache.org/licenses/LICENSE-2.0 13 | // 14 | // Unless required by applicable law or agreed to in writing, software 15 | // distributed under the License is distributed on an "AS IS" BASIS, 16 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | // See the License for the specific language governing permissions and 18 | // limitations under the License. 19 | 20 | #include "../../include/common.hpp" 21 | 22 | template 23 | void run_test(QUEUE &q, DATA data, int i) { 24 | cv::Mat ref; 25 | // 1) load in data 26 | cv::Mat frame(common::singleton::DataSet::Instance().m_height, 27 | common::singleton::DataSet::Instance().m_width, CV_8UC3, 28 | common::singleton::DataSet::Instance().m_data[i].get()); 29 | 30 | std::shared_ptr ret_val( 31 | new unsigned char[common::singleton::DataSet::Instance().m_height * 32 | common::singleton::DataSet::Instance().m_width * 3], 33 | [](unsigned char *dataMem) { delete[] dataMem; }); 34 | 35 | // 2) create gold_standard image 36 | cvtColor(frame, ref, CV_BGR2RGB); 37 | 38 | { 39 | // 3) define graph 40 | auto return_node = visioncpp::terminal< 41 | visioncpp::pixel::U8C3, common::singleton::DataSet::m_width, 42 | common::singleton::DataSet::m_height, visioncpp::memory_type::Buffer2D>( 43 | ret_val.get()); 44 | auto node = visioncpp::point_operation(data); 45 | 46 | // assign data from node to return_node 47 | auto assign_node = visioncpp::assign(return_node, node); 48 | // 4) execute pipe 49 | visioncpp::execute(assign_node, q); 50 | } 51 | // 7) verify 52 | verify(ref, ret_val); 53 | } 54 | -------------------------------------------------------------------------------- /tests/operators/OP_CVBGRToGRAY/OP_CVBGRToGRAY.hpp: -------------------------------------------------------------------------------- 1 | // This file is part of VisionCpp, a lightweight C++ template library 2 | // for computer vision and image processing. 3 | // 4 | // Copyright (C) 2016 Codeplay Software Limited. All Rights Reserved. 5 | // 6 | // Contact: visioncpp@codeplay.com 7 | // 8 | // Licensed under the Apache License, Version 2.0 (the "License"); 9 | // you may not use this file except in compliance with the License. 10 | // You may obtain a copy of the License at 11 | // 12 | // http://www.apache.org/licenses/LICENSE-2.0 13 | // 14 | // Unless required by applicable law or agreed to in writing, software 15 | // distributed under the License is distributed on an "AS IS" BASIS, 16 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | // See the License for the specific language governing permissions and 18 | // limitations under the License. 19 | 20 | #include "../../include/common.hpp" 21 | 22 | template 23 | void run_test(QUEUE &q, DATA data, int i) { 24 | cv::Mat ref; 25 | // 1) load in data 26 | cv::Mat frame(common::singleton::DataSet::Instance().m_height, 27 | common::singleton::DataSet::Instance().m_width, CV_8UC3, 28 | common::singleton::DataSet::Instance().m_data[i].get()); 29 | 30 | std::shared_ptr ret_val( 31 | new unsigned char[common::singleton::DataSet::Instance().m_height * 32 | common::singleton::DataSet::Instance().m_width], 33 | [](unsigned char *dataMem) { delete[] dataMem; }); 34 | 35 | // 2) create gold_standard image 36 | cvtColor(frame, ref, CV_BGR2GRAY); 37 | { 38 | // 3) define graph 39 | auto node = visioncpp::point_operation(data); 40 | auto return_node = visioncpp::terminal< 41 | visioncpp::pixel::U8C1, common::singleton::DataSet::m_width, 42 | common::singleton::DataSet::m_height, visioncpp::memory_type::Buffer2D>( 43 | ret_val.get()); 44 | 45 | auto node2 = visioncpp::point_operation(node); 46 | auto node3 = visioncpp::point_operation(node2); 47 | 48 | auto assign_node = visioncpp::assign(return_node, node3); 49 | // 4) execute pipe 50 | visioncpp::execute(assign_node, q); 51 | } 52 | // 7) verify 53 | verify(ref, ret_val); 54 | } 55 | -------------------------------------------------------------------------------- /tests/operators/OP_CVBGRToRGB/OP_CVBGRToRGB.hpp: -------------------------------------------------------------------------------- 1 | // This file is part of VisionCpp, a lightweight C++ template library 2 | // for computer vision and image processing. 3 | // 4 | // Copyright (C) 2016 Codeplay Software Limited. All Rights Reserved. 5 | // 6 | // Contact: visioncpp@codeplay.com 7 | // 8 | // Licensed under the Apache License, Version 2.0 (the "License"); 9 | // you may not use this file except in compliance with the License. 10 | // You may obtain a copy of the License at 11 | // 12 | // http://www.apache.org/licenses/LICENSE-2.0 13 | // 14 | // Unless required by applicable law or agreed to in writing, software 15 | // distributed under the License is distributed on an "AS IS" BASIS, 16 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | // See the License for the specific language governing permissions and 18 | // limitations under the License. 19 | 20 | #include "../../include/common.hpp" 21 | 22 | template 23 | void run_test(QUEUE &q, DATA data, int i) { 24 | cv::Mat ref; 25 | // 1) load in data 26 | cv::Mat frame(common::singleton::DataSet::Instance().m_height, 27 | common::singleton::DataSet::Instance().m_width, CV_8UC3, 28 | common::singleton::DataSet::Instance().m_data[i].get()); 29 | 30 | std::shared_ptr ret_val( 31 | new float[common::singleton::DataSet::Instance().m_height * 32 | common::singleton::DataSet::Instance().m_width * 3], 33 | [](float *dataMem) { delete[] dataMem; }); 34 | 35 | // 2) create gold_standard image 36 | cvtColor(frame, ref, CV_BGR2RGB); 37 | 38 | // that should being it down to 0.0 to 1.0 39 | ref /= 255.0f; 40 | 41 | // so we sync it all right 42 | { 43 | // 3) define graph 44 | // load in node data 45 | auto return_node = visioncpp::terminal< 46 | visioncpp::pixel::F32C3, common::singleton::DataSet::m_width, 47 | common::singleton::DataSet::m_height, visioncpp::memory_type::Buffer2D>( 48 | ret_val.get()); 49 | 50 | auto node = visioncpp::point_operation(data); 51 | 52 | // assign data from node to return_node 53 | auto assign_node = visioncpp::assign(return_node, node); 54 | // 4) execute pipe 55 | visioncpp::execute(assign_node, q); 56 | } 57 | 58 | // 7) verify 59 | verify(ref, ret_val); 60 | } 61 | -------------------------------------------------------------------------------- /tests/operators/OP_Filter2D/OP_Filter2D.hpp: -------------------------------------------------------------------------------- 1 | // This file is part of VisionCpp, a lightweight C++ template library 2 | // for computer vision and image processing. 3 | // 4 | // Copyright (C) 2016 Codeplay Software Limited. All Rights Reserved. 5 | // 6 | // Contact: visioncpp@codeplay.com 7 | // 8 | // Licensed under the Apache License, Version 2.0 (the "License"); 9 | // you may not use this file except in compliance with the License. 10 | // You may obtain a copy of the License at 11 | // 12 | // http://www.apache.org/licenses/LICENSE-2.0 13 | // 14 | // Unless required by applicable law or agreed to in writing, software 15 | // distributed under the License is distributed on an "AS IS" BASIS, 16 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | // See the License for the specific language governing permissions and 18 | // limitations under the License. 19 | 20 | #include "../../include/common.hpp" 21 | 22 | template 23 | void run_test(QUEUE &q, DATA data, int i) { 24 | // custom filter 25 | float filter_array[9] = {1.0 / 9.0, 1.0 / 9.0, 1.0 / 9.0, 26 | 1.0 / 9.0, 1.0 / 9.0, 1.0 / 9.0, 27 | 1.0 / 9.0, 1.0 / 9.0, 1.0 / 9.0}; 28 | cv::Mat ref; 29 | // 1) load in data 30 | cv::Mat frame(common::singleton::DataSet::Instance().m_height, 31 | common::singleton::DataSet::Instance().m_width, CV_8UC3, 32 | common::singleton::DataSet::Instance().m_data[i].get()); 33 | 34 | std::shared_ptr ret_val( 35 | new unsigned char[common::singleton::DataSet::Instance().m_height * 36 | common::singleton::DataSet::Instance().m_width * 3], 37 | [](unsigned char *dataMem) { delete[] dataMem; }); 38 | // 2) create gold_standard image 39 | int kernel_size = 3; 40 | cv::Mat intermid; 41 | cv::Mat kernel = cv::Mat::ones(kernel_size, kernel_size, CV_32F) / 42 | (float)(kernel_size * kernel_size); 43 | filter2D(intermid, ref, -1, kernel, cv::Point(-1, -1), 0, cv::BORDER_DEFAULT); 44 | 45 | { 46 | // 3) define graph 47 | auto return_node = visioncpp::terminal< 48 | visioncpp::pixel::U8C3, common::singleton::DataSet::m_height, 49 | common::singleton::DataSet::m_width, visioncpp::memory_type::Buffer2D>( 50 | ret_val.get()); 51 | 52 | auto node = visioncpp::point_operation(data); 53 | auto filter_node = 54 | visioncpp::terminal(filter_array); 56 | auto node2 = visioncpp::neighbour_operation( 57 | node, filter_node); 58 | auto node3 = visioncpp::point_operation(node2); 59 | 60 | // assign data from node to return_node 61 | auto assign_node = visioncpp::assign(return_node, node3); 62 | // 4) execute pipe 63 | visioncpp::execute(assign_node, q); 64 | } 65 | // 7) verify 66 | verify(ref, ret_val); 67 | } 68 | -------------------------------------------------------------------------------- /tests/operators/OP_GaussianBlur3x3/OP_GaussianBlur3x3.hpp: -------------------------------------------------------------------------------- 1 | // This file is part of VisionCpp, a lightweight C++ template library 2 | // for computer vision and image processing. 3 | // 4 | // Copyright (C) 2016 Codeplay Software Limited. All Rights Reserved. 5 | // 6 | // Contact: visioncpp@codeplay.com 7 | // 8 | // Licensed under the Apache License, Version 2.0 (the "License"); 9 | // you may not use this file except in compliance with the License. 10 | // You may obtain a copy of the License at 11 | // 12 | // http://www.apache.org/licenses/LICENSE-2.0 13 | // 14 | // Unless required by applicable law or agreed to in writing, software 15 | // distributed under the License is distributed on an "AS IS" BASIS, 16 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | // See the License for the specific language governing permissions and 18 | // limitations under the License. 19 | 20 | #include "../../include/common.hpp" 21 | 22 | template 23 | void run_test(QUEUE &q, DATA data, int i) { 24 | cv::Mat ref; 25 | // 1) load in data 26 | cv::Mat frame(common::singleton::DataSet::Instance().m_height, 27 | common::singleton::DataSet::Instance().m_width, CV_8UC3, 28 | common::singleton::DataSet::Instance().m_data[i].get()); 29 | 30 | std::shared_ptr ret_val( 31 | new unsigned char[common::singleton::DataSet::Instance().m_height * 32 | common::singleton::DataSet::Instance().m_width * 3], 33 | [](unsigned char *dataMem) { delete[] dataMem; }); 34 | // 2) create gold_standard image 35 | int kernel_size = 3; 36 | cv::Mat intermid; 37 | cv::Mat kernel = cv::Mat::ones(kernel_size, kernel_size, CV_32F) / 38 | (float)(kernel_size * kernel_size); 39 | filter2D(intermid, ref, -1, kernel, cv::Point(-1, -1), 0, cv::BORDER_DEFAULT); 40 | 41 | { 42 | // 3) define graph 43 | auto return_node = visioncpp::terminal< 44 | visioncpp::pixel::U8C3, common::singleton::DataSet::m_height, 45 | common::singleton::DataSet::m_width, visioncpp::memory_type::Buffer2D>( 46 | ret_val.get()); 47 | 48 | auto node = visioncpp::point_operation(data); 49 | auto node2 = visioncpp::neighbour_operation(node); 51 | auto node3 = visioncpp::point_operation(node2); 52 | 53 | // assign data from node to return_node 54 | auto assign_node = visioncpp::assign(return_node, node3); 55 | // 4) execute pipe 56 | visioncpp::execute(assign_node, q); 57 | } 58 | // 7) verify 59 | verify(ref, ret_val); 60 | } 61 | -------------------------------------------------------------------------------- /tests/operators/OP_SepFilterCol3x3/OP_SepFilterCol3x3.hpp: -------------------------------------------------------------------------------- 1 | // This file is part of VisionCpp, a lightweight C++ template library 2 | // for computer vision and image processing. 3 | // 4 | // Copyright (C) 2016 Codeplay Software Limited. All Rights Reserved. 5 | // 6 | // Contact: visioncpp@codeplay.com 7 | // 8 | // Licensed under the Apache License, Version 2.0 (the "License"); 9 | // you may not use this file except in compliance with the License. 10 | // You may obtain a copy of the License at 11 | // 12 | // http://www.apache.org/licenses/LICENSE-2.0 13 | // 14 | // Unless required by applicable law or agreed to in writing, software 15 | // distributed under the License is distributed on an "AS IS" BASIS, 16 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | // See the License for the specific language governing permissions and 18 | // limitations under the License. 19 | 20 | #include "../../include/common.hpp" 21 | 22 | template 23 | void run_test(QUEUE &q, DATA data, int i) { 24 | cv::Mat ref; 25 | // 1) load in data 26 | cv::Mat frame(common::singleton::DataSet::Instance().m_height, 27 | common::singleton::DataSet::Instance().m_width, CV_8UC3, 28 | common::singleton::DataSet::Instance().m_data[i].get()); 29 | 30 | std::shared_ptr ret_val( 31 | new unsigned char[common::singleton::DataSet::Instance().m_height * 32 | common::singleton::DataSet::Instance().m_width * 3], 33 | [](unsigned char *dataMem) { delete[] dataMem; }); 34 | // 2) create gold_standard image 35 | int kernel_size = 3; 36 | cv::Mat intermid; 37 | cv::Mat kernel = cv::Mat::ones(kernel_size, kernel_size, CV_32F) / 38 | (float)(kernel_size * kernel_size); 39 | filter2D(intermid, ref, -1, kernel, cv::Point(-1, -1), 0, cv::BORDER_DEFAULT); 40 | 41 | { 42 | float filter_array[3] = {1.0 / 3.0, 1.0 / 3.0, 1.0 / 3.0}; 43 | // 3) define graph 44 | auto return_node = visioncpp::terminal< 45 | visioncpp::pixel::U8C3, common::singleton::DataSet::m_height, 46 | common::singleton::DataSet::m_width, visioncpp::memory_type::Buffer2D>( 47 | ret_val.get()); 48 | 49 | auto filter_col = 50 | visioncpp::terminal(filter_array); 52 | auto filter_row = 53 | visioncpp::terminal(filter_array); 55 | 56 | auto node = visioncpp::point_operation(data); 57 | auto node2 = visioncpp::neighbour_operation( 58 | node, filter_col); 59 | auto node3 = visioncpp::neighbour_operation( 60 | node2, filter_row); 61 | auto node4 = visioncpp::point_operation(node3); 62 | 63 | // assign data from node to return_node 64 | auto assign_node = visioncpp::assign(return_node, node4); 65 | // 4) execute pipe 66 | visioncpp::execute(assign_node, q); 67 | } 68 | // 7) verify 69 | verify(ref, ret_val); 70 | } 71 | -------------------------------------------------------------------------------- /tests/operators/OP_UnsignedBGRToFloatRGB/OP_UnsignedBGRToFloatRGB.hpp: -------------------------------------------------------------------------------- 1 | // This file is part of VisionCpp, a lightweight C++ template library 2 | // for computer vision and image processing. 3 | // 4 | // Copyright (C) 2016 Codeplay Software Limited. All Rights Reserved. 5 | // 6 | // Contact: visioncpp@codeplay.com 7 | // 8 | // Licensed under the Apache License, Version 2.0 (the "License"); 9 | // you may not use this file except in compliance with the License. 10 | // You may obtain a copy of the License at 11 | // 12 | // http://www.apache.org/licenses/LICENSE-2.0 13 | // 14 | // Unless required by applicable law or agreed to in writing, software 15 | // distributed under the License is distributed on an "AS IS" BASIS, 16 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | // See the License for the specific language governing permissions and 18 | // limitations under the License. 19 | 20 | #include "../../include/common.hpp" 21 | 22 | template 23 | void run_test(QUEUE &q, DATA data, int i) { 24 | cv::Mat ref; 25 | // 1) load in data 26 | cv::Mat frame(common::singleton::DataSet::Instance().m_height, 27 | common::singleton::DataSet::Instance().m_width, CV_8UC3, 28 | common::singleton::DataSet::Instance().m_data[i].get()); 29 | 30 | std::shared_ptr ret_val( 31 | new float[common::singleton::DataSet::Instance().m_height * 32 | common::singleton::DataSet::Instance().m_width * 3], 33 | [](float *dataMem) { delete[] dataMem; }); 34 | 35 | // 2) create gold_standard image 36 | cvtColor(frame, ref, CV_BGR2RGB); 37 | ref = ref / 255.0f; 38 | 39 | { 40 | // 3) define graph 41 | auto return_node = visioncpp::terminal< 42 | visioncpp::pixel::F32C3, common::singleton::DataSet::m_width, 43 | common::singleton::DataSet::m_height, visioncpp::memory_type::Buffer2D>( 44 | ret_val.get()); 45 | auto node = visioncpp::point_operation(data); 46 | auto node2 = visioncpp::point_operation(node); 47 | 48 | // assign data from node to return_node 49 | auto assign_node = visioncpp::assign(return_node, node2); 50 | // 4) execute pipe 51 | visioncpp::execute(assign_node, q); 52 | } 53 | 54 | // 7) verify 55 | verify(ref, ret_val); 56 | } 57 | -------------------------------------------------------------------------------- /tests/operators/cc-gen.py: -------------------------------------------------------------------------------- 1 | # This file is part of VisionCpp, a lightweight C++ template library 2 | # for computer vision and image processing. 3 | # 4 | # Copyright (C) 2016 Codeplay Software Limited. All Rights Reserved. 5 | # 6 | # Contact: visioncpp@codeplay.com 7 | # 8 | # Licensed under the Apache License, Version 2.0 (the "License"); 9 | # you may not use this file except in compliance with the License. 10 | # You may obtain a copy of the License at 11 | # 12 | # http://www.apache.org/licenses/LICENSE-2.0 13 | # 14 | # Unless required by applicable law or agreed to in writing, software 15 | # distributed under the License is distributed on an "AS IS" BASIS, 16 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | # See the License for the specific language governing permissions and 18 | # limitations under the License. 19 | 20 | import os 21 | from string import Template 22 | from argparse import ArgumentParser 23 | import sys 24 | import os.path 25 | 26 | def main(): 27 | parser = ArgumentParser() 28 | parser.add_argument('--builddir', nargs=1) 29 | parser.add_argument('--testdir', nargs=1) 30 | args, leftover = parser.parse_known_args(sys.argv[1:]) 31 | 32 | autogenwarning = "// THIS FILE IS AUTO-GENERATED BY tests/operators/cc-gen.py \n" 33 | 34 | # open the template 35 | templatein = open( 'cc.template' ) 36 | # read it 37 | templatesrc = Template( templatein.read() ) 38 | 39 | # define targets 40 | targets = [ "cpu", "gpu" ] 41 | storages = [ "Buffer2D" ] 42 | executions = [ "Fuse", "NoFuse" ] 43 | 44 | # walk through each folder 45 | for root, dirs, files in os.walk(".", topdown=False): 46 | # for each folder 47 | for name in dirs: 48 | # for each target 49 | for target in targets: 50 | # for each storage 51 | for storage in storages: 52 | # for each execution policy 53 | for execution in executions: 54 | d={ 'test_name':name, 'test_target':target, 55 | 'test_storage': storage, 'test_execution':execution, 56 | 'test_dir' : args.testdir[0] } 57 | # replace 58 | result = templatesrc.substitute(d) 59 | s = [args.builddir[0],'autogen/'+ name +'/'+ name.upper()+'_'+storage.upper()+'_'+ target.upper() +'_'+execution.upper()+'.cpp'] 60 | path = os.path.join('',*s) 61 | print(path) 62 | os.makedirs(os.path.dirname(path), exist_ok=True) 63 | # write file 64 | with open(path, 'w') as file_: 65 | file_.write(autogenwarning + result) 66 | 67 | if __name__ == '__main__': 68 | sys.exit(main()) 69 | -------------------------------------------------------------------------------- /tests/operators/cc.template: -------------------------------------------------------------------------------- 1 | // This file is part of VisionCpp, a lightweight C++ template library 2 | // for computer vision and image processing. 3 | // 4 | // Copyright (C) 2016 Codeplay Software Limited. All Rights Reserved. 5 | // 6 | // Contact: visioncpp@codeplay.com 7 | // 8 | // Licensed under the Apache License, Version 2.0 (the "License"); 9 | // you may not use this file except in compliance with the License. 10 | // You may obtain a copy of the License at 11 | // 12 | // http://www.apache.org/licenses/LICENSE-2.0 13 | // 14 | // Unless required by applicable law or agreed to in writing, software 15 | // distributed under the License is distributed on an "AS IS" BASIS, 16 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | // See the License for the specific language governing permissions and 18 | // limitations under the License. 19 | 20 | #include "${test_dir}/${test_name}/${test_name}.hpp" 21 | 22 | // 0) define test name 23 | TEST(VisionCpp, ${test_name}_${test_target}_${test_storage}_${test_execution}) { 24 | 25 | // 1) chose device 26 | auto dev = 27 | visioncpp::make_device(); 28 | 29 | // 2) run test using buffer storage and fuse nodes 30 | for (int i = 0; i < common::singleton::DataSet::Instance().m_depth; i++) { 31 | run_test( 32 | dev, common::get${test_storage}(i), i); 33 | } 34 | } 35 | --------------------------------------------------------------------------------