考虑到有别的网友会检索到这个笔记,说明一下,笔记中PL/PS定义在硬件加速函数那块可能不大准确,应该说是在硬件内存中的‘不是SDSCC编译器’与‘是SDSCC编译器’。。。。。。。。。凑合理解。。。
xfopencv--examples
第一个例程学习accumulate
调用sd卡图片到PL中
int main(int argc, char** argv)
{
if (argc != 3)
{
fprintf(stderr,"Invalid Number of Arguments!\nUsage:\n");
fprintf(stderr," \n");
return -1;
}
cv::Mat in_img, in_img1, out_img;
cv::Mat in_gray, in_gray1, diff;
in_gray = cv::imread(argv[1], 0); // reading image
in_gray1 = cv::imread(argv[2], 0); // reading image
if (in_gray.data == NULL)
{
fprintf(stderr,"Cannot open image %s\n", argv[1]);
return 0;
}
if (in_gray1.data == NULL)
{
fprintf(stderr,"Cannot open image %s\n", argv[2]);
return 0;
}
cv::Mat inout_gray(in_gray.rows, in_gray.cols, CV_16U, 1);
cv::Mat inout_gray1(in_gray.rows, in_gray.cols, CV_32FC1, 1);
调用PL图片到PS中
static xf::Mat imgInput1(in_gray1.rows,in_gray1.cols);
static xf::Mat imgInput2(inout_gray.rows,inout_gray.cols);
static xf::Mat imgOutput(out_gray.rows,out_gray.cols);
imgInput1.copyTo(in_gray.data);
imgInput2.copyTo(in_gray1.data);
把图片从PS中提出到PL中
out_gray.data = imgOutput.copyFrom();
把图片从PL保存到sd卡中
imwrite("out_hls.jpg", out_gray);
用sdscc加速硬件时所用的计时手段
headers.h文件
#ifndef _XF_HEADERS_H_
#define _XF_HEADERS_H_
#include
#include
#if __SDSCC__
#undef __ARM_NEON__
#undef __ARM_NEON
#include "opencv2/opencv.hpp"
#include "opencv2/imgproc/imgproc.hpp"
#include "opencv2/highgui/highgui.hpp"
#define __ARM_NEON__
#define __ARM_NEON
#else
#include "opencv2/opencv.hpp"
#include "opencv2/imgproc/imgproc.hpp"
#include "opencv2/highgui/highgui.hpp"
#endif
#if __SDSCC__
#include "sds_lib.h"
#define TIME_STAMP_INIT unsigned int clock_start, clock_end; clock_start = sds_clock_counter();
#define TIME_STAMP { clock_end = sds_clock_counter(); printf("elapsed time %lu \n", clock_end-clock_start); clock_start = sds_clock_counter(); }
#endif
#include "common/xf_sw_utils.h"
#endif//_XF_HEADERS_H_
硬件加速函数前后调用时:
#include "xf_headers.h"
#if __SDSCC__
perf_counter hw_ctr;
hw_ctr.start();
#endif
accumulate_accel(imgInput1,imgInput2,imgOutput);
#if __SDSCC__
hw_ctr.stop();
uint64_t hw_cycles = hw_ctr.avg_cpu_cycles();
#endif
硬件函数中可以通过改参数设置每个始终有几个像素并行
#ifndef _XF_ACCUMULATE_CONFIG_H_
#define _XF_ACCUMULATE_CONFIG_H_
#include "hls_stream.h"
#include
#include "xf_config_params.h"
#include "common/xf_common.h"
#include "common/xf_utility.h"
#include "imgproc/xf_accumulate_image.hpp"
// Set the image height and width
#define HEIGHT 2160
#define WIDTH 3840
#if NO
#define NPC1 XF_NPPC1
#endif
#if RO
#define NPC1 XF_NPPC8
#endif
#define IN_TYPE XF_8UC1
#define OUT_TYPE XF_16UC1
void accumulate_accel(xf::Mat &imgInput1,xf::Mat &imgInput2,xf::Mat &imgOutput);
#endif//_XF_ACCUMULATE_CONFIG_H_
样例中多设置一个.h文件来确定参数
/* set the optimisation type */
#define NO 1 // Normal Operation
#define RO 0 // Resource Optimized
第二个是canny
硬件加速函数里面提到PS中复制内存,以及PL中复制图片的方式
#include "xf_canny_config.h"
void canny_accel(xf::Mat &_src,xf::Mat &_dst,xf::Mat &_dst1,xf::Mat &_dst2,unsigned char low_threshold,unsigned char high_threshold)
{
#pragma SDS async(1)
xf::Canny(_src,_dst,low_threshold,high_threshold);
#pragma SDS wait(1)
#if __SDSCC__
_dst1.data = (ap_uint<64>*)_dst.data;#PS复制
#else
_dst1.copyTo(_dst.data);#PL复制
#endif
xf::EdgeTracing(_dst1,_dst2);
}
第一个xf_canny可能是并行进去的,等待全部完后才能后,再进行下一个硬件加速程序
在canny中有一种txt文件的写法
FILE *fp = fopen("nmsvalues.txt","w");
int cnt = 0;
for (int i=0; i(i,j);
fprintf(fp,"%d ",v);
if (v>0)//(v>0 && v!=127 && v!=128)
cnt++;
if (minval > v)
minval = v;
if (maxval < v)
maxval = v;
}
fprintf(fp,"\n");
}
fclose(fp);
float err_per = 100.0 * (float)cnt / (diff.rows * diff.cols);
fprintf(stderr,"Minimum error in intensity = %f\n Maximum error in intensity = %f\n Percentage of pixels above error threshold = %f\nNo of Pixels with Error = %d\n",minval,maxval,err_per, cnt);
网上查了
fprintf 是输出到文件,当然,这个文件也可能是虚拟的文件。多一个文件指针FILE*。
printf 是直接输出到标准显示设备,就是屏幕的终端中。
示例:
char name[20] = "Mary";
FILE *out;
out = fopen( "output.txt", "w" );
if( out != NULL )
fprintf( out, "Hello %s\n", name );
不大明白canny里面为啥fclose了,还能fprintf,估计这时相当于printf了
深究可以看https://www.cnblogs.com/zhangyabin---acm/p/3203745.html这篇文章