【问题标题】:Grouping Timelapses by time difference algorithm按时差算法对 Timelapses 进行分组
【发布时间】:2019-02-07 03:53:19
【问题描述】:

我正在尝试编写一个程序,将 Timelapse 照片的时间戳分组在一起。延时照片和随机照片在一个文件夹中。

例如,如果上一张和当前照片之间的时间戳以秒为单位的差异为:346、850、13、14、13、14、15、12、12、13、16、11、438。

你可以合理猜测游戏中时光倒流从 13 点开始,到 11 点结束。

现在我正在尝试一个 hacky 解决方案来比较与前一个的百分比差异。

但必须有一个公式/算法通过时差将时间戳组合在一起。滚动意味着什么。

我是否正在寻找一个简单的解决方案? 谢谢!

def cat_algo(文件夹):

# Get a list with all the CR2 files in the folder we are processing
file_list = folder_to_file_list(folder)

# Extract the timestamp out of the CR2 file into a sorted dictionary
cr2_timestamp = collections.OrderedDict()
for file in file_list:
    cr2_timestamp[file] = return_date_from_raw(file)
    print str(file) + " - METADATA TIMESTAMP: " + \
        str(return_date_from_raw(file))

# Loop over the dictionary to compare the timestamps and create a new dictionary with a suspected group number per shot
# Make sure we know that there is no first file yet using this (can be refractored)
item_count = 1
group_count = 0
cr2_category = collections.OrderedDict()
# get item and the next item out of the sorted dictionary
for item, nextitem in zip(cr2_timestamp.items(), cr2_timestamp.items()[1::]):

    # if not the first CR2 file
    if item_count >= 2:
        current_date_stamp = item[1]
        next_date_stamp = nextitem[1]

        delta_previous = current_date_stamp - previous_date_stamp
        delta_next = next_date_stamp - current_date_stamp

        try:
            difference_score = int(delta_next.total_seconds() /
                                   delta_previous.total_seconds() * 100)
            print "diffscore: " + str(difference_score)
        except ZeroDivisionError:
            print "zde"

        if delta_previous > datetime.timedelta(minutes=5):
            # if difference_score < 20:
            print item[0] + " - hit - " + str(delta_previous)
            group_count += 1
            cr2_category[item[0]] = group_count
        else:
            cr2_category[item[0]] = group_count

            # create a algo to come up with percentage difference and use this to label timelapses.
        print int(delta_previous.total_seconds())
        print int(delta_next.total_seconds())

        # Calculations done, make the current date stamp the previous datestamp for the next iteration
        previous_date_stamp = current_date_stamp

        # If time difference with previous over X make a dict with name:number, in the end everything which has the
        # same number 5+ times in a row can be assumed as a timelapse.

    else:
        # If it is the first date stamp, assign it the current one to be used in the next loop
        previous_date_stamp = item[1]

    # To help make sure this is not the first image in the sequence.
    item_count += 1

print cr2_category

【问题讨论】:

    标签: python algorithm sorting grouping


    【解决方案1】:

    如果您使用 itertools.groupby,如果延迟符合您的延时摄影区域标准,则使用返回 True 的函数,根据延迟列表,您可以获得每个此类区域的索引。基本上,我们根据该函数的 True/False 输出进行分组。

    from itertools import groupby
    
    # time differences given in original post
    data = [346, 850, 13, 14, 13, 14, 15, 12, 12, 13, 16, 11, 438]
    
    MAX_DELAY = 25 # timelapse regions will have a delay no larger than this
    MIN_LENGTH = 3 # timelapse regions will have at least this many photos
    
    index = 0
    for timelapse, g in groupby(data, lambda x: x <= MAX_DELAY):
        length = len(list(g))
        if (timelapse and length > MIN_LENGTH):
            print ('timelapse index {}, length {}'.format(index, length))
        index += length
    

    输出:

    延时索引 2,长度 10

    【讨论】:

    • 调整参数以适应口味
    • 谢谢,但是如果输入是一个排序字典,其中包含多个延时,我可以调整什么来使上述工作正常工作?例如字典。可以包含镜头之间时差为 45 秒的延时摄影,也可以包含时差为 2 秒的延时摄影。
    • 听起来是个不同的问题。可能想用一些示例数据发布它并在评论中标记我。根据精度以及它们的快照以毫秒为单位的接近程度,可能有可能检测到周期(几乎没有误报),或者不可能。但是提前解决它会更聪明——在里面放一些相机元数据,或者给不同的相机自己的文件夹。 (您对这个问题的答案不满意吗?)
    • 可能我描述的情况太简单了。我将再次发布一个真实世界的例子。我认为这可以通过查看百分比差异(在序列或前一张照片上?)而不是时间差来解决,并且知道延时总是由 5 张以上的照片组成,时间差的差异最小。一些误报并不是一个大问题。在卸载过程中和使用元数据实际上有更好的方法来解决它,但在这种情况下,它是关于对已经使用脚本卸载的时间流逝进行排序。
    • 无法标记你,所以这里是链接:stackoverflow.com/questions/54688708/… 谢谢你到目前为止的帮助。
    猜你喜欢
    • 2023-02-04
    • 1970-01-01
    • 2019-07-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-09-28
    • 2014-08-27
    • 1970-01-01
    相关资源
    最近更新 更多