source: other-projects/diy-streetview-pano-capture/trunk/Server/classes/console/capture_cameras.pm@ 26886

Last change on this file since 26886 was 26886, checked in by davidb, 11 years ago

Bug fixes after testing on new laptop

File size: 4.3 KB
Line 
1#!/usr/bin/perl -w
2use warnings;
3use strict;
4
5use UUID;
6use File::HomeDir;
7use IO::Socket;
8use Net::hostent;
9use threads;
10use Thread::Queue;
11
12package 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 print "Aborting Capture!\n";
103 return;
104 }
105
106 if (system("uvcdynctrl -d $cameras[$count_cameras] --set='Focus, Auto' 0;
107 uvcdynctrl -d $cameras[$count_cameras] --set='Focus (absolute)' $focus;
108 uvcdynctrl -d $cameras[$count_cameras] --set='Brightness' $brightness;
109 uvcdynctrl -d $cameras[$count_cameras] --set='Exposure, Auto' 1;
110 uvcdynctrl -d $cameras[$count_cameras] --set='Exposure (Absolute)' $exposure;"))
111 {
112 print "WARNING: Camera initilisation returned errors!\n";
113 }
114
115 my $device_path = `udevadm info --query=path -n /dev/$cameras[$count_cameras]`;
116 my @device_info = split(/\//, $device_path);
117 #If my webcams could support it I would make a way for the cameras to be just as cool as Rainbow Dash
118 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"))
119 {
120 print $main::socket "{ \"success\":false }\n";
121 die(1);
122 }
123 else
124 {
125 print $main::socket "{ \"captured\":",$count_cameras + 1," }\n";
126 }
127
128 $count_cameras++;
129 }
130 print $main::socket "{ \"success\":true, \"set\":\"",$guid,"\" }\n";
131 print "Captured set $guid\n";
132 }
133
134 sub defaultsettings
135 {
136 return undef;
137 }
138
1391;
140}
Note: See TracBrowser for help on using the repository browser.