【问题标题】:OpenCv - create mask from edge - crop and save imageOpenCv - 从边缘创建蒙版 - 裁剪并保存图像
【发布时间】:2019-04-30 15:03:35
【问题描述】:

我有一个带有不透明徽标的视频,我的目标是识别保持静止的图像区域并将其提取。

这是我的代码:

import cv2
import numpy as np
import imutils
c = cv2.VideoCapture('sky.mp4')
_,f = c.read()
avg2 = np.float32(f)
while(1):
    _,f = c.read()
    cv2.accumulateWeighted(f,avg2,0.005)
    #cv2.accumulateWeighted(f,avg2,0.01)
    res2 = cv2.convertScaleAbs(avg2)

    # load the query image, compute the ratio of the old height
    # to the new height, clone it, and resize it
    ratio = res2.shape[0] / 300.0
    orig = res2.copy()
    res2 = imutils.resize(res2, height = 600)   

    # convert the image to grayscale, blur it, and find edges
    # in the image
    gray = cv2.cvtColor(res2, cv2.COLOR_BGR2GRAY)
    gray = cv2.bilateralFilter(gray, 11, 17, 17)
    edged = cv2.Canny(gray, 30, 200)    

    cv2.imshow('img',f)
    cv2.imshow('avg2',edged)
    k = cv2.waitKey(20)

    if k == 27:
        break
cv2.destroyAllWindows()
c.release()

cv2.accumulateWeighted 函数在经过一段时间后,可以清楚地识别出大部分仍留在框架上的部分。 原始框架部分:

边缘平均帧部分:

如何为整个平均边缘部分创建蒙版,将其裁剪并保存在单独的图像中?

【问题讨论】:

    标签: python opencv


    【解决方案1】:

    您可以使用cv2.findContours() 进行连通分量分析。然后使用cv2.boundingRect() 获取边界框。然后,您可以使用 Numpy 切片使用 img[r1:r2, c1:c2] 裁剪图像。

    【讨论】:

    • Thx,有没有一种简单的方法来评估矩形形状女巫在时间/帧内保持固定位置(带阈值)?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-06-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多