2013-04-05 108 views
1

我想使用OpenCV對來自Bumblebee2相機的矯正圖像進行一些處理。我使用FlyCapture2和Triclops從傳感器獲取圖像並糾正它們。我想將TriclopsColorImage轉換成cv :: Mat以與OpenCV一起使用。將圖像從Triclops轉換爲opencv RGB圖像。

從TriclopsColorImage對象,我可以得到以下幾點:

int nrows; // The number of rows in the image 
int ncols; //The number of columns in the image 
int rowinc; //The row increment of the image 
unsigned char * blue; //pixel data for the blue band of the image 
unsigned char * red; //pixel data for the red band of the image 
unsigned char * green; //pixel data for the green band of the image 

我不知道如何將這種信息轉換爲CV ::墊的圖像,這樣我可以在它的工作。有人可以請指點我正確的方向嗎?

回答

2

我還沒有測試過這個,我不知道你使用的是什麼版本的OpenCV,但是像下面這樣的東西應該指向正確的方向。所以,假設你的變量名稱來自於這個問題:

cv::Mat R(nrows, ncols, CV_8UC1, red, rowinc); 
cv::Mat G(nrows, ncols, CV_8UC1, green, rowinc); 
cv::Mat B(nrows, ncols, CV_8UC1, blue, rowinc); 

std::vector<cv::Mat> array_to_merge; 

array_to_merge.push_back(B); 
array_to_merge.push_back(G); 
array_to_merge.push_back(R); 

cv::Mat colour; 

cv::merge(array_to_merge, colour); 
+0

謝謝!奇蹟般有效。我剛剛提出了一個備用解決方案,我將其作爲替代方案發布,以備有人想知道。 – Jompa234 2013-04-05 14:20:05

0

替代解決方案我想了一段時間。

// Create a cv::Mat to hold the rectified color image. 
    cv::Mat cvColorImage(colorImage.nrows, colorImage.ncols,CV_8UC3); 

    unsigned char* bp = colorImage.blue; 
    unsigned char* rp = colorImage.red; 
    unsigned char* gp = colorImage.green; 

    for(int row = 0; row< colorImage.nrows; row++){ 

     for(int col =0; col< colorImage.rowinc; col++){ 

      //printf("%u %u %u ",*bp,*rp,*gp); 
      bp++; 
      rp++; 
      gp++; 

      cvColorImage.at<cv::Vec3b>(row,col)[0] = *bp; 

      cvColorImage.at<cv::Vec3b>(row,col)[1] = *gp; 

      cvColorImage.at<cv::Vec3b>(row,col)[2] = *rp; 

     } 
     cout << endl; 
    } 

    imshow("colorimage", cvColorImage); 
    waitKey(300);