How to check if two following frames are identical ?

asked 2018-06-06 19:36:30 -0600

Hi,

I'm using Python 3.5 and OpenCV 3.4.1. I just want to open a .avi video file and check if two frames in a row are identical in order to get the actual framerate of the game captured. I don't want to use an mse based comparison or something like that, I just want to know if two successives frames are EXACTLY identical.

I currently have the following code :

def unique_frame():
video_name = 'G:/VirtualDub Capture/RAW-Uncompressed.avi'
cap = cv2.VideoCapture(video_name)
fps = int(math.ceil(cap.get(cv2.CAP_PROP_FPS)))
fps_counter = fps
unique_fps_counter = 0
previous = cap.read()
while cap.isOpened():
    current = cap.read()
    if previous != current:
        unique_fps_counter += 1
    if fps_counter == 0:
        print(actual_fps_counter)
        unique_fps_counter = 0
        fps_counter = fps
    else:
        fps_counter -= 1

Obviously the '!=' part doesn't works. I'm a total newbie with OpenCV and I can't manage to find how to properly compare two frames.

Thank you in advance

edit retag flag offensive close merge delete

Comments

Check out cv2.absdiff().

It will return an image, which if no change occurs between frames, is pure-black. It literally takes the absolute value of the subtraction of one image from another, pixel by pixel.

sjhalayka gravatar imagesjhalayka ( 2018-06-06 21:02:13 -0600 )edit

Thanks I don't know how to check if there is at least one none zero pixel. I know there is the "countNonZero" function but it won't work since I have an RGB image. counNonZero works only for single channel image.

Kenshin gravatar imageKenshin ( 2018-06-07 07:42:35 -0600 )edit