Last active
February 11, 2022 08:52
-
-
Save xiaok/ded2dc90d7227c92999533bd4cb88c9f to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# pip install opencv-python | |
import cv2 | |
img1 = cv2.imread("a.png", cv2.IMREAD_GRAYSCALE) | |
img2 = cv2.imread("a_sample.png", cv2.IMREAD_GRAYSCALE) | |
def calc_hist(img): | |
hist = cv2.calcHist([img], channels=[0], mask=None, histSize=[256], ranges=[0, 256]) | |
hist = cv2.normalize(hist, hist, 0, 255, cv2.NORM_MINMAX) | |
hist = hist.squeeze(axis=-1) | |
return hist | |
hist1 = calc_hist(img1) | |
hist2 = calc_hist(img2) | |
score = cv2.compareHist(hist1, hist2, cv2.HISTCMP_CORREL) | |
# 数字越靠近1越是同一张图 | |
print(score) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment