OPENCV 图像缩放

浪子不回头ぞ 提交于 2020-03-06 11:46:20

工程下载地址

https://download.csdn.net/download/qq_16596909/11522434

opencv4 java netbeans开发,基于maven

可以按照倍率缩放,也可以指定分辨率缩放(可能会变形)

原图

 

 

 

0.5倍缩放

 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);
    }                                         

 

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!