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

asked 2015-01-29 12:45:23 -0500

Nate gravatar 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

edit retag flag offensive reopen merge delete

Closed for the following reason the question is answered, right answer was accepted by Nate
close date 2015-01-29 13:59:11.609022

Comments

Never mind. It was a problem with writing to textureImage that was causing the issue.

Nate gravatar imageNate ( 2015-01-29 13:58:57 -0500 )edit

^^ better don't return a pointer, but the Mat itself. else you're going to end up inevitably with refcount troubles

berak gravatar imageberak ( 2015-01-29 15:42:43 -0500 )edit