CV_IMPL IplImage*
cvLoadImage( const char* filename, int iscolor )
{
return (IplImage*)cv::imread_(filename, iscolor, cv::LOAD_IMAGE );
}
调用成员函数imread_(), 该函数原型如下:
enum { LOAD_CVMAT=0, LOAD_IMAGE=1, LOAD_MAT=2 };
static void*
imread_( const string& filename, int flags, int hdrtype, Mat* mat=0 )
{
IplImage* image = 0;
CvMat *matrix = 0;
Mat temp, *data = &temp;
ImageDecoder decoder = findDecoder(filename);
if( decoder.empty() )
return 0;
decoder->setSource(filename);
if( !decoder->readHeader() )
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);
}
if( !decoder->readData( *data ))
{
cvReleaseImage( &image );
cvReleaseMat( &matrix );
if( mat )
mat->release();
return 0;
}
return hdrtype == LOAD_CVMAT ? (void*)matrix :
hdrtype == LOAD_IMAGE ? (void*)image : (void*)mat;
}
此外,还有另外一个版本的cvLoadImageM():
CV_IMPL CvMat*
cvLoadImageM( const char* filename, int iscolor )
{
return (CvMat*)cv::imread_( filename, iscolor, cv::LOAD_CVMAT );
}
而imread_()还有另外一个版本的函数:
Mat imread( const string& filename, int flags )
{
Mat img;
imread_( filename, flags, LOAD_MAT, &img );
return img;
}