openCV源码阅读(1)loadimage.doc_第1页
openCV源码阅读(1)loadimage.doc_第2页
openCV源码阅读(1)loadimage.doc_第3页
openCV源码阅读(1)loadimage.doc_第4页
openCV源码阅读(1)loadimage.doc_第5页
全文预览已结束

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

/-cvLoadImage-Using the go to definition and go to declarlization in the VS, I find the cvLoadImage function in highgui module.It returns an IplImage structure calling imread_().And I also find a similar function called cvLoadImageM(). It returns a CvMat structure.CV_IMPL IplImage*cvLoadImage( const char* filename, int iscolor ) return (IplImage*)cv:imread_(filename, iscolor, cv:LOAD_IMAGE );CV_IMPL CvMat*cvLoadImageM( const char* filename, int iscolor ) return (CvMat*)cv:imread_( filename, iscolor, cv:LOAD_CVMAT );/-Tracking for the imread:enum LOAD_CVMAT=0, LOAD_IMAGE=1, LOAD_MAT=2 ;static void*imread_( const string& filename, int flags, int hdrtype, Mat* mat=0 )It declears the variables one of them (IplImage* image, CvMat *matrix) will be returned at the end of the function. IplImage* image = 0; CvMat *matrix = 0;And the temporary variables: Mat temp, *data = &temp;Find a decoder for the picture according its name. We will talk about the decoder later.There is an abstract class BaseImageDecoder which was inherited by 7 embodied class for various picture file forms, such as *.bmp, *.jpg.These embodied class has been stored in a vector called decoders.Using the findDecoder() to choose a decoder for current object. ImageDecoder decoder = findDecoder(filename);Defend the faluire from finding a decoder: if( decoder.empty() ) return 0;setSource for decoder member m_filename, and release its buffer m_buf. decoder-setSource(filename);read files head to get the informations in the picture, such as the width, height. if( !decoder-readHeader() ) return 0;store the size information into a CvSize variable. CvSize size; size.width = decoder-width(); size.height = decoder-height();the type information: 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); Charge whether you want an image or a mat:Hdtype is a parameter of the loadImage function. 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 Create an image based on the size and type we have just get, and convert the temporary arry into Mat. image = cvCreateImage( size, cvIplDepth(type), CV_MAT_CN(type) ); temp = cvarrToMat(image); Read the data of the pixels:If falure then release the storage and return 0 if( !decoder-readData( *data ) cvReleaseImage( &image ); cvReleaseMat( &matrix ); if( mat ) mat-release(); return 0; Return the result: return hdrtype = LOAD_CVMAT ? (void*)matrix : hdrtype = LOAD_IMAGE ? (void*)image : (void*)mat;To the mat read, just call the image function and give a LOAD_MAT hdtype:Mat imread( const string& filename, int flags ) Mat img; imread_( filename, flags, LOAD_MAT, &img ); return img;/-findDecoder-Those coders which will be used are stored in these two vectors.static vector decoders;static vector encoders;The findDecoder find a decoder from the above decoders for the application.ImageDecoder findDecoder( const string& filename )Find the length of the longest signature. size_t i, maxlen = 0; for( i = 0; i signatureLength(); maxlen = std:max(maxlen, len); Open the file in read and binary mode and return an ImageDecoder which is an abstract class as a NULL. FILE* f= fopen( filename.c_str(), rb ); if( !f ) return ImageDecoder();get the signature which can tell us which form the picture is and which decoder we need. string signature(maxlen, ); maxlen = fread( &signature0, 1, maxlen, f ); fclose(f); signature = signature.substr(0, maxlen);check the signature with each decoder in the decoders vector to decide the decoder. for( i = 0; i checkSignature(signature) ) return decodersi-newDecoder(); If the signature does not anyone we return a NULL. return ImageDecoder();class BaseImageDecoder;class BaseImageEncoder;typedef Ptr ImageEncoder;typedef Ptr ImageDecoder;/ base class for decoders /class BaseImageDecoderpublic: BaseImageDecoder(); virtual BaseImageDecoder() ; int width() const return m_width; ; int height() const return m_height; ; int type() const return m_type; ; virtual bool setSource( const string& filename ); virtual bool setSource( const Mat& buf ); virtual bool readHeader() = 0; virtual bool readData( Mat& img ) = 0; virtual size_t signatureLength() const; virtual bool checkSignature( const string& signature ) const; virtual Ima

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论