OpenCV 3 CUDA小测试
2015-07-31 11:53
274 查看
OpenCV 3版本的CUDA有了很大变化。刚刚在WIN7 64位系统编译好了带CUDA 7.0版本的OpenCV 3.0库。
进行了简单的测试。
CUDA版代码如下:
不用CUDA版:
#include<opencv2\opencv.hpp>
#include <time.h>
#include<iostream>
using namespace std;
using namespace cv;
int main()
{
clock_t t1 = clock();
Mat src_image = imread("Hi-RGB0971.tif");
Mat dst_image;
cvtColor(src_image, dst_image, CV_BGR2GRAY);
imshow("test", dst_image);
clock_t t2 = clock();
std::cout << "time: " << (t2 - t1) / 1000 << "s" << endl;
waitKey();
return 0;
}
测试下来,使用了CUDA编译的OpenCV库,运行的时间比没有使用CUDA库编译的OpenCV库还要长。我觉得是由于数据载入GPU和重新载入CPU耗费了时间。
后面会利用OpenCV库和CUDA单独写函数,分块处理影像,然后进行相关的测试。
进行了简单的测试。
CUDA版代码如下:
#include<opencv2\opencv.hpp> #include<opencv2/cudaimgproc.hpp> #include <time.h> #include<iostream> using namespace std; using namespace cv; int main() { clock_t t1 = clock(); int num_devices = cv::cuda::getCudaEnabledDeviceCount(); if (num_devices <= 0){ cerr << "There is no device." << endl; return -1; } int enable_device_id = -1; for (int i = 0; i < num_devices; i++){ cv::cuda::DeviceInfo dev_info(i); if (dev_info.isCompatible()){ enable_device_id = i; } } if (enable_device_id < 0){ cerr << "GPU module isn't built for GPU" << endl; } cv::cuda::setDevice(enable_device_id); Mat src_image = imread("Hi-RGB0971.tif"); Mat dst_image; cuda::GpuMat d_src_img(src_image);//upload src image to gpu cuda::GpuMat d_dst_img; cuda::cvtColor(d_src_img, d_dst_img, CV_BGR2GRAY); d_dst_img.download(dst_image); imshow("test", dst_image); clock_t t2 = clock(); std::cout << "time: " << (t2 - t1) / 1000 << "s" << endl; waitKey(); return 0; }
不用CUDA版:
#include<opencv2\opencv.hpp>
#include <time.h>
#include<iostream>
using namespace std;
using namespace cv;
int main()
{
clock_t t1 = clock();
Mat src_image = imread("Hi-RGB0971.tif");
Mat dst_image;
cvtColor(src_image, dst_image, CV_BGR2GRAY);
imshow("test", dst_image);
clock_t t2 = clock();
std::cout << "time: " << (t2 - t1) / 1000 << "s" << endl;
waitKey();
return 0;
}
测试下来,使用了CUDA编译的OpenCV库,运行的时间比没有使用CUDA库编译的OpenCV库还要长。我觉得是由于数据载入GPU和重新载入CPU耗费了时间。
后面会利用OpenCV库和CUDA单独写函数,分块处理影像,然后进行相关的测试。
相关文章推荐
- Linux rpm 命令参数使用详解[介绍和应用]
- 网站后台登录页面始终始终为父窗体的解决办法
- 【资源分享】迅为 iTOP-4412开发板平台详解
- django结合apache部署
- 基于Schema的AOP 配置使用详解
- 基于Schema的AOP 配置使用详解
- Thinking In Linux C/C++字节对齐详解
- Xcode is missing from working copy
- ]linux+svn自动同步
- linux初学(十八)之linux命令文本处理工具
- nginx 解决跨域问题
- apache apr的编译和引用
- CentOS Linux 修改 /etc/hostname 导致hadoop运行缓慢
- linux 跨机器文件相互拷贝:scp
- nginx server_name 多个
- linux查看修改字符集
- HDU 5336 XYZ and Drops
- CentOS6.5+php5.3听云安装过程
- 前端:将网站打造成单页面应用SPA
- linux 下的top 、free的性能分析详解