两幅不同分辨率图像的对比



我将两个视频文件分成帧进行比较。在一定的时间间隔后,捕获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库。

最新更新