初级会员
- 积分
- 99
- 金钱
- 99
- 注册时间
- 2023-2-22
- 在线时间
- 20 小时
|
发表于 2024-4-11 17:02:12
|
显示全部楼层
/**************************************************************************************
* ProcessSobel3x3 : Computes gradients for the column input data
**************************************************************************************/
template <int SRC_T,
int DST_T,
int ROWS,
int COLS,
int PLANES,
int DEPTH_SRC,
int DEPTH_DST,
int NPC,
//int XFCVDEPTH_IN = _XFCVDEPTH_DEFAULT,
//int XFCVDEPTH_gradx = _XFCVDEPTH_DEFAULT,
//int XFCVDEPTH_grady = _XFCVDEPTH_DEFAULT,
int WORDWIDTH_SRC,
int WORDWIDTH_DST,
int TC>
void ProcessSobel3x3(//xf::cv::Mat<SRC_T, ROWS, COLS, NPC, XFCVDEPTH_IN>& _src_mat,
//xf::cv::Mat<DST_T, ROWS, COLS, NPC, XFCVDEPTH_gradx>& _gradx_mat,
//xf::cv::Mat<DST_T, ROWS, COLS, NPC, XFCVDEPTH_grady>& _grady_mat,
xf::cv::Mat<SRC_T, ROWS, COLS, NPC>& _src_mat,
xf::cv::Mat<DST_T, ROWS, COLS, NPC>& _gradx_mat,
xf::cv::Mat<DST_T, ROWS, COLS, NPC>& _grady_mat,
XF_SNAME(WORDWIDTH_SRC) buf[3][(COLS >> XF_BITSHIFT(NPC))],
XF_PTNAME(DEPTH_SRC) src_buf1[XF_NPIXPERCYCLE(NPC) + 2],
XF_PTNAME(DEPTH_SRC) src_buf2[XF_NPIXPERCYCLE(NPC) + 2],
XF_PTNAME(DEPTH_SRC) src_buf3[XF_NPIXPERCYCLE(NPC) + 2],
XF_PTNAME(DEPTH_DST) GradientValuesX[XF_NPIXPERCYCLE(NPC)],
XF_PTNAME(DEPTH_DST) GradientValuesY[XF_NPIXPERCYCLE(NPC)],
XF_SNAME(WORDWIDTH_DST) & P0,
XF_SNAME(WORDWIDTH_DST) & P1,
uint16_t img_width,
uint16_t img_height,
ap_uint<13> row_ind,
uint16_t& shift_x,
uint16_t& shift_y,
ap_uint<2> tp,
ap_uint<2> mid,
ap_uint<2> bottom,
ap_uint<13> row,
int& read_index,
int& write_index) {
// clang-format off
#pragma HLS INLINE
// clang-format on
XF_SNAME(WORDWIDTH_SRC) buf0, buf1, buf2;
uint16_t npc = XF_NPIXPERCYCLE(NPC);
ap_uint<5> buf_size = XF_NPIXPERCYCLE(NPC) + 2;
Col_Loop:
for (ap_uint<13> col = 0; col < img_width; col++) {
// clang-format off
#pragma HLS LOOP_TRIPCOUNT min=TC max=TC
#pragma HLS pipeline
// clang-format on
if (row < img_height)
buf[row_ind][col] = _src_mat.read(read_index++); // Read data
else
buf[bottom][col] = 0;
buf0 = buf[tp][col];
buf1 = buf[mid][col];
buf2 = buf[bottom][col];
if (NPC == XF_NPPC8) {
xfExtractPixels<NPC, WORDWIDTH_SRC, DEPTH_SRC>(&src_buf1[2], buf0, 0);
xfExtractPixels<NPC, WORDWIDTH_SRC, DEPTH_SRC>(&src_buf2[2], buf1, 0);
xfExtractPixels<NPC, WORDWIDTH_SRC, DEPTH_SRC>(&src_buf3[2], buf2, 0);
} else {
src_buf1[2] = buf0;
src_buf2[2] = buf1;
src_buf3[2] = buf2;
}
xFSobel3x3<PLANES, NPC, DEPTH_SRC, DEPTH_DST>(GradientValuesX, GradientValuesY, src_buf1, src_buf2, src_buf3);
if (col == 0) {
shift_x = 0;
shift_y = 0;
P0 = 0;
P1 = 0;
xfPackPixels<NPC, WORDWIDTH_DST, DEPTH_DST>(&GradientValuesX[0], P0, 1, (npc - 1), shift_x);
xfPackPixels<NPC, WORDWIDTH_DST, DEPTH_DST>(&GradientValuesY[0], P1, 1, (npc - 1), shift_y);
} else {
xfPackPixels<NPC, WORDWIDTH_DST, DEPTH_DST>(&GradientValuesX[0], P0, 0, 1, shift_x);
xfPackPixels<NPC, WORDWIDTH_DST, DEPTH_DST>(&GradientValuesY[0], P1, 0, 1, shift_y);
_gradx_mat.write(write_index, P0);
_grady_mat.write(write_index++, P1);
shift_x = 0;
shift_y = 0;
P0 = 0;
P1 = 0;
xfPackPixels<NPC, WORDWIDTH_DST, DEPTH_DST>(&GradientValuesX[0], P0, 1, (npc - 1), shift_x);
xfPackPixels<NPC, WORDWIDTH_DST, DEPTH_DST>(&GradientValuesY[0], P1, 1, (npc - 1), shift_y);
}
src_buf1[0] = src_buf1[buf_size - 2];
src_buf1[1] = src_buf1[buf_size - 1];
src_buf2[0] = src_buf2[buf_size - 2];
src_buf2[1] = src_buf2[buf_size - 1];
src_buf3[0] = src_buf3[buf_size - 2];
src_buf3[1] = src_buf3[buf_size - 1];
} // Col_Loop
} |
|