Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Using cv::merge(...) to create a 2-channel, 16-bit, signed image?

Greetings all,

I'm trying to use cv::merge(...) to merge two CV_16S images into one CV_16SC2 image. Unfortunately, when I try to run the code, I get an unhanlded exception on the merge call. If anyone has an idea of how to fix this, I would greatly appreciate it.

Here is my code:

const cv::Mat* MyClass::GetTextureImage( const cv::Mat &frame) {

   // Convert to grayscale.
   cv::Mat grayscaleFrame;
   cv::cvtColor( frame, grayscaleFrame, CV_BGR2GRAY);

   // Get X- and Y- Sobel images.
   cv::Mat sobelX, sobelY;
   cv::Sobel( grayscaleFrame, sobelX, CV_16S, 1, 0, 3, 1.0, 0.0, cv::BORDER_REPLICATE);
   cv::Sobel( grayscaleFrame, sobelY, CV_16S, 0, 1, 3, 1.0, 0.0, cv::BORDER_REPLICATE);

   // Agglomerate Sobel images into a single multi-channel image.
   std::vector< cv::Mat> channels;
   channels.push_back( sobelX);
   channels.push_back( sobelY);
   cv::merge( channels, textureImage);

   return &textureImage;
}

The exception occurs when the cv::merge( ...) call is made. If anyone has any ideas on how to get this to work, I'd love to hear them.

Thanks!

-Nate