OPENCV image scaling

Zoom magnification can follow can be specified resolution scaling (may be deformed)

Artwork

 

 

 

0.5 times zoom

 private void jBresizeActionPerformed(java.awt.event.ActionEvent evt) {                                         
        // TODO add your handling code here:
        System.loadLibrary(Core.NATIVE_LIBRARY_NAME);
        org.opencv.core.Mat imgMat = imread("src\\resource\\" + jTFimgName.getText());//读取图片
        float scale = 0.5f;
        float width = imgMat.width();
        float height = imgMat.height();
        org.opencv.core.Mat dst = new Mat();
        Imgproc.resize(imgMat, dst, new Size(width * scale, height * scale));
        Imgcodecs.imwrite("src\\resource\\0.5.png", dst);
    }                                        

1.5倍缩放

 private void jBresize1ActionPerformed(java.awt.event.ActionEvent evt) {                                          
        // TODO add your handling code here:
        System.loadLibrary(Core.NATIVE_LIBRARY_NAME);
        org.opencv.core.Mat imgMat = imread("src\\resource\\" + jTFimgName.getText());//读取图片
        float scale = 1.5f;
        float width = imgMat.width();
        float height = imgMat.height();
        org.opencv.core.Mat dst = new Mat();       
        Imgproc.resize(imgMat, dst, new Size(width * scale, height * scale));
        Imgcodecs.imwrite("src\\resource\\1.5.png", dst);
    }                                         

 

指定分辨率缩放

 private void jBresize2ActionPerformed(java.awt.event.ActionEvent evt) {                                          
        // TODO add your handling code here:
        System.loadLibrary(Core.NATIVE_LIBRARY_NAME);
        org.opencv.core.Mat imgMat = imread("src\\resource\\" + jTFimgName.getText());//读取图片      
        org.opencv.core.Mat dst = new Mat();
        Imgproc.resize(imgMat, dst, new Size(320, 240));
        Imgcodecs.imwrite("src\\resource\\320X240.png", dst);
    }                                         

 

Guess you like

Origin www.cnblogs.com/jnhs/p/11334776.html