OPENCV 圖像縮放


工程下載地址

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

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM