在OpenCV 2.4.3中重新整形矩阵失败

时间:2012-11-15 15:04:17

标签: c++ opencv matrix resize

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

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;

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

1 个答案:

答案 0 :(得分:4)

reshape返回一个新的Mat标头

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;