-
Notifications
You must be signed in to change notification settings - Fork 0
/
utils.py
35 lines (26 loc) · 1.3 KB
/
utils.py
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
import argparse
import base64
import io
from matplotlib import pyplot as plt
from matplotlib.backends.backend_agg import FigureCanvasAgg as FigureCanvas
def main_parser():
parser = argparse.ArgumentParser(formatter_class=argparse.ArgumentDefaultsHelpFormatter)
parser.add_argument('--app_type', help='Flask app run type: remote (to connect from your own device to IRender)'
'or server (only for running web on IRender) (default: server)',
type=str, default='server')
parser.add_argument('--cnx_type', help='Database: local (database on your own device) '
'or server (only for running web on IRender) '
'or remote (to connect from your own device to IRender)'
'(default: server)',
type=str, default='server')
return parser.parse_args()
def plot_png(image):
fig = plt.figure()
ax = fig.add_subplot(111)
ax.imshow(image)
output = io.BytesIO()
FigureCanvas(fig).print_png(output)
# Encode PNG image to base64 string
pngImageB64String = "data:image/png;base64,"
pngImageB64String += base64.b64encode(output.getvalue()).decode('utf8')
return pngImageB64String