user3324136
user3324136

Reputation: 417

OpenCV find frozen frames in video

I have been trying to look at a video in my library and detect frozen frames using python and OpenCV.

There is one Stack Overflow question that had an answer, but I didn't quite understand the it. The answer is as follows:

Frozen frames: calculate absolute difference over HSV/RGB per every pixel in two consecutive frames np.arrays and determine max allowed diff that is valid for detecting frozen frames.

What is the best way to detect frozen frames greater than 3 seconds in a video?

Thank you so much.

Upvotes: 1

Views: 1503

Answers (1)

Soheyb Kadi
Soheyb Kadi

Reputation: 186

To calculate the absolute difference between two frames Frame1 and Frame2 you can use this:

Diff=np.sum(np.abs(Frame1-Frame2))

np is the short name for numpy which you should import at first by import numpy as np np.abs is calculating the absolute value of each pixel in the difference Frame1-Frame2 and obviously np.sum is summing all values so you end up with one value.

As for extending this to detect if the video is frozen for 3 seconds, you should do the above calculation either for each two "consecutive" images in the span of 3 seconds. Or calculate the difference between current frame and frame at current time - 3 seconds. Something like this:

time1=1000 #This is 1st second
time2=4000 #This is the 4th second

cap.set(cv.CV_CAP_PROP_POS_MSEC,time1) 
ret, Frame1= cap.read()

cap.set(cv.CV_CAP_PROP_POS_MSEC,time2)
ret, Frame2= cap.read()

cap is the video capture.

Upvotes: 3

Related Questions