1
0
mirror of https://github.com/opencv/opencv.git synced 2026-07-31 08:13:04 +04:00

Merge branch 4.x

This commit is contained in:
Alexander Smorkalov
2025-12-02 15:22:25 +03:00
56 changed files with 1639 additions and 876 deletions
+138
View File
@@ -113,6 +113,12 @@ Mat _InputArray::getMat_(int i) const
CV_Error(cv::Error::StsNotImplemented, "You should explicitly call download method for cuda::GpuMat object");
}
if( k == CUDA_GPU_MATND )
{
CV_Assert( i < 0 );
CV_Error(cv::Error::StsNotImplemented, "You should explicitly call download method for cuda::GpuMatND object");
}
if( k == CUDA_HOST_MEM )
{
CV_Assert( i < 0 );
@@ -360,6 +366,22 @@ void _InputArray::getGpuMatVector(std::vector<cuda::GpuMat>& gpumv) const
CV_Error(Error::StsNotImplemented, "CUDA support is not enabled in this OpenCV build (missing HAVE_CUDA)");
#endif
}
cuda::GpuMatND _InputArray::getGpuMatND() const
{
#ifdef HAVE_CUDA
_InputArray::KindFlag k = kind();
if (k == CUDA_GPU_MATND)
{
const cuda::GpuMatND* d_mat = (const cuda::GpuMatND*)obj;
return *d_mat;
}
CV_Error(cv::Error::StsNotImplemented, "getGpuMatND is available only for cuda::GpuMatND");
#else
CV_Error(Error::StsNotImplemented, "CUDA support is not enabled in this OpenCV build (missing HAVE_CUDA)");
#endif
}
ogl::Buffer _InputArray::getOGlBuffer() const
{
_InputArray::KindFlag k = kind();
@@ -382,11 +404,29 @@ _InputArray::KindFlag _InputArray::kind() const
int _InputArray::rows(int i) const
{
#ifdef HAVE_CUDA
_InputArray::KindFlag k = kind();
if (k == CUDA_GPU_MATND)
{
const cuda::GpuMatND& _gpuMatND = *(const cuda::GpuMatND*)obj;
return (_gpuMatND.dims < 1) ? 0 : _gpuMatND.size[0];
}
#endif
return size(i).height;
}
int _InputArray::cols(int i) const
{
#ifdef HAVE_CUDA
_InputArray::KindFlag k = kind();
if (k == CUDA_GPU_MATND)
{
const cuda::GpuMatND& _gpuMatND = *(const cuda::GpuMatND*)obj;
return (_gpuMatND.dims < 2) ? 0 : _gpuMatND.size[1];
}
#endif
return size(i).width;
}
@@ -655,8 +695,13 @@ bool _InputArray::sameSize(const _InputArray& arr) const
return false;
sz1 = m->size();
}
else if ( (k1 == CUDA_GPU_MATND) && (k2 == CUDA_GPU_MATND))
{
return ((const cuda::GpuMatND*)obj)->size == ((const cuda::GpuMatND*)arr.obj)->size;
}
else
sz1 = size();
if( arr.dims() > 2 )
return false;
return sz1 == arr.size();
@@ -744,6 +789,12 @@ int _InputArray::dims(int i) const
return 2;
}
if( k == CUDA_GPU_MATND )
{
CV_Assert( i < 0 );
return ((const cuda::GpuMatND*)obj)->dims;
}
if( k == CUDA_HOST_MEM )
{
CV_Assert( i < 0 );
@@ -799,6 +850,21 @@ size_t _InputArray::total(int i) const
return vv[i].total();
}
if( k == CUDA_GPU_MATND )
{
CV_Assert( i < 0 );
size_t res = 0;
const cuda::GpuMatND& _gpuMatND = *((const cuda::GpuMatND*)obj);
if (_gpuMatND.dims > 0)
{
res = 1;
for(int d = 0 ; d<_gpuMatND.dims ; ++d)
res *= _gpuMatND.size[d];
return res;
}
}
return size(i).area();
}
@@ -876,6 +942,9 @@ int _InputArray::type(int i) const
if( k == CUDA_GPU_MAT )
return ((const cuda::GpuMat*)obj)->type();
if( k == CUDA_GPU_MATND )
return ((const cuda::GpuMatND*)obj)->type();
if( k == CUDA_HOST_MEM )
return ((const cuda::HostMem*)obj)->type();
@@ -955,6 +1024,9 @@ bool _InputArray::empty() const
return vv.empty();
}
if( k == CUDA_GPU_MATND )
return ((const cuda::GpuMatND*)obj)->empty();
if( k == CUDA_HOST_MEM )
return ((const cuda::HostMem*)obj)->empty();
@@ -999,6 +1071,9 @@ bool _InputArray::isContinuous(int i) const
if( k == CUDA_GPU_MAT )
return i < 0 ? ((const cuda::GpuMat*)obj)->isContinuous() : true;
if( k == CUDA_GPU_MATND )
return i < 0 ? ((const cuda::GpuMatND*)obj)->isContinuous() : true;
CV_Error(cv::Error::StsNotImplemented, "Unknown/unsupported array type");
}
@@ -1037,6 +1112,11 @@ bool _InputArray::isSubmatrix(int i) const
return vv[i].isSubmatrix();
}
if( k == CUDA_GPU_MATND )
{
return ((const cuda::GpuMatND*)obj)->isSubmatrix();
}
CV_Error(cv::Error::StsNotImplemented, "");
}
@@ -1152,6 +1232,12 @@ size_t _InputArray::step(int i) const
CV_Assert(i >= 0 && (size_t)i < vv.size());
return vv[i].step;
}
if( k == CUDA_GPU_MATND )
{
const cuda::GpuMatND& _gpuMatND = *(const cuda::GpuMatND*)obj;
CV_Assert( i >= _gpuMatND.dims );
return _gpuMatND.step[i];
}
CV_Error(Error::StsNotImplemented, "");
}
@@ -1234,6 +1320,18 @@ void _OutputArray::create(Size _sz, int mtype, int i, bool allowTransposed, _Out
return;
#else
CV_Error(Error::StsNotImplemented, "CUDA support is not enabled in this OpenCV build (missing HAVE_CUDA)");
#endif
}
if( k == CUDA_GPU_MATND && i < 0 && !allowTransposed && fixedDepthMask == 0 )
{
CV_Assert(!fixedSize() || ((((cuda::GpuMatND*)obj)->dims == 2) && (((cuda::GpuMatND*)obj)->size[0] == _sz.height) && (((cuda::GpuMatND*)obj)->size[1] == _sz.width)));
CV_Assert(!fixedType() || ((cuda::GpuMatND*)obj)->type() == mtype);
#ifdef HAVE_CUDA
cuda::GpuMatND::SizeArray sizes = {_sz.height, _sz.width};
((cuda::GpuMatND*)obj)->create(sizes, mtype);
return;
#else
CV_Error(Error::StsNotImplemented, "CUDA support is not enabled in this OpenCV build (missing HAVE_CUDA)");
#endif
}
if( k == OPENGL_BUFFER && i < 0 && !allowTransposed && fixedDepthMask == 0 )
@@ -1288,6 +1386,18 @@ void _OutputArray::create(int _rows, int _cols, int mtype, int i, bool allowTran
return;
#else
CV_Error(Error::StsNotImplemented, "CUDA support is not enabled in this OpenCV build (missing HAVE_CUDA)");
#endif
}
if( k == CUDA_GPU_MATND && i < 0 && !allowTransposed && fixedDepthMask == 0 )
{
CV_Assert(!fixedSize() || ((((cuda::GpuMatND*)obj)->dims == 2) && (((cuda::GpuMatND*)obj)->size[0] == _rows) && (((cuda::GpuMatND*)obj)->size[1] == _cols)));
CV_Assert(!fixedType() || ((cuda::GpuMatND*)obj)->type() == mtype);
#ifdef HAVE_CUDA
cuda::GpuMatND::SizeArray sizes = {_rows, _cols};
((cuda::GpuMatND*)obj)->create(sizes, mtype);
return;
#else
CV_Error(Error::StsNotImplemented, "CUDA support is not enabled in this OpenCV build (missing HAVE_CUDA)");
#endif
}
if( k == OPENGL_BUFFER && i < 0 && !allowTransposed && fixedDepthMask == 0 )
@@ -1705,6 +1815,18 @@ void _OutputArray::create(int d, const int* sizes, int mtype, int i,
return;
}
if( k == CUDA_GPU_MATND && d > 0 && i < 0 && !allowTransposed && fixedDepthMask == 0 )
{
#ifdef HAVE_CUDA
cuda::GpuMatND::SizeArray sizeArray = cuda::GpuMatND::SizeArray(sizes, sizes+d);
((cuda::GpuMatND*)obj)->create(sizeArray, mtype);
return;
#else
CV_Error(Error::StsNotImplemented, "CUDA support is not enabled in this OpenCV build (missing HAVE_CUDA)");
#endif
}
CV_Error(Error::StsNotImplemented, "Unknown/unsupported array type");
}
@@ -1840,6 +1962,16 @@ void _OutputArray::release() const
#endif
}
if( k == CUDA_GPU_MATND )
{
#ifdef HAVE_CUDA
((cuda::GpuMatND*)obj)->release();
return;
#else
CV_Error(Error::StsNotImplemented, "CUDA support is not enabled in this OpenCV build (missing HAVE_CUDA)");
#endif
}
if( k == CUDA_HOST_MEM )
{
#ifdef HAVE_CUDA
@@ -1971,6 +2103,12 @@ std::vector<cuda::GpuMat>& _OutputArray::getGpuMatVecRef() const
CV_Assert(k == STD_VECTOR_CUDA_GPU_MAT);
return *(std::vector<cuda::GpuMat>*)obj;
}
cuda::GpuMatND& _OutputArray::getGpuMatNDRef() const
{
_InputArray::KindFlag k = kind();
CV_Assert( k == CUDA_GPU_MATND );
return *(cuda::GpuMatND*)obj;
}
ogl::Buffer& _OutputArray::getOGlBufferRef() const
{
+16 -5
View File
@@ -1164,20 +1164,31 @@ String tempfile( const char* suffix )
fname = String(aname);
}
#else
// Use GUID-based naming to avoid race condition with GetTempFileNameA
// See issue #19648
char temp_dir2[MAX_PATH] = { 0 };
char temp_file[MAX_PATH] = { 0 };
if (temp_dir.empty())
{
::GetTempPathA(sizeof(temp_dir2), temp_dir2);
temp_dir = std::string(temp_dir2);
}
if(0 == ::GetTempFileNameA(temp_dir.c_str(), "ocv", 0, temp_file))
GUID g;
HRESULT hr = CoCreateGuid(&g);
if (FAILED(hr))
return String();
char guidStr[40];
const char* mask = "%08x_%04x_%04x_%02x%02x_%02x%02x%02x%02x%02x%02x";
snprintf(guidStr, sizeof(guidStr), mask,
g.Data1, g.Data2, g.Data3, (unsigned int)g.Data4[0], (unsigned int)g.Data4[1],
(unsigned int)g.Data4[2], (unsigned int)g.Data4[3], (unsigned int)g.Data4[4],
(unsigned int)g.Data4[5], (unsigned int)g.Data4[6], (unsigned int)g.Data4[7]);
DeleteFileA(temp_file);
fname = temp_file;
fname = temp_dir;
if (!fname.empty() && fname[fname.size()-1] != '\\' && fname[fname.size()-1] != '/')
fname += "\\";
fname = fname + "ocv" + guidStr;
#endif
# else
# ifdef __ANDROID__