【发布时间】:2019-12-04 01:46:17
【问题描述】:
我想将一个 Mat 图像的所有通道添加到一个只有一个 sum-channel 的 Mat 图像中。我试过这样:
// sum up the channels of the image:
// 1 .store initial nr of rows/columns
int initialRows = frameVid1.rows;
int initialCols = frameVid1.cols;
// 2. check if matrix is continous
if (!frameVid1.isContinuous())
{
frameVid1 = frameVid1.clone();
}
// 3. reshape matrix to 3 color vectors
frameVid1 = frameVid1.reshape(3, initialRows*initialCols);
// 4. convert matrix to store bigger values than 255
frameVid1.convertTo(frameVid1, CV_32F);
// 5. sum up the three color vectors
reduce(frameVid1, frameVid1, 1, CV_REDUCE_SUM);
// 6. reshape to initial size
frameVid1 = frameVid1.reshape(1, initialRows);
// 7. convert back to CV_8UC1
frameVid1.convertTo(frameVid1, CV_8U);
但不知何故,reduce 不会像矩阵维度那样触及颜色通道。有没有别的函数可以总结一下?
还有为什么在步骤 4 中使用 CV_16U.) 不起作用? (我必须在里面放一个 CV_32F)
提前致谢!
【问题讨论】: