UPGRADE YOUR BROWSER

We have detected your current browser version is not the latest one. Xilinx.com uses the latest web technologies to bring you the best online experience possible. Please upgrade to a Xilinx.com supported browser:Chrome, Firefox, Internet Explorer 11, Safari. Thank you!

cancel
Showing results for 
Search instead for 
Did you mean: 
Adventurer
Adventurer
672 Views
Registered: ‎06-05-2018

hls::CvtColor & xf::Threshold

Jump to solution

Can somebody build a simple project successfully in Sdx ISE which just need read an image and convert its color space to gray using hls::CvtColor and then use xf::Threshold to get the result ? I failed.

0 Kudos
1 Solution

Accepted Solutions
Highlighted
Xilinx Employee
Xilinx Employee
408 Views
Registered: ‎05-25-2018

Re: hls::CvtColor & xf::Threshold

Jump to solution

Hi @wd-hyj,

Yes, you are right that HLS video functions cannot be synthesized for hardware in SDSoC, as they have hls::streams at interface level which are not supported by SDSoC.

But, the good news is, all the HLS Video Library functions have been ported to xfOpenCV in 2018.3 version. So, whatever the HLS video function that you intend to use, is now available in the xfOpenCV library with a synthesizable xf::Mat interface.

5 Replies
Adventurer
Adventurer
646 Views
Registered: ‎06-05-2018

Re: hls::CvtColor & xf::Threshold

Jump to solution

I have built the following code in Sdx successfully.

#include "opencv2/opencv.hpp"
#include "opencv2/highgui/highgui.hpp"
#include "opencv2/imgproc/imgproc.hpp"
//#include "sds_lib.h"
#include "/home/jumper/FPGA_projects/HLS2018.2/xiangAn_wd/xfOpenCV/include/common/xf_sw_utils.h"

#include "xf_myxf_accel.h"

int main(int argc, char** argv)
{
	cv::Mat in_img,in_img1,out_img,ocv_ref;
	cv::Mat in_gray,in_gray1,diff;

	// reading in the color image
	in_gray = cv::imread("./data/im0.jpg", 0);

	if (in_gray.data == NULL)
	{
		fprintf(stderr,"Cannot open image\n");
		return 0;
	}

	static xf::Mat<TYPE, HEIGHT, WIDTH, NPC1> imgInput(in_gray.rows,in_gray.cols);
	static xf::Mat<TYPE, HEIGHT, WIDTH, NPC1> imgOutput(in_gray.rows,in_gray.cols);
	static xf::Mat<TYPE, HEIGHT, WIDTH, NPC1> threshimgtb(in_gray.rows,in_gray.cols);
	static xf::Mat<TYPE, HEIGHT, WIDTH, NPC1> dilateimgtb(in_gray.rows,in_gray.cols);

#pragma SDS data copy(in_gray.data)
	imgInput.copyTo(in_gray.data);

	myxffun(imgInput,threshimgtb,dilateimgtb, imgOutput);

	// Write output image
	xf::imwrite("hls_out.jpg",imgOutput);

	return 0;
}

But i rebuilt it failed when it changed to the following :

#include "opencv2/opencv.hpp"
#include "opencv2/highgui/highgui.hpp"
#include "opencv2/imgproc/imgproc.hpp"
#include "opencv2/core/core.hpp"
//#include "sds_lib.h"

//the following two hpp can only be included in testbench!!!!!!!
#include "/home/jumper/FPGA_projects/HLS2018.2/xiangAn_wd/xfOpenCV/include/common/xf_sw_utils.h"
#include "/home/jumper/FPGA_projects/HLS2018.2/xiangAn_wd/xfOpenCV/include/common/xf_infra.h"

//why can't include these following head file?!
#include "hls_opencv.h"
#include "hls/hls_video_arithm.h"
#include "hls/hls_video_types.h"
#include "hls/hls_video_core.h"
#include "hls/hls_video_imgproc.h"

#include "xf_myxf_accel.h"

int main(int argc, char** argv)
{
	cv::Mat in_img,in_img1,out_img,ocv_ref;
	cv::Mat in_gray,in_gray1,diff;

	// reading in the color image
	in_gray = cv::imread("./data/im0.jpg",0);

	if (in_gray.data == NULL)
	{
		fprintf(stderr,"Cannot open image\n");
		return 0;
	}


	//hls video function can only be here ?!
	hls::stream<ap_axiu<24,1,1,1> > bgr_src;
	cvMat2AXIvideo(in_gray, bgr_src);
	hls::stream<ap_axiu<24,1,1,1> > bgr_scaleimg;

	hls::Mat<HEIGHT,WIDTH,HLS_8UC3> bgr_src_mat(HEIGHT,WIDTH);
	hls::Mat<HEIGHT,WIDTH,HLS_8UC3> bgr_scaleimg_mat(HEIGHT,WIDTH);
	hls::Scale(bgr_src_mat,bgr_scaleimg_mat,1.5);
	hls::Mat<HEIGHT,WIDTH,HLS_8UC1> grayimg;
	hls::CvtColor<HLS_BGR2GRAY>(bgr_scaleimg_mat, grayimg);

//	hls::stream<ap_axiu<24,1,1,1> > bgr_src;
//	cvMat2AXIvideo(in_gray, bgr_src);
//	hls::stream<ap_axiu<8,1,1,1> > grayimg;
//	hlsfun(bgr_src,grayimg);


	static xf::Mat<TYPE, HEIGHT, WIDTH, NPC1> imgInput(in_gray.rows,in_gray.cols);
	static xf::Mat<TYPE, HEIGHT, WIDTH, NPC1> imgOutput(in_gray.rows,in_gray.cols);
	static xf::Mat<TYPE, HEIGHT, WIDTH, NPC1> threshimgtb(in_gray.rows,in_gray.cols);
	static xf::Mat<TYPE, HEIGHT, WIDTH, NPC1> dilateimgtb(in_gray.rows,in_gray.cols);

//	xf::AXIvideo2xfMat(grayimg,imgInput);


#pragma SDS data copy(in_gray.data)
	imgInput.copyTo(in_gray.data);


	myxffun(imgInput,threshimgtb,dilateimgtb, imgOutput);

	// Write output image
	xf::imwrite<TYPE,HEIGHT,WIDTH,NPC1>("hls_out.jpg",imgOutput);

//	cv::Mat dstimg(HEIGHT,WIDTH,CV_8UC1);
//	dstimg.data=imgOutput.copyFrom();
//	cv::imwrite("debug.jpg",dstimg);

	return 0;
}

the error information is :

Preliminary link application ELF
/home/jumper/FPGA_projects/sdsoc2018.2/HLSxfOpenCV/Release/_sds/swstubs/xf_myxf_tb.o:在函数‘void xf::imwrite<0, 1080, 1920, 1>(char const*, xf::Mat<0, 1080, 1920, 1>&)’中:
xf_myxf_tb.cpp:(.text._ZN2xf7imwriteILi0ELi1080ELi1920ELi1EEEvPKcRNS_3MatIXT_EXT0_EXT1_EXT2_EEE[_ZN2xf7imwriteILi0ELi1080ELi1920ELi1EEEvPKcRNS_3MatIXT_EXT0_EXT1_EXT2_EEE]+0x2dc):对‘cv::_InputArray::_InputArray(cv::Mat const&)’未定义的引用
xf_myxf_tb.cpp:(.text._ZN2xf7imwriteILi0ELi1080ELi1920ELi1EEEvPKcRNS_3MatIXT_EXT0_EXT1_EXT2_EEE[_ZN2xf7imwriteILi0ELi1080ELi1920ELi1EEEvPKcRNS_3MatIXT_EXT0_EXT1_EXT2_EEE]+0x2fc):对‘cv::imwrite(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, cv::_InputArray const&, std::vector<int, std::allocator<int> > const&)’未定义的引用
/home/jumper/FPGA_projects/sdsoc2018.2/HLSxfOpenCV/Release/_sds/swstubs/xf_myxf_tb.o:在函数‘void hls::arithm_pro<hls::kernel_scale, 1080, 1920, 4096, unsigned char, 4096, double, double, double>(hls::Mat<1080, 1920, 4096>&, hls::Scalar<(((4096)&(((512)-(1))<<(11)))>>(11))+(1), unsigned char>, hls::Mat<1080, 1920, 4096>&, double, double, double)’中:
xf_myxf_tb.cpp:(.text._ZN3hls10arithm_proINS_12kernel_scaleELi1080ELi1920ELi4096EhLi4096EdddEEvRNS_3MatIXT0_EXT1_EXT2_EEENS_6ScalarIXplrsanT2_lsmiLi512ELi1ELi11ELi11ELi1EET3_EERNS2_IXT0_EXT1_EXT4_EEET5_T6_T7_[_ZN3hls10arithm_proINS_12kernel_scaleELi1080ELi1920ELi4096EhLi4096EdddEEvRNS_3MatIXT0_EXT1_EXT2_EEENS_6ScalarIXplrsanT2_lsmiLi512ELi1ELi11ELi11ELi1EET3_EERNS2_IXT0_EXT1_EXT4_EEET5_T6_T7_]+0xac):对‘hls::__isnan(double)’未定义的引用
/home/jumper/FPGA_projects/sdsoc2018.2/HLSxfOpenCV/Release/_sds/swstubs/xf_myxf_tb.o:在函数‘main’中:
xf_myxf_tb.cpp:(.text.startup+0x218):对‘cv::imread(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, int)’未定义的引用
xf_myxf_tb.cpp:(.text.startup+0x32c):对‘cv::Mat::operator _IplImage() const’未定义的引用
collect2: error: ld returned 1 exit status
ERROR: [SdsCompiler 83-5019] Exiting sds++ : Error when calling 'arm-linux-gnueabihf-g++    /home/jumper/FPGA_projects/sdsoc2018.2/HLSxfOpenCV/Release/_sds/swstubs/xf_myxf_accel.o /home/jumper/FPGA_projects/sdsoc2018.2/HLSxfOpenCV/Release/_sds/swstubs/xf_myxf_tb.o /home/jumper/FPGA_projects/sdsoc2018.2/HLSxfOpenCV/Release/_sds/swstubs/portinfo.o -L/home/jumper/workspace/xilinx_opencv_3.4.1/lib -lopencv_world   -L /opt/Xilinx/SDx/2018.2/target/aarch32-linux/lib -L/home/jumper/FPGA_projects/sdsoc2018.2/HLSxfOpenCV/Release/_sds/swstubs -Wl,--start-group  -Wl,--end-group -Wl,--start-group    -lpthread -lsds_lib -lxlnk_stub  -Wl,--end-group -o /home/jumper/FPGA_projects/sdsoc2018.2/HLSxfOpenCV/Release/_sds/swstubs/HLSxfOpenCV.elf'
make: *** [HLSxfOpenCV.elf] Error 1
sds++ log file saved as /home/jumper/FPGA_projects/sdsoc2018.2/HLSxfOpenCV/Release/_sds/reports/sds.log
ERROR: [SdsCompiler 83-5004] Build failed

makefile:45: recipe for target 'HLSxfOpenCV.elf' failed

I really do not know the reason.

0 Kudos
Xilinx Employee
Xilinx Employee
455 Views
Registered: ‎08-20-2018

Re: hls::CvtColor & xf::Threshold

Jump to solution

Hi @wd-hyj

 

Please navigate to C/C++ build settings -> C/C++ General->Paths and Symbols

In Includes tab, Under GNU C++, Add below include path,

<revision platform folder path>/zcu104-rv-ss-2018-2/petalinux/sdk/sysroots/aarch64-xilinx-linux/usr/include

 

Best Regards,

Nutan

Best Regards,
Nutan
-------------------------------------------------------------------------------
Please don't forget to reply, kudo and accept as a solution
0 Kudos
Adventurer
Adventurer
424 Views
Registered: ‎06-05-2018

Re: hls::CvtColor & xf::Threshold

Jump to solution
Thanks for your reply!Unfortunately, The error information was still the same after i added "/opt/Xilinx/zcu102_rv_ss/sw/sysroot/usr/include". Well,someone told me "HLS video function only supports simulation but not for synthesization so the error will occur when you use hls video function in Sdx!" ,is that right? Did you see someone uses hls video function in Sdx ? I haven't.
0 Kudos
Highlighted
Xilinx Employee
Xilinx Employee
409 Views
Registered: ‎05-25-2018

Re: hls::CvtColor & xf::Threshold

Jump to solution

Hi @wd-hyj,

Yes, you are right that HLS video functions cannot be synthesized for hardware in SDSoC, as they have hls::streams at interface level which are not supported by SDSoC.

But, the good news is, all the HLS Video Library functions have been ported to xfOpenCV in 2018.3 version. So, whatever the HLS video function that you intend to use, is now available in the xfOpenCV library with a synthesizable xf::Mat interface.

Adventurer
Adventurer
396 Views
Registered: ‎06-05-2018

Re: hls::CvtColor & xf::Threshold

Jump to solution
Really?thant's really a good news! I am considering to update my Sdx version!
0 Kudos