Get the App
SLTechnology News&Howtos  ›  Development  › 

How to use cvLoadImage () in OpenCV

Shulou Source: shulou.com Published: 2022-06-02 04:30:15 09月26日 Update

This article will explain in detail how to use cvLoadImage () in OpenCV. The editor thinks it is very practical, so I share it for you as a reference. I hope you can get something after reading this article.

CV_IMPL IplImage*cvLoadImage (const char* filename, int iscolor) {return (IplImage*) cv::imread_ (filename, iscolor, cv::LOAD_IMAGE);}

Call the member function imread_ (), which has the following prototype:

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;}

There is also another version of cvLoadImageM ():

CV_IMPL CvMat*cvLoadImageM (const char* filename, int iscolor) {return (CvMat*) cv::imread_ (filename, iscolor, cv::LOAD_CVMAT);}

Imread_ () has another version of the function:

Mat imread (const string& filename, int flags) {Mat img; imread_ (filename, flags, LOAD_MAT, & img); return img;} this article on "how to use cvLoadImage () in OpenCV" ends here. I hope the above content can be helpful to you, so that you can learn more knowledge. If you think the article is good, please share it for more people to see.

Tags: Functions articles more versions good practical content prototypes members articles knowledge references help related Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno NVidia Linux Apple MySQL OPPO Reno