2013-04-05 81 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); 
相关问题