【发布时间】:2018-07-09 19:11:26
【问题描述】:
我正在尝试实现从 RGB-LMS 和 LMS-RGB 返回的颜色转换,并使用 reshape 进行乘法矩阵,以下问题的答案:Fastest way to apply color matrix to RGB image using OpenCV 3.0?
我的 ori Mat 对象来自具有 3 通道 (RGB) 的图像,我需要将它们与 1 通道 (lms) 的矩阵相乘,看来我的矩阵类型有问题。我已阅读 reshape docs 以及与此问题相关的问题,例如 Issues multiplying Mat matrices,并且我相信我已按照说明进行操作。
这是我的代码:[已更新:转换为平面图像]
void test(const Mat &forreshape, Mat &output, Mat &pic, int rows, int cols)
{
Mat lms(3, 3, CV_32FC3);
Mat rgb(3, 3, CV_32FC3);
Mat intolms(rows, cols, CV_32F);
lms = (Mat_<float>(3, 3) << 1.4671, 0.1843, 0.0030,
3.8671, 27.1554, 3.4557,
4.1194, 45.5161 , 17.884 );
/* switch the order of the matrix according to the BGR order of color on OpenCV */
Mat transpose = (3, 3, CV_32F, lms).t(); // this will do transpose from matrix lms
pic = forreshape.reshape(1, rows*cols);
Mat flatFloatImage;
pic.convertTo(flatFloatImage, CV_32F);
rgb = flatFloatImag*transpose;
output = rgb.reshape(3, cols);
}
我定义了我的 Mat 对象,并使用 convertTo 将其转换为浮点数
Mat ori = imread("ori.png", CV_LOAD_IMAGE_COLOR);
int rows = ori.rows;
int cols = ori.cols;
Mat forreshape;
ori.convertTo(forreshape, CV_32F);
Mat pic(rows, cols, CV_32FC3);
Mat output(rows, cols, CV_32FC3);
错误是:
OpenCV Error: Assertion failed (type == B.type() && (type == CV_32FC1 || type == CV_64FC1 || type == CV_32FC2 || type == CV_64FC2)) ,
所以这是类型问题。
我尝试将所有类型更改为 32FC3 或 32FC1,但似乎不起作用。有什么建议吗?
【问题讨论】:
标签: c++ opencv image-processing matrix reshape