I'm new to parallel computing. I'm looking for expertise to give me a hand on how to implement CUDA in an OpenCV project.
The OpenCV project is to read the image and detect the corner in the image. The console will list out the time cost to demo the entire process. Now with the code below the result of time cost is 79.89 seconds. I need to use CUDA to reduce the time cost.
Below is the OpenCV code of the Harris Corner Detector:
#include "opencv2/highgui.hpp"
#include "opencv2/imgproc.hpp"
#include <iostream>
using namespace cv;
using namespace std;
Mat src, src_gray;
int thresh = 50;
int max_thresh = 100;
const char* source_window = "Source image";
const char* corners_window = "Corners detected";
void cornerHarris_demo(int, void*);
int main(int argc, char** argv)
{
CommandLineParser parser(argc, argv, "{@input | C:/Users/user/source/parallel/Test/building.jpg | input image}");
src = imread(samples::findFile(parser.get<String>("@input")));
if (src.empty())
{
cout << "Could not open or find the image!\n" << endl;
cout << "Usage: " << argv[0] << " <Input image>" << endl;
return -1;
}
cvtColor(src, src_gray, COLOR_BGR2GRAY);
namedWindow(source_window);
createTrackbar("Threshold: ", source_window, &thresh, max_thresh, cornerHarris_demo);
imshow(source_window, src);
double time_spent = 0.0;
clock_t begin = clock();
cornerHarris_demo(0, 0);
clock_t end = clock();
time_spent += (double)(end - begin) / CLOCKS_PER_SEC;
printf("time is %f",time_spent);
waitKey();
return 0;
}
void cornerHarris_demo(int, void*)
{
int blockSize = 2;
int apertureSize = 3;
double k = 0.04;
Mat dst = Mat::zeros(src.size(), CV_32FC1);
cornerHarris(src_gray, dst, blockSize, apertureSize, k);
Mat dst_norm, dst_norm_scaled;
normalize(dst, dst_norm, 0, 255, NORM_MINMAX, CV_32FC1, Mat());
convertScaleAbs(dst_norm, dst_norm_scaled);
for (int i = 0; i < dst_norm.rows; i++)
{
for (int j = 0; j < dst_norm.cols; j++)
{
if ((int)dst_norm.at<float>(i, j) > thresh)
{
circle(dst_norm_scaled, Point(j, i), 5, Scalar(0), 2, 8, 0);
}
}
}
namedWindow(corners_window);
imshow(corners_window, dst_norm_scaled);
}