比较 2 个不同分辨率的图像

Comparing image of 2 different resolution

我通过将 2 个视频文件分成帧来比较它们。在一定时间间隔后,捕获 2 帧(图像)。这些视频文件内容相同,但分辨率不同。所以我需要比较这两张图片。由于它们的分辨率不同,我无法将它们的 RGB 值矩阵进行比较。它肯定不会匹配。已经尝试过 Imagemagics 但它不适合,因为图像几乎相同,因为它们只是同一视频的不同帧。我如何区分这两个视频?

我做了什么


import cv2
import numpy
import math
import pytest
import matplotlib.pyplot as plt
import warnings
from matplotlib import pyplot as plt
from tkinter.filedialog import askopenfilename
import numpy as np
from PIL import Image, ImageChops
# from wand.image import Image
# from wand.display import display











clip = cv2.VideoCapture('./resources/sample.m4v')
converted_clip = cv2.VideoCapture('./resources/sample_convert.mp4')
clip_nof = int(clip.get(cv2.CAP_PROP_FRAME_COUNT))
con_clip_nof = int(converted_clip.get(cv2.CAP_PROP_FRAME_COUNT))

original_fps = int(clip.get(cv2.CAP_PROP_FPS))
convert_fps = int(converted_clip.get(cv2.CAP_PROP_FPS))




fps = int(converted_clip.get(cv2.CAP_PROP_FPS))
assert fps == 30.0

assert clip_nof == con_clip_nof


id = 0
conid = 0
frame_count = 1
while(True):
    clip.set(1, id)
    converted_clip.set(1, conid)
    ret, frame = clip.read()
    ret, con_frame = converted_clip.read()

    if not ret:
        break

    original_image = frame
    converted_image = con_frame

    plt.imsave('./resources/sample_frame/img%d.jpg' %
               (frame_count), original_image)
    plt.imsave('./resources/convert_frame/img%d.jpg' %
               (frame_count), converted_image)

    print(original_image.shape,converted_image.shape)

    oh,ow,od=original_image.shape
    ch,cw,cd=converted_image.shape



    # print(oh,ow,od,ch,cw,cd)
    # resize_linear(original_image,ch,cw)
    img1=Image.open('./resources/sample_frame/img%d.jpg'%(frame_count))
    img2=Image.open('./resources/convert_frame/img%d.jpg'%(frame_count))

    original_image_rgb_list=list(img1.getdata())
    converted_image_rgb_list=list(img2.getdata())


    print(len(original_image_rgb_list),len(converted_image_rgb_list))






    id = id+original_fps*2
    conid = conid+convert_fps*2

    frame_count = frame_count+1

    if(frame_count % 50 == 0):
        print("Number of frames checked are : %d" % frame_count)

    # assert original_image == converted_image

    # print(original_image, converted_image)

    


print(id, conid)
clip.release()
converted_clip.release()
cv2.destroyAllWindows()


将大图调整为与小图相同的大小。然后使用 imagehash library as discussed in this .