import cv2
import numpy as np
def is_frames_corrupted(frame1, frame2, threshold=0.99):
difference = cv2.absdiff(frame1, frame2)
mean_difference = np.mean(difference)
similarity = 1 - (mean_difference / 255.0)
return similarity >= threshold
def find_glitch_in_video(video_path, threshold=0.99):
cap = cv2.VideoCapture(video_path)
if not cap.isOpened():
print("Error opening video file")
return
ret, prev_frame = cap.read()
prev_frame = cv2.cvtColor(prev_frame, cv2.COLOR_BGR2GRAY)
while cap.isOpened():
ret, curr_frame = cap.read()
if not ret:
break
curr_frame_gray = cv2.cvtColor(curr_frame, cv2.COLOR_BGR2GRAY)
if is_frames_corrupted(prev_frame, curr_frame_gray, threshold):
print("Glitch found in the video")
cap.release()
return True
prev_frame = curr_frame_gray
print("No glitch found in the video")
cap.release()
return False
if __name__ == "__main__":
video_path = "path/to/your/video.mp4"
find_glitch_in_video(video_path)
花屏检测。
最新推荐文章于 2024-02-28 09:24:37 发布
本文介绍了一个使用OpenCV库在视频中检测帧差异的方法,用于识别并定位相似度低于阈值的异常帧,从而判断是否存在故障。函数`find_glitch_in_video`通过连续帧之间的差异来判断视频中的异常点。
摘要由CSDN通过智能技术生成