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);
besides your memcpy being horribly broken, you seem to copy only the blue channel ?
what if you just construct a mat from the triclops data , and convert it later ?
Mat tri16(HEIGHT, WIDTH, CV_16UC3, rectified_left_color_image );
Mat rgb; tri16.convertTo(CV_8UC3, rgb);
This is interesting. The blue channel thing is just because of my copy/paste haste, the original code was correct. Now i try with your solution. What do you mean with "horribly broken", anyway?
broken means: you tried to copy a 1channel row to 'interleaved' pixels.
hmm, if the color image comes in seperate channels, ignore my remark above.
your channels / merge solution seems to be the best approach possible