E_learner
E_learner

Reputation: 3582

reshaping a matrix failed in OpenCV 2.4.3

I am using OpenCV 2.4.3 to create and reshape a matrix like this:

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;

Then from the output, I see there is no change for the reshaped testMat. I used "reshape" many times in older version of OpenCV, but with this new version, I couldn't see any changes. Is this a bug? Or am I using it incorrectly here?

Upvotes: 1

Views: 4326

Answers (1)

Hammer
Hammer

Reputation: 10329

reshape returns a new 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;

Upvotes: 4

Related Questions