c++ - 在 OpenCV 2.4.3 中 reshape 矩阵失败

标签 c++ opencv matrix resize

我正在使用 OpenCV 2.4.3 创建和 reshape 这样的矩阵:

cv::Mat testMat = cv::Mat::zeros ( 500, 200, CV_8UC3 );
std::cout << "size of testMat: " << testMat.rows << " x " << testMat.cols << std::endl;

testMat.reshape ( 0, 1 );
std::cout << " size of reshaped testMat: " << testMat.rows << " x " << testMat.cols << std::endl;

然后从输出中,我看到 reshape 后的 testMat 没有变化。我在旧版本的 OpenCV 中多次使用“reshape”,但在这个新版本中,我看不到任何变化。这是一个错误吗?或者我在这里使用不正确?

最佳答案

reshape 返回一个新的 Mat header

cv::Mat testMat = cv::Mat::zeros ( 500, 200, CV_8UC3 );
std::cout << "size of testMat: " << testMat.rows << " x " << testMat.cols << std::endl;

cv::Mat result = testMat.reshape ( 0, 1 );
std::cout << " size of original testMat: " << testMat.rows << " x " << testMat.cols << std::endl;
std::cout << " size of reshaped testMat: " << result.rows << " x " << result.cols << std::endl;

关于c++ - 在 OpenCV 2.4.3 中 reshape 矩阵失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13400239/

相关文章:

c++ - 推力转换抛出错误 : "bulk_kernel_by_value: an illegal memory access was encountered"

c++ - 将参数传递到 C++ 共享库

c++ - 绘制图像后颜色消失

android - NDK - GNUSTL 从 NDK(修订版 r18)中删除后出现的问题

c++ - 试图找到 Mat 图像的大小

c++ - 如何访问/修改 OpenCV 中的矩阵元素?为什么 at() 被模板化?

c++ - 我可以在 Xcode 的消息/警告中打印预处理器值吗?

python - OpenCV:FFMPEG:未找到标记 0xffffffff/'����'(格式 'mp4/MP4 (MPEG-4 Part 14)')'

c++ - OpenCV 到 FlyCapture2 图像

c - 我的矩阵在可视化和分配上不一样?