我正在使用 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/