AppleScript C Perl Shell Xcode Other

4K time-lapse photography on a budget

Post Reply
coding / perl     Views: 792Prev .. Next
4K time-lapse photography on a budgetPosted: Monday, April 27, 2020 [21:09:03] - 1
rootPosted by:rootMember Since:
June 16 2010
Posts: 357
Project budget:
gPhoto2 - free
Canon PowerShot SX110IS 9MP camera ~ $30 eBay
Raspberry Pi - $35 +S/H
Total: $60-75

4K time-lapse photography on a budget

Any programming language will do, but Perl is our passion due to ease of implementing and widest availability in UNIX environment.
This is just a test script. It is not finished but works like a charm.
View Code#!/usr/bin/perl
print "Take image every number of seconds (minimum 7): ";
my $often = <STDIN>;$often =~ s/\D//g;
unless($often) {$often=7;}
if($often < 7) {$often=7;}
print "Take number of images (nothing for infinite): ";
my $noimges = <STDIN>;$noimges =~ s/\D//g;
if($noimges) {$noimges--;}

print "Run program in \"Auto (default)\"-Y \"Skip Settings\"-S \"Manual\"-N mode: [Y/S/N]\nIn Auto Mode the following values will be used:\n";
print "Aperture: F2.8\nISO: 100\nYour Choice: ";
my $automode = <STDIN>;$automode =~ s/\W//g;
unless($automode) {$automode='Y';}
our $shootingmode='';our $aperture=0;our $iso=2;
if($automode =~ m/n/i) {getmodes();
print "The following settings will be set to the camera:\n\tMode: $types{shootingmode}{$shootingmode}\n\tISO: $types{iso}{$iso}\n\tAperture: $types{aperture}{$aperture}\n";
} else {$shootingmode='0';}

my $program='gphoto2';## Making sure gphoto2 is not running which will prevent this program from running
open (IN, "ps axw |");while (<IN>) {
if (/$program/) {$_ =~ s/^\s+//;print "$program was runnig\n";my @spln=split(/ /,$_);my $jobid=shift(@spln);
print "Line: \"$_\"\nPID: $jobid\n";`kill -9 $jobid`;}
} ## WHILE END
close IN;
my $gphoto='/usr/local/bin';
my $totstart=time;
my $dest='/home/pi/MacPro/timelapse';# cd to the folder where you want to save images
# If time is not set on the camera - set it
my $camtime=time;$camtime -= 3600 * 9; # Adjust to your location time offset
`$gphoto/gphoto2 --set-config d034=$camtime`; # Set camera time
`$gphoto/gphoto2 --set-config imagequality=0`;# Superfine
`$gphoto/gphoto2 --set-config imagesize=0`;# Large
`$gphoto/gphoto2 --set-config exposurecompensation=6`;# none
`$gphoto/gphoto2 --set-config autorotation=1`;# Off

unless($automode =~ m/s/i) {
`$gphoto/gphoto2 --set-config shootingmode=2`;
`$gphoto/gphoto2 --set-config aperture=$aperture`;
`$gphoto/gphoto2 --set-config iso=$iso`;
`$gphoto/gphoto2 --set-config shootingmode=$shootingmode`;
if($shootingmode eq '1') {
`$gphoto/gphoto2 --set-config shutterspeed=$shutterspeed`;
`$gphoto/gphoto2 --set-config aperture=$aperture`;
}
if($shootingmode eq '0') {
`$gphoto/gphoto2 --set-config aperture=0`;
}
} ## END UNLESS SKIP

my $noshots=0;my $frdel=time;
while(1) {$noshots++;$frdel = time;
print "$noshots\. $gphoto/gphoto2 --capture-image-and-download\n";
`$gphoto/gphoto2 --capture-image-and-download`;
my $donesh=time;my $imlps = $donesh - $frdel;print "\tshot in $imlps sec";
my $sleep = $often - $imlps;
if($noshots > $noimges && $noimges) {print "\nDone $noshots images, program exiting\n";last;}
if($sleep > 0) {print "\tSleeping for $sleep";sleep($sleep);}
print "\n";
} ## FOR END

my $totend=time;
my $proglapse = $totend - $totstart;
my $runfor = cnvrtsecs($proglapse);

print "Program was running for $runfor\n";

sub getmodes { ######
our %types = ('aperture'=> {'0','2.8','1','3.2','2','3.5','3','4','4','4.5','5','5','6','5.6','7','6.3','8','7.1','9','8'},
'iso'=>{'0','Auto','1','80','2','100','3','200','4','400','5','800','6','1600'},
'shootingmode'=>{'0','Auto','1','TV','2','AV','3','Manual'}
);
my @readby = qw(shootingmode iso aperture);
foreach my $tp (@readby) {
if($tp eq 'aperture' && $shootingmode ne '2') {next;}
print "Enter choice for \"$tp\":\n";
foreach my $nmb (sort num keys %{$types{$tp}}) {
print "$nmb:\t$types{$tp}{$nmb}\n";
} ## FOREACH NUMBER
my $val = <STDIN>;$val =~ s/\D//g;
unless($types{$tp}{$val}) {print "\nValue $val for $tp is not valid - exit\n";exit(0);}
$$tp=$val;
} ## FOREACH TYPE END
if($shootingmode eq '1') {$aperture='1';}
} ## END GET MODES ##

sub num {$a <=> $b;}

sub cnvrtsecs {
my $s=shift;
return sprintf "%02d seconds", $s if $s < 60;
my $m = $s / 60; $s = $s % 60;
return sprintf "%02d minutes %02d seconds", $m, $s if $m < 60;
my $h = $m / 60; $m %= 60;
return sprintf "%02d hours %02d minutes %02d seconds", $h, $m, $s if $h < 24;
my $d = $h / 24; $h %= 24;
return sprintf "%d days %02d hours %02d minutes %02d seconds", $d, $h, $m, $s;
} ## END BACK TO MINUTES

Mounted storage can be used to save all images to a bigger Hard Drive. More on AFP share:
www.codemacs.com/raspberr..
To use external power supply for your Canon camera check ThingiVerse to see how adapter can be made or our AA Battery PS solution:
www.codemacs.com/other/an..There's no place like ~
4K time-lapse photography on a budget - working Perl programPosted: Thursday, April 30, 2020 [00:10:12] - 2
rootPosted by:rootMember Since:
June 16 2010
Posts: 357
This Perl program tested on Canon PowerShot SX110IS camera.
View Code#!/usr/bin/perl
use strict;
print "Take image every number of seconds (minimum 7): ";
my $often = <STDIN>;$often =~ s/\D//g;
unless($often) {$often=7;}
if($often < 7) {$often=7;}
print "Take number of images (nothing for infinite): ";
my $noimges = <STDIN>;$noimges =~ s/\D//g;
if($noimges) {$noimges--;}

my $program='gphoto2';
open (IN, "ps axw |");while (<IN>) {
if (/$program/) {$_ =~ s/^\s+//;print "$program was runnig\n";my @spln=split(/ /,$_);my $jobid=shift(@spln);
print "Line: \"$_\"\nPID: $jobid\n";`kill -9 $jobid`;}
} ## WHILE END
close IN;
my $totstart=time;
my $dest='/home/pi/MacPro/timelapse';
unless(-d $dest) {`mkdir $dest`;print "Created folder $dest\n";}
my $gphoto='/usr/local/bin';# Adjust path to your gphoto2 location - "which gphoto2"

getmodes();

my $noshots=0;my $frdel=time;
while(1) {$noshots++;$frdel = time;
print "$noshots\. $gphoto/gphoto2 --capture-image-and-download\n";
`$gphoto/gphoto2 --capture-image-and-download`;
my $donesh=time;my $imlps = $donesh - $frdel;print "\tshot in $imlps sec";
my $sleep = $often - $imlps;
if($noshots > $noimges && $noimges) {print "\nDone $noshots images, program exiting\n";last;}
if($sleep > 0) {print "\tSleeping for $sleep";sleep($sleep);}
print "\n";
} ## FOR END

my $totend=time;
my $proglapse = $totend - $totstart;
my $runfor = cnvrtsecs($proglapse);

print "Program was running for $runfor\n";

sub getmodes { ######

my %settings = (
'0' => {
'name','Auto',
'iso' => {
'0','Auto',
'1','80',
'2','100',
'3','200',
'4','400',
'5','800',
'6','1600'
}
},
'1' => {
'name','TV',
'shutterspeed' => {
'0','15',
'1','13',
'2','10',
'3','8',
'4','6',
'5','5',
'6','4',
'7','3.2',
'8','2.5',
'9','2',
'10','1.6',
'11','1.3',
'12','1',
'13','0.8',
'14','0.6',
'15','0.5',
'16','0.4',
'17','0.3',
'18','1/4',
'19','1/5',
'20','1/6',
'21','1/8',
'22','1/10',
'23','1/13',
'24','1/15',
'25','1/20',
'26','1/25',
'27','1/30',
'28','1/40',
'29','1/50',
'30','1/60',
'31','1/80',
'32','1/100',
'33','1/125',
'34','1/160',
'35','1/200',
'36','1/250',
'37','1/320',
'38','1/400',
'39','1/500',
'40','1/640',
'41','1/800',
'42','1/1000',
'43','1/1250',
'44','1/1600',
'45','1/2000',
'46','1/2500'
},
'iso' => {
'0','Auto',
'1','80',
'2','100',
'3','200',
'4','400',
'5','800',
'6','1600'
}
},
'2' => {
'name','AV',
'aperture' => {
'0','2.8',
'1','3.2',
'2','3.5',
'3','4',
'4','4.5',
'5','5',
'6','5.6',
'7','6.3',
'8','7.1',
'9','8'
},
'iso' => {
'0','Auto',
'1','80',
'2','100',
'3','200',
'4','400',
'5','800',
'6','1600'
}
},
'3' => {
'name','Manual',
'shutterspeed' => {
'0','15',
'1','13',
'2','10',
'3','8',
'4','6',
'5','5',
'6','4',
'7','3.2',
'8','2.5',
'9','2',
'10','1.6',
'11','1.3',
'12','1',
'13','0.8',
'14','0.6',
'15','0.5',
'16','0.4',
'17','0.3',
'18','1/4',
'19','1/5',
'20','1/6',
'21','1/8',
'22','1/10',
'23','1/13',
'24','1/15',
'25','1/20',
'26','1/25',
'27','1/30',
'28','1/40',
'29','1/50',
'30','1/60',
'31','1/80',
'32','1/100',
'33','1/125',
'34','1/160',
'35','1/200',
'36','1/250',
'37','1/320',
'38','1/400',
'39','1/500',
'40','1/640',
'41','1/800',
'42','1/1000',
'43','1/1250',
'44','1/1600'
},
'aperture' => {
'0','2.8',
'1','3.2',
'2','3.5',
'3','4',
'4','4.5',
'5','5',
'6','5.6',
'7','6.3',
'8','7.1',
'9','8'
},
'iso' => {
'0','80',
'1','100',
'2','200',
'3','400',
'4','800',
'5','1600'
}
}
);

print "Select shooting mode\n";
foreach my $mode (sort keys (%settings)) {my $moden = $mode;$moden++;
print "\t$moden\t$settings{$mode}{name}\n";
} ## FOREACH MODE END
print "\tS\tKeep Existing Settings\nYour Selection: ";
my $mdsel = <STDIN>;$mdsel =~ s/\D//g;$mdsel =~ s#5##g;
if($mdsel) {$mdsel--;

my $camtime=time;$camtime -= 3600 * 9;
`$gphoto/gphoto2 --set-config shootingmode=0`;# temporary switch mode so settings below can be changed
`$gphoto/gphoto2 --set-config d034=$camtime`;# set camera time
`$gphoto/gphoto2 --set-config imagequality=0`;# Superfine image quality
`$gphoto/gphoto2 --set-config imagesize=0`;# Large image size
`$gphoto/gphoto2 --set-config exposurecompensation=6`;# none - no exposure compensation
`$gphoto/gphoto2 --set-config autorotation=1`;# Off - do not auto rotate images

`$gphoto/gphoto2 --set-config shootingmode=$mdsel`;
print "Please choose appropriate settings for \"$settings{$mdsel}{name}\" mode:\n";
foreach my $settype (sort keys %{$settings{$mdsel}}) {
if($settype eq 'name') {next;}
my $settypepr=$settype;$settypepr =~ s/\b\w/\u$&/g;
print "$settypepr\n";
foreach my $stkey (sort num keys %{$settings{$mdsel}{$settype}}) {
print "\t$stkey\t$settings{$mdsel}{$settype}{$stkey}\n";
} ## FOREACH SET KEY END
my $currvalue = `$gphoto/gphoto2 --get-config $settype | grep "Current:"`;$currvalue =~ s#Current: ##;chomp $currvalue;
print "Current value: $currvalue\n";
print "Enter value: ";
my $keyselected = <STDIN>;$keyselected =~ s/\D//g;
if($keyselected) {`$gphoto/gphoto2 --set-config $settype=$keyselected`;}
} ## FOREACH TYPE OF SETTING END
} ## END IF SHOOTING MODE PRESENT
} ## END GET VALUES

sub num {$a <=> $b;}

sub cnvrtsecs {
my $s=shift;
return sprintf "%02d seconds", $s if $s < 60;
my $m = $s / 60; $s = $s % 60;
return sprintf "%02d minutes %02d seconds", $m, $s if $m < 60;
my $h = $m / 60; $m %= 60;
return sprintf "%02d hours %02d minutes %02d seconds", $h, $m, $s if $h < 24;
my $d = $h / 24; $h %= 24;
return sprintf "%d days %02d hours %02d minutes %02d seconds", $d, $h, $m, $s;
} ## END BACK TO MINUTES


Code produced no errors and runs stable.
Settings hash was taken from actual settings for each Shooting Mode after running
View Codegphoto2 --list-all-config > settings.txt


and running simple Perl to prep for hash code:
View Code#!/usr/bin/perl
use strict;
my @all = glob("/Users/User/Desktop/my_folder/time.lapse.camera/*");
foreach my $f (@all) {
unless($f =~ m/settings\./) {next;}
print "$f\n";my $d = `cat $f`;
$d =~ s#(Choice: )(.*?) (.*?)\n#'$2','$3',\n#gs;
open(T,">$f");print T $d;close(T);
} ## FOREACH FILE END


Any ideas and input are welcome.There's no place like ~
coding / perlPrev .. Next
 
Post Reply
Home - Coding: AppleScript C Perl Shell Xcode Other
Our Telegram Group