diff --git a/app/src/main/java/com/kamron/pogoiv/pokeflycomponents/fractions/InputFraction.java b/app/src/main/java/com/kamron/pogoiv/pokeflycomponents/fractions/InputFraction.java index ad679ef1b..dd7d05724 100644 --- a/app/src/main/java/com/kamron/pogoiv/pokeflycomponents/fractions/InputFraction.java +++ b/app/src/main/java/com/kamron/pogoiv/pokeflycomponents/fractions/InputFraction.java @@ -27,13 +27,10 @@ import com.kamron.pogoiv.scanlogic.Pokemon; import com.kamron.pogoiv.scanlogic.PokemonNameCorrector; import com.kamron.pogoiv.utils.LevelRange; -import com.kamron.pogoiv.utils.StringUtils; import com.kamron.pogoiv.utils.fractions.Fraction; import com.kamron.pogoiv.widgets.PokemonSpinnerAdapter; import java.util.ArrayList; -import java.util.HashMap; -import java.util.Map; import butterknife.BindView; import butterknife.ButterKnife; @@ -74,16 +71,12 @@ public class InputFraction extends Fraction { private Pokefly pokefly; private PokeInfoCalculator pokeInfoCalculator; - private final Map normalizedPokemonNameMap; public InputFraction(@NonNull Pokefly pokefly) { this.pokefly = pokefly; this.pokeInfoCalculator = PokeInfoCalculator.getInstance(); - Map pokemap = new HashMap<>(); - for (Pokemon pokemon : pokeInfoCalculator.getPokedex()) { - pokemap.put(StringUtils.normalize(pokemon.toString()), pokemon); // set display pokemon name as key - } - this.normalizedPokemonNameMap = pokemap; + + } @Override public int getLayoutResId() { @@ -294,13 +287,20 @@ public String apply(T input) { */ private Pokemon interpretWhichPokemonUserInput() { //below picks a pokemon from either the pokemon spinner or the user text input - Pokemon pokemon; + Pokemon pokemon = null; if (pokeInputSpinner.getVisibility() == View.VISIBLE) { //user picked pokemon from spinner //This could be pokemon = pokeInputSpinner.getSelectedItem(); if they didn't give it type Object. pokemon = pokeInputAdapter.getItem(pokeInputSpinner.getSelectedItemPosition()); } else { //user typed manually String userInput = autoCompleteTextView1.getText().toString(); - pokemon = normalizedPokemonNameMap.get(StringUtils.normalize(userInput)); + int lowestDist = Integer.MAX_VALUE; + for (Pokemon poke : pokeInfoCalculator.getPokedex()) { + int dist = Data.levenshteinDistance(poke.name, userInput); + if (dist < lowestDist) { + lowestDist = dist; + pokemon = poke; + } + } if (pokemon == null) { //no such pokemon was found, show error toast and abort showing results Toast.makeText(pokefly, userInput + pokefly.getString(R.string.wrong_pokemon_name_input), Toast.LENGTH_SHORT).show(); diff --git a/app/src/main/java/com/kamron/pogoiv/pokeflycomponents/ocrhelper/OcrHelper.java b/app/src/main/java/com/kamron/pogoiv/pokeflycomponents/ocrhelper/OcrHelper.java index 6be45cc95..01851e08d 100644 --- a/app/src/main/java/com/kamron/pogoiv/pokeflycomponents/ocrhelper/OcrHelper.java +++ b/app/src/main/java/com/kamron/pogoiv/pokeflycomponents/ocrhelper/OcrHelper.java @@ -158,50 +158,6 @@ private static Bitmap replaceColors(Bitmap srcBitmap, boolean mutateSrc, int kee return dstBitmap; } - private static Bitmap replaceColors(Bitmap srcBitmap, boolean mutateSrc, - int r, int g, int b, @Nullable Integer replaceColor, - @Nullable Float dH, @Nullable Float dS, @Nullable Float dV) { - int[] allPixels = new int[srcBitmap.getHeight() * srcBitmap.getWidth()]; - srcBitmap.getPixels(allPixels, 0, srcBitmap.getWidth(), 0, 0, srcBitmap.getWidth(), srcBitmap.getHeight()); - - final int bgColor; - if (replaceColor != null) { - bgColor = replaceColor; - } else { - bgColor = allPixels[0]; // Sample the top left color to use as background - } - - float[] targetHsv = new float[3]; - Color.RGBToHSV(r, g, b, targetHsv); - - float[] currentHsv = new float[3]; - for (int i = 0; i < allPixels.length; i++) { - if (allPixels[i] == bgColor) { - continue; - } - - Color.colorToHSV(allPixels[i], currentHsv); - - if (dH != null && Math.abs(targetHsv[0] - currentHsv[0]) > dH) { // Check hue - allPixels[i] = bgColor; - - } else if (dS != null && Math.abs(targetHsv[1] - currentHsv[1]) > dS) { // Check saturation - allPixels[i] = bgColor; - - } else if (dV != null && Math.abs(targetHsv[2] - currentHsv[2]) > dV) { // Check value - allPixels[i] = bgColor; - } - } - - Bitmap dstBitmap; - if (mutateSrc) { - dstBitmap = srcBitmap; - } else { - dstBitmap = Bitmap.createBitmap(srcBitmap.getWidth(), srcBitmap.getHeight(), srcBitmap.getConfig()); - } - dstBitmap.setPixels(allPixels, 0, srcBitmap.getWidth(), 0, 0, srcBitmap.getWidth(), srcBitmap.getHeight()); - return dstBitmap; - } /** * Scans the arc and tries to determine the pokemon level, returns 1 if nothing found. @@ -424,7 +380,7 @@ private static Optional getPokemonEvolutionCostFromImg(@NonNull Bitmap } } - movesetImage = replaceColors(movesetImage, true, 68, 105, 108, null, 3f, null, 0.1f); + movesetImage = replaceColors(movesetImage, true, 68, 105, 108, Color.BLACK, 50, false); tesseract.setImage(movesetImage); tesseract.setPageSegMode(TessBaseAPI.PageSegMode.PSM_SINGLE_BLOCK); @@ -1084,10 +1040,14 @@ public ScanData scanPokemon(@NonNull GoIVSettings settings, } Optional evolutionCost = getPokemonEvolutionCostFromImg(pokemonImage, ScanArea.calibratedFromSettings(POKEMON_EVOLUTION_COST_AREA, settings, luckyOffset)); - Pair moveset = getMovesetFromImg(pokemonImage, - estimatedLevelRange, - ScanArea.calibratedFromSettings(POKEMON_POWER_UP_CANDY_COST, settings, luckyOffset), - ScanArea.calibratedFromSettings(POKEMON_EVOLUTION_COST_AREA, settings, luckyOffset)); + Pair moveset = null; + if (requestFullScan) { + moveset = getMovesetFromImg(pokemonImage, + estimatedLevelRange, + ScanArea.calibratedFromSettings(POKEMON_POWER_UP_CANDY_COST, settings, luckyOffset), + ScanArea.calibratedFromSettings(POKEMON_EVOLUTION_COST_AREA, settings, luckyOffset)); + } + String moveFast = null; String moveCharge = null; if (moveset != null) {