Skip to content
Snippets Groups Projects
Commit c49e6493 authored by merschie's avatar merschie
Browse files

Docstring Documentation

parent c2110a2d
No related branches found
No related tags found
No related merge requests found
...@@ -17,6 +17,14 @@ chars = ''.join(char_list) ...@@ -17,6 +17,14 @@ chars = ''.join(char_list)
def image_to_base64(processed_image): def image_to_base64(processed_image):
"""Konvertiert ein Bild in ein base64-encoded-String
Args:
processed_image (np.Array): Ein schwarz-weiß Bild als numpy Array
Returns:
String: base64-encoded-String des Bildes
"""
processed_image = processed_image + 0.5 processed_image = processed_image + 0.5
processed_image = processed_image * 255 processed_image = processed_image * 255
#rotate image 90 degrees #rotate image 90 degrees
...@@ -32,8 +40,16 @@ def image_to_base64(processed_image): ...@@ -32,8 +40,16 @@ def image_to_base64(processed_image):
image_base64 = base64.b64encode(array_bytes).decode('utf-8') image_base64 = base64.b64encode(array_bytes).decode('utf-8')
return image_base64 return image_base64
def base64_to_image(processed_image): def base64_to_image(image_data):
image=base64.b64decode(processed_image.encode('utf-8')) """Konvertiert ein base64-encoded-String in ein Bild
Args:
processed_image (String): base64-encoded-String des Bildes
Returns:
np.Array: Numpy Array des Bildes
"""
image=base64.b64decode(image_data.encode('utf-8'))
image_array = np.frombuffer(image, dtype=np.uint64) image_array = np.frombuffer(image, dtype=np.uint64)
h=image_array[-2] h=image_array[-2]
w=image_array[-1] w=image_array[-1]
...@@ -44,7 +60,12 @@ def base64_to_image(processed_image): ...@@ -44,7 +60,12 @@ def base64_to_image(processed_image):
@app.route('/predictName', methods=['POST']) @app.route('/predictName', methods=['POST'])
def predictNach(): def predictName():
"""Sagt den Namen auf einem Bild vorher. Bekommt als Daten per json ein Bild und eine Namensliste. Das Bild muss schwarz weiß sein und base64-encoded sein. Die Namensliste muss ein String sein, der mit Leerzeichen getrennt alle möglichen Namen enthält.
Returns:
json: Im json Format wird das erkannte Wort und das zur Vorhersage genutztes Bild als base64-encoded-String zurückgegeben.
"""
image_data=json.loads(request.data)['image'] image_data=json.loads(request.data)['image']
image_array=base64_to_image(image_data) image_array=base64_to_image(image_data)
...@@ -55,10 +76,9 @@ def predictNach(): ...@@ -55,10 +76,9 @@ def predictNach():
#change corpus for name #change corpus for name
names=json.loads(request.data)['names'] names=json.loads(request.data)['names']
print(names)
model_name.corpus = names.split(' ') model_name.corpus = names.split(' ')
recognized, probability = htr_model.Model.infer_batch(model_name, batch) recognized, _ = htr_model.Model.infer_batch(model_name, batch)
image_base64 = image_to_base64(processed_image) image_base64 = image_to_base64(processed_image)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment