gpt4 book ai didi

python - 在视频中查找与图像匹配的帧

转载 作者:行者123 更新时间:2023-12-01 21:59:25 25 4
gpt4 key购买 nike

我正在尝试使用 opencv 查找与图像匹配的帧。我还想找到找到图像的时间范围。该视频是蒙面视频。到目前为止的代码:

 def occurence_counter(self):
img = cv2.imread('ref_img.jpg', cv2.IMREAD_COLOR)
# shrink
img = cv2.resize(img, (10, 10))
# convert to b&w
img = color.rgb2gray(img)
similarities = []

result = self.parse_video(img, str(self.lineEdit.text()).strip(), 1, False)
print result

def parse_video(self, image, video, n_matches, break_point=False,
verbose=False):

similarities = [{'frame': 0, 'similarity': 0}]
frame_count = 0

cap = cv2.VideoCapture(video)
while cap.isOpened():

ret, frame = cap.read()

if type(frame) == type(None):
break

# increment frame counter
frame_count += 1

# resize current video frame
small_frame = cv2.resize(frame, (10, 10))
# convert to greyscale
small_frame_bw = color.rgb2gray(small_frame)

最佳答案

找到相同的框架并不是那么容易的问题。有许多可能的解决方案。我将在此处以非常笼统的方式描述可能的解决方案。

Template Matching

模板匹配是计算图像中相应像素的相似度的算法。因此,如果您正在寻找非常相似的图像(没有旋转、平移、大的强度变化),它并不是那么糟糕的算法。对于整个图像来说并不是那么快。它主要用于在多张图像上查找相同的片段或在较大的图像上查找较小的图像,而不是检查两个图像的相似性。 https://opencv-python-tutroals.readthedocs.io/en/latest/py_tutorials/py_imgproc/py_template_matching/py_template_matching.html

对于整幅图像,简单地减去图像然后使用模板匹配会更容易。它要快得多。必须假设它们确实彼此相似。

Histogram Comparision

您可以使用直方图比较。这是最快的方法,但不准确。草和苹果都是绿色的,但彼此不同。在涉及颜色时,通常最好使用 HSV 颜色空间。 https://docs.opencv.org/3.4.1/d8/dc8/tutorial_histogram_comparison.html

Feature matching

算法是在图像上搜索相似的特征点。有许多算法可以在图像上查找特征。它们应该对比例变化和旋转等不敏感。但这取决于特征提取算法。 https://docs.opencv.org/3.0-beta/doc/py_tutorials/py_feature2d/py_features_meaning/py_features_meaning.html#features-meaning

Other alogithms

其他算法是 PSNR 或 SSIM。我从来没有用过它,但它被用来计算原始图像和模糊图像的相似性或整个视频序列的相似性。 https://docs.opencv.org/3.4.2/d5/dc4/tutorial_video_input_psnr_ssim.html

您也可以尝试比较图像的哈希值。这是非常有趣的算法(对我来说),但没有很好的记录。 https://www.pyimagesearch.com/2017/11/27/image-hashing-opencv-python/

特征匹配是此类任务最常用的算法。原因是当从不同角度、不同条件或仅部分重叠拍摄图像时,特征匹配算法可以检测到相似的图像片段。 Structure From Motion 算法通常使用特征匹配。 https://hub.packtpub.com/exploring-structure-motion-using-opencv/问题的解决方案始终取决于我们拥有的数据。所以没有一个答案。

关于python - 在视频中查找与图像匹配的帧,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54236427/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com