gym_image_id) + '.png' shutil.move(fullpath_filename, fort_dest_file) print('gym image id:', gym_image_id, 'is set as not valid') elif image_name[0] == 'Pokemon': pokemon_id, ext = os.path.splitext(image_name[1]) if len(image_name) > 2: form, ext = os.path.splitext(image_name[2]) else: form = None if pokemon_id.isdecimal() == True: print('pokemon_id:', pokemon_id) img = cv2.imread(str(fullpath_filename), 3) nearby = rs.RaidNearby(-1) pokemon_image_id = nearby.get_pokemon_image_id(img) pokemon_image_pokemon_id = db.get_pokemon_image_pokemon_id( session, pokemon_image_id) if pokemon_image_pokemon_id is None: nearby.detectMon(img) pokemon_image_id = nearby.get_pokemon_image_id(img) pokemon_image_pokemon_id = db.get_pokemon_image_pokemon_id( session, pokemon_image_id) if int(pokemon_id) == int(pokemon_image_pokemon_id): print('This pokemon image is already trained') os.remove(fullpath_filename) else: if int(pokemon_image_pokemon_id) == 0 or Force_update: form_int = 0 if form is not None and int(form) is not None: form_int = int(form)
def run_pokemonmatching(self, session, pokemon_fullpath_filename): p_url = Path(self.poke_image_path) poke_filename = os.path.basename(pokemon_fullpath_filename) LOG.info('find pokemon for {}'.format(poke_filename)) min_result_2 = 100 min_result = 100 pokemon = None pokemon_2 = None for pokemon_image_name in p_url.glob('*.png'): min_val = mt.pokemon_image_matching(str(pokemon_image_name), str(pokemon_fullpath_filename), False) pokemon_image_name_base = os.path.basename(pokemon_image_name) pokemon_image_name_base, ext = os.path.splitext(pokemon_image_name_base) if min_val < min_result: min_result_2 = min_result pokemon_2 = pokemon min_result = min_val parts = str(pokemon_image_name_base).split('_') id = parts[3] form = parts[4] pokemon = Pokemon(id, form) elif min_val < min_result_2: min_result_2 = min_val parts = str(pokemon_image_name_base).split('_') id = parts[3] form = parts[4] pokemon_2 = Pokemon(id, form) img = cv2.imread(str(pokemon_fullpath_filename), 3) pokemon_image_id = self.raidnearby.get_pokemon_image_id(img) pokemon_image_pokemon_id = db.get_pokemon_image_pokemon_id(session, pokemon_image_id) diff = abs(min_result - min_result_2) if pokemon is None or (diff < 0.005 and pokemon.id != pokemon_2.id) or \ (min_result > 0.055 and diff < 0.1) \ or min_result > 1.5: LOG.info('Can not find pokemon image: {}, check the image in not_find_img'.format(pokemon_image_id)) pokemon_result_file = os.getcwd() + '/not_find_img/PokemonImage_{}.png'.format(pokemon_image_id) shutil.move(pokemon_fullpath_filename, pokemon_result_file) else: if pokemon_image_pokemon_id is not None and int(pokemon_image_pokemon_id) == int(pokemon.id): LOG.info('This pokemon image is already trained') pokemon_result_file = os.getcwd() + '/success_img/Pokemon_' + str(pokemon_image_pokemon_id) + '_PokemonImages_' + str(pokemon_image_id) + '_' + '{:.3f}'.format(min_result) + '.png' shutil.move(pokemon_fullpath_filename, pokemon_result_file) else: LOG.info('gym_images id:{} pokemon_id:{}'.format(pokemon_image_id ,pokemon_image_pokemon_id)) if pokemon_image_pokemon_id == 0: try: db.update_pokemon_image(session, pokemon_image_id, pokemon.id, pokemon.form) except KeyboardInterrupt: os.killpg(0, signal.SIGINT) sys.exit(1) LOG.info('Successfully found pokemon id: {}'.format(pokemon.id)) pokemon_result_file = os.getcwd() + '/success_img/Pokemon_' + str(pokemon.id) + '_PokemonImages_' + str(pokemon_image_id) + '_' + '{:.3f}'.format(min_result) + '.png' shutil.move(pokemon_fullpath_filename, pokemon_result_file) else: LOG.info('The PokemonImage {} is already assigned as pokemon id: {}'.format(str(pokemon_image_id), str(pokemon_image_pokemon_id))) pokemon_result_file = os.getcwd() + '/success_img/Pokemon_' + str(pokemon_image_pokemon_id) + '_PokemonImages_' + str(pokemon_image_id) + '_' + '{:.3f}'.format(min_result) + '.png' shutil.move(pokemon_fullpath_filename, pokemon_result_file)