使用 cudaFilter 的範例 (須 include cudafilters.hpp)
#include "cuda_runtime.h"
#include "device_launch_parameters.h"
#include <opencv2/core.hpp>
#include <opencv2/imgcodecs.hpp>
#include <opencv2/highgui.hpp>
#include <opencv2/imgproc.hpp>
#include <opencv2/core/cuda.hpp>
#include <opencv2/cudafilters.hpp>
#include <stdio.h>
#include <Windows.h>
using namespace cv;
using namespace cuda;
int main()
{
int filterSize = 5;
char *filename = "D:\\LENA.JPG";
// load source image
Mat srcMat =
imread(filename, IMREAD_GRAYSCALE); //
Read the file and convert to grayscale
GpuMat srcGMat(srcMat), destGMat;
//run opencv cuda filter
Ptr<Filter>
filter = createBoxFilter(srcGMat.type(), -1, cv::Size(filterSize,
filterSize)); //BoxFilter=blurFilter
filter->apply(srcGMat,
destGMat);
// get processing result
Mat destMat;
destGMat.download(destMat);
//show results
imshow("Source window", srcMat);
imshow("Dest window", destMat);
waitKey(0); // Wait for a keystroke in the window
return 0;
}
|
執行結果 :
沒有留言:
張貼留言