を設定した。/media/masaaki/Ubuntu_Disk/Vitis_HLS/ZYBO_Z7_20/2021.2/xf_mode_filter_axis/test2.jpg
を設定した。/media/masaaki/Ubuntu_Disk/Vitis_HLS/ZYBO_Z7_20/2021.2/xf_mode_filter_axis/test2.jpg
の行をコメントアウトして、XPART、 XF_PROJ_ROOT、 OPENCV_INCLUDE、 OPENCV_LIB、 CSIM の環境変数を追加した。Vitis HLS のプロジェクトができれば文句ないので、CSIM だけ 1 にした。後、CLKP を 3.3 ns から 10 ns に変更した。build ディレクトリへのインクルード・パスと合成時のトップ関数の名前も修正した。source settings.tcl
#
# 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.
#
# 2022/02/07 : modified by marsee
#source settings.tcl
set PROJ "modefilter.prj"
set SOLN "sol1"
set XPART "xc7z020-clg400-1"
set XF_PROJ_ROOT "/media/masaaki/Ubuntu_Disk/Xilinx_github/Vitis_Libraries/vision"
set OPENCV_INCLUDE "/usr/local/include"
set OPENCV_LIB "/usr/local/lib"
set CSIM "1"
set BUILD_DIR "/media/masaaki/Ubuntu_Disk/Vitis_HLS/ZYBO_Z7_20/2021.2/xf_mode_filter_axis/build"
if {![info exists CLKP]} {
set CLKP 10
}
open_project -reset $PROJ
add_files "xf_modefilter_accel.cpp" -cflags "-I${XF_PROJ_ROOT}/L1/include -I ${BUILD_DIR} -I ./ -D__SDSVHLS__ -std=c++0x" -csimflags "-I${XF_PROJ_ROOT}/L1/include -I ${BUILD_DIR} -I ./ -D__SDSVHLS__ -std=c++0x"
add_files -tb "xf_modefilter_tb.cpp" -cflags "-I${OPENCV_INCLUDE} -I${XF_PROJ_ROOT}/L1/include -I ${XF_PROJ_ROOT}/L1/examples/modefilter/build -I ./ -D__SDSVHLS__ -std=c++0x" -csimflags "-I${XF_PROJ_ROOT}/L1/include -I ${XF_PROJ_ROOT}/L1/examples/modefilter/build -I ./ -D__SDSVHLS__ -std=c++0x"
set_top modefilter_axis
open_solution -reset $SOLN
set_part $XPART
create_clock -period $CLKP
if {$CSIM == 1} {
csim_design -ldflags "-L ${OPENCV_LIB} -lopencv_imgcodecs -lopencv_imgproc -lopencv_core -lopencv_highgui -lopencv_flann -lopencv_features2d" -argv " ${XF_PROJ_ROOT}/data/128x128.png "
}
if {$CSYNTH == 1} {
csynth_design
}
if {$COSIM == 1} {
cosim_design -ldflags "-L ${OPENCV_LIB} -lopencv_imgcodecs -lopencv_imgproc -lopencv_core -lopencv_highgui -lopencv_flann -lopencv_features2d" -argv " ${XF_PROJ_ROOT}/data/128x128.png "
}
if {$VIVADO_SYN == 1} {
export_design -flow syn -rtl verilog
}
if {$VIVADO_IMPL == 1} {
export_design -flow impl -rtl verilog
}
exit
/*
* Copyright 2020 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.
*/
// 2022/02/07 : modified by marsee
#ifndef _XF_MODE_FILTER_CONFIG_H_
#define _XF_MODE_FILTER_CONFIG_H_
#include <stdint.h>
#include "hls_stream.h"
#include "ap_int.h"
#include "common/xf_common.hpp"
#include "common/xf_utility.hpp"
#include "ap_axi_sdata.h"
#include "common/xf_infra.hpp"
#include "common/xf_axi_io.hpp"
#include "xf_config_params.h"
#include "imgproc/xf_modefilter.hpp"
#define HEIGHT 128
#define WIDTH 128
// Set the optimization type:
#if NO == 1
#define NPC1 XF_NPPC1
#define PTR_WIDTH 128
#else
#if GRAY
#define NPC1 XF_NPPC8
#else
#define NPC1 XF_NPPC1
#endif
#define PTR_WIDTH 128
#endif
// Set the pixel depth:
#if GRAY
#define TYPE XF_8UC1
#define STREAMW 8
#else
#define TYPE XF_8UC3
#define STREAMW 32
#endif
typedef hls::stream<ap_axiu<STREAMW,1,1,1> > AXI_STREAM;
void modefilter_axis(AXI_STREAM& _src, int32_t rows, int32_t cols, AXI_STREAM& _dst);
#endif // end of _XF_MEDIAN_BLUR_CONFIG_H_
/*
* Copyright 2020 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.
*/
// 2022/02/07 : Change to AXI4-Stream input / output. by marsee
#include "xf_modefilter_config.h"
void modefilter_axis(AXI_STREAM& _src, int32_t rows, int32_t cols, AXI_STREAM& _dst) {
// clang-format off
#pragma HLS INTERFACE mode=axis register_mode=both port=_src register
#pragma HLS INTERFACE mode=axis register_mode=both port=_dst register
#pragma HLS INTERFACE s_axilite port=rows bundle=control
#pragma HLS INTERFACE s_axilite port=cols bundle=control
#pragma HLS INTERFACE s_axilite port=return bundle=control
// clang-format on
xf::cv::Mat<TYPE, HEIGHT, WIDTH, NPC1> imgInput(rows, cols);
xf::cv::Mat<TYPE, HEIGHT, WIDTH, NPC1> imgOutput(rows, cols);
// clang-format off
#pragma HLS DATAFLOW
// clang-format on
xf::cv::AXIvideo2xfMat<STREAMW, TYPE>(_src, imgInput);
// Run xfOpenCV kernel:
xf::cv::modefilter<WINDOW_SIZE, XF_BORDER_REPLICATE, TYPE, HEIGHT, WIDTH, NPC1>(imgInput, imgOutput);
xf::cv::xfMat2AXIvideo<STREAMW, TYPE>(imgOutput, _dst);
return;
} // End of kernel
/*
* Copyright 2020 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.
*/
// 2022/02/07 : Change to AXI4-Stream input / output. by marsee
#include "opencv2/opencv.hpp"
#include "opencv2/imgproc/imgproc.hpp"
#include "opencv2/highgui/highgui.hpp"
#include "opencv2/imgcodecs/imgcodecs.hpp"
#include "common/xf_headers.hpp"
#include "common/xf_axi.hpp"
#include "common/xf_sw_utils.hpp"
#include <stdio.h>
#include <stdlib.h>
#include "xf_modefilter_config.h"
using namespace std;
cv::RNG rng(12345);
void mode_filter_rgb(cv::Mat _src, cv::Mat _dst, int win_sz) {
int win_sz_sq = win_sz * win_sz;
int window[win_sz_sq];
cv::Scalar value(rng.uniform(0, 255), rng.uniform(0, 255), rng.uniform(0, 255));
cv::Mat _src_border;
_src_border.create(_src.rows + win_sz - 1, _src.cols + win_sz - 1, CV_8UC3);
int border = floor(win_sz / 2);
cv::copyMakeBorder(_src, _src_border, border, border, border, border, cv::BORDER_REPLICATE, value);
for (int k = 0; k < 3; k++) {
for (int i = 0; i < _src.rows; i++) {
for (int j = 0; j < _src.cols; j++) {
for (int p = 0; p < win_sz; p++) {
for (int q = 0; q < win_sz; q++) {
// cout<<p<<" "<<q<<" "<<endl;
window[q + p * win_sz] = _src_border.at<cv::Vec3b>(i + p, j + q)[k];
}
}
int max_count = 0, idx = 0;
for (int m = 0; m < win_sz_sq; m++) {
int count = 1;
for (int n = m + 1; n < win_sz_sq - 1; n++) {
if (window[m] == window[n]) count++;
}
if (count > max_count) {
max_count = count;
}
}
for (int m = 0; m < win_sz_sq; m++) {
int count = 1;
for (int n = m + 1; n < win_sz_sq - 1; n++) {
if (window[m] == window[n]) count++;
}
if (count == max_count) {
idx = m;
}
}
_dst.at<cv::Vec3b>(i, j)[k] = window[idx];
}
}
}
return;
}
void mode_filter_gray(cv::Mat _src, cv::Mat _dst, int win_sz) {
int win_sz_sq = win_sz * win_sz;
int window[win_sz_sq];
int i_1_index = 0, j_1_index = 0, i_plus_index = 0, j_plus_index = 0;
cv::Mat _src_border;
_src_border.create(_src.rows + win_sz - 1, _src.cols + win_sz - 1, CV_8UC1);
int border = floor(win_sz / 2);
cv::copyMakeBorder(_src, _src_border, border, border, border, border, cv::BORDER_REPLICATE);
for (int i = 0; i < _src.rows; i++) {
for (int j = 0; j < _src.cols; j++) {
for (int p = 0; p < win_sz; p++) {
for (int q = 0; q < win_sz; q++) {
window[q + p * win_sz] = _src_border.at<uchar>(i + p, j + q);
}
}
int max_count = 0, idx = 0;
for (int i = 0; i < win_sz_sq; i++) {
int count = 1;
for (int j = i + 1; j < win_sz_sq - 1; j++) {
if (window[i] == window[j]) count++;
}
if (count > max_count) {
max_count = count;
}
}
for (int i = 0; i < win_sz_sq; i++) {
int count = 1;
for (int j = i + 1; j < win_sz_sq - 1; j++) {
if (window[i] == window[j]) count++;
}
if (count == max_count) {
idx = i;
}
}
_dst.at<uchar>(i, j) = window[idx];
}
}
return;
}
int main(int argc, char** argv) {
if (argc != 2) {
fprintf(stderr, "Usage: <executable> <input image path>\n");
return -1;
}
cv::Mat in_img, out_img, ocv_ref, ocv_ref1, diff;
// Reading in the image:
#if GRAY
cout << "gray:";
in_img = cv::imread(argv[1], 0); // reading in the gray image
imwrite("in_img1.jpg", in_img);
#else
in_img = cv::imread(argv[1], 1); // reading in the color image
imwrite("in_img2.jpg", in_img);
#endif
if (!in_img.data) {
return -1;
}
// imwrite("in_img.jpg", in_img);
// create memory for output image
#if GRAY
cout << "gray:";
ocv_ref.create(in_img.rows, in_img.cols, CV_8UC1);
ocv_ref1.create(in_img.rows, in_img.cols, CV_8UC1);
out_img.create(in_img.rows, in_img.cols, CV_8UC1); // create memory for output image
diff.create(in_img.rows, in_img.cols, CV_8UC1);
#else
ocv_ref.create(in_img.rows, in_img.cols, CV_8UC3);
ocv_ref1.create(in_img.rows, in_img.cols, CV_8UC3);
out_img.create(in_img.rows, in_img.cols, CV_8UC3); // create memory for output image
diff.create(in_img.rows, in_img.cols, CV_8UC3);
#endif
#if GRAY
cout << "gray:";
mode_filter_gray(in_img, ocv_ref, WINDOW_SIZE);
#else
cout << "rgb";
mode_filter_rgb(in_img, ocv_ref, WINDOW_SIZE);
#endif
//modefilter_accel((ap_uint<PTR_WIDTH>*)in_img.data, in_img.rows, in_img.cols, (ap_uint<PTR_WIDTH>*)out_img.data);
AXI_STREAM _src,_dst;
xf::cv::cvMat2AXIvideoxf<NPC1, STREAMW>(in_img, _src);
modefilter_axis(_src, in_img.rows, in_img.cols, _dst);
xf::cv::AXIvideo2cvMatxf<NPC1, STREAMW>(_dst, out_img);
imwrite("out_img.jpg", out_img);
imwrite("ocv_ref.jpg", ocv_ref);
// imwrite("ocv_ref.jpg", ocv_ref1);
cv::absdiff(ocv_ref, out_img, diff);
imwrite("diff.jpg", diff);
absdiff(ocv_ref, out_img, diff);
// Save the difference image for debugging purpose:
cv::imwrite("error.png", diff);
float err_per;
xf::cv::analyzeDiff(diff, 0, err_per);
if (err_per > 0.0f) {
fprintf(stderr, "ERROR: Test Failed.\n ");
return 1;
}
std::cout << "Test Passed " << std::endl;
return 0;
}
(base) masaaki@masaaki-H110M4-M01:/media/masaaki/Ubuntu_Disk/Vitis_HLS/ZYBO_Z7_20/2021.2/xf_fast_axis$ vitis_hls -f xf_fast_axis_home.tcl
****** Vitis HLS - High-Level Synthesis from C, C++ and OpenCL v2021.2 (64-bit)
**** SW Build 3367213 on Tue Oct 19 02:47:39 MDT 2021
**** IP Build 3369179 on Thu Oct 21 08:25:16 MDT 2021
** Copyright 1986-2021 Xilinx, Inc. All Rights Reserved.
source /media/masaaki/Ubuntu_Disk/tools/Xilinx/Vitis_HLS/2021.2/scripts/vitis_hls/hls.tcl -notrace
INFO: Applying HLS Y2K22 patch v1.2 for IP revision
INFO: [HLS 200-10] Running '/media/masaaki/Ubuntu_Disk/tools/Xilinx/Vitis_HLS/2021.2/bin/unwrapped/lnx64.o/vitis_hls'
INFO: [HLS 200-10] For user 'masaaki' on host 'masaaki-H110M4-M01' (Linux_x86_64 version 4.15.0-166-generic) on Sat Feb 05 03:21:48 JST 2022
INFO: [HLS 200-10] On os Ubuntu 18.04.6 LTS
INFO: [HLS 200-10] In directory '/media/masaaki/Ubuntu_Disk/Vitis_HLS/ZYBO_Z7_20/2021.2/xf_fast_axis'
WARNING: [HLS 200-40] Environment variable 'C_INCLUDE_PATH' is set to :/usr/local/cuda/include.
Sourcing Tcl script 'xf_fast_axis_home.tcl'
INFO: [HLS 200-1510] Running: open_project xf_fast_axis
INFO: [HLS 200-10] Creating and opening project '/media/masaaki/Ubuntu_Disk/Vitis_HLS/ZYBO_Z7_20/2021.2/xf_fast_axis/xf_fast_axis'.
INFO: [HLS 200-1510] Running: set_top fast_accel_axis
INFO: [HLS 200-1510] Running: add_files xf_fast_axis.cpp -cflags -I/media/masaaki/Ubuntu_Disk/Xilinx_github/Vitis_Libraries/vision/L1/include -std=c++0x
INFO: [HLS 200-10] Adding design file 'xf_fast_axis.cpp' to the project
INFO: [HLS 200-1510] Running: add_files -tb xf_fast_axis_tb.cpp -cflags -I/media/masaaki/Ubuntu_Disk/Xilinx_github/Vitis_Libraries/vision/L1/include -I/usr/local/include -std=c++0x -Wno-unknown-pragmas -csimflags -Wno-unknown-pragmas
INFO: [HLS 200-10] Adding test bench file 'xf_fast_axis_tb.cpp' to the project
INFO: [HLS 200-1510] Running: open_solution solution1 -flow_target vivado
INFO: [HLS 200-10] Creating and opening solution '/media/masaaki/Ubuntu_Disk/Vitis_HLS/ZYBO_Z7_20/2021.2/xf_fast_axis/xf_fast_axis/solution1'.
INFO: [HLS 200-1505] Using flow_target 'vivado'
Resolution: For help on HLS 200-1505 see www.xilinx.com/cgi-bin/docs/rdoc?v=2021.2;t=hls+guidance;d=200-1505.html
INFO: [HLS 200-1510] Running: set_part xc7z020-clg400-1
INFO: [HLS 200-1611] Setting target device to 'xc7z020-clg400-1'
INFO: [HLS 200-1510] Running: create_clock -period 10 -name default
INFO: [SYN 201-201] Setting up clock 'default' with a period of 10ns.
INFO: [HLS 200-1510] Running: config_export -format ip_catalog -rtl verilog -vivado_clock 10
INFO: [HLS 200-1510] Running: csim_design -ldflags -L/usr/local/lib -lopencv_core -lopencv_imgcodecs -lopencv_imgproc -argv /media/masaaki/Ubuntu_Disk/Vitis_HLS/ZYBO_Z7_20/2021.2/xf_fast_axis/test2.jpg
INFO: [SIM 211-2] *************** CSIM start ***************
INFO: [SIM 211-4] CSIM will launch GCC as the compiler.
Compiling ../../../../xf_fast_axis_tb.cpp in debug mode
Compiling ../../../../xf_fast_axis.cpp in debug mode
Generating csim.exe
Makefile.rules:392: recipe for target 'csim.exe' failed
In file included from /media/masaaki/Ubuntu_Disk/Xilinx_github/Vitis_Libraries/vision/L1/include/common/xf_structs.hpp:27:0,
from /media/masaaki/Ubuntu_Disk/Xilinx_github/Vitis_Libraries/vision/L1/include/common/xf_common.hpp:20,
from /media/masaaki/Ubuntu_Disk/Xilinx_github/Vitis_Libraries/vision/L1/include/common/xf_sw_utils.hpp:20,
from /media/masaaki/Ubuntu_Disk/Xilinx_github/Vitis_Libraries/vision/L1/include/common/xf_headers.hpp:28,
from ../../../../xf_fast_axis_tb.cpp:24:
/media/masaaki/Ubuntu_Disk/tools/Xilinx/Vitis_HLS/2021.2/include/ap_axi_sdata.h:97:45: warning: variable templates only available with -std=c++14 or -std=gnu++14
template <typename T> constexpr std::size_t bitwidth = sizeof(T) * CHAR_BIT;
^~~~~~~~
/media/masaaki/Ubuntu_Disk/tools/Xilinx/Vitis_HLS/2021.2/include/ap_axi_sdata.h:99:48: warning: variable templates only available with -std=c++14 or -std=gnu++14
template <std::size_t W> constexpr std::size_t bitwidth<ap_int<W>> = W;
^~~~~~~~~~~~~~~~~~~
/media/masaaki/Ubuntu_Disk/tools/Xilinx/Vitis_HLS/2021.2/include/ap_axi_sdata.h:100:48: warning: variable templates only available with -std=c++14 or -std=gnu++14
template <std::size_t W> constexpr std::size_t bitwidth<ap_uint<W>> = W;
^~~~~~~~~~~~~~~~~~~~
/media/masaaki/Ubuntu_Disk/tools/Xilinx/Vitis_HLS/2021.2/include/ap_axi_sdata.h:102:23: warning: variable templates only available with -std=c++14 or -std=gnu++14
constexpr std::size_t bitwidth<ap_fixed<_AP_W, _AP_I, _AP_Q, _AP_O, _AP_N>> = _AP_W;
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/media/masaaki/Ubuntu_Disk/tools/Xilinx/Vitis_HLS/2021.2/include/ap_axi_sdata.h:104:23: warning: variable templates only available with -std=c++14 or -std=gnu++14
constexpr std::size_t bitwidth<ap_ufixed<_AP_W, _AP_I, _AP_Q, _AP_O, _AP_N>> = _AP_W;
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/media/masaaki/Ubuntu_Disk/tools/Xilinx/Vitis_HLS/2021.2/include/ap_axi_sdata.h:107:23: warning: variable templates only available with -std=c++14 or -std=gnu++14
constexpr std::size_t bytewidth = (bitwidth<T> + CHAR_BIT - 1) / CHAR_BIT;
^~~~~~~~~
In file included from /media/masaaki/Ubuntu_Disk/Xilinx_github/Vitis_Libraries/vision/L1/include/common/xf_axi.hpp:23:0,
from ../../../../xf_fast_axis_tb.cpp:25:
/media/masaaki/Ubuntu_Disk/tools/Xilinx/Vitis_HLS/2021.2/include/utils/x_hls_utils.h:246:10: warning: ‘hls_preserve’ attribute directive ignored [-Wattributes]
T reg(T d)
^
In file included from /media/masaaki/Ubuntu_Disk/Xilinx_github/Vitis_Libraries/vision/L1/include/common/xf_structs.hpp:27:0,
from /media/masaaki/Ubuntu_Disk/Xilinx_github/Vitis_Libraries/vision/L1/include/common/xf_common.hpp:20,
from ../../../../xf_fast_axis.h:12,
from ../../../../xf_fast_axis.cpp:6:
/media/masaaki/Ubuntu_Disk/tools/Xilinx/Vitis_HLS/2021.2/include/ap_axi_sdata.h:97:45: warning: variable templates only available with -std=c++14 or -std=gnu++14
template <typename T> constexpr std::size_t bitwidth = sizeof(T) * CHAR_BIT;
^~~~~~~~
/media/masaaki/Ubuntu_Disk/tools/Xilinx/Vitis_HLS/2021.2/include/ap_axi_sdata.h:99:48: warning: variable templates only available with -std=c++14 or -std=gnu++14
template <std::size_t W> constexpr std::size_t bitwidth<ap_int<W>> = W;
^~~~~~~~~~~~~~~~~~~
/media/masaaki/Ubuntu_Disk/tools/Xilinx/Vitis_HLS/2021.2/include/ap_axi_sdata.h:100:48: warning: variable templates only available with -std=c++14 or -std=gnu++14
template <std::size_t W> constexpr std::size_t bitwidth<ap_uint<W>> = W;
^~~~~~~~~~~~~~~~~~~~
/media/masaaki/Ubuntu_Disk/tools/Xilinx/Vitis_HLS/2021.2/include/ap_axi_sdata.h:102:23: warning: variable templates only available with -std=c++14 or -std=gnu++14
constexpr std::size_t bitwidth<ap_fixed<_AP_W, _AP_I, _AP_Q, _AP_O, _AP_N>> = _AP_W;
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/media/masaaki/Ubuntu_Disk/tools/Xilinx/Vitis_HLS/2021.2/include/ap_axi_sdata.h:104:23: warning: variable templates only available with -std=c++14 or -std=gnu++14
constexpr std::size_t bitwidth<ap_ufixed<_AP_W, _AP_I, _AP_Q, _AP_O, _AP_N>> = _AP_W;
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/media/masaaki/Ubuntu_Disk/tools/Xilinx/Vitis_HLS/2021.2/include/ap_axi_sdata.h:107:23: warning: variable templates only available with -std=c++14 or -std=gnu++14
constexpr std::size_t bytewidth = (bitwidth<T> + CHAR_BIT - 1) / CHAR_BIT;
^~~~~~~~~
In file included from /media/masaaki/Ubuntu_Disk/Xilinx_github/Vitis_Libraries/vision/L1/include/common/xf_axi_io.hpp:19:0,
from /media/masaaki/Ubuntu_Disk/Xilinx_github/Vitis_Libraries/vision/L1/include/common/xf_infra.hpp:29,
from ../../../../xf_fast_axis.h:15,
from ../../../../xf_fast_axis.cpp:6:
/media/masaaki/Ubuntu_Disk/tools/Xilinx/Vitis_HLS/2021.2/include/utils/x_hls_utils.h:246:10: warning: ‘hls_preserve’ attribute directive ignored [-Wattributes]
T reg(T d)
^
obj/xf_fast_axis_tb.o: In function `main':
/media/masaaki/Ubuntu_Disk/Vitis_HLS/ZYBO_Z7_20/2021.2/xf_fast_axis/xf_fast_axis/solution1/csim/build/../../../../xf_fast_axis_tb.cpp:51: undefined reference to `cv::FAST(cv::_InputArray const&, std::vector<cv::KeyPoint, std::allocator<cv::KeyPoint> >&, int, bool)'
collect2: error: ld returned 1 exit status
make: *** [csim.exe] Error 1
ERROR: [SIM 211-100] 'csim_design' failed: compilation error(s).
INFO: [SIM 211-3] *************** CSIM finish ***************
INFO: [HLS 200-111] Finished Command csim_design CPU user time: 7.47 seconds. CPU system time: 0.5 seconds. Elapsed time: 6.79 seconds; current allocated memory: -937.109 MB.
4
while executing
"source xf_fast_axis_home.tcl"
("uplevel" body line 1)
invoked from within
"uplevel \#0 [list source $arg] "
INFO: [HLS 200-112] Total CPU user time: 9.37 seconds. Total CPU system time: 0.94 seconds. Total elapsed time: 15.71 seconds; peak allocated memory: 211.121 MB.
INFO: [Common 17-206] Exiting vitis_hls at Sat Feb 5 03:22:04 2022...
(base) masaaki@masaaki-H110M4-M01:/media/masaaki/Ubuntu_Disk/Vitis_HLS/ZYBO_Z7_20/2021.2/xf_fast_axis$
だった。xf_fast_axis_tb.cpp:51: undefined reference to `cv::FAST(cv::_InputArray const&, std::vector<cv::KeyPoint, std::allocator<cv::KeyPoint> >&, int, bool)'
/*
* 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.
*/
// xf_fast_axis_tb.cpp
// 2022/02/03 by marsee
// fast_accel を AXI4-Stream 入出力に変更
// 2022/02/04 : cv::FASTと関連する文ををコメントアウト、コンパイルが通らなかったため。。。orz
#include "opencv2/opencv.hpp"
#include "opencv2/imgproc/imgproc.hpp"
#include "opencv2/highgui/highgui.hpp"
#include "opencv2/imgcodecs/imgcodecs.hpp"
#include "opencv2/features2d.hpp"
#include "common/xf_headers.hpp"
#include "common/xf_axi.hpp"
#include "common/xf_sw_utils.hpp"
#include "xf_fast_axis.h"
void fast_accel_axis(AXI_STREAM& _src, AXI_STREAM& _dst, unsigned char threshold,
int32_t row, int32_t cols);
int main(int argc, char** argv) {
cv::Mat in_img, out_img, out_img_ocv, out_hls;
cv::Mat in_gray;
in_img = cv::imread(argv[1], 1); // reading in the color image
if (!in_img.data) {
fprintf(stderr, "Failed to load the image ... %s\n ", argv[1]);
return -1;
}
std::vector<cv::KeyPoint> keypoints;
uchar_t threshold = 20; // threshold
cvtColor(in_img, in_gray, cv::COLOR_BGR2GRAY);
// OPenCV reference function
//cv::FAST(in_gray, keypoints, threshold, true, (cv::FastFeatureDetector::DetectorType)0);
unsigned short imgwidth = in_img.cols;
unsigned short imgheight = in_img.rows;
out_hls.create(in_gray.rows, in_gray.cols, CV_8U);
// Call the top function
AXI_STREAM _src,_dst;
xf::cv::cvMat2AXIvideoxf<NPxPC, STREAMW>(in_gray, _src);
fast_accel_axis(_src, _dst, threshold, imgheight, imgwidth);
xf::cv::AXIvideo2cvMatxf<NPxPC, STREAMW>(_dst, out_hls);
std::vector<cv::Point> hls_points;
std::vector<cv::Point> ocv_points;
std::vector<cv::Point> common_points;
std::vector<cv::Point> noncommon_points;
FILE *fp, *fp1;
fp = fopen("ocvpoints.txt", "w");
fp1 = fopen("hlspoints.txt", "w");
int nsize = keypoints.size();
printf("ocvpoints:%d=\n", nsize);
for (int i = 0; i < nsize; i++) {
int x = keypoints[i].pt.x;
int y = keypoints[i].pt.y;
ocv_points.push_back(cv::Point(x, y));
// fprintf(fp, "x = %d, y = %d\n", x, y);
}
// fclose(fp);
out_img_ocv = in_img.clone();
int ocv_x = 0, ocv_y = 0;
for (int cnt1 = 0; cnt1 < keypoints.size(); cnt1++) {
ocv_x = keypoints[cnt1].pt.x;
ocv_y = keypoints[cnt1].pt.y;
cv::circle(out_img_ocv, cv::Point(ocv_x, ocv_y), 5, cv::Scalar(0, 0, 255), 2, 8, 0);
}
cv::imwrite("output_ocv.png", out_img_ocv);
//
out_img = in_gray.clone();
for (int j = 0; j < out_hls.rows; j++) {
for (int i = 0; i < out_hls.cols; i++) {
unsigned char value = out_hls.at<unsigned char>(j, i);
if (value != 0) {
short int y, x;
y = j;
x = i;
cv::Point tmp;
tmp.x = i;
tmp.y = j;
hls_points.push_back(tmp);
if (j > 0) cv::circle(out_img, cv::Point(x, y), 5, cv::Scalar(0, 0, 255, 255), 2, 8, 0);
}
}
}
int nsize1 = hls_points.size();
printf("hls_points.size() = %d\n", hls_points.size());
int Nocv = ocv_points.size();
int Nhls = hls_points.size();
for (int r = 0; r < nsize1; r++) {
int a, b;
a = (int)hls_points[r].x;
b = (int)hls_points[r].y;
fprintf(fp1, "x = %d, y = %d\n", a, b);
}
fclose(fp1);
for (int j = 0; j < Nocv; j++) {
for (int k = 0; k < Nhls; k++) {
if ((ocv_points[j].x == ((hls_points[k].x))) && (ocv_points[j].y == ((hls_points[k].y)))) {
common_points.push_back(ocv_points[j]);
}
}
}
FILE* fpt3;
fpt3 = fopen("common.txt", "w");
for (unsigned int p = 0; p < common_points.size(); p++) {
fprintf(fpt3, "x = %d, y = %d\n", common_points[p].x, common_points[p].y);
}
fclose(fpt3);
cv::imwrite("output_hls.png", out_img);
// Results verification:
float persuccess, perloss, pergain;
int totalocv = ocv_points.size();
int totalhls = hls_points.size();
int ncommon = common_points.size();
persuccess = (((float)ncommon / totalhls) * 100);
perloss = (((float)(totalocv - ncommon) / totalocv) * 100);
pergain = (((float)(totalhls - ncommon) / totalhls) * 100);
std::cout << "INFO: Verification results:" << std::endl;
std::cout << "\tCommon = " << ncommon << std::endl;
std::cout << "\tSuccess = " << persuccess << std::endl;
std::cout << "\tLoss = " << perloss << std::endl;
std::cout << "\tGain = " << pergain << std::endl;
/*if (persuccess < 80) {
fprintf(stderr, "ERROR: Test Failed.\n ");
return EXIT_FAILURE;
} */
return 0;
}
open_project xf_fast_axis
set_top fast_accel_axis
add_files xf_fast_axis.cpp -cflags "-I/media/masaaki/Ubuntu_Disk/Xilinx_github/Vitis_Libraries/vision/L1/include -std=c++0x"
add_files -tb xf_fast_axis_tb.cpp -cflags "-I/media/masaaki/Ubuntu_Disk/Xilinx_github/Vitis_Libraries/vision/L1/include -I/usr/local/include -std=c++0x -Wno-unknown-pragmas" -csimflags "-Wno-unknown-pragmas"
open_solution "solution1" -flow_target vivado
set_part {xc7z020-clg400-1}
create_clock -period 10 -name default
config_export -format ip_catalog -rtl verilog -vivado_clock 10
csim_design -ldflags {-L/usr/local/lib -lopencv_core -lopencv_imgcodecs -lopencv_imgproc} -argv {/media/masaaki/Ubuntu_Disk/Vitis_HLS/ZYBO_Z7_20/2021.2/xf_fast_axis/test2.jpg}
exit
// xf_fast_axis.h
// 2022/02/03 by marsee
// Vitis_Libraries/vision/L1/examples/fast/xf_fast_config.h, Vitis_Libraries/vision/L1/examples/fast/build/xf_config_params.h を引用
//
#ifndef _XF_FAST_CONFIG_H_
#define _XF_FAST_CONFIG_H_
#include <stdint.h>
#include "hls_stream.h"
#include "ap_int.h"
#include "common/xf_common.hpp"
#include "common/xf_utility.hpp"
#include "ap_axi_sdata.h"
#include "common/xf_infra.hpp"
#include "common/xf_axi_io.hpp"
#include "features/xf_fast.hpp"
#define RGB 0
#define GRAY 1
#define NPxPC XF_NPPC1
#if GRAY
#define TYPE XF_8UC1
#define CHANNELS 1
#define STREAMW 8
#else
#define TYPE XF_8UC3
#define CHANNELS 3
#define STREAMW 32
#endif
typedef hls::stream<ap_axiu<STREAMW,1,1,1> > AXI_STREAM;
#define NMS 1
#define WIDTH 1920
#define HEIGHT 1080
#define MAXCORNERS 1024
#endif
// xf_fast_axis.cpp
// 2022/02/03 by marsee
// Vitis_Libraries/vision/L1/examples/fast/xf_fast_accel.cpp から引用した
// https://github.com/Xilinx/Vitis_Libraries/blob/master/vision/L1/examples/fast/xf_fast_accel.cpp
#include "xf_fast_axis.h"
void fast_accel_axis(AXI_STREAM& _src, AXI_STREAM& _dst, unsigned char threshold,
int32_t row, int32_t cols){
#pragma HLS INTERFACE mode=s_axilite port=threshold
#pragma HLS INTERFACE mode=s_axilite port=cols
#pragma HLS INTERFACE mode=s_axilite port=row
#pragma HLS INTERFACE mode=s_axilite port=return
#pragma HLS INTERFACE mode=axis register_mode=both port=_src register
#pragma HLS INTERFACE mode=axis register_mode=both port=_dst register
xf::cv::Mat<TYPE, HEIGHT, WIDTH, NPxPC> img_in(row, cols);
xf::cv::Mat<TYPE, HEIGHT, WIDTH, NPxPC> img_out(row, cols);
#pragma HLS DATAFLOW
xf::cv::AXIvideo2xfMat<STREAMW, TYPE>(_src, img_in);
xf::cv::fast<NMS, TYPE, HEIGHT, WIDTH, NPxPC>(img_in, img_out, threshold);
xf::cv::xfMat2AXIvideo<STREAMW, TYPE>(img_out, _dst);
}
/*
* 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.
*/
// xf_fast_axis_tb.cpp
// 2022/02/03 : fast_accel を AXI4-Stream 入出力に変更 by marsee
//
#include "opencv2/opencv.hpp"
#include "opencv2/imgproc/imgproc.hpp"
#include "opencv2/highgui/highgui.hpp"
#include "opencv2/imgcodecs/imgcodecs.hpp"
#include "common/xf_headers.hpp"
#include "common/xf_axi.hpp"
#include "common/xf_sw_utils.hpp"
#include "xf_fast_axis.h"
void fast_accel_axis(AXI_STREAM& _src, AXI_STREAM& _dst, unsigned char threshold,
int32_t row, int32_t cols);
int main(int argc, char** argv) {
cv::Mat in_img, out_img, out_img_ocv, out_hls;
cv::Mat in_gray;
in_img = cv::imread(argv[1], 1); // reading in the color image
if (!in_img.data) {
fprintf(stderr, "Failed to load the image ... %s\n ", argv[1]);
return -1;
}
std::vector<cv::KeyPoint> keypoints;
uchar_t threshold = 20; // threshold
cvtColor(in_img, in_gray, cv::COLOR_BGR2GRAY);
// OPenCV reference function
cv::FAST(in_gray, keypoints, threshold, NMS);
unsigned short imgwidth = in_img.cols;
unsigned short imgheight = in_img.rows;
out_hls.create(in_gray.rows, in_gray.cols, CV_8U);
// Call the top function
AXI_STREAM _src,_dst;
xf::cv::cvMat2AXIvideoxf<NPxPC, STREAMW>(in_gray, _src);
fast_accel_axis(_src, _dst, threshold, imgheight, imgwidth);
xf::cv::AXIvideo2cvMatxf<NPxPC, STREAMW>(_dst, out_hls);
std::vector<cv::Point> hls_points;
std::vector<cv::Point> ocv_points;
std::vector<cv::Point> common_points;
std::vector<cv::Point> noncommon_points;
FILE *fp, *fp1;
fp = fopen("ocvpoints.txt", "w");
fp1 = fopen("hlspoints.txt", "w");
int nsize = keypoints.size();
printf("ocvpoints:%d=\n", nsize);
for (int i = 0; i < nsize; i++) {
int x = keypoints[i].pt.x;
int y = keypoints[i].pt.y;
ocv_points.push_back(cv::Point(x, y));
// fprintf(fp, "x = %d, y = %d\n", x, y);
}
// fclose(fp);
out_img_ocv = in_img.clone();
int ocv_x = 0, ocv_y = 0;
for (int cnt1 = 0; cnt1 < keypoints.size(); cnt1++) {
ocv_x = keypoints[cnt1].pt.x;
ocv_y = keypoints[cnt1].pt.y;
cv::circle(out_img_ocv, cv::Point(ocv_x, ocv_y), 5, cv::Scalar(0, 0, 255), 2, 8, 0);
}
cv::imwrite("output_ocv.png", out_img_ocv);
//
out_img = in_gray.clone();
for (int j = 0; j < out_hls.rows; j++) {
for (int i = 0; i < out_hls.cols; i++) {
unsigned char value = out_hls.at<unsigned char>(j, i);
if (value != 0) {
short int y, x;
y = j;
x = i;
cv::Point tmp;
tmp.x = i;
tmp.y = j;
hls_points.push_back(tmp);
if (j > 0) cv::circle(out_img, cv::Point(x, y), 5, cv::Scalar(0, 0, 255, 255), 2, 8, 0);
}
}
}
int nsize1 = hls_points.size();
int Nocv = ocv_points.size();
int Nhls = hls_points.size();
for (int r = 0; r < nsize1; r++) {
int a, b;
a = (int)hls_points[r].x;
b = (int)hls_points[r].y;
fprintf(fp1, "x = %d, y = %d\n", a, b);
}
fclose(fp1);
for (int j = 0; j < Nocv; j++) {
for (int k = 0; k < Nhls; k++) {
if ((ocv_points[j].x == ((hls_points[k].x))) && (ocv_points[j].y == ((hls_points[k].y)))) {
common_points.push_back(ocv_points[j]);
}
}
}
FILE* fpt3;
fpt3 = fopen("common.txt", "w");
for (unsigned int p = 0; p < common_points.size(); p++) {
fprintf(fpt3, "x = %d, y = %d\n", common_points[p].x, common_points[p].y);
}
fclose(fpt3);
cv::imwrite("output_hls.png", out_img);
// Results verification:
float persuccess, perloss, pergain;
int totalocv = ocv_points.size();
int totalhls = hls_points.size();
int ncommon = common_points.size();
persuccess = (((float)ncommon / totalhls) * 100);
perloss = (((float)(totalocv - ncommon) / totalocv) * 100);
pergain = (((float)(totalhls - ncommon) / totalhls) * 100);
std::cout << "INFO: Verification results:" << std::endl;
std::cout << "\tCommon = " << ncommon << std::endl;
std::cout << "\tSuccess = " << persuccess << std::endl;
std::cout << "\tLoss = " << perloss << std::endl;
std::cout << "\tGain = " << pergain << std::endl;
if (persuccess < 80) {
fprintf(stderr, "ERROR: Test Failed.\n ");
return EXIT_FAILURE;
}
return 0;
}
日 | 月 | 火 | 水 | 木 | 金 | 土 |
---|---|---|---|---|---|---|
- | - | - | - | - | 1 | 2 |
3 | 4 | 5 | 6 | 7 | 8 | 9 |
10 | 11 | 12 | 13 | 14 | 15 | 16 |
17 | 18 | 19 | 20 | 21 | 22 | 23 |
24 | 25 | 26 | 27 | 28 | 29 | 30 |
31 | - | - | - | - | - | - |