[26882] | 1 | #!/usr/bin/perl -w
|
---|
| 2 | use warnings;
|
---|
| 3 | use strict;
|
---|
| 4 |
|
---|
| 5 | use UUID;
|
---|
| 6 | use File::HomeDir;
|
---|
| 7 | use IO::Socket;
|
---|
| 8 | use Net::hostent;
|
---|
| 9 | use threads;
|
---|
| 10 | use Thread::Queue;
|
---|
| 11 |
|
---|
| 12 | package capture_cameras
|
---|
| 13 | {
|
---|
| 14 | my $server;
|
---|
| 15 | my $queue = Thread::Queue -> new;
|
---|
| 16 | sub new
|
---|
| 17 | {
|
---|
| 18 | my $class = shift;
|
---|
| 19 | my $self = {};
|
---|
| 20 | bless($self, $class);
|
---|
| 21 | return $self;
|
---|
| 22 | }
|
---|
| 23 |
|
---|
| 24 | sub command
|
---|
| 25 | {
|
---|
| 26 | return "Capture";
|
---|
| 27 | }
|
---|
| 28 |
|
---|
| 29 | sub doupstart
|
---|
| 30 | {
|
---|
| 31 | return 0;
|
---|
| 32 | }
|
---|
| 33 |
|
---|
| 34 | sub help
|
---|
| 35 | {
|
---|
| 36 | return "take images from all the cameras connected and output them to ~/DIY_Streetview/images [The directory will be created if it doesn't exist.]";
|
---|
| 37 | }
|
---|
| 38 |
|
---|
| 39 | sub do
|
---|
| 40 | {
|
---|
| 41 | my $home = File::HomeDir->my_home;
|
---|
| 42 | if (!-d "$home/DIY_Streetview/images")
|
---|
| 43 | {
|
---|
| 44 | if (system ("mkdir $home/DIY_Streetview/images")) { print "Failed to create required folder '~/DIY_Streetview/images'\n"; die(); }
|
---|
| 45 | }
|
---|
| 46 | #UUID is a Universaly Unique IDentifier
|
---|
| 47 | #GUID is a Globaly Unique IDentified
|
---|
| 48 | #GUID is another name for UUID
|
---|
| 49 | #Since $uuid will have the Raw UUID, $guid has the String version of the UUID
|
---|
| 50 |
|
---|
| 51 | my ($uuid, $guid);
|
---|
| 52 | UUID::generate($uuid);
|
---|
| 53 | UUID::unparse($uuid, $guid);
|
---|
| 54 |
|
---|
| 55 | my $gps = $main::settings{'gps'};
|
---|
| 56 | my $location;
|
---|
| 57 | my ($GPSLOGFILE, $time) = (undef,time());
|
---|
| 58 | open $GPSLOGFILE, ">>$home/DIY_Streetview/sets.log" or die "Cannot open GPS logfile: $!";
|
---|
| 59 |
|
---|
| 60 | if (defined($gps) && $gps->hasgps)
|
---|
| 61 | {
|
---|
| 62 | $location = $gps->locsv;
|
---|
| 63 | print $GPSLOGFILE "$time, $guid, $location\n";
|
---|
| 64 | }
|
---|
| 65 | else
|
---|
| 66 | {
|
---|
| 67 | $location = "No GPS Device detected at program start. Storing 0,0.";
|
---|
| 68 | print $GPSLOGFILE "$time, $guid, 0, 0\n";
|
---|
| 69 | }
|
---|
| 70 |
|
---|
| 71 | close $GPSLOGFILE;
|
---|
| 72 |
|
---|
| 73 | #Just so OSs don't choke on to many files in a folder.
|
---|
| 74 | my $imagepath = $guid;
|
---|
| 75 | $imagepath =~ s/-/\//g;
|
---|
| 76 |
|
---|
| 77 | if (!-d "$home/DIY_Streetview/images/$imagepath/")
|
---|
| 78 | {
|
---|
| 79 | my @dirs = split(/\//, $imagepath);
|
---|
| 80 | my $path = "$home/DIY_Streetview/images/";
|
---|
| 81 |
|
---|
| 82 | while (scalar(@dirs) > 0)
|
---|
| 83 | {
|
---|
| 84 | my $tmp = shift(@dirs);
|
---|
| 85 | $path = "$path/$tmp";
|
---|
| 86 | system ("mkdir $path");
|
---|
| 87 | }
|
---|
| 88 | }
|
---|
| 89 |
|
---|
| 90 | my @cameras = @{$main::plugins{'camera'}};
|
---|
| 91 | my %settings = %{$main::settings{'camera'}};
|
---|
| 92 | my $focus = $settings{'focus'};
|
---|
| 93 | my $brightness = $settings{'brightness'};
|
---|
| 94 | my $exposure = $settings{'exposure'};
|
---|
| 95 |
|
---|
| 96 | my $count_cameras = 0;
|
---|
| 97 | while ($count_cameras < scalar(@cameras))
|
---|
| 98 | {
|
---|
| 99 | if (!-e "/dev/$cameras[$count_cameras]")
|
---|
| 100 | {
|
---|
| 101 | print "ERROR: Camera ID: $count_cameras has been disconnected! Redetecting cameras.\n";
|
---|
| 102 | detect_cameras::do;
|
---|
| 103 | print "Aborting Capture!\n";
|
---|
| 104 | return;
|
---|
| 105 | }
|
---|
| 106 |
|
---|
| 107 | if (system("uvcdynctrl -d $cameras[$count_cameras] --set='Focus, Auto' 0;
|
---|
| 108 | uvcdynctrl -d $cameras[$count_cameras] --set='Focus (absolute)' $focus;
|
---|
| 109 | uvcdynctrl -d $cameras[$count_cameras] --set='Brightness' $brightness;
|
---|
| 110 | uvcdynctrl -d $cameras[$count_cameras] --set='Exposure, Auto' 1;
|
---|
| 111 | uvcdynctrl -d $cameras[$count_cameras] --set='Exposure (Absolute)' $exposure;"))
|
---|
| 112 | {
|
---|
| 113 | print "WARNING: Camera initilisation returned errors!\n";
|
---|
| 114 | }
|
---|
| 115 |
|
---|
| 116 | my $device_path = `udevadm info --query=path -n /dev/$cameras[$count_cameras]`;
|
---|
| 117 | my @device_info = split(/\//, $device_path);
|
---|
| 118 | #If my webcams could support it I would make a way for the cameras to be just as cool as Rainbow Dash
|
---|
| 119 | if (system("avconv -f video4linux2 -i /dev/$cameras[$count_cameras] -t 1 -vframes 1 -s hd1080 -vsync 1 -an $home/DIY_Streetview/images/$imagepath/image_$device_info[6].png -loglevel 'error' > /dev/null"))
|
---|
| 120 | {
|
---|
| 121 | print $main::socket "{ \"success\":false }\n";
|
---|
| 122 | die(1);
|
---|
| 123 | }
|
---|
| 124 | else
|
---|
| 125 | {
|
---|
| 126 | print $main::socket "{ \"captured\":",$count_cameras + 1," }\n";
|
---|
| 127 | }
|
---|
| 128 |
|
---|
| 129 | $count_cameras++;
|
---|
| 130 | }
|
---|
| 131 | print $main::socket "{ \"success\":true, \"set\":\"",$guid,"\" }\n";
|
---|
| 132 | print "Captured set $guid\n";
|
---|
| 133 | }
|
---|
| 134 |
|
---|
| 135 | sub defaultsettings
|
---|
| 136 | {
|
---|
| 137 | return undef;
|
---|
| 138 | }
|
---|
| 139 |
|
---|
| 140 | 1;
|
---|
| 141 | }
|
---|