Web.
This commit is contained in:
parent
cfad55dd65
commit
5cab218b50
37
adapter.py
37
adapter.py
|
@ -10,27 +10,22 @@ from runner import find_homography, warp_board
|
||||||
from tensor_classifier import predict_board
|
from tensor_classifier import predict_board
|
||||||
|
|
||||||
|
|
||||||
while True:
|
stdin = sys.stdin.readline()
|
||||||
try:
|
stdin_decoded = base64.b64decode(stdin)
|
||||||
stdin = sys.stdin.readline()
|
img_array = np.frombuffer(stdin_decoded, dtype=np.uint8)
|
||||||
stdin_decoded = base64.b64decode(stdin)
|
camera_img = cv2.imdecode(img_array, flags=cv2.COLOR_BGR2RGB)
|
||||||
img_array = np.frombuffer(stdin_decoded, dtype=np.uint8)
|
camera_img = cv2.cvtColor(camera_img, cv2.COLOR_BGR2RGB)
|
||||||
camera_img = cv2.imdecode(img_array, flags=cv2.COLOR_BGR2RGB)
|
|
||||||
camera_img = cv2.cvtColor(camera_img, cv2.COLOR_BGR2RGB)
|
|
||||||
|
|
||||||
# def do_everything:
|
# def do_everything:
|
||||||
homography = find_homography(camera_img)
|
homography = find_homography(camera_img)
|
||||||
warped_board = warp_board(camera_img, homography)
|
warped_board = warp_board(camera_img, homography)
|
||||||
occupied_squares = find_occupied_squares(warped_board)
|
occupied_squares = find_occupied_squares(warped_board)
|
||||||
board = predict_board(occupied_squares)
|
board = predict_board(occupied_squares)
|
||||||
|
|
||||||
# Finally, output to stdout for unity to read
|
# Finally, output to stdout for unity to read
|
||||||
result = {
|
result = {
|
||||||
"homography": homography.tolist(),
|
"homography": homography.tolist(),
|
||||||
"board": board.to_array,
|
"board": board.to_array,
|
||||||
}
|
}
|
||||||
|
|
||||||
print(json.dumps(result))
|
print(json.dumps(result))
|
||||||
exit() # TODO
|
|
||||||
except Exception as e:
|
|
||||||
print(e)
|
|
||||||
|
|
41
web.py
Normal file
41
web.py
Normal file
|
@ -0,0 +1,41 @@
|
||||||
|
import base64
|
||||||
|
|
||||||
|
import cv2
|
||||||
|
import numpy as np
|
||||||
|
from flask import Flask, jsonify, request
|
||||||
|
|
||||||
|
from main import find_occupied_squares
|
||||||
|
from runner import find_homography, warp_board
|
||||||
|
from tensor_classifier import predict_board
|
||||||
|
|
||||||
|
app = Flask(__name__)
|
||||||
|
|
||||||
|
|
||||||
|
@app.route("/", methods=["POST"])
|
||||||
|
def process():
|
||||||
|
data = request.get_json(force=True)
|
||||||
|
|
||||||
|
decoded = base64.b64decode(data["img"])
|
||||||
|
img_array = np.frombuffer(decoded, dtype=np.uint8)
|
||||||
|
camera_img = cv2.imdecode(img_array, flags=cv2.COLOR_BGR2RGB)
|
||||||
|
camera_img = cv2.cvtColor(camera_img, cv2.COLOR_BGR2RGB)
|
||||||
|
|
||||||
|
# def do_everything:
|
||||||
|
homography = find_homography(camera_img)
|
||||||
|
warped_board = warp_board(camera_img, homography)
|
||||||
|
occupied_squares = find_occupied_squares(warped_board)
|
||||||
|
board = predict_board(occupied_squares)
|
||||||
|
|
||||||
|
# Finally, output for unity to read
|
||||||
|
return jsonify({
|
||||||
|
"homography": homography.tolist(),
|
||||||
|
"board": board.to_array,
|
||||||
|
})
|
||||||
|
|
||||||
|
|
||||||
|
def main():
|
||||||
|
app.run(host='0.0.0.0', debug=True)
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
main()
|
Loading…
Reference in New Issue
Block a user