将GPU Stream与OpenCV和Nvidia Jetson TK1结合使用

时间:2014-08-22 00:53:18

标签: c++ opencv gpu

几周前我已经获得了Nvidia Jetson TK1,我正在尝试同时使用CPU和GPU,因此使用了Stream类。通过一个简单的测试,我意识到它没有做我认为应该做的事情,我可能使用它错误,或者可能是编译器选项。

在发布此问题之前,我已检查此链接以获取答案:how to use gpu::Stream in OpenCV?

这是我的代码:

#include <stdio.h> 
#include <iostream>   
#include "opencv2/core/core.hpp"
#include "opencv2/features2d/features2d.hpp"
#include "opencv2/highgui/highgui.hpp"
#include "opencv2/imgproc/imgproc.hpp"
#include "opencv2/objdetect/objdetect.hpp"
#include "opencv2/gpu/gpu.hpp"
#include <time.h> 

using namespace cv;
using namespace std;
using namespace gpu;    


int main(int argc,char** argv)    
{    
 unsigned long AAtime=0, BBtime=0;  
gpu::setDevice(0);
gpu::FeatureSet(FEATURE_SET_COMPUTE_30);
Mat host_src= imread(argv[1],0);
GpuMat gpu_src, gpu_dst;

Stream stream;

gpu_src.upload(host_src);

AAtime = getTickCount(); 
blur(gpu_src, gpu_dst, Size(5,5), Point(-1,-1), stream);

//Cpu function
int k=0;
for(unsigned long long int j=0;j<10;j++)
for(unsigned long long int i=0;i<10000000;i++)
 k+=rand(); 

stream.waitForCompletion();
Mat host_dst;
BBtime = getTickCount();  
 cout<<(BBtime - AAtime)/getTickFrequency()<<endl;
gpu_dst.download(host_dst);

 return 0;  

}   

通过计时器功能,我看到总体时间是CPU + GPU,而不是两者中最长的,所以它们不能并行工作。我尝试使用CudaMem,因为jet47显示但是当我观看图像时它只是条纹而不是我的图像:

CudaMem host_src_pl(Size(900, 1200), CV_8UC1, CudaMem::ALLOC_PAGE_LOCKED); // My image is 1200 by 900
CudaMem host_dst_pl;
Mat host_src= imread(argv[1],0);
host_src = host_src_pl;
//rest of the code

要编译,我使用了这个命令:“g ++ -Ofast -mfpu = neon -funsafe-math-optimizations -fabi-version = 8 -Wabi -std = c ++ 11 -march = armv7-a testStream.cpp -fopenmp -lopencv_core -lopencv_imgproc -lopencv_highgui -lopencv_calib3d -lopencv_contrib -lopencv_features2d -lopencv_flann -lopencv_gpu -lopencv_legacy -lopencv_ml -lopencv_objdetect -lopencv_photo -lopencv_stitching -lopencv_superres -lopencv_video -lopencv_videostab -o gpuStream”有些人可能是多余的,我想没有他们和它同样的

我想念什么?谢谢你的回答:)

0 个答案:

没有答案