Exemplo n.º 1
0
	UMatData* allocate(int dims0, const int* sizes, int type, void* data,
			size_t* step, int flags, UMatUsageFlags usageFlags) const {
		if (data != 0) {
			CV_Error(Error::StsAssert, "The data should normally be NULL!");
			// probably this is safe to do in such extreme case
			return stdAllocator->allocate(dims0, sizes, type, data, step, flags,
					usageFlags);
		}
		PyEnsureGIL gil;

		int depth = CV_MAT_DEPTH(type);
		int cn = CV_MAT_CN(type);
		const int f = (int) (sizeof(size_t) / 8);
		int typenum =
				depth == CV_8U ? NPY_UBYTE :
				depth == CV_8S ? NPY_BYTE :
				depth == CV_16U ? NPY_USHORT :
				depth == CV_16S ? NPY_SHORT :
				depth == CV_32S ? NPY_INT :
				depth == CV_32F ? NPY_FLOAT :
				depth == CV_64F ?
						NPY_DOUBLE : f * NPY_ULONGLONG + (f ^ 1) * NPY_UINT;
		int i, dims = dims0;
		cv::AutoBuffer<npy_intp> _sizes(dims + 1);
		for (i = 0; i < dims; i++)
			_sizes[i] = sizes[i];
		if (cn > 1)
			_sizes[dims++] = cn;
		PyObject* o = PyArray_SimpleNew(dims, _sizes, typenum);
		if (!o)
			CV_Error_(Error::StsError,
					("The numpy array of typenum=%d, ndims=%d can not be created", typenum, dims));
		return allocate(o, dims0, sizes, type, step);
	}
		//! Function called to init the container. Sets the sizes, and the memory storage order
		void _init() {

			_w = coord_type();
			_w(0) = value_dimensions;
			for (uint64 i = 1; i < coord_dimensions; i++) {
				_w(i) = _w(i-1)*_sizes(i-1);
			}

			uint64 N = _sizes.prod();

			if (_owner)
				_data = new value_data_type[N*value_dimensions]();
		}
Exemplo n.º 3
0
 //! @brief Return the depth size.
 __host__ __device__
 inline int depth() const
 {
   return _sizes(2);
 }
Exemplo n.º 4
0
 //! @brief Return the number of columns.
 __host__ __device__
 inline int height() const
 {
   return _sizes(1);
 }
Exemplo n.º 5
0
 //! @brief Return the number of rows.
 __host__ __device__
 inline int width() const
 {
   return _sizes(0);
 }
Exemplo n.º 6
0
 //! @brief Return the i-th sizes of the multi-array.
 __host__ __device__
 inline int size(int i) const
 {
   return _sizes(i);
 }