Hi all, @marioruiz
Refer to the PYNQ Helloworld for the resize IP example, I try to use the OtsuThreshold and Threshold function in vitis library to replace the opencv:
ret, img_binary = cv2.threshold(img_gray, 0, 255, cv2.THRESH_BINARY | cv2.THRESH_OTSU)
Code in HLS IP:
void binaryimage_accel(stream_t& stream_in,
stream_t& stream_out,
int rows,
int cols) {
#pragma HLS INTERFACE axis register both port=stream_in
#pragma HLS INTERFACE axis register both port=stream_out
#pragma HLS INTERFACE s_axilite port=rows offset=0x10
#pragma HLS INTERFACE s_axilite port=cols offset=0x18
#pragma HLS INTERFACE s_axilite port=return
xf::cv::Mat<INTYPE, HEIGHT, WIDTH, NPIX> img_in(rows, cols);
xf::cv::Mat<INTYPE, HEIGHT, WIDTH, NPIX> img_out(rows, cols);
#pragma HLS DATAFLOW
uint8_t otsuval;
short int maxval = 255;
// Convert stream to xf::cv::Mat
axis2xfMat<DATA_WIDTH, INTYPE, HEIGHT, WIDTH, NPIX>(stream_in, img_in);
// OtsuThreshold
xf::cv::OtsuThreshold<INTYPE, HEIGHT, WIDTH, NPIX>(img_in, otsuval);
// Thresholding wit the otsu threshould
xf::cv::Threshold<XF_THRESHOLD_TYPE_BINARY, XF_8UC1, HEIGHT, WIDTH, NPIX>(img_in, img_out, otsuval, maxval);
// Convert xf::cv::Mat to stream
xfMat2axis<DATA_WIDTH, INTYPE, HEIGHT, WIDTH, NPIX>(img_out, stream_out);
}
Got build error as below, it seems the Threshold only accept the SRC_T = XF_8UC1.
ERROR: [HLS 207-3339] no matching function for call to ‘Threshold’ (src/binaryimage.cpp:122:5)
INFO: [HLS 207-4378] candidate function not viable: no known conversion from ‘xf::cv::Mat<XF_8UC3, 1080, 1920, XF_NPPC1>’ to ‘xf::cv::Mat<0, 1080, 1920, 1> &’ for 1st argument (/home/willychiang/Desktop/PYNQ_KV260/ip/vitis_lib/vision/L1/include/imgproc/xf_threshold.hpp:106:6)
"
https://github.com/Xilinx/Vitis_Libraries/blob/master/vision/L1/include/imgproc/xf_threshold.hpp
But the stream_in is converting to xf::cv::Mat by axis2xfMat with 24bit DATA_WIDTH (I think it only support 8UC3).
Does have any ways to transfer the 8UC3 Mat to 8UC1 foramt?
Another question about the rgb2gray_accel in Composable_Pipeline, why we need to transfer the gray image back to rgb?