I'm frustrated trying to find a method that would allow me to scale a Mat object to a different size. Please, could anybody help me with this?
My project is using the Java wrapper, but I'll be happy if the answer provided is for the C++ native OpenCV library.
If by resizing you mean scaling an image use the resize() function as follows:
resize(src, dst, dst.size(), 0, 0, interpolation);
Otherwise if you just need to change the number of rows of your Mat use the Mat::reshape() function. Pay attention that the reshape return a new Mat header:
cv::Mat dst = src.reshape ( 0, newRowVal );
Finally if you want to arbitrarily reshape the Mat (changing rows and cols) you probably need to define a new Mat with the destination dimensions and copy the src Mat to it:
Mat dst(newRowVal, newColVal, src.type());
src.setTo(0);
src.copyTo(dst(Rect(Point(0, 0), src.size())));
You can use resize()
function
Create a new Mat result of new dimensions
resize(input // input image
result // result image
result.size() // new dimensions
0,
0,
INTER_CUBIC // interpolation method
);
to know more interpolation methods, you can check this doc: geometric_transformations.html#resize
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With