-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebcam.php
388 lines (371 loc) · 21.6 KB
/
webcam.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
<!DOCTYPE html>
<?php
define('BASE_DIR', dirname(__FILE__));
require_once(BASE_DIR.'/config.php');
$config = array();
$debugString = "";
$options_mm = array('Average' => 'average', 'Spot' => 'spot', 'Backlit' => 'backlit', 'Matrix' => 'matrix');
$options_em = array('Off' => 'off', 'Auto' => 'auto', 'Night' => 'night', 'Nightpreview' => 'nightpreview', 'Backlight' => 'backlight', 'Spotlight' => 'spotlight', 'Sports' => 'sports', 'Snow' => 'snow', 'Beach' => 'beach', 'Verylong' => 'verylong', 'Fixedfps' => 'fixedfps');
$options_wb = array('Off' => 'off', 'Auto' => 'auto', 'Sun' => 'sun', 'Cloudy' => 'cloudy', 'Shade' => 'shade', 'Tungsten' => 'tungsten', 'Fluorescent' => 'fluorescent', 'Incandescent' => 'incandescent', 'Flash' => 'flash', 'Horizon' => 'horizon');
$options_ie = array('None' => 'none', 'Negative' => 'negative', 'Solarise' => 'solarise', 'Sketch' => 'sketch', 'Denoise' => 'denoise', 'Emboss' => 'emboss', 'Oilpaint' => 'oilpaint', 'Hatch' => 'hatch', 'Gpen' => 'gpen', 'Pastel' => 'pastel', 'Watercolour' => 'watercolour', 'Film' => 'film', 'Blur' => 'blur', 'Saturation' => 'saturation', 'Colourswap' => 'colourswap', 'Washedout' => 'washedout', 'Posterise' => 'posterise', 'Colourpoint' => 'colourpoint', 'ColourBalance' => 'colourbalance', 'Cartoon' => 'cartoon');
$options_ce_en = array('Disabled' => '0', 'Enabled' => '1');
$options_ro = array('No rotate' => '0', 'Rotate_90' => '90', 'Rotate_180' => '180', 'Rotate_270' => '270');
$options_fl = array('None' => '0', 'Horizontal' => '1', 'Vertical' => '2', 'Both' => '3');
$options_bo = array('Off' => '0', 'Background' => '2');
$options_av = array('V2' => '2', 'V3' => '3');
$options_at_en = array('Disabled' => '0', 'Enabled' => '1');
$options_ac_en = array('Disabled' => '0', 'Enabled' => '1');
$options_ab = array('Off' => '0', 'On' => '1');
$options_vs = array('Off' => '0', 'On' => '1');
$options_rl = array('Off' => '0', 'On' => '1');
function initCamPos() {
$tr = fopen("pipan_bak.txt", "r");
if($tr){
while(($line = fgets($tr)) != false) {
$vals = explode(" ", $line);
echo '<script type="text/javascript">init_pt(',$vals[0],',',$vals[1],');</script>';
}
fclose($tr);
}
}
function pipan_controls() {
initCamPos();
echo "<div class='container-fluid text-center liveimage'>";
echo "<input type='button' class='btn btn-primary' value='up' onclick='servo_up();'><br>";
echo " <input type='button' class='btn btn-primary' value='left' onclick='servo_left();'>";
echo " <input type='button' class='btn btn-primary' value='down' onclick='servo_down();'>";
echo " <input type='button' class='btn btn-primary' value='right' onclick='servo_right();'>";
echo "</div>";
}
function pilight_controls() {
echo "<tr>";
echo "<td>Pi-Light:</td>";
echo "<td>";
echo "R: <input type='text' size=4 id='pilight_r' value='255'>";
echo "G: <input type='text' size=4 id='pilight_g' value='255'>";
echo "B: <input type='text' size=4 id='pilight_b' value='255'><br>";
echo "<input type='button' value='ON/OFF' onclick='led_switch();'>";
echo "</td>";
echo "</tr>";
}
function getExtraStyles() {
$files = scandir('css');
foreach($files as $file) {
if(substr($file,0,3) == 'es_') {
echo "<option value='$file'>" . substr($file,3, -4) . '</option>';
}
}
}
function getStyle() {
return 'css/' . file_get_contents(BASE_DIR . '/css/extrastyle.txt');
}
function makeOptions($options, $selKey) {
global $config;
switch ($selKey) {
case 'flip':
$cvalue = (($config['vflip'] == 'true') ? 2:0);
$cvalue += (($config['hflip'] == 'true') ? 1:0);
break;
case 'MP4Box':
$cvalue = $config[$selKey];
if ($cvalue == 'background') $cvalue = 2;
break;
default: $cvalue = $config[$selKey]; break;
}
if ($cvalue == 'false') $cvalue = 0;
else if ($cvalue == 'true') $cvalue = 1;
foreach($options as $name => $value) {
if ($cvalue != $value) {
$selected = '';
} else {
$selected = ' selected';
}
echo "<option value='$value'$selected>$name</option>";
}
}
function makeInput($id, $size, $selKey='') {
global $config, $debugString;
if ($selKey == '') $selKey = $id;
switch ($selKey) {
case 'tl_interval':
if (array_key_exists($selKey, $config)) {
$value = $config[$selKey] / 10;
} else {
$value = 3;
}
break;
case 'watchdog_interval':
if (array_key_exists($selKey, $config)) {
$value = $config[$selKey] / 10;
} else {
$value = 0;
}
break;
default: $value = $config[$selKey]; break;
}
echo "<input type='text' size=$size id='$id' value='$value'>";
}
if (isset($_POST['extrastyle'])) {
if (file_exists('css/' . $_POST['extrastyle'])) {
$fp = fopen(BASE_DIR . '/css/extrastyle.txt', "w");
fwrite($fp, $_POST['extrastyle']);
fclose($fp);
}
}
$toggleButton = "Simple";
$displayStyle = 'style="display:block;"';
if(isset($_COOKIE["display_mode"])) {
if($_COOKIE["display_mode"] == "Simple") {
$toggleButton = "Full";
$displayStyle = 'style="display:none;"';
}
}
$streamButton = "MJPEG-Stream";
$mjpegmode = 0;
if(isset($_COOKIE["stream_mode"])) {
if($_COOKIE["stream_mode"] == "MJPEG-Stream") {
$streamButton = "Default-Stream";
$mjpegmode = 1;
}
}
$config = readConfig($config, CONFIG_FILE1);
$config = readConfig($config, CONFIG_FILE2);
$video_fps = $config['video_fps'];
$divider = $config['divider'];
?>
<html>
<head>
<meta name="viewport" content="width=550, initial-scale=1">
<title><?php echo CAM_STRING; ?></title>
<link rel="stylesheet" href="css/style_minified.css" />
<link rel="stylesheet" href="<?php echo getStyle(); ?>" />
<script src="js/style_minified.js"></script>
<script src="js/script.js"></script>
<script src="js/pipan.js"></script>
</head>
<body onload="setTimeout('init(<?php echo "$mjpegmode, $video_fps, $divider" ?>);', 100);">
<div class="navbar navbar-inverse navbar-fixed-top" role="navigation" <?php echo $displayStyle; ?>>
<div class="container">
<div class="navbar-header">
<a class="navbar-brand" href="#"><?php echo CAM_STRING; ?></a>
</div>
</div>
</div>
<input id="toggle_display" type="button" class="btn btn-primary" value="<?php echo $toggleButton; ?>" style="position:absolute;top:60px;right:10px;" onclick="set_display(this.value);">
<div class="container-fluid text-center liveimage">
<div><img id="mjpeg_dest" <?php if(file_exists("pipan_on")) echo "ontouchstart=\"pipan_start()\""; ?> onclick="toggle_fullscreen(this);" src="/loading.jpg"></div>
<div id="main-buttons" <?php echo $displayStyle; ?> >
<input id="video_button" type="button" class="btn btn-primary">
<input id="image_button" type="button" class="btn btn-primary">
<input id="timelapse_button" type="button" class="btn btn-primary">
<input id="md_button" type="button" class="btn btn-primary">
<input id="halt_button" type="button" class="btn btn-danger">
</div>
</div>
<div id="secondary-buttons" class="container-fluid text-center" <?php echo $displayStyle; ?> >
<?php if (file_exists("pipan_on")) pipan_controls(); ?>
<a href="preview.php" class="btn btn-default">Download Videos and Images</a>
<a href="motion.php" class="btn btn-default">Edit motion settings</a>
<a href="schedule.php" class="btn btn-default">Edit schedule settings</a>
</div>
<div class="container-fluid text-center">
<div class="panel-group" id="accordion" <?php echo $displayStyle; ?> >
<div class="panel panel-default">
<div class="panel-heading">
<h2 class="panel-title">
<a data-toggle="collapse" data-parent="#accordion" href="#collapseOne">Camera Settings</a>
</h2>
</div>
<div id="collapseOne" class="panel-collapse collapse">
<div class="panel-body">
<table class="settingsTable">
<tr>
<td>Resolutions:</td>
<td>Load Preset: <select onchange="set_preset(this.value)">
<option value="1920 1080 25 25 2592 1944">Select option...</option>
<option value="1920 1080 25 25 2592 1944">Std FOV</option>
<option value="1296 730 25 25 2592 1944">16:9 wide FOV</option>
<option value="1296 976 25 25 2592 1944">4:3 full FOV</option>
<option value="1920 1080 01 30 2592 1944">Std FOV, x30 Timelapse</option>
</select><br>
Custom Values:<br>
Video res: <?php makeInput('video_width', 4); ?>x<?php makeInput('video_height', 4); ?>px<br>
Video fps: <?php makeInput('video_fps', 2); ?>recording, <?php makeInput('MP4Box_fps', 2); ?>boxing<br>
Image res: <?php makeInput('image_width', 4); ?>x<?php makeInput('image_height', 4); ?>px<br>
<input type="button" value="OK" onclick="set_res();">
</td>
</tr>
<tr>
<td>Timelapse-Interval (0.1...3200):</td>
<td><?php makeInput('tl_interval', 4); ?>s <input type="button" value="OK" onclick="send_cmd('tv ' + 10 * document.getElementById('tl_interval').value)"></td>
</tr>
<tr>
<td>Annotation (max 127 characters):</td>
<td>
Text: <?php makeInput('annotation', 20); ?><input type="button" value="OK" onclick="send_cmd('an ' + encodeURI(document.getElementById('annotation').value))"><input type="button" value="Default" onclick="document.getElementById('annotation').value = 'RPi Cam %Y.%M.%D_%h:%m:%s'; send_cmd('an ' + encodeURI(document.getElementById('annotation').value))"><br>
Background:><select onchange="send_cmd('ab ' + this.value)"><?php makeOptions($options_ab, 'anno_background'); ?></select>
</td>
</tr>
<?php if (file_exists("pilight_on")) pilight_controls(); ?>
<tr>
<td>Buffer (1000... ms), default 0:</td>
<td><?php makeInput('video_buffer', 4); ?><input type="button" value="OK" onclick="send_cmd('bu ' + document.getElementById('video_buffer').value)"></td>
</tr> <tr>
<td>Sharpness (-100...100), default 0:</td>
<td><?php makeInput('sharpness', 4); ?><input type="button" value="OK" onclick="send_cmd('sh ' + document.getElementById('sharpness').value)"></td>
</tr>
<tr>
<td>Contrast (-100...100), default 0:</td>
<td><?php makeInput('contrast', 4); ?><input type="button" value="OK" onclick="send_cmd('co ' + document.getElementById('contrast').value)">
</td>
</tr>
<tr>
<td>Brightness (0...100), default 50:</td>
<td><?php makeInput('brightness', 4); ?><input type="button" value="OK" onclick="send_cmd('br ' + document.getElementById('brightness').value)"></td>
</tr>
<tr>
<td>Saturation (-100...100), default 0:</td>
<td><?php makeInput('saturation', 4); ?><input type="button" value="OK" onclick="send_cmd('sa ' + document.getElementById('saturation').value)"></td>
</tr>
<tr>
<td>ISO (100...800), default 0:</td>
<td><?php makeInput('iso', 4); ?><input type="button" value="OK" onclick="send_cmd('is ' + document.getElementById('iso').value)"></td>
</tr>
<tr>
<td>Metering Mode, default 'average':</td>
<td><select onchange="send_cmd('mm ' + this.value)"><?php makeOptions($options_mm, 'metering_mode'); ?></select></td>
</tr>
<tr>
<td>Video Stabilisation, default: 'off'</td>
<td><select onchange="send_cmd('vs ' + this.value)"><?php makeOptions($options_vs, 'video_stabilisation'); ?></select></td>
</tr>
<tr>
<td>Exposure Compensation (-10...10), default 0:</td>
<td><?php makeInput('exposure_compensation', 4); ?><input type="button" value="OK" onclick="send_cmd('ec ' + document.getElementById('exposure_compensation').value)"></td>
</tr>
<tr>
<td>Exposure Mode, default 'auto':</td>
<td><select onchange="send_cmd('em ' + this.value)"><?php makeOptions($options_em, 'exposure_mode'); ?></select></td>
</tr>
<tr>
<td>White Balance, default 'auto':</td>
<td><select onchange="send_cmd('wb ' + this.value)"><?php makeOptions($options_wb, 'white_balance'); ?></select></td>
</tr>
<tr>
<td>Image Effect, default 'none':</td>
<td><select onchange="send_cmd('ie ' + this.value)"><?php makeOptions($options_ie, 'image_effect'); ?></select></td>
</tr>
<tr>
<td>Colour Effect, default 'disabled':</td>
<td><select id="ce_en"><?php makeOptions($options_ce_en, 'colour_effect_en'); ?></select>
u:v = <?php makeInput('ce_u', 4, 'colour_effect_u'); ?>:<?php makeInput('ce_v', 4, 'colour_effect_v'); ?>
<input type="button" value="OK" onclick="set_ce();">
</td>
</tr>
<tr>
<td>Rotation, default 0:</td>
<td><select onchange="send_cmd('ro ' + this.value)"><?php makeOptions($options_ro, 'rotation'); ?></select></td>
</tr>
<tr>
<td>Flip, default 'none':</td>
<td><select onchange="send_cmd('fl ' + this.value)"><?php makeOptions($options_fl, 'flip'); ?></select></td>
</tr>
<tr>
<td>Sensor Region, default 0/0/65536/65536:</td>
<td>
x<?php makeInput('roi_x', 5, 'sensor_region_x'); ?> y<?php makeInput('roi_y', 5, 'sensor_region_y'); ?> w<?php makeInput('roi_w', 5, 'sensor_region_w'); ?> h<?php makeInput('roi_h', 4, 'sensor_region_h'); ?> <input type="button" value="OK" onclick="set_roi();">
</td>
</tr>
<tr>
<td>Shutter speed (0...330000), default 0:</td>
<td><?php makeInput('shutter_speed', 4); ?><input type="button" value="OK" onclick="send_cmd('ss ' + document.getElementById('shutter_speed').value)">
</td>
</tr>
<tr>
<td>Image quality (0...100), default 85:</td>
<td>
<?php makeInput('image_quality', 4); ?><input type="button" value="OK" onclick="send_cmd('qu ' + document.getElementById('image_quality').value)">
</td>
</tr>
<tr>
<td>Preview quality (0...100) Default 25:<br>Width (128...1024) Default 512:<br>Divider (1-16) Default 1:</td>
<td>
Qu: <?php makeInput('quality', 4); ?>
Wi: <?php makeInput('width', 4); ?>
Di: <?php makeInput('divider', 4); ?>
<input type="button" value="OK" onclick="set_preview();">
</td>
</tr>
<tr>
<td>Raw Layer, default: 'off'</td>
<td><select onchange="send_cmd('rl ' + this.value)"><?php makeOptions($options_rl, 'raw_layer'); ?></select></td>
</tr>
<tr>
<td>Video bitrate (0...25000000), default 17000000:</td>
<td>
<?php makeInput('video_bitrate', 10); ?><input type="button" value="OK" onclick="send_cmd('bi ' + document.getElementById('video_bitrate').value)">
</td>
</tr>
<tr>
<td>MP4 Boxing mode :</td>
<td><select onchange="send_cmd('bo ' + this.value)"><?php makeOptions($options_bo, 'MP4Box'); ?></select></td>
</tr>
<tr>
<td>Annotation size(0-99):</td>
<td>
<?php makeInput('anno_text_size', 3); ?><input type="button" value="OK" onclick="send_cmd('as ' + document.getElementById('anno_text_size').value)">
</td>
</tr>
<tr>
<td>Custom text color:</td>
<td><select id="at_en"><?php makeOptions($options_at_en, 'anno3_custom_text_colour'); ?></select>
y:u:v = <?php makeInput('at_y', 3, 'anno3_custom_text_Y'); ?>:<?php makeInput('at_u', 4, 'anno3_custom_text_U'); ?>:<?php makeInput('at_v', 4, 'anno3_custom_text_V'); ?>
<input type="button" value="OK" onclick="set_at();">
</td>
</tr>
<tr>
<td>Custom background color:</td>
<td><select id="ac_en"><?php makeOptions($options_ac_en, 'anno3_custom_background_colour'); ?></select>
y:u:v = <?php makeInput('ac_y', 3, 'anno3_custom_background_Y'); ?>:<?php makeInput('ac_u', 4, 'anno3_custom_background_U'); ?>:<?php makeInput('ac_v', 4, 'anno3_custom_background_V'); ?>
<input type="button" value="OK" onclick="set_ac();">
</td>
</tr>
<tr>
<td>Watchdog, default interval 3s, errors 3</td>
<td>Interval <?php makeInput('watchdog_interval', 3); ?>s Errors <?php makeInput('watchdog_errors', 3); ?>
<input type="button" value="OK" onclick="send_cmd('wd ' + 10 * document.getElementById('watchdog_interval').value + ' ' + document.getElementById('watchdog_errors').value)">
</td>
</tr>
</table>
</div>
</div>
</div>
<div class="panel panel-default">
<div class="panel-heading">
<h2 class="panel-title">
<a data-toggle="collapse" data-parent="#accordion" href="#collapseTwo">System</a>
</h2>
</div>
<div id="collapseTwo" class="panel-collapse collapse">
<div class="panel-body">
<input id="toggle_stream" type="button" class="btn btn-primary" value="<?php echo $streamButton; ?>" onclick="set_stream_mode(this.value);">
<input id="shutdown_button" type="button" value="shutdown system" onclick="sys_shutdown();" class="btn btn-danger">
<input id="reboot_button" type="button" value="reboot system" onclick="sys_reboot();" class="btn btn-danger">
<input id="reset_button" type="button" value="reset settings" onclick="send_cmd('rs 1');setTimeout(function(){location.reload(true);}, 1000);" class="btn btn-danger">
<form action='<?php echo ROOT_PHP; ?>' method='POST'>
<br>Style
<select name='extrastyle' id='extrastyle'>
<?php getExtraStyles(); ?>
</select>
<button type="submit" name="OK" value="OK" >OK</button>
</form>
</div>
</div>
</div>
</div>
</div>
<?php if ($debugString != "") echo "$debugString<br>"; ?>
</body>
</html>