@@ -55,7 +55,7 @@ namespace cv { namespace cuda { namespace device
5555{
5656 namespace gfft
5757 {
58- int findCorners_gpu (const cudaTextureObject_t &eigTex_, const int &rows, const int &cols, float threshold, PtrStepSzb mask, float2* corners, int max_count, cudaStream_t stream);
58+ int findCorners_gpu (const cudaTextureObject_t &eigTex_, const int &rows, const int &cols, float threshold, PtrStepSzb mask, float2* corners, int max_count, int * counterPtr, cudaStream_t stream);
5959 void sortCorners_gpu (const cudaTextureObject_t &eigTex_, float2* corners, int count, cudaStream_t stream);
6060 }
6161}}}
@@ -67,7 +67,7 @@ namespace
6767 public:
6868 GoodFeaturesToTrackDetector (int srcType, int maxCorners, double qualityLevel, double minDistance,
6969 int blockSize, bool useHarrisDetector, double harrisK);
70-
70+ ~GoodFeaturesToTrackDetector ();
7171 void detect (InputArray image, OutputArray corners, InputArray mask, Stream& stream);
7272
7373 private:
@@ -82,6 +82,8 @@ namespace
8282 GpuMat buf_;
8383 GpuMat eig_;
8484 GpuMat tmpCorners_;
85+
86+ int * counterPtr_;
8587 };
8688
8789 GoodFeaturesToTrackDetector::GoodFeaturesToTrackDetector (int srcType, int maxCorners, double qualityLevel, double minDistance,
@@ -93,6 +95,12 @@ namespace
9395 cornerCriteria_ = useHarrisDetector ?
9496 cuda::createHarrisCorner (srcType, blockSize, 3 , harrisK) :
9597 cuda::createMinEigenValCorner (srcType, blockSize, 3 );
98+ cudaSafeCall (cudaMalloc (&counterPtr_, sizeof (int )));
99+ }
100+
101+ GoodFeaturesToTrackDetector::~GoodFeaturesToTrackDetector ()
102+ {
103+ cudaSafeCall (cudaFree (counterPtr_));
96104 }
97105
98106 void GoodFeaturesToTrackDetector::detect (InputArray _image, OutputArray _corners, InputArray _mask, Stream& stream)
@@ -125,17 +133,19 @@ namespace
125133 PtrStepSzf eig = eig_;
126134 cv::cuda::device::createTextureObjectPitch2D<float >(&eigTex_, eig, texDesc);
127135
128- int total = findCorners_gpu (eigTex_, eig_.rows , eig_.cols , static_cast <float >(maxVal * qualityLevel_), mask, tmpCorners_.ptr <float2>(), tmpCorners_.cols , stream_);
129-
136+ int total = findCorners_gpu (eigTex_, eig_.rows , eig_.cols , static_cast <float >(maxVal * qualityLevel_), mask, tmpCorners_.ptr <float2>(), tmpCorners_.cols , counterPtr_, stream_);
130137
131138 if (total == 0 )
132139 {
133140 _corners.release ();
141+ cudaSafeCall ( cudaDestroyTextureObject (eigTex_) );
134142 return ;
135143 }
136144
137145 sortCorners_gpu (eigTex_, tmpCorners_.ptr <float2>(), total, stream_);
138146
147+ cudaSafeCall ( cudaDestroyTextureObject (eigTex_) );
148+
139149 if (minDistance_ < 1 )
140150 {
141151 tmpCorners_.colRange (0 , maxCorners_ > 0 ? std::min (maxCorners_, total) : total).copyTo (_corners, stream);
0 commit comments