首页 > 其他 > 详细

opencv3.3 CUDA 初学实例

时间:2017-12-15 14:38:47      阅读:406      评论:0      收藏:0      [点我收藏+]
#include "opencv2/core.hpp"  
#include "opencv2/cudaarithm.hpp"  
#include "opencv2/cudafilters.hpp"  
#include "opencv2/cudaimgproc.hpp"
#include "opencv2/highgui.hpp"
#include <iostream>


int main( )
{
	int num_devices = cv::cuda::getCudaEnabledDeviceCount();

	if (num_devices <= 0)
	{
		std::cout << "There is no device." << std::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)
	{
		std::cout << "GPU module isn‘t built for GPU" << std::endl;
		return -1;
	}
	cv::cuda::setDevice(enable_device_id);

	std::cout << "GPU is ready, device ID is " << num_devices << "\n";

	cv::Mat src_image = cv::imread("1118.png", 1);
	cv::Mat dst_image;
	cv::cuda::GpuMat d_src_img(src_image);
	cv::cuda::GpuMat d_dst_img;
	cv::cuda::cvtColor(d_src_img, d_dst_img, CV_BGR2GRAY);
	d_dst_img.download(dst_image);
	cv::namedWindow("test", 0);
	cv::imshow("test", dst_image);
	cv::waitKey(0);
	return 0;
}

  

opencv3.3 CUDA 初学实例

原文:http://www.cnblogs.com/luoyinjie/p/8042689.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!