马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有账号?立即注册
×
一个朋侪想用python来读取视频帧,根据帧和帧之间相似度判断剪辑陈迹;但是末了发现并没什么用……
原理就是遍历地读取图像相邻帧,将图像相邻帧前处理惩罚后,缩小什么的,盘算d_hash,然后盘算其汉明间隔,然后把汉明间隔变成相似度,比力相似度,如果相似度低于阈值,就标记时间什么的
不外我一想,欸!好像可以用来解GIF隐写
我就把代码放这里了
1.处理惩罚视频版本的
- import cv2
- import numpy as np
- from PIL import Image
- # Constants
- VIDEO_FILE = "faker.mp4"
- FRAME_PREFIX = "frame"
- FAIL_THRESHOLD = 0.77
- def d_hash(image):
- """Calculate the difference hash for the given image."""
- hash_bits = []
- for i in range(8):
- for j in range(8):
- hash_bits.append(1 if image[i, j] > image[i, j + 1] else 0)
- return hash_bits
- def hamming_distance(hash1, hash2):
- """Calculate the Hamming distance between two hashes."""
- return sum(1 for x, y in zip(hash1, hash2) if x != y)
- def process_frame(frame):
- """Process frame to convert it to a format suitable for hash computation."""
- return np.array(Image.fromarray(frame).resize((9, 8), Image.LANCZOS).convert('L'), 'f')
- def mai
复制代码 |