1. 背景知識(shí)
OPENCV(Open Source Computer Vision)被廣泛的使用在計(jì)算機(jī)視覺(jué)開(kāi)發(fā)上。使用Vivado HLS視頻庫(kù)在zynq-7000全可編程soc上加速OPENCV 應(yīng)用的開(kāi)發(fā),將大大提升我們的計(jì)算機(jī)視覺(jué)開(kāi)發(fā)。
圖1和圖2展示了如何使用opencv加速zynq-7000全可編程 soc的計(jì)算機(jī)視覺(jué)開(kāi)發(fā)。
1> 使用Vivado HLS開(kāi)發(fā)opencv的計(jì)算機(jī)視覺(jué)IP;
2> 將IP添加到SOC系統(tǒng)中
3> 驗(yàn)證和下板實(shí)驗(yàn)
本次重點(diǎn)為HLS的圖像讀入顯示,視頻讀入顯示,以及攝像頭的讀入顯示。
2. HLS 使用到的函數(shù)
enum
{
/* 8bit,color or not */
CV_LOAD_IMAGE_UNCHANGED =-1,//讀取圖像的原通道數(shù)
/* 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);
其他函數(shù)可以采用點(diǎn)擊右鍵 open declaration查看。
Test.cpp 源碼:
#include"Test.h"
#include"hls_opencv.h"
usingnamespace cv;
int main (int argc, char**argv) {
/*
//方法1 cvLoadImage函數(shù)加載圖片
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函數(shù)加載圖片
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");//獲取視頻數(shù)據(jù)
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);//捕獲攝像頭數(shù)據(jù)0--筆記本自帶攝像頭 1--外部攝像頭
cvNamedWindow("AVIplayer",0);
while(true)
{
if(cvGrabFrame(capture))
{
frame = cvRetrieveFrame(capture);
cvShowImage("AVIplayer",frame);
if(cvWaitKey(10)>=0)break;
}
else
{
break;//沒(méi)有采集到視頻數(shù)據(jù)退出
}
}
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圖像獲取實(shí)驗(yàn)
對(duì)于工程的創(chuàng)建請(qǐng)參考《HLS入門一》
實(shí)驗(yàn)原圖1
//方法1cvLoadImage函數(shù)加載圖片
IplImage* src = cvLoadImage(INPUT_IMAGE,CV_LOAD_IMAGE_GRAYSCALE);
實(shí)驗(yàn)結(jié)果1
//讀取視頻文件
IplImage *frame;
CvCapture *capture = cvCaptureFromAVI("1.avi");//獲取視頻數(shù)據(jù)
cvNamedWindow("AVIplayer",0);
評(píng)論
查看更多