From 8b8b1f93941faf49e4e65d247112cb1fd6434d45 Mon Sep 17 00:00:00 2001 From: Peter Roch Date: Wed, 19 Feb 2020 13:44:33 +0100 Subject: [PATCH] added example code using cuda functions --- vs_cudatest/CudaTest/CudaTest/Test.cpp | 44 +++++++++++++++++++++++--- 1 file changed, 40 insertions(+), 4 deletions(-) diff --git a/vs_cudatest/CudaTest/CudaTest/Test.cpp b/vs_cudatest/CudaTest/CudaTest/Test.cpp index 6a60b89..4f77c94 100644 --- a/vs_cudatest/CudaTest/CudaTest/Test.cpp +++ b/vs_cudatest/CudaTest/CudaTest/Test.cpp @@ -1,16 +1,52 @@ #include #include #include +#include +#include +#include +#include using namespace std; using namespace cv; int main() { - cout << "Hello world" << endl; + cout << "program started" << endl; + + int count = cuda::getCudaEnabledDeviceCount(); + if (count <= 0) { + cout << "Oh no" << endl; + return -1; + } + cout << "Cuda is enabled" << endl; + Mat image = imread("car.jpg"); - - namedWindow("window"); - imshow("window", image); + resize(image, image, Size(), 2.5, 2.5); + imshow("original image", image); + Mat img; + image.copyTo(img); + Mat edges; + cvtColor(img, edges, COLOR_BGR2GRAY); + medianBlur(edges, edges, 11); + Canny(edges, edges, 30, 60); + imshow("CPU computed edges", edges); + + // ----- // + cout << "Cuda device info:" << endl; + cuda::printCudaDeviceInfo(0); + image.copyTo(img); + cuda::GpuMat gpuImg; + gpuImg.upload(img); + cuda::GpuMat gpuEdges; + cuda::cvtColor(gpuImg, gpuEdges, COLOR_BGR2GRAY); + Ptr medianFilter = cuda::createMedianFilter(gpuEdges.type(), 11); + medianFilter->apply(gpuEdges, gpuEdges); + Ptr detector = cuda::createCannyEdgeDetector(30, 60); + detector->detect(gpuEdges, gpuEdges); + + Mat result; + gpuEdges.download(result); + imshow("GPU computed Edges", result); + // ----- // waitKey(0); return 0;