本文整理汇总了C++中ImageDecoder::readHeader方法的典型用法代码示例。如果您正苦于以下问题:C++ ImageDecoder::readHeader方法的具体用法?C++ ImageDecoder::readHeader怎么用?C++ ImageDecoder::readHeader使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ImageDecoder
的用法示例。
在下文中一共展示了ImageDecoder::readHeader方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: findDecoder
static void*
imdecode_( const Mat& buf, int flags, int hdrtype, Mat* mat=0 )
{
CV_Assert(buf.data && buf.isContinuous());
IplImage* image = 0;
CvMat *matrix = 0;
Mat temp, *data = &temp;
string filename;
ImageDecoder decoder = findDecoder(buf);
if( decoder.empty() )
return 0;
if( !decoder->setSource(buf) )
{
filename = tempfile();
FILE* f = fopen( filename.c_str(), "wb" );
if( !f )
return 0;
size_t bufSize = buf.cols*buf.rows*buf.elemSize();
fwrite( &buf.data[0], 1, bufSize, f );
fclose(f);
decoder->setSource(filename);
}
if( !decoder->readHeader() )
{
if( !filename.empty() )
remove(filename.c_str());
return 0;
}
CvSize size;
size.width = decoder->width();
size.height = decoder->height();
int type = decoder->type();
if( flags != -1 )
{
if( (flags & CV_LOAD_IMAGE_ANYDEPTH) == 0 )
type = CV_MAKETYPE(CV_8U, CV_MAT_CN(type));
if( (flags & CV_LOAD_IMAGE_COLOR) != 0 ||
((flags & CV_LOAD_IMAGE_ANYCOLOR) != 0 && CV_MAT_CN(type) > 1) )
type = CV_MAKETYPE(CV_MAT_DEPTH(type), 3);
else
type = CV_MAKETYPE(CV_MAT_DEPTH(type), 1);
}
if( hdrtype == LOAD_CVMAT || hdrtype == LOAD_MAT )
{
if( hdrtype == LOAD_CVMAT )
{
matrix = cvCreateMat( size.height, size.width, type );
temp = cvarrToMat(matrix);
}
else
{
mat->create( size.height, size.width, type );
data = mat;
}
}
else
{
image = cvCreateImage( size, cvIplDepth(type), CV_MAT_CN(type) );
temp = cvarrToMat(image);
}
bool code = decoder->readData( *data );
if( !filename.empty() )
remove(filename.c_str());
if( !code )
{
cvReleaseImage( &image );
cvReleaseMat( &matrix );
if( mat )
mat->release();
return 0;
}
return hdrtype == LOAD_CVMAT ? (void*)matrix :
hdrtype == LOAD_IMAGE ? (void*)image : (void*)mat;
}
示例2: if
/**
* Read an image into memory and return the information
*
* @param[in] filename File to load
* @param[in] flags Flags
* @param[in] hdrtype { LOAD_CVMAT=0,
* LOAD_IMAGE=1,
* LOAD_MAT=2
* }
* @param[in] mat Reference to C++ Mat object (If LOAD_MAT)
* @param[in] scale_denom Scale value
*
*/
static void*
imread_( const String& filename, int flags, int hdrtype, Mat* mat=0 )
{
IplImage* image = 0;
CvMat *matrix = 0;
Mat temp, *data = &temp;
/// Search for the relevant decoder to handle the imagery
ImageDecoder decoder;
#ifdef HAVE_GDAL
if(flags != IMREAD_UNCHANGED && (flags & IMREAD_LOAD_GDAL) == IMREAD_LOAD_GDAL ){
decoder = GdalDecoder().newDecoder();
}else{
#endif
decoder = findDecoder( filename );
#ifdef HAVE_GDAL
}
#endif
/// if no decoder was found, return nothing.
if( !decoder ){
return 0;
}
int scale_denom = 1;
if( flags > IMREAD_LOAD_GDAL )
{
if( flags & IMREAD_REDUCED_GRAYSCALE_2 )
scale_denom = 2;
else if( flags & IMREAD_REDUCED_GRAYSCALE_4 )
scale_denom = 4;
else if( flags & IMREAD_REDUCED_GRAYSCALE_8 )
scale_denom = 8;
}
/// set the scale_denom in the driver
decoder->setScale( scale_denom );
/// set the filename in the driver
decoder->setSource( filename );
// read the header to make sure it succeeds
if( !decoder->readHeader() )
return 0;
// established the required input image size
CvSize size;
size.width = decoder->width();
size.height = decoder->height();
// grab the decoded type
int type = decoder->type();
if( (flags & IMREAD_LOAD_GDAL) != IMREAD_LOAD_GDAL && flags != IMREAD_UNCHANGED )
{
if( (flags & CV_LOAD_IMAGE_ANYDEPTH) == 0 )
type = CV_MAKETYPE(CV_8U, CV_MAT_CN(type));
if( (flags & CV_LOAD_IMAGE_COLOR) != 0 ||
((flags & CV_LOAD_IMAGE_ANYCOLOR) != 0 && CV_MAT_CN(type) > 1) )
type = CV_MAKETYPE(CV_MAT_DEPTH(type), 3);
else
type = CV_MAKETYPE(CV_MAT_DEPTH(type), 1);
}
if( hdrtype == LOAD_CVMAT || hdrtype == LOAD_MAT )
{
if( hdrtype == LOAD_CVMAT )
{
matrix = cvCreateMat( size.height, size.width, type );
temp = cvarrToMat( matrix );
}
else
{
mat->create( size.height, size.width, type );
data = mat;
}
}
else
{
image = cvCreateImage( size, cvIplDepth(type), CV_MAT_CN(type) );
temp = cvarrToMat( image );
}
// read the image data
if( !decoder->readData( *data ))
{
//.........这里部分代码省略.........
示例3: mat
/**
* Read an image into memory and return the information
*
* @param[in] filename File to load
* @param[in] flags Flags
* @param[in] mats Reference to C++ vector<Mat> object to hold the images
*
*/
static bool
imreadmulti_(const String& filename, int flags, std::vector<Mat>& mats)
{
/// Search for the relevant decoder to handle the imagery
ImageDecoder decoder;
#ifdef HAVE_GDAL
if (flags != IMREAD_UNCHANGED && (flags & IMREAD_LOAD_GDAL) == IMREAD_LOAD_GDAL){
decoder = GdalDecoder().newDecoder();
}
else{
#endif
decoder = findDecoder(filename);
#ifdef HAVE_GDAL
}
#endif
/// if no decoder was found, return nothing.
if (!decoder){
return 0;
}
/// set the filename in the driver
decoder->setSource(filename);
// read the header to make sure it succeeds
if (!decoder->readHeader())
return 0;
for (;;)
{
// grab the decoded type
int type = decoder->type();
if( (flags & IMREAD_LOAD_GDAL) != IMREAD_LOAD_GDAL && flags != IMREAD_UNCHANGED )
{
if ((flags & CV_LOAD_IMAGE_ANYDEPTH) == 0)
type = CV_MAKETYPE(CV_8U, CV_MAT_CN(type));
if ((flags & CV_LOAD_IMAGE_COLOR) != 0 ||
((flags & CV_LOAD_IMAGE_ANYCOLOR) != 0 && CV_MAT_CN(type) > 1))
type = CV_MAKETYPE(CV_MAT_DEPTH(type), 3);
else
type = CV_MAKETYPE(CV_MAT_DEPTH(type), 1);
}
// read the image data
Mat mat(decoder->height(), decoder->width(), type);
if (!decoder->readData(mat))
{
// optionally rotate the data if EXIF' orientation flag says so
if( (flags & IMREAD_IGNORE_ORIENTATION) == 0 && flags != IMREAD_UNCHANGED )
{
ApplyExifOrientation(filename, mat);
}
break;
}
mats.push_back(mat);
if (!decoder->nextPage())
{
break;
}
}
return !mats.empty();
}
示例4: findDecoder
static void*
imdecode_( const Vector<uchar>& buf, int flags, int hdrtype, Mat* mat=0 )
{
IplImage* image = 0;
CvMat *matrix = 0;
Mat temp, *data = &temp;
char fnamebuf[L_tmpnam];
const char* filename = 0;
ImageDecoder decoder = findDecoder(buf);
if( !decoder.obj )
return 0;
if( !decoder->setSource(buf) )
{
filename = tmpnam(fnamebuf);
FILE* f = fopen( filename, "wb" );
if( !f )
return 0;
fwrite( &buf[0], 1, buf.size(), f );
fclose(f);
decoder->setSource(filename);
}
if( !decoder->readHeader() )
{
if( filename )
unlink(filename);
return 0;
}
CvSize size;
size.width = decoder->width();
size.height = decoder->height();
int type = decoder->type();
if( flags != -1 )
{
if( (flags & CV_LOAD_IMAGE_ANYDEPTH) == 0 )
type = CV_MAKETYPE(CV_8U, CV_MAT_CN(type));
if( (flags & CV_LOAD_IMAGE_COLOR) != 0 ||
((flags & CV_LOAD_IMAGE_ANYCOLOR) != 0 && CV_MAT_CN(type) > 1) )
type = CV_MAKETYPE(CV_MAT_DEPTH(type), 3);
else
type = CV_MAKETYPE(CV_MAT_DEPTH(type), 1);
}
if( hdrtype == LOAD_CVMAT || hdrtype == LOAD_MAT )
{
if( hdrtype == LOAD_CVMAT )
{
matrix = cvCreateMat( size.height, size.width, type );
temp = cvarrToMat(matrix);
}
else
{
mat->create( size.height, size.width, type );
data = mat;
}
}
else
{
image = cvCreateImage( size, cvIplDepth(type), CV_MAT_CN(type) );
temp = cvarrToMat(image);
}
bool code = decoder->readData( *data );
if( filename )
unlink(filename);
if( !code )
{
cvReleaseImage( &image );
cvReleaseMat( &matrix );
if( mat )
mat->release();
return 0;
}
return hdrtype == LOAD_CVMAT ? (void*)matrix :
hdrtype == LOAD_IMAGE ? (void*)image : (void*)mat;
}