这篇文章将为大家详细讲解有关OpenCV中cvLoadImage()怎么用,小编觉得挺实用的,因此分享给大家做个参考,希望大家阅读完这篇文章后可以有所收获。
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; }
关于“OpenCV中cvLoadImage()怎么用”这篇文章就分享到这里了,希望以上内容可以对大家有一定的帮助,使各位可以学到更多知识,如果觉得文章不错,请把它分享出去让更多的人看到。
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。