-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
77 lines (58 loc) · 2.75 KB
/
main.cpp
File metadata and controls
77 lines (58 loc) · 2.75 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#include <iostream>
#include <string>
#include <opencv2/highgui.hpp>
#include <opencv2/imgproc.hpp>
#include <opencv2/cudaarithm.hpp>
#include <opencv2/cudaimgproc.hpp>
int main()
{
//Version check code is from Satya Mallick's post https://learnopencv.com/how-to-find-opencv-version-python-cpp/
std::cout << "OpenCV version : " << CV_VERSION << std::endl;
std::cout << "Major version : " << CV_MAJOR_VERSION << std::endl;
std::cout << "Minor version : " << CV_MINOR_VERSION << std::endl;
std::cout << "Subminor version : " << CV_SUBMINOR_VERSION << std::endl;
std::cout << "*****************************************************" << std::endl;
std::string imDir = "C:\\Users\\batuh\\OneDrive\\Masaüstü\\lena.png"; //Change it to a proper image path for your system
cv::Mat inputImage = cv::imread(imDir, cv::IMREAD_UNCHANGED);
cv::namedWindow("Input Image", cv::WINDOW_NORMAL);
cv::imshow("Input Image", inputImage);
cv::waitKey();
//Test of CPU functions
cv::Mat grayImage;
cv::cvtColor(inputImage, grayImage, cv::COLOR_BGR2GRAY);
cv::namedWindow("Gray Image", cv::WINDOW_NORMAL);
cv::imshow("Gray Image", grayImage);
cv::waitKey();
//Test of GPU availability and functions
int cudaEnabDevCount = cv::cuda::getCudaEnabledDeviceCount();
if(cudaEnabDevCount)
std::cout << "Number of available CUDA device(s): " << cudaEnabDevCount << std::endl;
else
std::cout << "You don't have any available CUDA device(s)" << std::endl;
std::cout << "*****************************************************" << std::endl;
std::cout << "List of all available CUDA device(s):" << std::endl;
for (int devId = 0; devId < cudaEnabDevCount; ++devId) {
cv::cuda::setDevice(devId);
std::cout << "Available "; cv::cuda::printShortCudaDeviceInfo(cv::cuda::getDevice());
}
std::cout << "*****************************************************" << std::endl;
cv::cuda::DeviceInfo cudaDeviceInfo;
bool devCompatib = false;
std::cout << "List of all compatiable CUDA device(s):" << std::endl;
for (int devId = 0; devId < cudaEnabDevCount; ++devId) {
cudaDeviceInfo = cv::cuda::DeviceInfo::DeviceInfo(devId);
devCompatib = cudaDeviceInfo.isCompatible();
if (devCompatib)
std::cout << "Compatiable "; cv::cuda::printShortCudaDeviceInfo(cv::cuda::getDevice());
}
std::cout << "*****************************************************" << std::endl;
cv::cuda::GpuMat inputImageGpu, imageGrayGpu;
inputImageGpu.upload(inputImage);
cv::cuda::cvtColor(inputImageGpu, imageGrayGpu, cv::COLOR_BGR2GRAY);
cv::Mat imageGrayCpu;
imageGrayGpu.download(imageGrayCpu);
cv::namedWindow("Gray Image GPU", cv::WINDOW_NORMAL);
cv::imshow("Gray Image GPU", imageGrayCpu);
cv::waitKey();
cv::destroyAllWindows();
}