linux下安装opencv(opencv-3.4.12)
链接:https://opencv.org/releases/
sudo apt-get install build-essential
sudo apt-get install cmake git libgtk2.0-dev pkg-config libavcodec-dev libavformat-dev libswscale-dev libjpeg.dev libtiff4.dev
unzip opencv-3.4.12.zip
cd opencv-3.4.12
mkdir build
cd build
cmake -DCMAKE_BUILD_TYPE=Release -DOPENCV_GENERATE_PKGCONFIG=ON -DCMAKE_INSTALL_PREFIX=/usr/local ..
make -j8
sudo make install
里面包含一个run_hls.tcl,使用该文件生成项目工程,配置参数在该命令里已经执行,这样可以防止手工创建工程环境配置出现错误
配置hls运行前的环境,保证vitis_hls命令有效(原来叫vivado_hls)
source /home/cao/tools/Xilinx/Vitis_HLS/2020.2/settings64.sh
opencv引用和库生效,如果不执行,则vitis_hls -f run_hls.tcl会报如下错error while loading shared libraries: libopencv_imgcodecs.so.3.4: cannot open shared object file: No such file or directory
export OPENCV_INCLUDE=/usr/local/include/opencv2/
export OPENCV_LIB=/usr/local/lib/
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/lib/
(ubuntu1804区域截图并保存至图库快捷键为Shift+PRT SC)
如若仍然报错,请看文末更新
之后进入到下载的代码dilation下,在terminal中执行
vitis_hls -f run_hls.tcl
生成名为dilatiom.prj的工程,并执行综合、联合仿真等全部操作
需要注意run_hls.tcl的如下内容
source settings.tcl
set PROJ "dilation.prj"
第一句的settings.tcl貌似没有,第二句为工程名字,和后面的-p 后参数对应上
在该目录下创建setting.tcl
并添加如下内容
set XPART xcu250-figd2104-2L-e
set CSIM 0
set CSYNTH 1
set COSIM 1
set VIVADO_SYN 0
set VIVADO_IMPL 0
set QOR_CHECK 0
set OPENCV_INCLUDE "/usr/local/include/opencv2/"
set OPENCV_LIB "/usr/local/lib/"
set XF_PROJ_ROOT "/home/cao/git/repository/Vitis_Libraries-master/vision"
最后一句是下载的赛灵思视觉vision库目录,根据位置修改
然后可视化界面打开生成好的工程
vitis_hls -p dilatiom.prj
右键sol1,添加输入图片路径参数,(下载的代码里有)
阅读代码,大意为,首先使用cv里的cv::dilate生成out_ocv.jpg图片,然后使用自定义的函数生成hw_out.jpg图片,最后对两张图进行减法运算,生成out_error.jpg
但是没有搞懂其中的这两句话,为啥生成图片在前,处理程序在后,不应该显出里,再把处理结果写入图片吗
// Write output image
cv::imwrite("hw_out.jpg", out_img);
dilation_accel((ap_uint*)in_img.data, (ap_uint*)out_img.data, structure_element,
height, width);
左图为输入图像,右边三张为程序生成的图片
128×128.png out_ocv.jpg hw_out.jpg out_error.jpg
最后输出的日志文件里显示,表明自定义函数和cv里的结果完全相同
最大误差、最小误差、平均误差均为0
更新
今天重新打开项目,又报opencv的错误了,添加export DEVICE变量
export DEVICE=/home/cao/workspace/zcu102/export/zcu102/zcu102.xpfm
export OPENCV_INCLUDE=/usr/local/include/opencv2/
export OPENCV_LIB=/usr/local/lib/
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/lib/
使用make命令重新生成工程
make run CSIM=1 CSYNTH=1 COSIM=0
问题解决!
参考链接
https://blog.csdn.net/sinat_39724439/article/details/110131986
https://forums.xilinx.com/t5/High-Level-Synthesis-HLS/Vitis-HLS-opencv/td-p/1168414
https://forums.xilinx.com/t5/High-Level-Synthesis-HLS/Using-Vitis-Vision-Libraries-and-OpenCV/td-p/1170435
https://blog.csdn.net/u010879745/article/details/104800847
https://github.com/Xilinx/Vitis_Libraries/tree/master/vision/L1