forked from camera360developers/photosphere
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcapture_sphere.sh
executable file
·184 lines (146 loc) · 4.41 KB
/
capture_sphere.sh
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
#!/bin/bash
# Snaps THETA S pictures
# uploads them and deletes the
# images on the camera to free up memory
# needs to be called using crontab for a time lapse
# implementation
# if not arguments
if [ "$*" == "" ]; then
echo "No arguments provided"
echo "use: -u true / false (upload)"
echo "use: -n true / false (night mode)"
echo "use: -s xxx.xxx.xxx.xxx (ip address / domain name)"
exit 1
fi
# query arguments
while getopts ":h?u:n:s:" opt; do
case "$opt" in
h|\?)
echo "No arguments provided"
echo "use: -u true / false (upload)"
echo "use: -n true / false (night mode)"
echo "use: -s xxx.xxx.xxx.xxx (ip address / domain name)"
exit 0
;;
u)
upload=$OPTARG
;;
n)
nightmode=$OPTARG
;;
s)
server=$OPTARG
;;
:)
echo "Option -$OPTARG requires an argument." >&2
exit 1
;;
esac
done
# set paths explicitly
PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games"
# set working directory
# in which to save the data
#cd ~/tmp/ # for testing only
cd /var/tmp/
# make sure to unmount the camera
# basically in text mode it should not
# auto mount (as far as I know)
# cameraname
camera="virtualforest"
datetime=` date +%Y_%m_%d_%H%M%S`
# check if the camera is connected
# if not exit cleanly
status=`ptpcam -i | grep "serial" | wc -l`
if [ "$status" = "0" ];
then
echo ""
echo "Your camera is not active, connected or mounted as a drive!"
echo "-----------------------------------------------------------"
echo "Check your usb cable, turn the camera on and make sure"
echo "that your camera is not mounted as a drive."
echo ""
exit 0
fi
# check the battery status
battery=`ptpcam --show-property=0x5001 | grep "to:" | awk '{print $6}'`
# output battery status to file
echo $battery >> battery_status.txt
if [ "$battery" -lt 20 ];
then
echo "low battery"
exit 0
fi
# set the timeout to indefinite
# as well as the sleep delay
# this prevents timed shutdowns
ptpcam --set-property=0xd803 --val=0 # sleep delay
ptpcam --set-property=0xd802 --val=0 # set auto power off
ptpcam --set-property=0x502c --val=100 # set shutter sound to max
# list all files on the device
handle=`ptpcam -L | grep 0x | awk '{print $1}' | sed 's/://g'`
# clear all files on the device before capturing
# any new data
do
ptpcam --delete-object=$i
done
if [[ "$nightmode" == "FALSE" || "$nightmode" == "F" ]] || [[ "$nightmode" == "f" || "$nightmode" == "false" ]];
then
# loop over 3 exposure settings
exposures="2000 0 -2000"
for exp in $exposures;do
# Change settings
ptpcam --set-property=0x500E --val=0x8003 # ISO priority
ptpcam --set-property=0x5005 --val=0x8001 # set WB
ptpcam --set-property=0x500F --val=100 # set ISO
ptpcam --set-property=0x5010 --val=$exp # set compensation
# snap picture
# and wait for it to complete (max 60s)
ptpcam -c
sleep 60
# list last file
handle=`ptpcam -L | grep 0x | awk '{print $1}' | sed 's/://g'`
echo $handle
filename=`ptpcam -L | grep 0x | awk '{print $5}'`
# grab the last file
ptpcam --get-file=$handle
# grab filename of the last downloaded file
filename=`ls -t | head -1`
# create filename based upon time / date
newfilename=`echo $camera\_exp$exp\_$datetime.jpg`
# rename the last file created
mv $filename $newfilename
# remove file
ptpcam --delete-object=$handle
done
else
# nightmode
# not working yet, doesn't accept the
# shutter speeds !!!!!
# Change settings
ptpcam --set-property=0x500E --val=0x0004 # ISO priority
ptpcam --set-property=0x5005 --val=0x8001 # set WB
ptpcam --set-property=0xD00F --val=30,1 # set shutter
# snap picture
# and wait for it to complete (max 60s)
ptpcam -c
sleep 60
# list last file
handle=`ptpcam -L | grep 0x | awk '{print $1}' | sed 's/://g'`
filename=`ptpcam -L | grep 0x | awk '{print $5}'`
# grab the last file
ptpcam --get-file=$handle
# create filename based upon time / date
newfilename=`echo $camera\_exp0\_$datetime.jpg`
# rename the last file created
mv $filename $newfilename
# remove file
ptpcam --delete-object=$handle
fi
# upload new data to an image server
if [[ "$upload" == "TRUE" || "$upload" == "T" ]] \
|| [[ "$upload" == "t" || "$upload" == true ]]
then
# puts images in the 'data' folder of an anonymous FTP server
lftp ftp://anonymous:anonymous@${server} -e "mirror --verbose --reverse --Remove-source-files ./ ./data/ ;quit"
fi