Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

Comment on

( #3333=superdoc: print w/ replies, xml ) Need Help??

This literally builds upon the excellent solution offered by roboticus. The next step is to get the EXIF date/time info from the image files, and convert that into seconds (the directory read is non-recursive):

use strict; use warnings; use Image::ExifTool qw(:Public); use Date::Calc qw/Date_to_Time/; my $imageDir = './images'; my %timeFiles; ### Read each file's EXIF info and convert to seconds ### A Hash of Arrays (HoA) is used in case images have the same time for my $image (<$imageDir/*>) { # Skip image if no DateTimeOriginal info (highly unlikely) next unless my $dateTime = ImageInfo($image)->{DateTimeOriginal}; # Convert 'YYYY:MM:DD HH:MM:SS' to seconds my $time = Date_to_Time( split /[:\s]/, $dateTime ); push @{ $timeFiles{$time} }, $image; } ### <roboticus code> ### Sort the times from the hash my @times = sort { $a<=>$b } keys %timeFiles; ### Group together the pix whose time is less than MAX_TIME_DIFF secon +ds ### apart my $MAX_TIME_DIFF=10; # Minimum time between photos my $MIN_GRP_SIZE=3; # Minimum "interesting" group size my @groups; my $cur_group = [ shift @times ]; while (@times) { if ($$cur_group[-1]+$MAX_TIME_DIFF >= $times[0]) { # small interval, add to current group push @$cur_group, shift @times; } else { # store last group (if interesting) and start # a new one. push @groups, $cur_group if @$cur_group >= $MIN_GRP_SIZE; $cur_group = [ shift @times ]; } } ### </roboticus code> ### Get each group for my $group(@groups){ # The time in each group for my $time(@$group){ # The hash value is an array ref # $_ takes the value of each array element, viz., a file name print "$_: $time\n" for @{ $timeFiles{$time} }; } # Print blank lines between groups print "\n\n"; }

Partial output:

./images/IMG_7139.CR2: 1336823075 ./images/IMG_7140.CR2: 1336823077 ./images/IMG_7141.CR2: 1336823079 ./images/IMG_7142.CR2: 1336823082 ./images/IMG_7143.CR2: 1336823084 ./images/IMG_7144.CR2: 1336823086 ./images/IMG_7145.CR2: 1336823088 ./images/IMG_7152.CR2: 1336823437 ./images/IMG_7153.CR2: 1336823442 ./images/IMG_7154.CR2: 1336823446 ./images/IMG_7155.CR2: 1336823451 ./images/IMG_7156.CR2: 1336823455 ./images/IMG_7157.CR2: 1336823467 ./images/IMG_7158.CR2: 1336823470 ./images/IMG_7159.CR2: 1336823473 ./images/IMG_7160.CR2: 1336823653 ./images/IMG_7161.CR2: 1336823657 ./images/IMG_7162.CR2: 1336823661 ./images/IMG_7163.CR2: 1336823664 ./images/IMG_7164.CR2: 1336823667

I actually use Hugin (excellent pano app!) and this directory read shows names of images that Hugin eventually stitched into a wonderful pano.


In reply to Re: Group file per time interval by Kenosis
in thread Group file per time interval by raiten

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?
    Username:
    Password:

    What's my password?
    Create A New User
    Chatterbox?
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others avoiding work at the Monastery: (6)
    As of 2015-07-05 00:00 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









      Results (60 votes), past polls