functions.py 文件源码

python
阅读 19 收藏 0 点赞 0 评论 0

项目:scene_detection 作者: VieVie31 项目源码 文件源码
def get_joly_scenes_sementation(imgs, nb_std_above_mean_th=5.):
    """This function return the a list of potential scene chament segmentation without perceptual hash function.

    :param imgs: the list of frames (in grayscale) of the video to segment
    :param nb_std_above_mean_th: number of std above the mean of differences between frame to set a segmentation threshold    
    :type imgs: list(np.array)
    :type nb_std_above_mean_th: float

    :return: the list of indexes of begining / ending sequences...
    :rtype: list(tupple)
    """
    #compute diff between images
    diffs = [0]

    im1 = rgb2grey(resize(imgs[0], (8, 8)))
    im1 = (im1 - im1.min()) / (im1.max() - im1.min()) * 255 #dynamic expension
    for i in range(len(imgs) - 1):
        im2 = rgb2grey(resize(imgs[i + 1], (8, 8)))
        im2 = (im2 - im2.min()) / (im2.max() - im2.min()) * 255
        diffs.append(abs(im1 - im2).sum())
        im1 = im2

    diffs = np.array(diffs)

    scene_change_threshold = diffs.mean() + diffs.std() * nb_std_above_mean_th

    #make the scene segmentation
    scenes = []
    changes = diffs > scene_change_threshold #list(bollinger(diffs, lag=5, th=nb_std_above_mean_th)) 
    sequence_begining = 0
    for i in range(len(changes)):
        if changes[i]:
            scenes.append((sequence_begining, i))
            sequence_begining = i

    return scenes
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号