-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdip.py
More file actions
executable file
·83 lines (70 loc) · 2.87 KB
/
dip.py
File metadata and controls
executable file
·83 lines (70 loc) · 2.87 KB
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
#!/usr/bin/python
from S3 import DownloadImagesFromS3
from S3 import ListLocalImages
from S3 import UploadFileToS3
from utility import *
from vision import *
from display import *
import imp
zero = imp.load_source('zero', '../basil-zero/zero.py')
from zero import *
def RemoveFiles(path, beginning):
files = os.listdir(path)
for file in files:
if file.startswith(beginning):
print('deleting %s' % os.path.join(path, file))
os.remove(os.path.join(path, file))
args = ParseArguments()
if args.download:
print('skipped=%d downloaded=%d failed=%d' % DownloadImagesFromS3(args.group + '/' + args.prefix, args.substring, args.group))
quit()
if len(args.prefix.split('-')) != 2:
print('prefix must be in the form sensorname-batchname (batchname can contain ^ (carets)')
quit()
if args.clean:
print(args.prefix.split('-'))
if len(args.prefix.split('-')) == 2:
print('cleaning')
RemoveFiles('prior/' + args.group, args.prefix)
RemoveFiles('CSV/' + args.group, args.prefix)
box = BoundingBox()
# attempt to load existing csv file for this analysis
processed_files = []
try:
with open('CSV/' + args.group + '/' + args.prefix + '.csv', 'rb') as csvfile:
csv_data = csv.reader(csvfile)
first = True
for row in csv_data:
if not first:
processed_files.append(row[10])
first = False
# print(processed_files)
# print(len(processed_files))
except:
print('dip: csv file does not exist')
for image_file in ListLocalImages('downloaded/' + args.group + '/' + args.prefix, args.substring):
if not (image_file.replace('downloaded/', '') in processed_files): # has not been analyzed yet
print('processing ' + image_file)
locals()[args.routine](image_file, cv2.imread(image_file), box, args.group)
else:
print('skipping ' + image_file)
ProcessKeystrokes()
cv2.destroyAllWindows()
print('Windows destroyed.')
if args.upload:
sensor_hostname = args.prefix.split('-')[0]
if not UploadFileToS3('CSV/' + args.group + '/' + args.prefix + '.csv', 'CSV/' + args.group + '/' + args.prefix + '.csv'):
print ("now, this is a big problem. could not upload CSV results.")
quit()
if not args.timelapse:
quit()
try:
print("ffmpeg -r 15 -pattern_type glob -i 'timelapse/" + args.group + '/' + args.prefix + "*.jpg' -s 1440:1080 -vcodec libx264 -filter:v 'crop="
+ str(int(box.rect.xmax - box.rect.xmin)) + \
':' + str(int(box.rect.ymax - box.rect.ymin)) + ':' + \
str(int(box.rect.xmin)) + ':' + str(int(box.rect.ymin))) + \
"' timelapse.mp4"
except:
command = "ffmpeg -r 15 -pattern_type glob -i 'timelapse/" + args.group + '/' + args.prefix + "*.jpg' -s 1440:1080 -vcodec libx264 ~/Desktop/timelapse-" + args.prefix + "-" + args.routine + ".mp4"
print(command)
os.popen(command)