.. _program_listing_file__tmp_ws_src_vitis_common_include_features_xf_harris.hpp: Program Listing for File xf_harris.hpp ====================================== |exhale_lsh| :ref:`Return to documentation for file ` (``/tmp/ws/src/vitis_common/include/features/xf_harris.hpp``) .. |exhale_lsh| unicode:: U+021B0 .. UPWARDS ARROW WITH TIP LEFTWARDS .. code-block:: cpp /* * Copyright 2019 Xilinx, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #ifndef _XF_HARRIS_HPP_ #define _XF_HARRIS_HPP_ #ifndef __cplusplus #error C++ is needed to use this file! #endif #include "hls_stream.h" #include "../common/xf_common.hpp" #include "../common/xf_utility.hpp" #include "../imgproc/xf_box_filter.hpp" #include "../imgproc/xf_sobel.hpp" #include "xf_harris_utils.hpp" #include "xf_max_suppression.hpp" #include "xf_pack_corners.hpp" #ifndef __SYNTHESIS__ #include #endif namespace xf { namespace cv { /************************************************************************ * xFCornerHarrisDetector : CornerHarris function to find corners in the image ************************************************************************/ template void xFCornerHarrisDetector(xf::cv::Mat& _src_mat, xf::cv::Mat& _dst_mat, uint16_t img_height, uint16_t img_width, uint16_t _nms_radius, uint16_t _threshold, uint16_t k) { int scale; if (FILTERSIZE == XF_FILTER_3X3) scale = 6; else if (FILTERSIZE == XF_FILTER_5X5) scale = 12; else if (FILTERSIZE == XF_FILTER_7X7) scale = 1; xf::cv::Mat gradx_2(img_height, img_width); xf::cv::Mat grady_2(img_height, img_width); xf::cv::Mat gradxy(img_height, img_width); xf::cv::Mat gradx2g(img_height, img_width); xf::cv::Mat grady2g(img_height, img_width); xf::cv::Mat gradxyg(img_height, img_width); xf::cv::Mat score(img_height, img_width); xf::cv::Mat thresh(img_height, img_width); // clang-format off #pragma HLS STREAM variable=gradx_2.data depth=2 #pragma HLS STREAM variable=grady_2.data depth=2 #pragma HLS STREAM variable=gradxy.data depth=2 #pragma HLS STREAM variable=grady2g.data depth=2 #pragma HLS STREAM variable=gradx2g.data depth=2 #pragma HLS STREAM variable=gradxyg.data depth=2 #pragma HLS STREAM variable=score.data depth=2 #pragma HLS STREAM variable=thresh.data depth=2 // clang-format on // clang-format off #pragma HLS DATAFLOW // clang-format on if (FILTERSIZE == XF_FILTER_7X7) { xf::cv::Mat gradx_mat(img_height, img_width); xf::cv::Mat grady_mat(img_height, img_width); xf::cv::Mat gradx1_mat(img_height, img_width); xf::cv::Mat gradx2_mat(img_height, img_width); xf::cv::Mat grady1_mat(img_height, img_width); xf::cv::Mat grady2_mat(img_height, img_width); // clang-format off #pragma HLS STREAM variable=gradx_mat.data depth=2 #pragma HLS STREAM variable=grady_mat.data depth=2 #pragma HLS STREAM variable=gradx1_mat.data depth=2 #pragma HLS STREAM variable=gradx2_mat.data depth=2 #pragma HLS STREAM variable=grady1_mat.data depth=2 #pragma HLS STREAM variable=grady2_mat.data depth=2 // clang-format on Sobel(_src_mat, gradx_mat, grady_mat); xFDuplicate(gradx_mat, gradx1_mat, gradx2_mat, img_height, img_width); xFDuplicate(grady_mat, grady1_mat, grady2_mat, img_height, img_width); xFSquare( gradx1_mat, gradx_2, scale, FILTERSIZE, img_height, img_width); xFSquare( grady1_mat, grady_2, scale, FILTERSIZE, img_height, img_width); xFMultiply( gradx2_mat, grady2_mat, gradxy, scale, FILTERSIZE, img_height, img_width); } else { xf::cv::Mat gradx_mat(img_height, img_width); xf::cv::Mat grady_mat(img_height, img_width); xf::cv::Mat gradx1_mat(img_height, img_width); xf::cv::Mat grady1_mat(img_height, img_width); xf::cv::Mat gradx2_mat(img_height, img_width); xf::cv::Mat grady2_mat(img_height, img_width); // clang-format off #pragma HLS STREAM variable=gradx_mat.data depth=2 #pragma HLS STREAM variable=grady_mat.data depth=2 #pragma HLS STREAM variable=gradx1_mat.data depth=2 #pragma HLS STREAM variable=gradx2_mat.data depth=2 #pragma HLS STREAM variable=grady1_mat.data depth=2 #pragma HLS STREAM variable=grady2_mat.data depth=2 // clang-format on Sobel(_src_mat, gradx_mat, grady_mat); xFDuplicate(gradx_mat, gradx1_mat, gradx2_mat, img_height, img_width); xFDuplicate(grady_mat, grady1_mat, grady2_mat, img_height, img_width); xFSquare( gradx1_mat, gradx_2, scale, FILTERSIZE, img_height, img_width); xFSquare( grady1_mat, grady_2, scale, FILTERSIZE, img_height, img_width); xFMultiply( gradx2_mat, grady2_mat, gradxy, scale, FILTERSIZE, img_height, img_width); } boxFilter(gradx_2, gradx2g); boxFilter(grady_2, grady2g); boxFilter(gradxy, gradxyg); xFComputeScore( gradx2g, grady2g, gradxyg, score, img_height, img_width, k, FILTERSIZE); xFThreshold(score, thresh, _threshold, img_height, img_width); xFMaxSuppression(thresh, _dst_mat, _nms_radius, img_height, img_width); } template void cornerHarris(xf::cv::Mat& src, xf::cv::Mat& dst, uint16_t threshold, uint16_t k) { // clang-format off #pragma HLS inline off // clang-format on uint16_t img_height = src.rows; uint16_t img_width = src.cols; //>> XF_BITSHIFT(NPC); #ifndef __SYNTHESIS__ assert(((FILTERSIZE == XF_FILTER_3X3) || (FILTERSIZE == XF_FILTER_5X5) || (FILTERSIZE == XF_FILTER_7X7)) && "filter width must be 3, 5 or 7"); assert(((BLOCKWIDTH == XF_FILTER_3X3) || (BLOCKWIDTH == XF_FILTER_5X5) || (BLOCKWIDTH == XF_FILTER_7X7)) && "block width must be 3, 5 or 7"); assert(((NMSRADIUS == XF_NMS_RADIUS_1) || (NMSRADIUS == XF_NMS_RADIUS_2)) && "radius size must be 1, 2"); assert(((img_height <= ROWS) && (src.cols <= COLS)) && "ROWS and COLS should be greater than input image"); assert(((NPC == XF_NPPC1) || (NPC == XF_NPPC8)) && " NPC must be 0 or 3 "); #endif if (NPC == XF_NPPC8) { xFCornerHarrisDetector> XF_BITSHIFT(NPC)), XF_128UW, XF_256UW, USE_URAM>(src, dst, img_height, img_width, NMSRADIUS, threshold, k); } else if (NPC == XF_NPPC1) { xFCornerHarrisDetector> XF_BITSHIFT(NPC)), XF_16UW, XF_32UW, USE_URAM>(src, dst, img_height, img_width, NMSRADIUS, threshold, k); } } } // namespace cv } // namespace xf #endif // _XF_HARRIS_HPP_