initial commit
Browse files
app.py
CHANGED
|
@@ -39,6 +39,10 @@ trapezoid_pts = np.array([[250, 150], [400, 150], [450, 300], [200, 300]], np.in
|
|
| 39 |
# Create temp directory for uploads if it doesn't exist
|
| 40 |
os.makedirs("temp", exist_ok=True)
|
| 41 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 42 |
def is_inside_trapezoid(box, trapezoid_pts):
|
| 43 |
"""Check if the center of a detected object is inside the trapezoidal area."""
|
| 44 |
x1, y1, x2, y2 = box
|
|
@@ -108,12 +112,6 @@ def encode_image_to_base64(image):
|
|
| 108 |
_, buffer = cv2.imencode('.jpg', image)
|
| 109 |
return base64.b64encode(buffer).decode('utf-8')
|
| 110 |
|
| 111 |
-
@app.on_event("startup")
|
| 112 |
-
async def startup_event():
|
| 113 |
-
"""Load the YOLO model when the app starts."""
|
| 114 |
-
global model
|
| 115 |
-
model = YOLO(model_name)
|
| 116 |
-
print(f"Model {model_name} loaded successfully")
|
| 117 |
|
| 118 |
@app.get("/")
|
| 119 |
async def root():
|
|
|
|
| 39 |
# Create temp directory for uploads if it doesn't exist
|
| 40 |
os.makedirs("temp", exist_ok=True)
|
| 41 |
|
| 42 |
+
"""Load the YOLO model when the app starts."""
|
| 43 |
+
model = YOLO(model_name)
|
| 44 |
+
print(f"Model {model_name} loaded successfully")
|
| 45 |
+
|
| 46 |
def is_inside_trapezoid(box, trapezoid_pts):
|
| 47 |
"""Check if the center of a detected object is inside the trapezoidal area."""
|
| 48 |
x1, y1, x2, y2 = box
|
|
|
|
| 112 |
_, buffer = cv2.imencode('.jpg', image)
|
| 113 |
return base64.b64encode(buffer).decode('utf-8')
|
| 114 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 115 |
|
| 116 |
@app.get("/")
|
| 117 |
async def root():
|