本文整理汇总了C++中InputArray::isMat方法的典型用法代码示例。如果您正苦于以下问题:C++ InputArray::isMat方法的具体用法?C++ InputArray::isMat怎么用?C++ InputArray::isMat使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类InputArray
的用法示例。
在下文中一共展示了InputArray::isMat方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: if
static std::vector<Mat> extractMatVector(InputArray in)
{
if (in.isMat() || in.isUMat())
{
return std::vector<Mat>(1, in.getMat());
}
else if (in.isMatVector())
{
return *static_cast<const std::vector<Mat>*>(in.getObj());
}
else if (in.isUMatVector())
{
std::vector<Mat> vmat;
in.getMatVector(vmat);
return vmat;
}
else
{
CV_Assert(in.isMat() || in.isMatVector() || in.isUMat() || in.isUMatVector());
return std::vector<Mat>();
}
}
示例2: computeFeatures
//static
void QualityBRISQUE::computeFeatures(InputArray img, OutputArray features)
{
CV_Assert(features.needed());
CV_Assert(img.isMat());
CV_Assert(!img.getMat().empty());
auto mat = mat_convert(img.getMat());
const auto vals = ComputeBrisqueFeature(mat);
cv::Mat valmat( cv::Size( (int)vals.size(), 1 ), CV_32FC1, (void*)vals.data()); // create row vector, type depends on brisque_calc_element_type
if (features.isUMat())
valmat.copyTo(features.getUMatRef());
else if (features.isMat())
// how to move data instead?
// if calling this:
// features.getMatRef() = valmat;
// then shared data is erased when valmat is released, corrupting the data in the outputarray for the caller
valmat.copyTo(features.getMatRef());
else
CV_Error(cv::Error::StsNotImplemented, "Unsupported output type");
}
示例3: dscreate
void HDF5Impl::dswrite( InputArray Array, const String& dslabel,
const int* dims_offset, const int* dims_counts ) const
{
// only Mat support
CV_Assert( Array.isMat() );
Mat matrix = Array.getMat();
// memory array should be compact
CV_Assert( matrix.isContinuous() );
int n_dims = matrix.dims;
int channs = matrix.channels();
int *dsizes = new int[n_dims];
hsize_t *dsdims = new hsize_t[n_dims];
hsize_t *offset = new hsize_t[n_dims];
// replicate Mat dimensions
for ( int d = 0; d < n_dims; d++ )
{
offset[d] = 0;
dsizes[d] = matrix.size[d];
dsdims[d] = matrix.size[d];
}
// FixMe: If one of the groups the dataset belongs to does not exist,
// FixMe: dscreate() will fail!
// FixMe: It should be an error if the specified dataset has not been created instead of trying to create it
// pre-create dataset if needed
if ( hlexists( dslabel ) == false )
dscreate( n_dims, dsizes, matrix.type(), dslabel );
// set custom amount of data
if ( dims_counts != NULL )
{
for ( int d = 0; d < n_dims; d++ )
dsdims[d] = dims_counts[d];
}
// open dataset
hid_t dsdata = H5Dopen( m_h5_file_id, dslabel.c_str(), H5P_DEFAULT );
// create input data space
hid_t dspace = H5Screate_simple( n_dims, dsdims, NULL );
// set custom offsets
if ( dims_offset != NULL )
{
for ( int d = 0; d < n_dims; d++ )
offset[d] = dims_offset[d];
}
// create offset write window space
hid_t fspace = H5Dget_space( dsdata );
H5Sselect_hyperslab( fspace, H5S_SELECT_SET,
offset, NULL, dsdims, NULL );
// convert type
hid_t dstype = GetH5type( matrix.type() );
// expand channs
if ( matrix.channels() > 1 )
{
hsize_t adims[1] = { (hsize_t)channs };
dstype = H5Tarray_create( dstype, 1, adims );
}
// write into dataset
H5Dwrite( dsdata, dstype, dspace, fspace,
H5P_DEFAULT, matrix.data );
if ( matrix.channels() > 1 )
H5Tclose( dstype );
delete [] dsizes;
delete [] dsdims;
delete [] offset;
H5Sclose( dspace );
H5Sclose( fspace );
H5Dclose( dsdata );
}
示例4:
void HDF5Impl::dsinsert( InputArray Array, const String& dslabel,
const int* dims_offset, const int* dims_counts ) const
{
// only Mat support
CV_Assert( Array.isMat() );
// check dataset exists
if ( hlexists( dslabel ) == false )
CV_Error_(Error::StsInternal, ("Dataset '%s' does not exist.", dslabel.c_str()));
Mat matrix = Array.getMat();
// memory array should be compact
CV_Assert( matrix.isContinuous() );
int n_dims = matrix.dims;
int channs = matrix.channels();
hsize_t *dsdims = new hsize_t[n_dims];
hsize_t *offset = new hsize_t[n_dims];
// replicate Mat dimensions
for ( int d = 0; d < n_dims; d++ )
{
offset[d] = 0;
dsdims[d] = matrix.size[d];
}
// set custom amount of data
if ( dims_counts != NULL )
{
for ( int d = 0; d < n_dims; d++ )
{
CV_Assert( dims_counts[d] <= matrix.size[d] );
dsdims[d] = dims_counts[d];
}
}
// open dataset
hid_t dsdata = H5Dopen( m_h5_file_id, dslabel.c_str(), H5P_DEFAULT );
// create input data space
hid_t dspace = H5Screate_simple( n_dims, dsdims, NULL );
// set custom offsets
if ( dims_offset != NULL )
{
for ( int d = 0; d < n_dims; d++ )
offset[d] = dims_offset[d];
}
// get actual file space and dims
hid_t fspace = H5Dget_space( dsdata );
int f_dims = H5Sget_simple_extent_ndims( fspace );
hsize_t *fsdims = new hsize_t[f_dims];
H5Sget_simple_extent_dims( fspace, fsdims, NULL );
H5Sclose( fspace );
CV_Assert( f_dims == n_dims );
// compute new extents
hsize_t *nwdims = new hsize_t[n_dims];
for ( int d = 0; d < n_dims; d++ )
{
// init
nwdims[d] = 0;
// add offset
if ( dims_offset != NULL )
nwdims[d] += dims_offset[d];
// add counts or matrix size
if ( dims_counts != NULL )
nwdims[d] += dims_counts[d];
else
nwdims[d] += matrix.size[d];
// clamp back if smaller
if ( nwdims[d] < fsdims[d] )
nwdims[d] = fsdims[d];
}
// extend dataset
H5Dextend( dsdata, nwdims );
// get the extended data space
fspace = H5Dget_space( dsdata );
H5Sselect_hyperslab( fspace, H5S_SELECT_SET,
offset, NULL, dsdims, NULL );
// convert type
hid_t dstype = GetH5type( matrix.type() );
// expand channs
if ( matrix.channels() > 1 )
{
hsize_t adims[1] = { (hsize_t)channs };
dstype = H5Tarray_create( dstype, 1, adims );
}
// write into dataset
H5Dwrite( dsdata, dstype, dspace, fspace,
//.........这里部分代码省略.........