October 2019
Intermediate to advanced
426 pages
10h 8m
English
We will start with the translate image text endpoint. The following code will continue with the Python code of app.py:
...import json...###### RESTful endpoints####@app.route('/images/{image_id}/translated-text', methods = ['POST'], cors = True)def translate_image_text(image_id): """detects then translates text in the specified image""" request_data = json.loads(app.current_request.raw_body) from_lang = request_data['fromLang'] to_lang = request_data['toLang'] MIN_CONFIDENCE = 80.0 text_lines = recognition_service.detect_text(image_id) translated_lines = [] for line in text_lines: # check confidence if float(line['confidence']) >= MIN_CONFIDENCE: translated_line = translation_service.translate_text(line[ ...
Read now
Unlock full access