2012-01-09 128 views
2

我有一個位圖陣列已經包含的圖像的圖像對象,然後我需要構造一個OPENCV對象來操作它。我看到的唯一構造函數是:OpenCV的,創建從位圖

cv::imread(fileName...); 

有什麼其他方法可以從現有結構創建圖像?

OpenCV 2.3

回答

3

得到的指針數據,圖像通道,和尺寸,並使用了許多,許多建設者在那裏的一個:

Mat image(width, height, CV_8UC3, ucharDataPtr); 

這裏,CV_8UC3是OpenCV的方式來索引數據類型。 8表示8位,U表示無符號 - 所以它是一個無符號字符 - 默認圖像格式。 C3表示3個通道。如果你的位圖有一個alpha通道,你會寫CV_8UC4。如果它是灰色的,則CV_8UC1,依此類推。

重要:

此構造方法不復制數據。因此,請確保在使用Mat時保持原始位圖對象處於活動狀態。如果你想複製它,那麼在構造函數中有一個「withCopy參數」。只需檢查文檔。

+0

墊圖像(寬度,高度,CV_8UC3,ucharDataPtr).clone(),如果你要複製的數據; – 2013-02-06 15:11:16

0

只是指向陣列上的IplImage或cvMat。一個的與CvMat結構如下:

CvMat      // 2D array 
    |-- int type;   // elements type (uchar,short,int,float,double) and flags 
    |-- int step;   // full row length in bytes 
    |-- int rows, cols; // dimensions 
    |-- int height, width; // alternative dimensions reference 
    |-- union data; 
     |-- uchar* ptr;  // data pointer for an unsigned char matrix 
     |-- short* s;  // data pointer for a short matrix 
     |-- int* i;  // data pointer for an integer matrix 
     |-- float* fl;  // data pointer for a float matrix 
     |-- double* db;  // data pointer for a double matrix 

(http://www.cs.iit.edu/~agam/cs512/lect-notes/opencv-intro/opencv-intro.html)