Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to resize an image in Java with OpenCV?

Tags:

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 
like image 518
midhun0003 Avatar asked Jan 03 '14 11:01

midhun0003


People also ask

Can you resize an image in Java?

Resizing an Image Using BufferedImage. getScaledInstance() You can resize an image in Java using the getScaledInstance() function, available in the Java Image class.

Can we use OpenCV with Java?

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.

Which function is used to resize an image in 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.


2 Answers

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 ); 
like image 172
berak Avatar answered Sep 22 '22 15:09

berak


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

like image 23
asmmahmud Avatar answered Sep 18 '22 15:09

asmmahmud