【问题标题】:What's fastest way to compare image in python with opencv [closed]将python中的图像与opencv进行比较的最快方法是什么[关闭]
【发布时间】: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


【解决方案1】:

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-08-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-10-31
    相关资源
    最近更新 更多