Allow access to CUDA memory and stream pointers for interoperability.

pull/16513/head
Peter Würtz 5 years ago
parent 43a907ddda
commit 53c0189ed7
  1. 6
      modules/core/include/opencv2/core/cuda.hpp
  2. 6
      modules/core/include/opencv2/core/cuda.inl.hpp
  3. 9
      modules/core/src/cuda_stream.cpp
  4. 8
      modules/python/test/test_cuda.py

@ -305,6 +305,9 @@ public:
//! returns true if GpuMat data is NULL
CV_WRAP bool empty() const;
// returns pointer to cuda memory
CV_WRAP void* cudaPtr() const;
//! internal use method: updates the continuity flag
CV_WRAP void updateContinuityFlag();
@ -681,6 +684,9 @@ public:
//! returns true if stream object is not default (!= 0)
operator bool_type() const;
//! return Pointer to CUDA stream
CV_WRAP void* cudaPtr() const;
class Impl;
private:

@ -343,6 +343,12 @@ bool GpuMat::empty() const
return data == 0;
}
inline
void* GpuMat::cudaPtr() const
{
return data;
}
static inline
GpuMat createContinuous(int rows, int cols, int type)
{

@ -535,6 +535,15 @@ Stream& cv::cuda::Stream::Null()
#endif
}
void* cv::cuda::Stream::cudaPtr() const
{
#ifndef HAVE_CUDA
return nullptr;
#else
return impl_->stream;
#endif
}
cv::cuda::Stream::operator bool_type() const
{
#ifndef HAVE_CUDA

@ -26,5 +26,13 @@ class cuda_test(NewOpenCVTests):
self.assertTrue(np.allclose(cuMat.download(), npMat))
def test_cuda_interop(self):
npMat = (np.random.random((128, 128, 3)) * 255).astype(np.uint8)
cuMat = cv.cuda_GpuMat()
cuMat.upload(npMat)
self.assertTrue(cuMat.cudaPtr() != 0)
stream = cv.cuda_Stream()
self.assertTrue(stream.cudaPtr() != 0)
if __name__ == '__main__':
NewOpenCVTests.bootstrap()

Loading…
Cancel
Save