I am comparing 2 video files by separating them into their frames. After a certain time interval, 2 frames(image) are captured. These video files content are same but they are different in resolution. So i need to compare these 2 images. As they are different in resolution, I cant take their matrix Of RGB values to compare. It definitely wont match. Already tried Imagemagics but its not suitable because the images can be almost same as they are just different frames of same video. How can i differentiate between these two videos?
What i did
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()
CodePudding user response:
Resize the bigger image to same size of smaller image. Then use imagehash library as discussed in this question.