-
Charls Babu authored
Update images/Screenshot from 2023-02-27 22-24-46.png, README.md, edge_detection.h, edge_detection.cpp
Charls Babu authoredUpdate images/Screenshot from 2023-02-27 22-24-46.png, README.md, edge_detection.h, edge_detection.cpp
edge_detection.cpp 1.70 KiB
#include "edge_detection.h"
void edge_detect(stream_t& stream_in, stream_t& stream_out1, stream_t& stream_out2)
{
#pragma HLS INTERFACE ap_ctrl_none port=return
#pragma HLS INTERFACE axis port=stream_in
#pragma HLS INTERFACE axis port=stream_out1
#pragma HLS INTERFACE axis port=stream_out2
//xf::cv::Mat-type local variables for intermediate results
xf::cv::Mat<XF_8UC3, MAX_HEIGHT, MAX_WIDTH, XF_NPPC1> img0(MAX_HEIGHT, MAX_WIDTH);
xf::cv::Mat<XF_8UC1, MAX_HEIGHT, MAX_WIDTH, XF_NPPC1> img1(MAX_HEIGHT, MAX_WIDTH);
xf::cv::Mat<XF_8UC1, MAX_HEIGHT, MAX_WIDTH, XF_NPPC1> img2x(MAX_HEIGHT, MAX_WIDTH);
xf::cv::Mat<XF_8UC1, MAX_HEIGHT, MAX_WIDTH, XF_NPPC1> img2y(MAX_HEIGHT, MAX_WIDTH);
xf::cv::Mat<XF_8UC3, MAX_HEIGHT, MAX_WIDTH, XF_NPPC1> img3x(MAX_HEIGHT, MAX_WIDTH);
xf::cv::Mat<XF_8UC3, MAX_HEIGHT, MAX_WIDTH, XF_NPPC1> img3y(MAX_HEIGHT, MAX_WIDTH);
#pragma HLS DATAFLOW
//Interpret AXI-Stream interface and pull the frame from it
xf::cv::AXIvideo2xfMat<24, XF_8UC3, MAX_HEIGHT, MAX_WIDTH, XF_NPPC1>(stream_in, img0);
//Convert to grayscale
xf::cv::rgb2gray<XF_8UC3, XF_8UC1, MAX_HEIGHT, MAX_WIDTH>(img0, img1);
//Run the Sobel operator on the x-axis with a 3x3 kernel
xf::cv::Sobel<XF_BORDER_CONSTANT,XF_FILTER_3X3,XF_8UC1,XF_8UC1,MAX_HEIGHT,MAX_WIDTH>(img1, img2x, img2y);
//Convert back to RGB format for display purposes
xf::cv::gray2rgb<XF_8UC1, XF_8UC3, MAX_HEIGHT, MAX_WIDTH>(img2x, img3x);
xf::cv::gray2rgb<XF_8UC1, XF_8UC3, MAX_HEIGHT, MAX_WIDTH>(img2y, img3y);
//Pack the frame back into AXI-Stream interface
xf::cv::xfMat2AXIvideo<24, XF_8UC3, MAX_HEIGHT, MAX_WIDTH, XF_NPPC1>(img3x, stream_out1);
xf::cv::xfMat2AXIvideo<24, XF_8UC3, MAX_HEIGHT, MAX_WIDTH, XF_NPPC1>(img3y, stream_out2);
}