码迷,mamicode.com
首页 > 其他好文 > 详细

opencv3.3 CUDA 初学实例

时间:2017-12-15 15:04:57      阅读:500      评论:0      收藏:0      [点我收藏+]

标签:pen   download   opencv3   devices   初学   enabled   str   module   gui   

#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 初学实例

标签:pen   download   opencv3   devices   初学   enabled   str   module   gui   

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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!