I have some video recording of my screen where I am drawing some diagrams, but there are a lot of moments where the screen is idle. Because I am using Camtasia, the cursor is not saved directly on the video itself so it makes it easier to detect idle moments.
I extracted all frames using ffmpeg. Here are 3 sequential frames:
I tried many methods from numpy to opencv to phash but I am unable to get correct results for these images. They either return True for all or False for all, but as you can see only the first 2 images at the same, the last one is different.
Here is my latest code:
import cv2
import numpy as np
from skimage.metrics import structural_similarity as ssim
def mse(imageA, imageB):
# Mean Squared Error between the two images
err = np.sum((imageA.astype("float") - imageB.astype("float")) ** 2)
err /= float(imageA.shape[0] * imageA.shape[1])
return err
def are_images_equal(image1_path, image2_path, mse_threshold=100, ssim_threshold=0.95):
try:
# Read images
image1 = cv2.imread(image1_path)
image2 = cv2.imread(image2_path)
if image1 is None or image2 is None:
return False
# Convert images to grayscale
gray1 = cv2.cvtColor(image1, cv2.COLOR_BGR2GRAY)
gray2 = cv2.cvtColor(image2, cv2.COLOR_BGR2GRAY)
# Compute MSE
mse_value = mse(gray1, gray2)
if mse_value > mse_threshold:
return False
# Compute SSIM
ssim_index, _ = ssim(gray1, gray2, full=True)
if ssim_index < ssim_threshold:
return False
return True
except Exception as e:
print(f"An error occurred: {e}")
return False