天天看點

OpenCV4讀取記憶體圖檔到Mat方法一(适用于OpenCV3):

方法一(适用于OpenCV3):

#include <opencv2/opencv.hpp>
#include <opencv2/imgproc/imgproc_c.h>
#include <iostream>

char * lpFileBuf = GetFileBuf("girl.bmp");

CvMat mCvmat = cvMat(512*3, 768*3, CV_8UC1, lpFileBuf);
IplImage*IpImg = cvDecodeImage(&mCvmat, 1);

//opencv 2.0 CvMat->Mat資料轉換 //Mat b =  Mat(mat,true);
//opencv3.0 CvMat->Mat資料轉換 //Mat image = cvarrToMat(pp);

Mat image = cvarrToMat(IpImg).clone();
cvReleaseImage(&IpImg);

imshow("123", image);
           

方法二(适用于OpenCV4):

#include <opencv2/opencv.hpp>
cv::_InputArray pic_arr(bmpFileBuf, nBmpBufSize);
cv::Mat src_mat = cv::imdecode(pic_arr, cv::IMREAD_UNCHANGED);
cv::imshow("123", src_mat);
           

繼續閱讀