How to scale a matrix in OpenCV

I'm upset trying to find a method that will allow me to scale the Mat object to a different size. Please can someone help me with this?

My project uses the Java shell, but I will be glad if an answer is provided for its own OpenCV C ++ library.

+4
source share
2 answers

If by resizing you mean scaling an image, use resize () as follows:

resize(src, dst, dst.size(), 0, 0, interpolation); 

Otherwise, if you just need to change the number of lines of your mat, use the Mat :: reshape () function. Note that reshape returns a new Mat header:

 cv::Mat dst = src.reshape ( 0, newRowVal ); 

Finally, if you want to arbitrarily change the shape of the Mat (changing rows and columns), you probably need to define a new Mat with destination sizes and copy src Mat to it:

 Mat dst(newRowVal, newColVal, src.type()); src.setTo(0); src.copyTo(dst(Rect(Point(0, 0), src.size()))); 
+8
source

You can use resize() function

Create a new Mat result for new dimensions

 resize(input // input image result // result image result.size() // new dimensions 0, 0, INTER_CUBIC // interpolation method ); 

To learn more interpolation methods, you can check this document: geometric_transformations.html # resize

+9
source

All Articles