-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
30 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
.git | ||
samples/ | ||
data/ | ||
|
||
# Byte-compiled / optimized / DLL files | ||
__pycache__/ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,34 @@ | ||
import os | ||
from PIL import Image | ||
from src.digitizer import Digitizer | ||
from src.route_converters import IdentifierConverter | ||
from io import BytesIO | ||
from flask import Flask, request | ||
|
||
MODEL_FILE = 'models/yolov8-detect-20240229.onnx' | ||
model = 'models/yolov8-detect-20240229.onnx' | ||
data_dir = 'data/' | ||
|
||
digitizer = Digitizer(model) | ||
|
||
digitizer = Digitizer(MODEL_FILE) | ||
app = Flask(__name__) | ||
app.url_map.converters['identifier'] = IdentifierConverter | ||
|
||
@app.route('/digitize', methods=['POST']) | ||
def digitize(): | ||
data = request.get_data() | ||
image = Image.open(BytesIO(data)) | ||
result = digitizer.detect_string(image) | ||
return result | ||
return digitizer.detect_string(image) | ||
|
||
@app.route('/meter/<identifier:meter_id>', methods=['POST']) | ||
def update_meter(meter_id): | ||
data = request.get_data() | ||
image = Image.open(BytesIO(data)) | ||
image.save(os.path.join(data_dir, f'{meter_id}.jpg')) | ||
return digitizer.detect_string(image) | ||
|
||
@app.route('/meter/<identifier:meter_id>/image', methods=['GET']) | ||
def meter_image(meter_id): | ||
image_path = os.path.join(data_dir, f'{meter_id}.jpg') | ||
if not os.path.exists(image_path): | ||
return 'Image not found', 404 | ||
return open(image_path, 'rb').read(), 200, {'Content-Type': 'image/jpeg'} |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
from werkzeug.routing import BaseConverter | ||
|
||
class IdentifierConverter(BaseConverter): | ||
def __init__(self, url_map, *items): | ||
super(IdentifierConverter, self).__init__(url_map) | ||
self.regex = r"[0-9a-zA-Z]{1,20}" |