0

I am trying to display multiple images from RGBD sensor in one window using OpenCV in C++. I can display each channel individually in its own window, but unsuccessful In displaying all in one. I am following a solution for Show multiple (2,3,4,…) images in the same window in OpenCV (proposed by Vinvinod down the page).

The solution copies all images into a region in the output image, then scales the output image. As each image stems from different image type (color is CV_8UC4, Depth is CV_8UC1, infrared is CV_16U) this fails. How could I force / cast / converTo all images into a common format that will display the multiple channels in the one image?

I have tried:

if (img0.type() != CV_8UC4)
                {
                    cv::Mat tempImg = cv::Mat(depthFrameWidth, depthFrameHeight, CV_8UC4);
                    tempImg.convertTo(img0, CV_8UC4);
                    vecImg.push_back(tempImg);
                }
Community
  • 1
  • 1
  • 1
    the result must be a CV_8UC3 image if you want to display it with openCV, so you have to think about HOW you want to visualize. e.g. alter the first 3 channels by your depth channel, or by your infrared channel? Or converting your colors to grayscale and use depth and infrared as your second and third channel? or do you want to show them as different tiles? then just resize to subimages?!? – Micka Jan 13 '15 at 06:41
  • I want to show them as resized subimages as per the solution proposed in the question's link. That is a color subimage next to the depth subimage next to the infrared image. What that solution does is copy each image into a different region of the output image that is then resized. As I understand it, this requires all input images to be of the same type (for example CV_8UC3). My question is how to convert my depth and infrared to such type. My code above fails, and I'm not sure how to rectify. – user2598073 Jan 13 '15 at 22:06
  • first use `cv::Mat infrared3Channel;` and `cv::cvtColor(infrared,infrared3Channel, CV_GRAY2BGR)` or `aVector.push_back(infrared); aVector.push_back(infrared); aVector.push_back(infrared); cv::merge(aVector, infrared3Channel;` and afterwards maybe convert to type (if not `8U` yet): `infrared3Channel.convertTo(...)` – Micka Jan 14 '15 at 06:11
  • so to change the number of channels you can use `cv::cvtColor` or `cv::merge` and to change the type you have to use `cv::convertTo` – Micka Jan 14 '15 at 06:13
  • 1
    Great. Thanks Micka. A combination of cvtColor() followed by convertTo() did the trick. – user2598073 Jan 15 '15 at 01:58

0 Answers0