@@ -66,6 +66,7 @@ namespace
6666 {
6767 public:
6868 FAST_Impl (int threshold, bool nonmaxSuppression, int max_npoints);
69+ ~FAST_Impl ();
6970
7071 virtual void detect (InputArray _image, std::vector<KeyPoint>& keypoints, InputArray _mask);
7172 virtual void detectAsync (InputArray _image, OutputArray _keypoints, InputArray _mask, Stream& stream);
@@ -95,6 +96,12 @@ namespace
9596 FAST_Impl::FAST_Impl (int threshold, bool nonmaxSuppression, int max_npoints) :
9697 threshold_ (threshold), nonmaxSuppression_(nonmaxSuppression), max_npoints_(max_npoints)
9798 {
99+ cudaSafeCall ( cudaMalloc (&d_counter, sizeof (unsigned int )) );
100+ }
101+
102+ FAST_Impl::~FAST_Impl ()
103+ {
104+ cudaSafeCall ( cudaFree (d_counter) );
98105 }
99106
100107 void FAST_Impl::detect (InputArray _image, std::vector<KeyPoint>& keypoints, InputArray _mask)
@@ -116,8 +123,6 @@ namespace
116123 {
117124 using namespace cv ::cuda::device::fast;
118125
119- cudaSafeCall ( cudaMalloc (&d_counter, sizeof (unsigned int )) );
120-
121126 const GpuMat img = _image.getGpuMat ();
122127 const GpuMat mask = _mask.getGpuMat ();
123128
@@ -165,8 +170,6 @@ namespace
165170 kpLoc.colRange (0 , count).copyTo (locRow, stream);
166171 keypoints.row (1 ).setTo (Scalar::all (0 ), stream);
167172 }
168-
169- cudaSafeCall ( cudaFree (d_counter) );
170173 }
171174
172175 void FAST_Impl::convert (InputArray _gpu_keypoints, std::vector<KeyPoint>& keypoints)
0 commit comments