在OpenCV中比较python中图像的最快方法

时间:2019-08-12 08:56:27

标签: python opencv image-comparison

我必须将视频的所有帧与一张图像进行比较,并且使用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))

1 个答案:

答案 0 :(得分:1)

您可以使用均方误差(mse)或峰值信号与噪声比(psnr)来比较图像。它们通常用于衡量编解码器的质量。