I have been building an application that uses cuda::TemplateMatching, after some testing found the application crashes due to a memory leak. I created a sample test to verify it was nothing caused by code from my application and sure enough, it still has the same issue. Could anyone verify that I’m correctly using cuda::TemplateMatching? I feel like I’m missing something but I have gone through the documentation, examples, and even the source code and can not figure out where is my error. In advance thank you!
#include "opencv2/cudaimgproc.hpp"
#include "opencv2/opencv.hpp"
using namespace cv;
int main()
{
Mat image, imageTemplate;
cuda::GpuMat gpuResult;
//Load images from file
image = imread("Sunflower.jpg",IMREAD_GRAYSCALE);
if (image.empty())
{
return 1;
}
imageTemplate = imread("SunflowerTemplate.jpg", IMREAD_GRAYSCALE);
if (imageTemplate.empty())
{
return 2;
}
//Load images to gpuMat
cuda::GpuMat gpuImage(image);
cuda::GpuMat gpuTemplate(imageTemplate);
cv::Ptr<cuda::TemplateMatching> mapMatching = cv::cuda::createTemplateMatching(CV_8U, TM_SQDIFF, Size(0, 0));
for (int a = 0; a <= 9000; a++)
{
mapMatching->match(gpuImage, gpuTemplate, gpuResult);
}
return 0;
}