【发布时间】:2019-08-12 08:56:27
【问题描述】:
我必须将所有视频帧与一张图像进行比较,而使用 compare_ssim 会花费很多时间。将图像与图像的相似程度得分进行比较的最快方法是什么?
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import cv2
from skimage.measure import compare_ssim as ssim
import time
start_time = time.time()
# Load File
opening = cv2.VideoCapture("/content/drive/My Drive/Skipper/DrStone-OP1.webm")
episode = cv2.VideoCapture("/content/drive/My Drive/Skipper/[Erai-raws] Dr. Stone - 06 [720p].mkv")
# Get First
opening.set(1, 0)
off_ret, opening_firstframe = opening.read()
opening_firstframe = cv2.cvtColor(opening_firstframe, cv2.COLOR_BGR2GRAY)
# (H, W) = opening_firstframe.shape
# Iterate over the episode
while episode.isOpened():
ep_ret, ep_frame = episode.read()
if ep_ret:
frames = episode.get(cv2.CAP_PROP_POS_FRAMES)
#ep_frame = cv2.resize(ep_frame, (W, H))
ep_frame = cv2.cvtColor(ep_frame, cv2.COLOR_BGR2GRAY)
sim_index = ssim(opening_firstframe, ep_frame) * 100
print(str(frames) + " : " + str(sim_index))
else:
break
print("--- %s seconds ---" % (time.time() - start_time))
【问题讨论】:
-
你想如何比较它们?位准确吗?实时 ?请提供最小代码
-
@ma3oun 代码添加
-
您可以启动四个线程或进程,或者您的 CPU 有多少个内核,然后将帧循环传递给每个线程/进程。
标签: python opencv image-comparison