我想将图像上传到以下变量中gpu::GpuMat test;。首先,将输入图像(src)转换为灰度图像cvtColor( src, src_gray, COLOR_BGR2GRAY );,然后将其上传test.upload(src_gray);。不幸的是,上传花费了很多时间。超过2分钟。图像尺寸为169x90。我知道,由于带宽的原因,通常会有一些延迟,但是我认为两分钟对于这么小的图像来说实在太多了。最后,我要提到的是,在上传第一个图像之后,下一个图像的加载几乎是即时的。有初始化程序吗?我们可以改善这种延迟吗?
int main( int, char** argv )
{
/// Load source image and convert it to gray
string filename = argv[1] ;//"yourfile.avi";
VideoCapture capture(filename);
if( !capture.isOpened() )
throw "Error when reading steam_avi";
int framenumber=1;
Mat src, src_gray;
gpu::GpuMat test;
namedWindow( "w", 1);
time_t start,end;
time (&start);
for( ; ; )
{
//printf("Frame %d: \n", framenumber++ );
capture >> src;
cvtColor( src, src_gray, COLOR_BGR2GRAY );
test.upload(src_gray);//it takes too long even for an image of 169x90
if( src_gray.empty() )
break;
imshow("w", src_gray);
waitKey(20); // waits to display frame
}
time (&end);
double dif = difftime (end,start);
printf ("Elasped time is %.2lf seconds.", dif );
getchar();
return(0);
}
Run Code Online (Sandbox Code Playgroud)

使用--memory = pageable参数。
PS:Win 7 64x,CUDA SDK 5.5,Opencv 2.4.6,GeForce 9600。
由于CUDA上下文初始化,任何gpu函数的首次调用都很慢。所有下一次通话将更快。在时间测量之前调用一些gpu函数:
gpu::GpuMat test;
test.create(1, 1, CV_8U); // Just to initialize context
time(&start);
...
time(&end);
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2858 次 |
| 最近记录: |