diff --git a/modules/cudafeatures2d/src/fast.cpp b/modules/cudafeatures2d/src/fast.cpp index e2c13b06b2b..5138ec0b89c 100644 --- a/modules/cudafeatures2d/src/fast.cpp +++ b/modules/cudafeatures2d/src/fast.cpp @@ -66,6 +66,7 @@ namespace { public: FAST_Impl(int threshold, bool nonmaxSuppression, int max_npoints); + ~FAST_Impl(); virtual void detect(InputArray _image, std::vector& keypoints, InputArray _mask); virtual void detectAsync(InputArray _image, OutputArray _keypoints, InputArray _mask, Stream& stream); @@ -95,6 +96,12 @@ namespace FAST_Impl::FAST_Impl(int threshold, bool nonmaxSuppression, int max_npoints) : threshold_(threshold), nonmaxSuppression_(nonmaxSuppression), max_npoints_(max_npoints) { + cudaSafeCall( cudaMalloc(&d_counter, sizeof(unsigned int)) ); + } + + FAST_Impl::~FAST_Impl() + { + cudaSafeCall( cudaFree(d_counter) ); } void FAST_Impl::detect(InputArray _image, std::vector& keypoints, InputArray _mask) @@ -116,8 +123,6 @@ namespace { using namespace cv::cuda::device::fast; - cudaSafeCall( cudaMalloc(&d_counter, sizeof(unsigned int)) ); - const GpuMat img = _image.getGpuMat(); const GpuMat mask = _mask.getGpuMat(); @@ -165,8 +170,6 @@ namespace kpLoc.colRange(0, count).copyTo(locRow, stream); keypoints.row(1).setTo(Scalar::all(0), stream); } - - cudaSafeCall( cudaFree(d_counter) ); } void FAST_Impl::convert(InputArray _gpu_keypoints, std::vector& keypoints)