cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Highlighted
Observer
Observer
1,242 Views
Registered: ‎10-31-2019

Vitis Vision library xf::cv::cvMat2AXIvideoxf problem

Hi,

I am trying to implement an image processing ip core with axi-stream interface in Vivado_HLS 2019.2 using Vitis vision library. I started with 'Standalone_HLS_AXI_Example' of xfOpenCV from here and modified the source files and project settings accoring to the 'Getting Started with HLS' section of this. The C-based test bench is now like this:

 

#include "xf_headers.h"
#include "xf_dilation_config.h"
#include "common/xf_axi.hpp"

int main(int argc, char** argv)
{

	if(argc != 2)
	{
		fprintf(stderr,"Invalid Number of Arguments!\nUsage:\n");
		fprintf(stderr,"<Executable Name> <input image path> \n");
		return -1;
	}

	cv::Mat out_img,ocv_ref;
	cv::Mat in_img,in_img1,diff;

	// reading in the color image
	in_img = cv::imread(argv[1], 0);
	if (in_img.data == NULL)
	{
		fprintf(stderr,"Cannot open image at %s\n", argv[1]);
		return 0;
	}
	// create memory for output images
	ocv_ref.create(in_img.rows,in_img.cols,CV_8UC1);
	diff.create(in_img.rows,in_img.cols,CV_8UC1);
	in_img1.create(in_img.rows,in_img.cols,CV_8UC1);

	uint16_t height = in_img.rows;
	uint16_t width = in_img.cols;



	///////////////// 	Opencv  Reference  ////////////////////////
	cv::Mat element = cv::getStructuringElement( 0,cv::Size(3, 3), cv::Point(-1, -1));
	cv::dilate(in_img, ocv_ref, element, cv::Point(-1, -1), 1, cv::BORDER_CONSTANT);
	cv::imwrite("out_ocv.jpg", ocv_ref);

	#if __SDSCC__
	unsigned char *structure_element=(unsigned char *)sds_alloc_non_cacheable(sizeof(unsigned char)*FILTER_SIZE*FILTER_SIZE);
	#else
	unsigned char structure_element[FILTER_SIZE*FILTER_SIZE];
	#endif


	for(int i=0;i<(FILTER_SIZE*FILTER_SIZE);i++)
	{
		structure_element[i]=element.data[i];
	}

	hls::stream< xf::cv::ap_axiu<8,1,1,1> > _src,_dst;

	#if __SDSCC__
	perf_counter hw_ctr;
	hw_ctr.start();
	#endif

	xf::cv::cvMat2AXIvideoxf<NPC1,8>(in_img, _src);

	ip_accel_app(_src, _dst,height,width, structure_element);

	xf::cv::AXIvideo2cvMatxf<NPC1,8>(_dst, in_img1);

	#if __SDSCC__
	hw_ctr.stop();
	uint64_t hw_cycles = hw_ctr.avg_cpu_cycles();
	#endif

	cv::imwrite("hls.jpg", in_img1);
	//////////////////  Compute Absolute Difference ////////////////////

	cv::absdiff(ocv_ref, in_img1, diff);
	cv::imwrite("out_error.jpg", diff);

	// Find minimum and maximum differences.
		double minval=256,maxval=0;
	int cnt = 0;
	for (int i=0; i<in_img.rows; i++)
	{
		for(int j=0; j<in_img.cols; j++)
		{
			uchar v = diff.at<uchar>(i,j);
			if (v>0)
				cnt++;
			if (minval > v)
				minval = v;
			if (maxval < v)
				maxval = v;
		}
	}

	float err_per = 100.0*(float)cnt/(in_img.rows*in_img.cols);
	fprintf(stderr,"Minimum error in intensity = %f\n Maximum error in intensity = %f\n Percentage of pixels above error threshold = %f\n",minval,maxval,err_per);

	if(err_per > 0.0f)
		return 1;


	return 0;

}

The problem is that I get this error in the test bench file:

 

 

Symbol 'cvMat2AXIvideoxf' could not be resolved

Also when I run the C-Simulation process, I get these errors:

 

Starting C simulation ...
/home/mhg/tools/Xilinx/Vivado/2019.2/bin/vivado_hls /home/mhg/Desktop/Standalone_HLS_AXI_Example/axi_hls_stream_example/solution1/csim.tcl
INFO: [HLS 200-10] Running '/home/mhg/tools/Xilinx/Vivado/2019.2/bin/unwrapped/lnx64.o/vivado_hls'
INFO: [HLS 200-10] For user 'mhg' on host 'mhg-araz' (Linux_x86_64 version 4.15.0-66-generic) on Thu Nov 14 13:34:07 +0330 2019
INFO: [HLS 200-10] On os Ubuntu 18.04.3 LTS
INFO: [HLS 200-10] In directory '/home/mhg/Desktop/Standalone_HLS_AXI_Example'
Sourcing Tcl script '/home/mhg/Desktop/Standalone_HLS_AXI_Example/axi_hls_stream_example/solution1/csim.tcl'
INFO: [HLS 200-10] Opening project '/home/mhg/Desktop/Standalone_HLS_AXI_Example/axi_hls_stream_example'.
INFO: [HLS 200-10] Opening solution '/home/mhg/Desktop/Standalone_HLS_AXI_Example/axi_hls_stream_example/solution1'.
INFO: [SYN 201-201] Setting up clock 'default' with a period of 10ns.
INFO: [SYN 201-201] Setting up clock 'default' with an uncertainty of 2.7ns.
INFO: [HLS 200-10] Setting target device to 'xc7z020-clg400-1'
INFO: [HLS 200-435] Setting 'config_sdx -optimization_level' configuration: config_export -vivado_optimization_level=2
INFO: [HLS 200-435] Setting 'config_export -vivado_optimization_level' configuration: config_export -vivado_phys_opt=place
INFO: [HLS 200-435] Setting 'config_sdx -target' configuration: config_export -vivado_optimization_level=0
INFO: [HLS 200-435] Setting 'config_export -vivado_optimization_level' configuration: config_export -vivado_phys_opt=none
INFO: [HLS 200-435] Setting 'config_sdx -target' configuration: set_clock_uncertainty 27%
INFO: [XFORM 203-1161] The maximum of name length is set into 80.
INFO: [XFORM 203-1171] Pipeline the innermost loop with trip count more than 64 or its parent loop when its trip count is less than or equal 64.
INFO: [SIM 211-2] *************** CSIM start ***************
INFO: [SIM 211-4] CSIM will launch GCC as the compiler.
   Compiling ../../../../xf_dilation_tb.cpp in debug mode
csim.mk:75: recipe for target 'obj/xf_dilation_tb.o' failed
In file included from ../../../../xf_headers.h:63:0,
                 from ../../../../xf_dilation_tb.cpp:33:
../../../../../../tools/Xilinx/Vitis_Libraries/vision/L1/include/common/xf_axi.hpp:31:27: error: variable or field ‘cvMat2AXIvideoxf’ declared void
 void cvMat2AXIvideoxf(cv::Mat& cv_mat, hls::stream<ap_axiu<W, 1, 1, 1> >& AXI_video_strm);
                           ^~~
../../../../../../tools/Xilinx/Vitis_Libraries/vision/L1/include/common/xf_axi.hpp:31:30: error: missing template arguments before ‘&’ token
 void cvMat2AXIvideoxf(cv::Mat& cv_mat, hls::stream<ap_axiu<W, 1, 1, 1> >& AXI_video_strm);
                              ^
../../../../../../tools/Xilinx/Vitis_Libraries/vision/L1/include/common/xf_axi.hpp:31:32: error: ‘cv_mat’ was not declared in this scope
 void cvMat2AXIvideoxf(cv::Mat& cv_mat, hls::stream<ap_axiu<W, 1, 1, 1> >& AXI_video_strm);
                                ^~~~~~
../../../../../../tools/Xilinx/Vitis_Libraries/vision/L1/include/common/xf_axi.hpp:31:73: error: expected primary-expression before ‘&’ token
 void cvMat2AXIvideoxf(cv::Mat& cv_mat, hls::stream<ap_axiu<W, 1, 1, 1> >& AXI_video_strm);
                                                                         ^
../../../../../../tools/Xilinx/Vitis_Libraries/vision/L1/include/common/xf_axi.hpp:31:75: error: ‘AXI_video_strm’ was not declared in this scope
 void cvMat2AXIvideoxf(cv::Mat& cv_mat, hls::stream<ap_axiu<W, 1, 1, 1> >& AXI_video_strm);
                                                                           ^~~~~~~~~~~~~~
../../../../../../tools/Xilinx/Vitis_Libraries/vision/L1/include/common/xf_axi.hpp:125:78: error: ‘xf::cv::Mat’ is not a type
 void AXIvideo2cvMatxf(hls::stream<ap_axiu<W, 1, 1, 1> >& AXI_video_strm, cv::Mat& cv_mat);
                                                                              ^~~
../../../../../../tools/Xilinx/Vitis_Libraries/vision/L1/include/common/xf_axi.hpp:128:27: error: variable or field ‘cvMat2AXIvideoxf’ declared void
 void cvMat2AXIvideoxf(cv::Mat& cv_mat, hls::stream<ap_axiu<W, 1, 1, 1> >& AXI_video_strm) {
                           ^~~
../../../../../../tools/Xilinx/Vitis_Libraries/vision/L1/include/common/xf_axi.hpp:128:30: error: missing template arguments before ‘&’ token
 void cvMat2AXIvideoxf(cv::Mat& cv_mat, hls::stream<ap_axiu<W, 1, 1, 1> >& AXI_video_strm) {
                              ^
../../../../../../tools/Xilinx/Vitis_Libraries/vision/L1/include/common/xf_axi.hpp:128:32: error: ‘cv_mat’ was not declared in this scope
 void cvMat2AXIvideoxf(cv::Mat& cv_mat, hls::stream<ap_axiu<W, 1, 1, 1> >& AXI_video_strm) {
                                ^~~~~~
../../../../../../tools/Xilinx/Vitis_Libraries/vision/L1/include/common/xf_axi.hpp:128:73: error: expected primary-expression before ‘&’ token
 void cvMat2AXIvideoxf(cv::Mat& cv_mat, hls::stream<ap_axiu<W, 1, 1, 1> >& AXI_video_strm) {
                                                                         ^
../../../../../../tools/Xilinx/Vitis_Libraries/vision/L1/include/common/xf_axi.hpp:128:75: error: ‘AXI_video_strm’ was not declared in this scope
 void cvMat2AXIvideoxf(cv::Mat& cv_mat, hls::stream<ap_axiu<W, 1, 1, 1> >& AXI_video_strm) {
                                                                           ^~~~~~~~~~~~~~
../../../../../../tools/Xilinx/Vitis_Libraries/vision/L1/include/common/xf_axi.hpp:225:78: error: ‘xf::cv::Mat’ is not a type
 void AXIvideo2cvMatxf(hls::stream<ap_axiu<W, 1, 1, 1> >& AXI_video_strm, cv::Mat& cv_mat) {

I have attached the full c-sim log file and the source codes.

 

I would appreciate any help on this problem.

 

0 Kudos
5 Replies
Highlighted
Observer
Observer
1,123 Views
Registered: ‎10-31-2019

Hi,

For the reference of others who may have the same problem, I found a temprory work around for this problem. Maybe later I will come back to solve it properly.

I used xf::cv::xfMat2AXIvideo and xf::cv::AXIvideo2xfMat in the test bench instead of xf::cv::cvMat2AXIvideoxf and xf::cv::AXIvideo2cvMatxf and also used the '.copyTo' to move the data of the input cv::Mat array to the xf::cv::Mat.

 

This is a part of the test bench I used for Median_Blure example:

    static xf::cv::Mat<TYPE, HEIGHT, WIDTH, NPxPC> imgInput(in_height, in_width);
    static xf::cv::Mat<TYPE, HEIGHT, WIDTH, NPxPC> imgOutput(in_height, in_width);

    hls::stream< xf::cv::ap_axiu<8,1,1,1> > _src;
    hls::stream< xf::cv::ap_axiu<8,1,1,1> > _dst;

    imgInput.copyTo(in_img.data);

    xf::cv::xfMat2AXIvideo(imgInput, _dst);

    median_blur_accel_ip(_src, _dst);

    xf::cv::AXIvideo2xfMat(_src, imgOutput);
0 Kudos
Highlighted
Participant
Participant
510 Views
Registered: ‎08-10-2020

I have the exact same problem while using "cvMat2AXIvideoxf" function. It seems like something is wrong with the "common/xf_axi.hpp" file that doesn't let it compile. 
Has anyone any ideas what the problem might be?



Thanks

0 Kudos
Highlighted
Contributor
Contributor
343 Views
Registered: ‎01-27-2019

@ali_fltand @mohammadhgh ,

Have you succeeded in using xf::cv in standalone hls mode?

 

 

0 Kudos
Highlighted
Participant
Participant
302 Views
Registered: ‎08-10-2020

@dr.elichan yes, what is your issue with that?

0 Kudos
Highlighted
Contributor
Contributor
230 Views
Registered: ‎01-27-2019

@ali_flt
I haven't started to do any testing yet.
Just want to find a workable example first.

0 Kudos