资源描述:
《openCV源码阅读(1)loadimage》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、//----cvLoadImage--------------------------------------------------------Usingthe‘gotodefinition’and‘gotodeclarlization’intheVS,IfindthecvLoadImagefunctioninhighguimodule.ItreturnsanIplImagestructurecallingimread_().AndIalsofindasimilarfunctioncalledcvLoadImageM().ItreturnsaCvM
2、atstructure.CV_IMPLIplImage*cvLoadImage(constchar*filename,intiscolor){return(IplImage*)cv::imread_(filename,iscolor,cv::LOAD_IMAGE);}CV_IMPLCvMat*cvLoadImageM(constchar*filename,intiscolor){return(CvMat*)cv::imread_(filename,iscolor,cv::LOAD_CVMAT);}//-------------------------
3、--------------------------------------------Trackingfortheimread:enum{LOAD_CVMAT=0,LOAD_IMAGE=1,LOAD_MAT=2};staticvoid*imread_(conststring&filename,intflags,inthdrtype,Mat*mat=0){Itdeclearsthevariablesoneofthem(IplImage*image,CvMat*matrix)willbereturnedattheendofthefunction.Ipl
4、Image*image=0;CvMat*matrix=0;Andthetemporaryvariables:Mattemp,*data=&temp;Findadecoderforthepictureaccordingitsname.Wewilltalkaboutthedecoderlater.ThereisanabstractclassBaseImageDecoderwhichwasinheritedby7embodiedclassforvariouspicturefileforms,suchas*.bmp,*.jpg.Theseembodiedcl
5、asshasbeenstoredinavectorcalleddecoders.UsingthefindDecoder()tochooseadecoderforcurrentobject.ImageDecoderdecoder=findDecoder(filename);Defendthefaluirefromfindingadecoder:if(decoder.empty())return0;setSourcefordecoder’memberm_filename,andreleaseitsbufferm_buf.decoder->setSourc
6、e(filename);readfile’sheadtogettheinformationsinthepicture,suchasthewidth,height.if(!decoder->readHeader())return0;storethesizeinformationintoaCvSizevariable.CvSizesize;size.width=decoder->width();size.height=decoder->height();thetypeinformation:inttype=decoder->type();if(flags
7、!=-1){if((flags&CV_LOAD_IMAGE_ANYDEPTH)==0)type=CV_MAKETYPE(CV_8U,CV_MAT_CN(type));if((flags&CV_LOAD_IMAGE_COLOR)!=0
8、
9、((flags&CV_LOAD_IMAGE_ANYCOLOR)!=0&&CV_MAT_CN(type)>1))type=CV_MAKETYPE(CV_MAT_DEPTH(type),3);elsetype=CV_MAKETYPE(CV_MAT_DEPTH(type),1);}Chargewhetheryouwantan
10、imageoramat:HdtypeisaparameteroftheloadImagefunction.i