After cropping an image how can I resize it?
Mat croppedimage = cropImage( image, rect ); Mat resizeimage = croppedimage.resize( any dimension ); //need to change this line
Resizing an Image Using BufferedImage. getScaledInstance() You can resize an image in Java using the getScaledInstance() function, available in the Java Image class.
4, OpenCV supports desktop Java development using nearly the same interface as for Android development. This guide will help you to create your first Java (or Scala) application using OpenCV.
resize() Function. To resize images with OpenCV, use the cv2. resize() function. It takes the original image, modifies it, and returns a new image.
I think, you want this.
e.g.
Mat croppedimage = cropImage(image,rect); Mat resizeimage = new Mat(); Size sz = new Size(100,100); Imgproc.resize( croppedimage, resizeimage, sz );
If you want to scale an image using OpenCV java then do the following:
import static org.opencv.imgproc.Imgproc.*; import static org.opencv.imgcodecs.Imgcodecs.imread;
Main code:
Mat src = imread("imageName.jpg"); Mat resizeimage = new Mat(); Size scaleSize = new Size(300,200); resize(src, resizeimage, scaleSize , 0, 0, INTER_AREA);
For downscaling it is recommended to use: INTER_AREA and for upscaling use INTER_CUBIC
For more details: OpenCV Ref for 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