Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/opencv/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
gpu::morphologyEx在CPU方面比morphologyEx慢? 我写了一个C++代码,用于比较使用CPU和GPU版本的OpenCV的形态分析方法的性能。这是我的密码: #include <opencv2/opencv.hpp> #include <opencv2/gpu/gpu.hpp> #include <sys/time.h> #include <ctime> using namespace cv; using namespace std; double start_timer() { double start_time = (double) getTickCount(); return start_time; } double end_timer(double start_time,int num_tests) { double time = (1000 * ((double) getTickCount() - start_time)/ getTickFrequency()); cout << "Average time of " << num_tests << " frames is: " << time/num_tests << " ms" << endl; return time; } int main() { Mat cpuSrc; cv::gpu::GpuMat src_gpu, dst_gpu; Mat dst; Mat element; int element_shape = MORPH_RECT; element = getStructuringElement(element_shape, Size(10, 10 ), Point(-1, -1) ); cpuSrc = imread("images.jpeg",CV_LOAD_IMAGE_ANYDEPTH); if (!cpuSrc.data) { cerr << "Cannot read the data" << endl; return -1; } cout << "Starting calculating time for CPU ....." << endl; double start_time = start_timer(); int d = 0; while(d<100) { cv::morphologyEx(cpuSrc, dst, CV_MOP_OPEN, element,Point(-1,-1),1); } double total_time_cpu = end_timer(start_time,d); //-------------------------------------------------------------- cout << "Starting calculating time for GPU ....." << endl; d = 0; cv::gpu::GpuMat buf1, buf2; gpu::Stream stream; double start_time_1 = start_timer(); while(d<100) { stream.enqueueUpload(cpuSrc, src_gpu); cv::gpu::morphologyEx(src_gpu,dst_gpu,CV_MOP_OPEN,element, buf1,buf2,Point(-1,-1),1,stream); stream.enqueueDownload(dst_gpu, dst); } stream.waitForCompletion(); double total_time_gpu = end_timer(start_time_1,d); cout << "Gain is: " << total_time_cpu / total_time_gpu << endl; return 0; } #包括 #包括 #包括 #包括 使用名称空间cv; 使用名称空间std; 双启动定时器() { double start_time=(double)getTickCount(); 返回开始时间; } 双端定时器(双启动时间,整数测试) { 双时间=(1000*((双)getTickCount()-开始时间)/getTickFrequency()); cout_C++_Opencv_Cuda_Gpu_Mathematical Morphology - Fatal编程技术网

gpu::morphologyEx在CPU方面比morphologyEx慢? 我写了一个C++代码,用于比较使用CPU和GPU版本的OpenCV的形态分析方法的性能。这是我的密码: #include <opencv2/opencv.hpp> #include <opencv2/gpu/gpu.hpp> #include <sys/time.h> #include <ctime> using namespace cv; using namespace std; double start_timer() { double start_time = (double) getTickCount(); return start_time; } double end_timer(double start_time,int num_tests) { double time = (1000 * ((double) getTickCount() - start_time)/ getTickFrequency()); cout << "Average time of " << num_tests << " frames is: " << time/num_tests << " ms" << endl; return time; } int main() { Mat cpuSrc; cv::gpu::GpuMat src_gpu, dst_gpu; Mat dst; Mat element; int element_shape = MORPH_RECT; element = getStructuringElement(element_shape, Size(10, 10 ), Point(-1, -1) ); cpuSrc = imread("images.jpeg",CV_LOAD_IMAGE_ANYDEPTH); if (!cpuSrc.data) { cerr << "Cannot read the data" << endl; return -1; } cout << "Starting calculating time for CPU ....." << endl; double start_time = start_timer(); int d = 0; while(d<100) { cv::morphologyEx(cpuSrc, dst, CV_MOP_OPEN, element,Point(-1,-1),1); } double total_time_cpu = end_timer(start_time,d); //-------------------------------------------------------------- cout << "Starting calculating time for GPU ....." << endl; d = 0; cv::gpu::GpuMat buf1, buf2; gpu::Stream stream; double start_time_1 = start_timer(); while(d<100) { stream.enqueueUpload(cpuSrc, src_gpu); cv::gpu::morphologyEx(src_gpu,dst_gpu,CV_MOP_OPEN,element, buf1,buf2,Point(-1,-1),1,stream); stream.enqueueDownload(dst_gpu, dst); } stream.waitForCompletion(); double total_time_gpu = end_timer(start_time_1,d); cout << "Gain is: " << total_time_cpu / total_time_gpu << endl; return 0; } #包括 #包括 #包括 #包括 使用名称空间cv; 使用名称空间std; 双启动定时器() { double start_time=(double)getTickCount(); 返回开始时间; } 双端定时器(双启动时间,整数测试) { 双时间=(1000*((双)getTickCount()-开始时间)/getTickFrequency()); cout

gpu::morphologyEx在CPU方面比morphologyEx慢? 我写了一个C++代码,用于比较使用CPU和GPU版本的OpenCV的形态分析方法的性能。这是我的密码: #include <opencv2/opencv.hpp> #include <opencv2/gpu/gpu.hpp> #include <sys/time.h> #include <ctime> using namespace cv; using namespace std; double start_timer() { double start_time = (double) getTickCount(); return start_time; } double end_timer(double start_time,int num_tests) { double time = (1000 * ((double) getTickCount() - start_time)/ getTickFrequency()); cout << "Average time of " << num_tests << " frames is: " << time/num_tests << " ms" << endl; return time; } int main() { Mat cpuSrc; cv::gpu::GpuMat src_gpu, dst_gpu; Mat dst; Mat element; int element_shape = MORPH_RECT; element = getStructuringElement(element_shape, Size(10, 10 ), Point(-1, -1) ); cpuSrc = imread("images.jpeg",CV_LOAD_IMAGE_ANYDEPTH); if (!cpuSrc.data) { cerr << "Cannot read the data" << endl; return -1; } cout << "Starting calculating time for CPU ....." << endl; double start_time = start_timer(); int d = 0; while(d<100) { cv::morphologyEx(cpuSrc, dst, CV_MOP_OPEN, element,Point(-1,-1),1); } double total_time_cpu = end_timer(start_time,d); //-------------------------------------------------------------- cout << "Starting calculating time for GPU ....." << endl; d = 0; cv::gpu::GpuMat buf1, buf2; gpu::Stream stream; double start_time_1 = start_timer(); while(d<100) { stream.enqueueUpload(cpuSrc, src_gpu); cv::gpu::morphologyEx(src_gpu,dst_gpu,CV_MOP_OPEN,element, buf1,buf2,Point(-1,-1),1,stream); stream.enqueueDownload(dst_gpu, dst); } stream.waitForCompletion(); double total_time_gpu = end_timer(start_time_1,d); cout << "Gain is: " << total_time_cpu / total_time_gpu << endl; return 0; } #包括 #包括 #包括 #包括 使用名称空间cv; 使用名称空间std; 双启动定时器() { double start_time=(double)getTickCount(); 返回开始时间; } 双端定时器(双启动时间,整数测试) { 双时间=(1000*((双)getTickCount()-开始时间)/getTickFrequency()); cout,c++,opencv,cuda,gpu,mathematical-morphology,C++,Opencv,Cuda,Gpu,Mathematical Morphology,在初始化过程中,您应该调用: cv::gpu::setDevice(0); 它将加快初始化速度。您能给出映像大小、处理器的确切型号和系统配置(包括操作系统详细信息)吗..?任何gpu函数的第一次调用都包括CUDA上下文初始化,这可能需要很长时间。因此,第一次测量值是异常值,它会影响总平均时间。@scap3y图像大小540*960。Ubuntu 12.04 LTS 64位。英特尔公司至强E5/Core i7 DMI2(版本07)即使添加了此初始化,结果仍然完全相同(

在初始化过程中,您应该调用:

cv::gpu::setDevice(0);

它将加快初始化速度。

您能给出映像大小、处理器的确切型号和系统配置(包括操作系统详细信息)吗..?任何gpu函数的第一次调用都包括CUDA上下文初始化,这可能需要很长时间。因此,第一次测量值是异常值,它会影响总平均时间。@scap3y图像大小540*960。Ubuntu 12.04 LTS 64位。英特尔公司至强E5/Core i7 DMI2(版本07)即使添加了此初始化,结果仍然完全相同(