试图与欧几里得距离找到最接近的距离
import imagehash
from PIL import Image
import glob
import numpy as np
import csv
from scipy.spatial import distance
image_list = []
list_rows = []
for filename in glob.glob('/home/folder1/*.jpg'):
im = Image.open(filename)
image_list.append(im)
img_hash = imagehash.average_hash(im)
print(img_hash)
list_rows.append([img_hash])
np.savetxt("numpy_test.csv", list_rows, delimiter=",", fmt='% s')
with open('numpy_test.csv', newline='') as f:
reader = csv.reader(f)
data = list(reader)
print(data)
for hashes in data:
print(hashes)
mouni = []
mouni_rows = []
for file in glob.glob('/home/folder2/test.jpg'):
img = Image.open(file)
mouni.append(img)
img_hash = imagehash.average_hash(img)
print(img_hash)
mouni_rows.append([img_hash])
np.savetxt("numpy_test_mouni.csv", mouni_rows, delimiter=",", fmt='% s')
with open('numpy_test_mouni.csv', newline='') as f:
reader = csv.reader(f)
mouni = list(reader)
print(mouni)
for k in mouni:
print(k)
for i in hashes:
for y in k:
dist = np.linalg.norm(i - y)
print(dist)
-folder1包含一些图像,从其中imagehashes fulacetd并保存到.csv file
-folder2仅包含1个图像,并将imageHash提取并保存到另一个.csv文件中
- 目标是将1 imagehash从1 image中进行比较。使用欧几里得距离的散列,以找到最接近的哈希距离。但是错误是:typeError:未支撑的操作数类型 - :'str'和'str'
真正赞赏的任何建议。先感谢您
import imagehash
from PIL import Image
import glob
import numpy as np
import csv
from scipy.spatial import distance
image_list = []
list_rows = []
for filename in glob.glob('/home/folder1/*.jpg'):
im = Image.open(filename)
image_list.append(im)
img_hash = imagehash.average_hash(im)
print(img_hash)
list_rows.append([img_hash])
np.savetxt("numpy_test.csv", list_rows, delimiter=",", fmt='% s')
with open('numpy_test.csv', newline='') as f:
reader = csv.reader(f)
data = list(reader)
print(data)
for hashes in data:
print(hashes)
mouni = []
mouni_rows = []
for file in glob.glob('/home/folder2/test.jpg'):
img = Image.open(file)
mouni.append(img)
img_hash = imagehash.average_hash(img)
print(img_hash)
mouni_rows.append([img_hash])
np.savetxt("numpy_test_mouni.csv", mouni_rows, delimiter=",", fmt='% s')
with open('numpy_test_mouni.csv', newline='') as f:
reader = csv.reader(f)
mouni = list(reader)
print(mouni)
for k in mouni:
print(k)
for i in hashes:
for y in k:
dist = np.linalg.norm(i - y)
print(dist)
-Folder1 contains some images from which imagehashes are extracetd and saved to a .csv file
-Folder2 contains only 1 image and imagehash is extracted and saved to an other .csv file
-The goal is to compare the imagehash from the 1 image with the rest of the hashes using the euclidean distance in order to find the closest ones. But the error is: TypeError: unsupported operand type(s) for -: 'str' and 'str'
Any advice really appreciated. Thank you in advance
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论