added example code using cuda functions
This commit is contained in:
@@ -1,16 +1,52 @@
|
||||
#include <iostream>
|
||||
#include <opencv2/core/core.hpp>
|
||||
#include <opencv2/highgui/highgui.hpp>
|
||||
#include <opencv2/imgproc.hpp>
|
||||
#include <opencv2/core/cuda.hpp>
|
||||
#include <opencv2/cudaimgproc.hpp>
|
||||
#include <opencv2/cudafilters.hpp>
|
||||
|
||||
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<cuda::Filter> medianFilter = cuda::createMedianFilter(gpuEdges.type(), 11);
|
||||
medianFilter->apply(gpuEdges, gpuEdges);
|
||||
Ptr<cuda::CannyEdgeDetector> detector = cuda::createCannyEdgeDetector(30, 60);
|
||||
detector->detect(gpuEdges, gpuEdges);
|
||||
|
||||
Mat result;
|
||||
gpuEdges.download(result);
|
||||
imshow("GPU computed Edges", result);
|
||||
// ----- //
|
||||
waitKey(0);
|
||||
|
||||
return 0;
|
||||
|
||||
Reference in New Issue
Block a user