DHASH感知算法盘算视频相邻帧的相似度

[复制链接]
发表于 2026-1-12 17:59:05 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有账号?立即注册

×
一个朋侪想用python来读取视频帧,根据帧和帧之间相似度判断剪辑陈迹;但是末了发现并没什么用……
原理就是遍历地读取图像相邻帧,将图像相邻帧前处理惩罚后,缩小什么的,盘算d_hash,然后盘算其汉明间隔,然后把汉明间隔变成相似度,比力相似度,如果相似度低于阈值,就标记时间什么的
不外我一想,欸!好像可以用来解GIF隐写
我就把代码放这里了
1.处理惩罚视频版本的
  1. import cv2
  2. import numpy as np
  3. from PIL import Image
  4. # Constants
  5. VIDEO_FILE = "faker.mp4"
  6. FRAME_PREFIX = "frame"
  7. FAIL_THRESHOLD = 0.77
  8. def d_hash(image):
  9.     """Calculate the difference hash for the given image."""
  10.     hash_bits = []
  11.     for i in range(8):
  12.         for j in range(8):
  13.             hash_bits.append(1 if image[i, j] > image[i, j + 1] else 0)
  14.     return hash_bits
  15. def hamming_distance(hash1, hash2):
  16.     """Calculate the Hamming distance between two hashes."""
  17.     return sum(1 for x, y in zip(hash1, hash2) if x != y)
  18. def process_frame(frame):
  19.     """Process frame to convert it to a format suitable for hash computation."""
  20.     return np.array(Image.fromarray(frame).resize((9, 8), Image.LANCZOS).convert('L'), 'f')
  21. def mai
复制代码
回复

使用道具 举报

登录后关闭弹窗

登录参与点评抽奖  加入IT实名职场社区
去登录
快速回复 返回顶部 返回列表