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

最佳答案

重塑返回新的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中失败,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/13400239/

10-13 04:56