navneeth
navneeth

Reputation: 1317

Bin photos by time taken

I have a set of 5 cameras that operate independently of each other. I need to bin the photo's into a groups of 5 images, taken within say a 1 second window. I have access to the exif tags and can identify the image capture time.

What is the best way to do it ? A psuedo-python code solution is preferred.

Eg.Input:

Cam1 = [002.jpg, 003,jpg, 008.jpg ...]
Cam2 = [005.jpg, 023,jpg, 081.jpg ...]
Cam3 = [014.jpg, 013,jpg, 009.jpg ...]
Cam4 = [011.jpg, 034,jpg, 049.jpg ...]
Cam5 = [001.jpg, 056,jpg, 081.jpg ...]

Expected output:

Grouped = [[002.jpg, 023.jpg, 013.jpg, 049.jpg, 056.jpg], ......]

Here the elements of Grouped[0] all have the same time time stamp.

Upvotes: 0

Views: 49

Answers (1)

parchment
parchment

Reputation: 4002

Get the difference between the capture time and a defined starting time in seconds and put the images in a dictionary with that key.

image_dict = collections.defaultdict(list)

for image in images:
    # Will return float
    diff = (capture_time - starting_time).total_seconds()

    image_dict[int(diff)].append(image)

Then you can convert it to your preferred format:

final = []
for key in sorted(image_dict.keys()):
    final.append(image_dict[key])

Upvotes: 1

Related Questions