Skip to content

Commit 10dcb23

Browse files
committed
Merge branch 4.x
2 parents 1f76093 + 115e941 commit 10dcb23

File tree

6 files changed

+40
-23
lines changed

6 files changed

+40
-23
lines changed

modules/cudaarithm/src/cuda/threshold.cu

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ __global__ void otsu_sums(uint *histogram, uint *threshold_sums, unsigned long l
127127
}
128128

129129
__global__ void
130-
otsu_variance(float2 *variance, uint *histogram, uint *threshold_sums, unsigned long long *sums)
130+
otsu_variance(float2 *variance, uint *histogram, uint *threshold_sums, unsigned long long *sums, uint n_samples)
131131
{
132132
const uint n_bins = 256;
133133

@@ -137,7 +137,6 @@ otsu_variance(float2 *variance, uint *histogram, uint *threshold_sums, unsigned
137137
int bin_idx = threadIdx.x;
138138
int threshold = blockIdx.x;
139139

140-
uint n_samples = threshold_sums[0];
141140
uint n_samples_above = threshold_sums[threshold];
142141
uint n_samples_below = n_samples - n_samples_above;
143142

@@ -149,15 +148,21 @@ otsu_variance(float2 *variance, uint *histogram, uint *threshold_sums, unsigned
149148
float threshold_variance_below_f32 = 0;
150149
if (bin_idx > threshold)
151150
{
152-
float mean = (float) sum_above / n_samples_above;
153-
float sigma = bin_idx - mean;
154-
threshold_variance_above_f32 = sigma * sigma;
151+
if (n_samples_above > 0)
152+
{
153+
float mean = (float) sum_above / n_samples_above;
154+
float sigma = bin_idx - mean;
155+
threshold_variance_above_f32 = sigma * sigma;
156+
}
155157
}
156158
else
157159
{
158-
float mean = (float) sum_below / n_samples_below;
159-
float sigma = bin_idx - mean;
160-
threshold_variance_below_f32 = sigma * sigma;
160+
if (n_samples_below > 0)
161+
{
162+
float mean = (float) sum_below / n_samples_below;
163+
float sigma = bin_idx - mean;
164+
threshold_variance_below_f32 = sigma * sigma;
165+
}
161166
}
162167

163168
uint bin_count = histogram[bin_idx];
@@ -198,15 +203,14 @@ __device__ bool has_lowest_score(
198203
}
199204

200205
__global__ void
201-
otsu_score(uint *otsu_threshold, uint *threshold_sums, float2 *variance)
206+
otsu_score(uint *otsu_threshold, uint *threshold_sums, float2 *variance, uint n_samples)
202207
{
203208
const uint n_thresholds = 256;
204209

205210
__shared__ float shared_memory[n_thresholds];
206211

207212
int threshold = threadIdx.x;
208213

209-
uint n_samples = threshold_sums[0];
210214
uint n_samples_above = threshold_sums[threshold];
211215
uint n_samples_below = n_samples - n_samples_above;
212216

@@ -241,7 +245,7 @@ otsu_score(uint *otsu_threshold, uint *threshold_sums, float2 *variance)
241245
}
242246
}
243247

244-
void compute_otsu(uint *histogram, uint *otsu_threshold, Stream &stream)
248+
void compute_otsu(uint *histogram, uint *otsu_threshold, uint n_samples, Stream &stream)
245249
{
246250
const uint n_bins = 256;
247251
const uint n_thresholds = 256;
@@ -261,12 +265,12 @@ void compute_otsu(uint *histogram, uint *otsu_threshold, Stream &stream)
261265
otsu_sums<<<grid_all, block_all, 0, cuda_stream>>>(
262266
histogram, gpu_threshold_sums.ptr<uint>(), gpu_sums.ptr<unsigned long long>());
263267
otsu_variance<<<grid_all, block_all, 0, cuda_stream>>>(
264-
gpu_variances.ptr<float2>(), histogram, gpu_threshold_sums.ptr<uint>(), gpu_sums.ptr<unsigned long long>());
268+
gpu_variances.ptr<float2>(), histogram, gpu_threshold_sums.ptr<uint>(), gpu_sums.ptr<unsigned long long>(), n_samples);
265269
otsu_score<<<grid_score, block_score, 0, cuda_stream>>>(
266-
otsu_threshold, gpu_threshold_sums.ptr<uint>(), gpu_variances.ptr<float2>());
270+
otsu_threshold, gpu_threshold_sums.ptr<uint>(), gpu_variances.ptr<float2>(), n_samples);
267271
}
268272

269-
// TODO: Replace this is cv::cuda::calcHist
273+
// TODO: Replace this with cv::cuda::calcHist
270274
template <uint n_bins>
271275
__global__ void histogram_kernel(
272276
uint *histogram, const uint8_t *image, uint width,
@@ -334,7 +338,7 @@ double cv::cuda::threshold(InputArray _src, OutputArray _dst, double thresh, dou
334338
calcHist(src, gpu_histogram, stream);
335339

336340
GpuMat gpu_otsu_threshold(1, 1, CV_32SC1, pool.getAllocator());
337-
compute_otsu(gpu_histogram.ptr<uint>(), gpu_otsu_threshold.ptr<uint>(), stream);
341+
compute_otsu(gpu_histogram.ptr<uint>(), gpu_otsu_threshold.ptr<uint>(), src.rows * src.cols, stream);
338342

339343
cv::Mat mat_otsu_threshold;
340344
gpu_otsu_threshold.download(mat_otsu_threshold, stream);

modules/cudacodec/include/opencv2/cudacodec.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -395,6 +395,7 @@ class CV_EXPORTS_W NVSurfaceToColorConverter {
395395
* @param stream Stream for the asynchronous version.
396396
*/
397397
CV_WRAP virtual bool convert(InputArray yuv, OutputArray color, const SurfaceFormat surfaceFormat, const ColorFormat outputFormat, const BitDepth bitDepth = BitDepth::UNCHANGED, const bool planar = false, cuda::Stream& stream = cuda::Stream::Null()) = 0;
398+
virtual ~NVSurfaceToColorConverter() {};
398399
};
399400

400401
/** @brief Creates a NVSurfaceToColorConverter.

modules/cudafeatures2d/include/opencv2/cudafeatures2d.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,11 +118,11 @@ class CV_EXPORTS_W DescriptorMatcher : public cv::Algorithm
118118

119119
/** @brief Clears the train descriptor collection.
120120
*/
121-
CV_WRAP virtual void clear() = 0;
121+
CV_WRAP virtual void clear() CV_OVERRIDE = 0;
122122

123123
/** @brief Returns true if there are no train descriptors in the collection.
124124
*/
125-
CV_WRAP virtual bool empty() const = 0;
125+
CV_WRAP virtual bool empty() const CV_OVERRIDE = 0;
126126

127127
/** @brief Trains a descriptor matcher.
128128

modules/cudaoptflow/src/nvidiaOpticalFlow.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1020,9 +1020,6 @@ void NvidiaOpticalFlowImpl_2::calc(InputArray _frame0, InputArray _frame1, Input
10201020
GpuMat flowXYGpuMat(Size((m_width + m_hwGridSize - 1) / m_hwGridSize,
10211021
(m_height + m_hwGridSize - 1) / m_hwGridSize), CV_16SC2,
10221022
(void*)m_flowXYcuDevPtr, m_outputBufferStrideInfo.strideInfo[0].strideXInBytes);
1023-
GpuMat flowXYGpuMatUpScaled(Size((m_width + m_gridSize - 1) / m_gridSize,
1024-
(m_height + m_gridSize - 1) / m_gridSize), CV_16SC2,
1025-
(void*)m_flowXYUpScaledcuDevPtr, m_outputUpScaledBufferStrideInfo.strideInfo[0].strideXInBytes);
10261023

10271024
//check whether frame0 is Mat or GpuMat
10281025
if (_frame0.isMat())
@@ -1105,6 +1102,9 @@ void NvidiaOpticalFlowImpl_2::calc(InputArray _frame0, InputArray _frame1, Input
11051102

11061103
if (m_scaleFactor > 1)
11071104
{
1105+
GpuMat flowXYGpuMatUpScaled(Size((m_width + m_gridSize - 1) / m_gridSize,
1106+
(m_height + m_gridSize - 1) / m_gridSize), CV_16SC2,
1107+
(void*)m_flowXYUpScaledcuDevPtr, m_outputUpScaledBufferStrideInfo.strideInfo[0].strideXInBytes);
11081108
uint32_t nSrcWidth = flowXYGpuMat.size().width;
11091109
uint32_t nSrcHeight = flowXYGpuMat.size().height;
11101110
uint32_t nSrcPitch = m_outputBufferStrideInfo.strideInfo[0].strideXInBytes;

modules/cudev/include/opencv2/cudev/ptr2d/zip.hpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,12 @@ template <class PtrTuple> struct PtrTraits< ZipPtrSz<PtrTuple> > : PtrTraitsBase
179179
}}
180180

181181
#if defined(__CUDACC_VER_MAJOR__) && (__CUDACC_VER_MAJOR__ > 12 || (__CUDACC_VER_MAJOR__ == 12 && __CUDACC_VER_MINOR__ >= 4))
182+
#if (__CUDACC_VER_MAJOR__ > 13 || (__CUDACC_VER_MAJOR__ == 13 && __CUDACC_VER_MINOR__ >= 2))
183+
_CCCL_BEGIN_NAMESPACE_CUDA_STD
184+
#else
182185
_LIBCUDACXX_BEGIN_NAMESPACE_STD
186+
#endif
187+
183188

184189
template< class... Types >
185190
struct tuple_size< cv::cudev::ZipPtr<tuple<Types...> > >
@@ -198,7 +203,11 @@ template<size_t N, class... Types >
198203
struct tuple_element<N, cv::cudev::ZipPtrSz<tuple<Types...> > >
199204
: tuple_element<N, tuple<Types...> > { };
200205

206+
#if (__CUDACC_VER_MAJOR__ > 13 || (__CUDACC_VER_MAJOR__ == 13 && __CUDACC_VER_MINOR__ >= 2))
207+
_CCCL_END_NAMESPACE_CUDA_STD
208+
#else
201209
_LIBCUDACXX_END_NAMESPACE_STD
210+
#endif
202211

203212
#endif
204213
#endif

modules/ximgproc/include/opencv2/ximgproc/disparity_filter.hpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,11 +62,14 @@ class CV_EXPORTS_W DisparityFilter : public Algorithm
6262
@param left_view left view of the original stereo-pair to guide the filtering process, 8-bit single-channel
6363
or three-channel image.
6464
65-
@param filtered_disparity_map output disparity map.
65+
@param filtered_disparity_map output disparity map, single-channel CV_16S type,
66+
with disparity values scaled by 16.
67+
6668
6769
@param disparity_map_right optional argument, some implementations might also use the disparity map
68-
of the right view to compute confidence maps. If provided, it must be a single-channel CV_32F matrix,
69-
otherwise a runtime assertion will fail.
70+
of the right view to compute confidence maps. If provided, it must be a single-channel CV_16S matrix.
71+
Disparity values are expected to be scaled by 16 (one-pixel disparity corresponds to the value of 16).
72+
7073
7174
@param ROI region of the disparity map to filter. Optional, usually it should be set automatically.
7275

0 commit comments

Comments
 (0)