0
我正在處理使用指定算法MSE和SSI處理圖像以用於比較圖像結構的android應用程序。從文件夾中讀取所有圖像文件進行處理
我有工作代碼,它允許我從選定的文件夾中選擇兩個圖像並對它們執行所需的操作,但下一步是允許用戶選擇一個文件夾,然後它會自動讀取所有圖像並執行所需的操作並保存被發現相似的圖像。
我有下面的代碼,但在一分鐘它正在通過圖像工作,它最終會通過超時錯誤。
有什麼我做錯了,或者我應該改變,以便順利運行。有需要處理的文件夾中有172個圖像。
public void addItemsOnSpinner() {
spinner1 = (Spinner) findViewById(R.id.spinner);
List<String> list = new ArrayList<String>();
list.add("New images");
list.add("All downloads");
list.add("Bluetooth");
list.add("Camera shots");
ArrayAdapter<String> dataAdapter = new ArrayAdapter<String>(this,
android.R.layout.simple_spinner_item, list);
dataAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
spinner1.setAdapter(dataAdapter);
selection = String.valueOf(spinner1.getSelectedItem());
}
@Override
public void onClick(View v) {
int n =0;
if (v == submit) {
for (int i = 1; i <= 172; i++) {
for (int j = 1; j <= 172; j++) {
absoluteFilePath = folder + "/" + selection + "/image" + i + ".bmp";
bMap1 = BitmapFactory.decodeFile(absoluteFilePath);
absoluteFilePath2 = folder + "/" + selection + "/image" + j + ".bmp";
bMap2 = BitmapFactory.decodeFile(absoluteFilePath2);
Toast.makeText(LoadFile.this, "Comparing Image" + i + " against Image" + j,
Toast.LENGTH_SHORT).show();
//loop through each image compare image by image
calculateMSE(bMap1, bMap2, 256, 256);
calculateSSI(bMap1, bMap2, 4);
//calculateSSI(bMap1, bMap2, 8);
//calculateSSI(bMap1, bMap2, 16);
//calculateSSI(bMap1, bMap2, 32);
//if images are similar save file paths to array
if(calculateMSE(bMap1, bMap2, 256, 256) <= 0.4 && calculateSSI(bMap1, bMap2, 4) >= 0.6){
ImageView image1 = (ImageView) findViewById(R.id.imgView);
image1.setImageBitmap(bMap1);
ImageView image2 = (ImageView) findViewById(R.id.imgView2);
image2.setImageBitmap(bMap2);
//saving file path to array
bitmapArray1 [n] = bMap1;
bitmapArray2 [n] = bMap2;
n++;
}
嘗試用較少的圖像。如果可行,很有可能您的內存不足 –
請提供LogCat輸出的錯誤。 '允許我從所選文件夾中選擇兩個圖像'的代碼' – Fildor
'。如果你需要兩個兩個圖像,那麼你會如何從目錄列表中選擇它們? '在當前正在處理圖像的時刻'?請詳細解釋你的意思。 '它最終會通過一個超時錯誤'。請更好地解釋發生了什麼。 – greenapps