嵌入式技术
1. 背景知识
OPENCV(Open Source Computer Vision)被广泛的使用在计算机视觉开发上。使用Vivado HLS视频库在zynq-7000全可编程soc上加速OPENCV 应用的开发,将大大提升我们的计算机视觉开发。
图1和图2展示了如何使用opencv加速zynq-7000全可编程 soc的计算机视觉开发。
1> 使用Vivado HLS开发opencv的计算机视觉IP;
2> 将IP添加到SOC系统中
3> 验证和下板实验
本次重点为HLS的图像读入显示,视频读入显示,以及摄像头的读入显示。
2. HLS 使用到的函数
enum
{
/* 8bit,color or not */
CV_LOAD_IMAGE_UNCHANGED =-1,//读取图像的原通道数
/* 8bit,gray */
CV_LOAD_IMAGE_GRAYSCALE =0,//读取灰度图片
/* ?,color */
CV_LOAD_IMAGE_COLOR =1,//读取彩色图片
/* anydepth, ? */
CV_LOAD_IMAGE_ANYDEPTH =2,//任意深度
/* ?,any color */
CV_LOAD_IMAGE_ANYCOLOR =4//任意颜色
};
/* loadimage from file
iscolor can be a combination of aboveflags where CV_LOAD_IMAGE_UNCHANGED
overrides the other flags
using CV_LOAD_IMAGE_ANYCOLOR alone isequivalent to CV_LOAD_IMAGE_UNCHANGED
unless CV_LOAD_IMAGE_ANYDEPTH is specifiedimages are converted to 8bit
*/
CVAPI(IplImage*) cvLoadImage(constchar*filename, int iscolor CV_DEFAULT(CV_LOAD_IMAGE_COLOR));
Filename 文件名
Iscolor 图像的颜色和深度
使用方法:
IplImage*src = cvLoadImage(filename,CV_LOAD_IMAGE_GRAYSCALE);
其他函数可以采用点击右键 open declaration查看。
Test.cpp 源码:
#include"Test.h"
#include"hls_opencv.h"
usingnamespace cv;
int main (int argc, char**argv) {
/*
//方法1 cvLoadImage函数加载图片
IplImage* src =cvLoadImage(INPUT_IMAGE,CV_LOAD_IMAGE_GRAYSCALE);
IplImage* dst =cvCreateImage(cvGetSize(src), src->depth, src->nChannels);//获取原始图像大小
AXI_STREAM src_axi, dst_axi;
IplImage2AXIvideo(src, src_axi);
AXIvideo2IplImage(src_axi, dst);
cvSaveImage(OUTPUT_IMAGE, dst);
cvShowImage( "result_1080p",dst);
cvReleaseImage(&src);
cvWaitKey();
*/
/*
//方法2 cvLoadImage函数加载图片
Mat src_rgb = imread(INPUT_IMAGE,CV_LOAD_IMAGE_COLOR);//加载图片并灰度显示
IplImage src = src_rgb;
cvSaveImage(OUTPUT_IMAGE, &src);
cvShowImage("src",&src);
waitKey(0);
return 0;
*/
/*
//读取视频文件
IplImage *frame;
CvCapture *capture =cvCaptureFromAVI("1.avi");//获取视频数据
cvNamedWindow("AVI player",0);
while(true)
{
if(cvGrabFrame(capture))
{
frame = cvRetrieveFrame(capture);
cvShowImage("AVI player",frame);
if(cvWaitKey(10)>=0) break;
}
else
{
break;
}
}
cvReleaseCapture(&capture);
cvDestroyWindow("AVI player");
return 0;
*/
//摄像头操作
IplImage *frame;
CvCapture *capture = cvCaptureFromCAM(1);//捕获摄像头数据0--笔记本自带摄像头 1--外部摄像头
cvNamedWindow("AVIplayer",0);
while(true)
{
if(cvGrabFrame(capture))
{
frame = cvRetrieveFrame(capture);
cvShowImage("AVIplayer",frame);
if(cvWaitKey(10)>=0)break;
}
else
{
break;//没有采集到视频数据退出
}
}
cvReleaseCapture(&capture);
cvDestroyWindow("AVIplayer");
return 0;
}
Test.h源码:
#ifndef_TOP_H_
#define_TOP_H_
#include"hls_video.h"
//maximum image size
#defineMAX_WIDTH 1920
#defineMAX_HEIGHT 1080
// I/OImage Settings
#defineINPUT_IMAGE "test_1080p.jpg"
#defineOUTPUT_IMAGE "result_1080p.bmp"
#defineOUTPUT_IMAGE_GOLDEN "result_1080p_golden.bmp"
//typedef video library core structures
typedef hls::stream> AXI_STREAM;
typedef hls::Scalar<3, unsignedchar> RGB_PIXEL;
typedef hls::Mat RGB_IMAGE;
#endif
3. VIVADO HLS图像获取实验
对于工程的创建请参考《HLS入门一》
实验原图1
//方法1cvLoadImage函数加载图片
IplImage* src = cvLoadImage(INPUT_IMAGE,CV_LOAD_IMAGE_GRAYSCALE);
实验结果1
//读取视频文件
IplImage *frame;
CvCapture *capture = cvCaptureFromAVI("1.avi");//获取视频数据
cvNamedWindow("AVIplayer",0);
全部0条评论
快来发表一下你的评论吧 !