Skip to content

Commit

Permalink
inclusão de novas imagens para teste e adicionado código limpo para c…
Browse files Browse the repository at this point in the history
…omparação
  • Loading branch information
K4du84 committed Nov 24, 2022
1 parent c282ede commit c25ca9a
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 2 deletions.
4 changes: 2 additions & 2 deletions hashpercent.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@
print(tamanho[i])
i += 1
#CALCULO DA DIFERENÇA ENTRE AS HASH
"""""""#COMO O CALCULO DA DIFERENÇA DO HASH VARIA DE 0 A 100, ONDE ZERO SIGNIFICA QUE É MAIS SEMELHANTE, " \
"PARA TERMOS O RETORNO EM PORCENTAGEM É NECESSÁRIO FORMATSAR O RESULTADO"""
"""""""COMO O CALCULO DA DIFERENÇA DO HASH VARIA DE 0 A 100, ONDE ZERO SIGNIFICA QUE É MAIS SEMELHANTE, " \
"PARA TERMOS O RETORNO EM PORCENTAGEM É NECESSÁRIO FORMATAR O RESULTADO -- 100 - (((HASH1 - HASH2)/ LEN DO HASH) * 100)"""
#Figura 4 do array é a modelo HORSE_MODEL
#Figura 0 do array é a identica ao modelo HORSE1
print("-------------------------------------")
Expand Down
48 changes: 48 additions & 0 deletions maissemelhante_FINAL.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
#BIBLIOTECAS
from glob import glob
import os
from PIL import Image
import imagehash


# PROGRAMA COM FINALIDADE DE RETORNAR A IMAGEM MAIS SEMELHANTE DO BANCO DE DADOS COM A PASSADA PELO USUÁRIO
i = 0
hashes = {}

# DEFINIÇÃO DAS INFORMAÇÕES DA IMAGEM MODELO, QUE QUEREMOS COMPARAR COM O BANCO DE DADOS.
modelo = "C:\\ImageBD\\unqlo\\WHITE-HORSE.jpg"
hash_modelo = imagehash.whash(Image.open(modelo))
tamanho = len(hash_modelo)

# ALIMENTAÇÃO DA LISTA COM OS ARQUIVOS DO BANCO DE DADOS
img_names = glob(os.path.join(os.getcwd(), '*.jpg'))
print("")
# IMPRESSÕES REALIZADAS APENAS PARA ACOMPANHARMOS O PROCESSO QUE ESTAVA SENDO FEITO
print("LISTA COMPLETA")
for fn in img_names:
print("Arquivo ", i + 1, " - ", img_names[i])
# ACHEI MELHOR JÁ ALIMENTAR A LISTA JÁ COM A SIMILARIDADE CALCULADA
hashes[i] = 100 - (((hash_modelo - imagehash.whash(Image.open(img_names[i])))/ tamanho) * 100)
print("Similaridade Hash ", i + 1, " - ", hashes[i])
i += 1

#CRIAÇÃO DO LOOP PARA IDENTIFICAR A MAIOR SIMILARIDADE E A QUE ARQUIVO PENTENCE
j = 0
mais_similar = 0
arquivo_similar = None

print("tamanho lista hash = ", len(hashes))
for hs in hashes:
if hashes[j] > mais_similar:
mais_similar = hashes[j]
arquivo_similar = img_names[j]
j += 1
print("")
print("________________________")
print("")
print("A Imagem mais similar é a",arquivo_similar, ",com ", mais_similar, "% de similaridade.")
print("")
print("________________________")
print("")


Binary file added unqlo/BLACK_HORSE.jpg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added unqlo/WHITE-HORSE.JPG
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit c25ca9a

Please sign in to comment.