Ask Your Question

Revision history [back]

Fastest conversion from TriclopsImage to cv::Mat

Hi there, I'm forced to use the Bumblebee stereo algorithm that use the TriclopsImage and TriclopsImage16 data structures defined by Triclops. I want to convert those structures into a cv::Mat in the fastest way. I've tried with memcpy but it does not work:

Mat srcright(HEIGHT, WIDTH, CV_8UC3);    
for (int i = 0; i < HEIGHT; i++) {
                    memcpy(&srcleft.ptr(i)[0], &rectified_left_color_image.blue[i * rectified_left_color_image.rowinc], WIDTH * sizeof (uchar));
                    memcpy(&srcleft.ptr(i)[1], &rectified_left_color_image.blue[i * rectified_left_color_image.rowinc], WIDTH * sizeof (uchar));
                    memcpy(&srcleft.ptr(i)[2], &rectified_left_color_image.blue[i * rectified_left_color_image.rowinc], WIDTH * sizeof (uchar));
        }

it produces kind of a shrinked image.

Fastest conversion from TriclopsImage to cv::Mat

Hi there, I'm forced to use the Bumblebee stereo algorithm that use the TriclopsImage and TriclopsImage16 data structures defined by Triclops. I want to convert those structures into a cv::Mat in the fastest way. I've tried with memcpy but it does not work:

Mat srcright(HEIGHT, WIDTH, CV_8UC3);    
for (int i = 0; i < HEIGHT; i++) {
                    memcpy(&srcleft.ptr(i)[0], &rectified_left_color_image.blue[i * rectified_left_color_image.rowinc], WIDTH * sizeof (uchar));
                    memcpy(&srcleft.ptr(i)[1], &rectified_left_color_image.blue[i * rectified_left_color_image.rowinc], WIDTH * sizeof (uchar));
                    memcpy(&srcleft.ptr(i)[2], &rectified_left_color_image.blue[i * rectified_left_color_image.rowinc], WIDTH * sizeof (uchar));
        }

it produces kind of a shrinked image.image. With the nested for and the point to point assignement with at() is ok but I would prefer a fastest way to do it.

Fastest conversion from TriclopsImage to cv::Mat

Hi there, I'm forced to use the Bumblebee stereo algorithm that use the TriclopsImage and TriclopsImage16 data structures defined by Triclops. I want to convert those structures into a cv::Mat in the fastest way. I've tried with memcpy but it does not work:

Mat srcright(HEIGHT, WIDTH, CV_8UC3);    
for (int i = 0; i < HEIGHT; i++) {
                    memcpy(&srcleft.ptr(i)[0], &rectified_left_color_image.blue[i * rectified_left_color_image.rowinc], WIDTH * sizeof (uchar));
                    memcpy(&srcleft.ptr(i)[1], &rectified_left_color_image.blue[i * rectified_left_color_image.rowinc], WIDTH * sizeof (uchar));
                    memcpy(&srcleft.ptr(i)[2], &rectified_left_color_image.blue[i * rectified_left_color_image.rowinc], WIDTH * sizeof (uchar));
        }

it produces kind of a shrinked image. With the nested for and the point to point assignement with at() is ok but I would prefer a fastest way to do it.

EDIT Now it works, here there's the code:

vector<Mat> channels;

channels.push_back(Mat(HEIGHT, WIDTH, CV_8UC1, rectified_left_color_image.blue));
channels.push_back(Mat(HEIGHT, WIDTH, CV_8UC1, rectified_left_color_image.green));
channels.push_back(Mat(HEIGHT, WIDTH, CV_8UC1, rectified_left_color_image.red));

merge(channels, srcleft);