使用 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;
}


執行結果 :

undefined

arrow
arrow
    文章標籤
    CUDA OpenCV
    全站熱搜
    創作者介紹
    創作者 ghostyguo 的頭像
    ghostyguo

    No More Codes

    ghostyguo 發表在 痞客邦 留言(0) 人氣()