Commit 12dc52c2 authored by Andrey Morozov's avatar Andrey Morozov

implemented asynchronous call for StereoBM()

parent dc0f3139
...@@ -349,7 +349,7 @@ namespace cv ...@@ -349,7 +349,7 @@ namespace cv
void operator() ( const GpuMat& left, const GpuMat& right, GpuMat& disparity); void operator() ( const GpuMat& left, const GpuMat& right, GpuMat& disparity);
//! Acync version //! Acync version
void operator() ( const GpuMat& left, const GpuMat& right, GpuMat& disparity, const CudaStream& stream); void operator() ( const GpuMat& left, const GpuMat& right, GpuMat& disparity, const CudaStream & stream);
//! Some heuristics that tries to estmate //! Some heuristics that tries to estmate
// if current GPU will be faster then CPU in this algorithm. // if current GPU will be faster then CPU in this algorithm.
......
This diff is collapsed.
...@@ -46,25 +46,26 @@ ...@@ -46,25 +46,26 @@
#pragma warning( disable: 4251 4710 4711 4514 4996 ) #pragma warning( disable: 4251 4710 4711 4514 4996 )
#endif #endif
#ifdef HAVE_CONFIG_H #ifdef HAVE_CONFIG_H
#include <cvconfig.h> #include <cvconfig.h>
#endif #endif
#include <iostream> #include <iostream>
#include <limits> #include <limits>
#include "opencv2/gpu/gpu.hpp" #include "opencv2/gpu/gpu.hpp"
#include "opencv2/gpu/stream_accessor.hpp"
#if defined(HAVE_CUDA) #if defined(HAVE_CUDA)
#include "cuda_shared.hpp" #include "cuda_shared.hpp"
#include "cuda_runtime_api.h" #include "cuda_runtime_api.h"
#else /* defined(HAVE_CUDA) */ #else /* defined(HAVE_CUDA) */
static inline void throw_nogpu() { CV_Error(CV_GpuNotFound, "The library is compilled with no GPU support"); } static inline void throw_nogpu() { CV_Error(CV_GpuNotFound, "The library is compilled with no GPU support"); }
#endif /* defined(HAVE_CUDA) */ #endif /* defined(HAVE_CUDA) */
#endif /* __OPENCV_PRECOMP_H__ */ #endif /* __OPENCV_PRECOMP_H__ */
...@@ -56,25 +56,26 @@ void cv::gpu::StereoBM_GPU::operator() ( const GpuMat&, const GpuMat&, GpuMat&, ...@@ -56,25 +56,26 @@ void cv::gpu::StereoBM_GPU::operator() ( const GpuMat&, const GpuMat&, GpuMat&,
#else /* !defined (HAVE_CUDA) */ #else /* !defined (HAVE_CUDA) */
namespace cv { namespace gpu namespace cv { namespace gpu
{ {
namespace impl namespace impl
{ {
extern "C" void stereoBM_GPU(const DevMem2D& left, const DevMem2D& right, const DevMem2D& disp, int ndisp, int winsz, const DevMem2D_<uint>& minSSD_buf); //extern "C" void stereoBM_GPU(const DevMem2D& left, const DevMem2D& right, const DevMem2D& disp, int ndisp, int winsz, const DevMem2D_<uint>& minSSD_buf);
extern "C" void stereoBM_GPU(const DevMem2D& left, const DevMem2D& right, const DevMem2D& disp, int ndisp, int winsz, const DevMem2D_<uint>& minSSD_buf, const cudaStream_t & stream);
extern "C" void prefilter_xsobel(const DevMem2D& input, const DevMem2D& output, int prefilterCap = 31); extern "C" void prefilter_xsobel(const DevMem2D& input, const DevMem2D& output, int prefilterCap = 31);
extern "C" void postfilter_textureness(const DevMem2D& input, int winsz, float avergeTexThreshold, const DevMem2D& disp); extern "C" void postfilter_textureness(const DevMem2D& input, int winsz, float avergeTexThreshold, const DevMem2D& disp);
} }
}} }}
const float defaultAvgTexThreshold = 3; const float defaultAvgTexThreshold = 3;
cv::gpu::StereoBM_GPU::StereoBM_GPU() cv::gpu::StereoBM_GPU::StereoBM_GPU()
: preset(BASIC_PRESET), ndisp(DEFAULT_NDISP), winSize(DEFAULT_WINSZ), avergeTexThreshold(defaultAvgTexThreshold) {} : preset(BASIC_PRESET), ndisp(DEFAULT_NDISP), winSize(DEFAULT_WINSZ), avergeTexThreshold(defaultAvgTexThreshold) {}
cv::gpu::StereoBM_GPU::StereoBM_GPU(int preset_, int ndisparities_, int winSize_) cv::gpu::StereoBM_GPU::StereoBM_GPU(int preset_, int ndisparities_, int winSize_)
: preset(preset_), ndisp(ndisparities_), winSize(winSize_), avergeTexThreshold(defaultAvgTexThreshold) : preset(preset_), ndisp(ndisparities_), winSize(winSize_), avergeTexThreshold(defaultAvgTexThreshold)
{ {
const int max_supported_ndisp = 1 << (sizeof(unsigned char) * 8); const int max_supported_ndisp = 1 << (sizeof(unsigned char) * 8);
CV_Assert(0 < ndisp && ndisp <= max_supported_ndisp); CV_Assert(0 < ndisp && ndisp <= max_supported_ndisp);
CV_Assert(ndisp % 8 == 0); CV_Assert(ndisp % 8 == 0);
CV_Assert(winSize % 2 == 1); CV_Assert(winSize % 2 == 1);
...@@ -92,12 +93,12 @@ bool cv::gpu::StereoBM_GPU::checkIfGpuCallReasonable() ...@@ -92,12 +93,12 @@ bool cv::gpu::StereoBM_GPU::checkIfGpuCallReasonable()
int numSM = getNumberOfSMs(device); int numSM = getNumberOfSMs(device);
if (major > 1 || numSM > 16) if (major > 1 || numSM > 16)
return true; return true;
return false; return false;
} }
void cv::gpu::StereoBM_GPU::operator() ( const GpuMat& left, const GpuMat& right, GpuMat& disparity) void stereo_gpu_operator ( GpuMat& minSSD, GpuMat& leBuf, GpuMat& riBuf, int preset, int ndisp, int winSize, float avergeTexThreshold, const GpuMat& left, const GpuMat& right, GpuMat& disparity, const cudaStream_t & stream)
{ {
CV_DbgAssert(left.rows == right.rows && left.cols == right.cols); CV_DbgAssert(left.rows == right.rows && left.cols == right.cols);
CV_DbgAssert(left.type() == CV_8UC1); CV_DbgAssert(left.type() == CV_8UC1);
...@@ -109,26 +110,33 @@ void cv::gpu::StereoBM_GPU::operator() ( const GpuMat& left, const GpuMat& right ...@@ -109,26 +110,33 @@ void cv::gpu::StereoBM_GPU::operator() ( const GpuMat& left, const GpuMat& right
GpuMat le_for_bm = left; GpuMat le_for_bm = left;
GpuMat ri_for_bm = right; GpuMat ri_for_bm = right;
if (preset == PREFILTER_XSOBEL) if (preset == StereoBM_GPU::PREFILTER_XSOBEL)
{ {
leBuf.create( left.size(), left.type()); leBuf.create( left.size(), left.type());
riBuf.create(right.size(), right.type()); riBuf.create(right.size(), right.type());
impl::prefilter_xsobel( left, leBuf); impl::prefilter_xsobel( left, leBuf);
impl::prefilter_xsobel(right, riBuf); impl::prefilter_xsobel(right, riBuf);
le_for_bm = leBuf; le_for_bm = leBuf;
ri_for_bm = riBuf; ri_for_bm = riBuf;
} }
impl::stereoBM_GPU(le_for_bm, ri_for_bm, disparity, ndisp, winSize, minSSD);
impl::stereoBM_GPU(le_for_bm, ri_for_bm, disparity, ndisp, winSize, minSSD, stream);
if (avergeTexThreshold) if (avergeTexThreshold)
impl::postfilter_textureness(le_for_bm, winSize, avergeTexThreshold, disparity); impl::postfilter_textureness(le_for_bm, winSize, avergeTexThreshold, disparity);
} }
void cv::gpu::StereoBM_GPU::operator() ( const GpuMat& left, const GpuMat& right, GpuMat& disparity)
{
::stereo_gpu_operator(minSSD, leBuf, riBuf, preset, ndisp, winSize, avergeTexThreshold, left, right, disparity, 0);
}
void cv::gpu::StereoBM_GPU::operator() ( const GpuMat& left, const GpuMat& right, GpuMat& disparity, const CudaStream& stream) void cv::gpu::StereoBM_GPU::operator() ( const GpuMat& left, const GpuMat& right, GpuMat& disparity, const CudaStream& stream)
{ {
CV_Assert(!"Not implemented"); ::stereo_gpu_operator(minSSD, leBuf, riBuf, preset, ndisp, winSize, avergeTexThreshold, left, right, disparity, StreamAccessor::getStream(stream));
} }
#endif /* !defined (HAVE_CUDA) */ #endif /* !defined (HAVE_CUDA) */
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment