We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
需求描述: 比较两张图片的像素信息——若完全相同,输出true;若不同,输出false。
目前的 compare 节点,若输入 image 到 a 和 b,并选择a==b,输出的东西很奇怪:
tensor([[[[True, True, True], [True, True, True], [True, True, True], ..., [True, True, True], [True, True, True], [True, True, True]], [[True, True, True], [True, True, True], [True, True, True], ..., [True, True, True], [True, True, True], [True, True, True]], [[True, True, True], [True, True, True], [True, True, True], ..., [True, True, True], [True, True, True], [True, True, True]], ..., [[True, True, True], [True, True, True], [True, True, True], ..., [True, True, True], [True, True, True], [True, True, True]], [[True, True, True], [True, True, True], [True, True, True], ..., [True, True, True], [True, True, True], [True, True, True]], [[True, True, True], [True, True, True], [True, True, True], ..., [True, True, True], [True, True, True], [True, True, True]]]])
The text was updated successfully, but these errors were encountered:
OpenCV 是一个强大的计算机视觉库,可以用来比较两张图片。
import cv2 def compare_images(img1_path, img2_path): img1 = cv2.imread(img1_path) img2 = cv2.imread(img2_path) if img1.shape != img2.shape: return False difference = cv2.subtract(img1, img2) b, g, r = cv2.split(difference) if cv2.countNonZero(b) == 0 and cv2.countNonZero(g) == 0 and cv2.countNonZero(r) == 0: return True else: return False # 使用示例 if compare_images('image1.jpg', 'image2.jpg'): print("图片相同") else: print("图片不同")
PIL 是 Python 的图像处理库,也可以用来比较两张图片。
from PIL import Image def compare_images(img1_path, img2_path): img1 = Image.open(img1_path) img2 = Image.open(img2_path) if img1.size != img2.size: return False diff = ImageChops.difference(img1, img2) if diff.getbbox() is None: return True else: return False # 使用示例 if compare_images('image1.jpg', 'image2.jpg'): print("图片相同") else: print("图片不同")
使用图像哈希算法(如感知哈希、平均哈希等)可以更快速地比较两张图片。这些算法通过计算图像的特征向量,然后比较这些向量 来判断两张图片是否相同。
ImageHash 是一个用于计算图像哈希值的库。
import imagehash from PIL import Image def compare_images(img1_path, img2_path): img1 = Image.open(img1_path) img2 = Image.open(img2_path) hash1 = imagehash.average_hash(img1) hash2 = imagehash.average_hash(img2) return hash1 == hash2 # 使用示例 if compare_images('image1.jpg', 'image2.jpg'): print("图片相同") else: print("图片不同") 遇事不决问AI
Sorry, something went wrong.
No branches or pull requests
需求描述:
比较两张图片的像素信息——若完全相同,输出true;若不同,输出false。
目前的 compare 节点,若输入 image 到 a 和 b,并选择a==b,输出的东西很奇怪:
The text was updated successfully, but these errors were encountered: