亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

調整大小過程中的 OpenImaj OutOfMemoryError

調整大小過程中的 OpenImaj OutOfMemoryError

楊__羊羊 2022-11-02 10:14:37
我有兩張照片,一張是放大的,第二張是大的廣角照片??紤]第一個圖像是第二個圖像的裁剪(盡管它不是)。我從每張照片中選擇一個像素,代表兩張照片中的相同事物(比如一個男人的鼻子)。我將第一張圖片以一定的透明度覆蓋在第二張圖片的頂部,對齊兩個選定的像素?現在我想縮放第二張圖像,直到第一張圖像基本上消失,因為第二張圖像的比例與第一張圖像的比例匹配。我正在使用 OpenImaj,并使用 MBFImage.overlayInPlace() 成功完成了這項工作。我遇到的問題是,當我使用 ResizeProcessor 縮放第二個圖像時,如果我必須將第二個圖像縮放太多( >5x ),我會得到一個“OutOfMemoryError: Java Heap Space”。我已經使用 JDK 12 64bit 將 -Xmx 提升到 12G。我嘗試了 ResizeProcessor、BilinearInterpolation 和 BicubicInterpolation 調整器,結果都一樣。這是我最近嘗試的方法。根據我給 JVM 的內存量,它有時會在調整大小時失敗,有時會在 toRGB() 上失?。簆rivate MBFImage scaleImage2(float scaleFactor) throws IOException {    FImage img2Flat = image2.flatten();    int width = (int)Math.round(img2Flat.getWidth() * scaleFactor);    int height = (int)Math.round(img2Flat.getHeight() * scaleFactor);    BilinearInterpolation resizer = new BilinearInterpolation(width, height, 1/scaleFactor);    resizer.processImage(img2Flat);    return img2Flat.toRGB();}這是我疊加圖像的地方:private MBFImage createScaledOverlay() {    MBFImage scaledImg2 = null;    if(scaledLastCrop == null) {        try {            scaledLastCrop = scaleLastCrop();        } catch (IOException e) {            e.printStackTrace();        }    }    try {        scaledImg2 = scaleImage2(image2ScaleFactor);    } catch (IOException e) {        e.printStackTrace();    }    int img2ScaledPixelx = Math.round(image2SelectedPixel.x * image2ScaleFactor);    int img2ScaledPixely = Math.round(image2SelectedPixel.y * image2ScaleFactor);    int lastCropScaledPixelx = (int)Math.round(lastCropSelectedPixel.x * lastCropScaleFactor);    int lastCropScaledPixely = (int)Math.round(lastCropSelectedPixel.y * lastCropScaleFactor);    scaledImg2.overlayInplace(scaledLastCrop, img2ScaledPixelx - lastCropScaledPixelx, img2ScaledPixely - lastCropScaledPixely);    return scaledImg2;}我可以選擇兩條前進的道路之一:修復 OutOfMemoryError疊加兩個圖像的另一種方法
查看完整描述

1 回答

?
慕村225694

TA貢獻1880條經驗 獲得超4個贊

有時一個解決方案是如此明顯以至于令人尷尬。

現在想想,我真正的目標是找到兩個圖像之間的比例因子。我可以縮小 image1,而不是放大 image2。這要少得多的內存密集型。然后關于 image2 我可以反轉這個比例因子。


查看完整回答
反對 回復 2022-11-02
  • 1 回答
  • 0 關注
  • 108 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號