#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; }