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.
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.
|