@@ -55,7 +55,7 @@ namespace cv { namespace cuda { namespace device
55
55
{
56
56
namespace gfft
57
57
{
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);
59
59
void sortCorners_gpu (const cudaTextureObject_t &eigTex_, float2* corners, int count, cudaStream_t stream);
60
60
}
61
61
}}}
@@ -67,7 +67,7 @@ namespace
67
67
public:
68
68
GoodFeaturesToTrackDetector (int srcType, int maxCorners, double qualityLevel, double minDistance,
69
69
int blockSize, bool useHarrisDetector, double harrisK);
70
-
70
+ ~GoodFeaturesToTrackDetector ();
71
71
void detect (InputArray image, OutputArray corners, InputArray mask, Stream& stream);
72
72
73
73
private:
@@ -82,6 +82,8 @@ namespace
82
82
GpuMat buf_;
83
83
GpuMat eig_;
84
84
GpuMat tmpCorners_;
85
+
86
+ int * counterPtr_;
85
87
};
86
88
87
89
GoodFeaturesToTrackDetector::GoodFeaturesToTrackDetector (int srcType, int maxCorners, double qualityLevel, double minDistance,
@@ -93,6 +95,12 @@ namespace
93
95
cornerCriteria_ = useHarrisDetector ?
94
96
cuda::createHarrisCorner (srcType, blockSize, 3 , harrisK) :
95
97
cuda::createMinEigenValCorner (srcType, blockSize, 3 );
98
+ cudaSafeCall (cudaMalloc (&counterPtr_, sizeof (int )));
99
+ }
100
+
101
+ GoodFeaturesToTrackDetector::~GoodFeaturesToTrackDetector ()
102
+ {
103
+ cudaSafeCall (cudaFree (counterPtr_));
96
104
}
97
105
98
106
void GoodFeaturesToTrackDetector::detect (InputArray _image, OutputArray _corners, InputArray _mask, Stream& stream)
@@ -125,17 +133,19 @@ namespace
125
133
PtrStepSzf eig = eig_;
126
134
cv::cuda::device::createTextureObjectPitch2D<float >(&eigTex_, eig, texDesc);
127
135
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_);
130
137
131
138
if (total == 0 )
132
139
{
133
140
_corners.release ();
141
+ cudaSafeCall ( cudaDestroyTextureObject (eigTex_) );
134
142
return ;
135
143
}
136
144
137
145
sortCorners_gpu (eigTex_, tmpCorners_.ptr <float2>(), total, stream_);
138
146
147
+ cudaSafeCall ( cudaDestroyTextureObject (eigTex_) );
148
+
139
149
if (minDistance_ < 1 )
140
150
{
141
151
tmpCorners_.colRange (0 , maxCorners_ > 0 ? std::min (maxCorners_, total) : total).copyTo (_corners, stream);
0 commit comments