如何使用opencv的gpu库呢?我这两天一直在搞这个事情,环境的配置见上文(转载),这里我先举个简单的例子,实现这样的功能:host读入一幅图像,加载到GPU上,在GPU上复制一份然后下传到host上,显示出来即可。
// gpu_opencv.cpp : 定义控制台应用程序的入口点。 // #include "stdafx.h" #include <iostream> #include <opencv2/opencv.hpp> #include <opencv2/gpu/gpu.hpp> // GPU structures and methods int main(){ cv::gpu::setDevice(0); cv::Mat host_image = cv::imread("C:\\Users\\Administrator\\Documents\\Visual Studio 2010\\Projects\\gpu_opencv\\1.jpg"); cv::Mat host_result(host_image.rows,host_image.cols,host_image.channels()); cv::gpu::GpuMat device_image1; device_image1.upload(host_image); //allocate memory and upload to GPU cv::gpu::GpuMat device_image2; device_image1.copyTo(device_image2); //allocate memory and GPU-GPU copy device_image2.download(host_result); //download data cv::imshow("location",host_result); cv::waitKey(0); }
时间: 2024-11-05 13:04:21