-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.py
69 lines (57 loc) · 2.29 KB
/
server.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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
from flask import Flask, render_template, request, Response, jsonify
import parking_model
import parkingPositionsDetector
import dbHandler
import threading
from flask_cors import CORS
import pymongo
from pymongo import MongoClient
import cProfile
import time
# Create a Flask instance and enable CORS
app = Flask(__name__)
CORS(app)
# Define a route for the index page
@app.route("/")
def index():
# Call the getTotalSpaces and getFreeSpaces methods from the parking_model module
totalSpaces = model.getTotalSpaces()
freeSpaces = model.getFreeSpaces()
# Render the HTML template with the total spaces and free spaces values
return render_template('/HTML/index.html', total_spaces=totalSpaces, free_spaces=freeSpaces)
# Define a route for the video feed
@app.route("/video_feed")
def video_feed():
# Return a response with the generated video
return Response(model.generate(), mimetype="multipart/x-mixed-replace; boundary=frame")
# Define a route for the parking space information
@app.route("/info")
def info():
# Call the getFreeSpaces and getTotalSpaces methods from the parking_model module
freeSpaces = model.getFreeSpaces()
totalSpaces = model.getTotalSpaces()
# Return a JSON object with the total spaces and free spaces values
return jsonify(totalSpaces_value=totalSpaces, freeSpaces_value=freeSpaces)
# Main function
if __name__ == "__main__":
# Define the stream video source
stream = 'resultvideo2013.avi'
# stream = 'http://eitancamhome:[email protected]:6677/video'
# Create an instance of the DbHandler
db = dbHandler.DbHandler()
# Define the weights for the parking space detector
weights = 'yolov5s'
# Create an instance of the parking_model class
model = parking_model.Model(stream, db, weights)
# Start a new thread for the stream method
t1 = threading.Thread(target=model.stream)
t1.daemon = True
t1.start()
# Create an instance of the parkingPositionsDetector class
detector = parkingPositionsDetector.Detector(stream, db)
# Start a new thread for the detectionAlgorithm method
t2 = threading.Thread(target=detector.detectionAlgorithm)
t2.daemon = True
t2.start()
# Start the Flask app
app.run(host="0.0.0.0", port=5000, debug=True, threaded=True, use_reloader=False)