我想將iplimage轉換爲cv :: mat(不是CvMat)。有了這個代碼的價值主題溢出...iplimage to mat 32位轉換錯誤
IplImage mhi32f = cvCreateImage(cvSize(draw_rect.width,draw_rect.height), IPL_DEPTH_32F, 1);
cv::Mat mhi32_mat(mhi32f);
mhi32_mat.convertTo(mhi32_mat,CV_32FC1);
有什麼建議嗎?
我想將iplimage轉換爲cv :: mat(不是CvMat)。有了這個代碼的價值主題溢出...iplimage to mat 32位轉換錯誤
IplImage mhi32f = cvCreateImage(cvSize(draw_rect.width,draw_rect.height), IPL_DEPTH_32F, 1);
cv::Mat mhi32_mat(mhi32f);
mhi32_mat.convertTo(mhi32_mat,CV_32FC1);
有什麼建議嗎?
爲解釋here,你就必須做到這一點
Mat imgMat(iplimg); //Construct an Mat image "img" out of an IplImage
首先,IplImage mhi32f = ...
應該是IplImage* mhi32f = ...
,但我會認爲這是您的錯誤。
你的例子很好,除了你不需要convertTo
調用。如果要將IplImage
數據複製到Mat
對象,只需將true
作爲第二個參數傳遞給構造函數,如here所示。
此處給出了一個類型是已CV_32FC1
一個例子:
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/imgproc/imgproc.hpp>
#include <iostream>
using namespace std;
using namespace cv;
int main(int argc, char** argv)
{
IplImage* mhi32f = cvCreateImage(cvSize(320, 240), IPL_DEPTH_32F, 1);
cv::Mat mhi32_mat(mhi32f);
assert(mhi32_mat.type() == CV_32FC1);
cout << "Already a CV_32FC1 matrix..." << endl;
return 0;
}
希望有所幫助。
與墊imgMat(iplimg,真);它是一個副本!謝謝! – Phil 2012-02-08 20:28:38