重塑OpenCV中2.4.3失败矩阵(reshaping a matrix failed in Op

2019-07-03 20:37发布

我使用的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的“重塑”很多次,但是这个新版本中,我看不到任何变化。 这是一个错误? 还是我用它不正确吗?

Answer 1:

重塑返回一个新的垫头

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;


文章来源: reshaping a matrix failed in OpenCV 2.4.3