// xf_sobel.cpp
// 2020/02/13 by marsee
// xfopencv/HLS_Use_Model/Standalone_HLS_AXI_Example/xf_ip_accel_app.cpp のコードを引用している
// https://github.com/Xilinx/xfopencv/blob/master/HLS_Use_Model/Standalone_HLS_AXI_Example/xf_ip_accel_app.cpp
#include "xf_sobel_config.h"
#include "common/xf_infra.h"
void xf_sobel(hls::stream< ap_axiu<8,1,1,1> >& _src,hls::stream< ap_axiu<8,1,1,1> >& _dst,int height,int width){
#pragma HLS INTERFACE s_axilite port=return
#pragma HLS INTERFACE axis register both port=_src
#pragma HLS INTERFACE axis register both port=_dst
xf::Mat<XF_8UC1, HEIGHT, WIDTH, NPC1> imgInput1(height,width);
xf::Mat<XF_8UC1, HEIGHT, WIDTH, NPC1> dstgx(height,width);
xf::Mat<XF_8UC1, HEIGHT, WIDTH, NPC1> dstgy(height,width);
#pragma HLS stream variable=imgInput1.data dim=1 depth=1
#pragma HLS stream variable=imgOutput1.data dim=1 depth=1
#pragma HLS dataflow
xf::AXIvideo2xfMat(_src, imgInput1);
sobel_accel(imgInput1,dstgx, dstgy);
xf::xfMat2AXIvideo(dstgx, _dst);
}
// xf_sobel_tb.cpp
// 2020/02/13 by marsee
// xfopencv/HLS_Use_Model/Standalone_HLS_AXI_Example/xf_dilation_tb.cpp のコードを引用している
// https://github.com/Xilinx/xfopencv/blob/master/HLS_Use_Model/Standalone_HLS_AXI_Example/xf_dilation_tb.cpp
#include "xf_headers.h"
#include "xf_sobel_config.h"
#include "common/xf_infra.h"
#include "common/xf_axi.h"
void xf_sobel(hls::stream< ap_axiu<8,1,1,1> >& _src,hls::stream< ap_axiu<8,1,1,1> >& _dst,int height,int width);
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::Sobel(in_img, ocv_ref, CV_8UC1, 1, 0, 3);
cv::imwrite("out_ocv.jpg", ocv_ref);
hls::stream< ap_axiu<8,1,1,1> > _src,_dst;
cvMat2AXIvideoxf<NPC1>(in_img, _src);
xf_sobel(_src, _dst, height, width);
AXIvideo2cvMatxf<NPC1>(_dst, in_img1);
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.3f)
return 1;
return 0;
}
日 | 月 | 火 | 水 | 木 | 金 | 土 |
---|---|---|---|---|---|---|
- | - | - | - | - | 1 | 2 |
3 | 4 | 5 | 6 | 7 | 8 | 9 |
10 | 11 | 12 | 13 | 14 | 15 | 16 |
17 | 18 | 19 | 20 | 21 | 22 | 23 |
24 | 25 | 26 | 27 | 28 | 29 | 30 |
31 | - | - | - | - | - | - |