-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtool.py
More file actions
75 lines (60 loc) · 2.25 KB
/
tool.py
File metadata and controls
75 lines (60 loc) · 2.25 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
# ofrom flask import Flask, render_template, request
from bottle import Bottle, run, request, template
app = Bottle()
import os
import json
import glob
import base64
import shutil
current_rects = []
to_label = glob.glob('static/raw/*.jpg')
# app = Flask(__name__)
@app.route('/')
def index():
return template('templates/show_image.html')
@app.route('/fetchimage')
def fetchimage():
image = to_label.pop(0)
image = image.replace('\\', '/')
print("serving image: {}".format(image))
with open(image, "rb") as image_file:
encoded_string = base64.b64encode(image_file.read())
image_name = image.split('/')[-1]
print(image, 'static/processing/' + image_name)
shutil.move(image, 'static/processing/' + image_name)
return json.dumps({'image': encoded_string.decode('utf-8'), 'filename': image_name})
def mul(s):
return str(int(s) * 2)
@app.route('/saveSelections/<data>', method='POST')
def save(data):
data = json.loads(data)
rects = data['rects']
filename = data['filename']
textFilename = filename.replace('.jpg', '.txt')
with open('static/labels/{}'.format(textFilename), 'w') as f:
for rect in rects:
if(rect['stop_x'] < rect['start_x']):
leftx = rect['stop_x']
rightx = rect['start_x']
else:
leftx = rect['start_x']
rightx = rect['stop_x']
if(rect['stop_y'] < rect['start_y']):
topy = rect['stop_y']
bottomy = rect['start_y']
else:
topy = rect['start_y']
bottomy = rect['stop_y']
print( leftx, topy, rightx, bottomy)
f.write("{} {} {} {} {}\n".format(mul(leftx), mul(topy), \
mul(rightx), mul(bottomy), rect['class']))
shutil.move('static/processing/' + filename, 'static/dist/' + filename)
return ''
@app.route('/delete/<data>', method='POST')
def delete(data):
data = json.loads(data)
filename = data['filename']
shutil.move('static/processing/' + filename, 'static/deleted/' + filename)
return ''
if __name__ == '__main__':
run(app, host='localhost', port=8080)