Using cv::merge(...) to create a 2-channel, 16-bit, signed image? [closed]
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
Never mind. It was a problem with writing to textureImage that was causing the issue.
^^ better don't return a pointer, but the Mat itself. else you're going to end up inevitably with refcount troubles