My objective is to determine similarity between two exact same videos. My approach is a bit naive i.e. to compare them frame by frame and see if two frame exactly matches or not. I am using the following python code for this:
import cv2
import numpy as np
capture = cv2.VideoCapture("video.wmv")
capture2 = cv2.VideoCapture("video.wmv")
counter = 0
while True:
f, frame = capture.read()
f2, frame2 = capture2.read()
frame = cv2.GaussianBlur(frame,(15,15),0)
frame2 = cv2.GaussianBlur(frame2, (15, 15), 0)
try:
res = frame - frame2
if(np.count_nonzero(res) > 0 ):
counter += 1
else: continue
except:
print(counter)
The total number of frames in my video is around 600K. The code runs for almost 20K frames with exact matches and the counter remains zero (i.e. exact frame matching) but after 20K frames it started returning the following exception for all frames to come
unsupported operand type(s) for -: 'NoneType' and 'NoneType'
From the exception I understand that it is not reading any frames that is why returning a NonType. Please guide me whether my approach for comparing videos is correct (I know it is not efficient way). Also why I am getting this error ?