4K time-lapse photography on a budget
Post Reply4K time-lapse photography on a budgetPosted: Monday, April 27, 2020 [21:09:03] - 1
Project budget: gPhoto2 - free Canon PowerShot SX110IS 9MP camera ~ $30 eBay Raspberry Pi - $35 +S/H Total: $60-75 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. print "Take image every number of seconds (minimum 7): "; my $often = <STDIN>; unless($often) {$often=7;} if($often < 7) {$often=7;} print "Take number of images (nothing for infinite): "; my $noimges = <STDIN>; 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>; unless($automode) {$automode='Y';} our $shootingmode=''; 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'; open (IN, "ps axw |"); if (/$program/) {$_ =~ s/^\s+//; print "Line: \"$_\"\nPID: $jobid\n"; } ## WHILE END close IN; my $gphoto='/usr/local/bin'; my $totstart=time; my $dest='/home/pi/MacPro/timelapse'; # If time is not set on the camera - set it my $camtime=time; `$gphoto/gphoto2 --set-config d034=$camtime`; # Set camera time `$gphoto/gphoto2 --set-config imagequality=0`; `$gphoto/gphoto2 --set-config imagesize=0`; `$gphoto/gphoto2 --set-config exposurecompensation=6`; `$gphoto/gphoto2 --set-config autorotation=1`; 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; while(1) {$noshots++; print "$noshots\. $gphoto/gphoto2 --capture-image-and-download\n"; `$gphoto/gphoto2 --capture-image-and-download`; my $donesh=time; my $sleep = $often - $imlps; if($noshots > $noimges && $noimges) {print "\nDone $noshots images, program exiting\n"; if($sleep > 0) {print "\tSleeping for $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>; unless($types{$tp}{$val}) {print "\nValue $val for $tp is not valid - exit\n"; $$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.. |
4K time-lapse photography on a budget - working Perl programPosted: Thursday, April 30, 2020 [00:10:12] - 2
This Perl program tested on Canon PowerShot SX110IS camera. use strict; print "Take image every number of seconds (minimum 7): "; my $often = <STDIN>; unless($often) {$often=7;} if($often < 7) {$often=7;} print "Take number of images (nothing for infinite): "; my $noimges = <STDIN>; if($noimges) {$noimges--;} my $program='gphoto2'; open (IN, "ps axw |"); if (/$program/) {$_ =~ s/^\s+//; print "Line: \"$_\"\nPID: $jobid\n"; } ## WHILE END close IN; my $totstart=time; my $dest='/home/pi/MacPro/timelapse'; unless(-d $dest) {`mkdir $dest`; my $gphoto='/usr/local/bin'; getmodes(); my $noshots=0; while(1) {$noshots++; print "$noshots\. $gphoto/gphoto2 --capture-image-and-download\n"; `$gphoto/gphoto2 --capture-image-and-download`; my $donesh=time; my $sleep = $often - $imlps; if($noshots > $noimges && $noimges) {print "\nDone $noshots images, program exiting\n"; if($sleep > 0) {print "\tSleeping for $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; print "\t$moden\t$settings{$mode}{name}\n"; } ## FOREACH MODE END print "\tS\tKeep Existing Settings\nYour Selection: "; my $mdsel = <STDIN>; if($mdsel) {$mdsel--; my $camtime=time; `$gphoto/gphoto2 --set-config shootingmode=0`; `$gphoto/gphoto2 --set-config d034=$camtime`; `$gphoto/gphoto2 --set-config imagequality=0`; `$gphoto/gphoto2 --set-config imagesize=0`; `$gphoto/gphoto2 --set-config exposurecompensation=6`; `$gphoto/gphoto2 --set-config autorotation=1`; `$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; 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:"`; print "Current value: $currvalue\n"; print "Enter value: "; my $keyselected = <STDIN>; 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 and running simple Perl to prep for hash code: 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"; $d =~ s#(Choice: )(.*?) (.*?)\n#'$2','$3',\n#gs; open(T,">$f"); } ## FOREACH FILE END Any ideas and input are welcome. |