mirror of
				https://github.com/StefBuwalda/ProjectIOT.git
				synced 2025-10-30 19:29:57 +00:00 
			
		
		
		
	Basic server for demo, database manager wip
This commit is contained in:
		
							
								
								
									
										1
									
								
								dbmanager.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										1
									
								
								dbmanager.py
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1 @@ | ||||
| from flask_sqlalchemy import SQLAlchemy | ||||
							
								
								
									
										59
									
								
								server.py
									
									
									
									
									
								
							
							
						
						
									
										59
									
								
								server.py
									
									
									
									
									
								
							| @@ -0,0 +1,59 @@ | ||||
| from flask import Flask, request, jsonify | ||||
| import os | ||||
| from pyplatex import ANPR | ||||
| import torch | ||||
| from ultralytics.nn.tasks import DetectionModel | ||||
| import asyncio | ||||
|  | ||||
| torch.serialization.add_safe_globals({"DetectionModel": DetectionModel}) | ||||
|  | ||||
| # Web Server | ||||
| app = Flask(__name__) | ||||
|  | ||||
| # Saving images locally | ||||
| UPLOAD_FOLDER = "uploads" | ||||
| os.makedirs(UPLOAD_FOLDER, exist_ok=True) | ||||
|  | ||||
|  | ||||
| # Default app route | ||||
| @app.route("/") | ||||
| def home(): | ||||
|     return "Hello, World!" | ||||
|  | ||||
|  | ||||
| # API to process vehicle | ||||
| @app.route("/api", methods=["POST"]) | ||||
| def data(): | ||||
|     # Check if image is present | ||||
|     if "image" not in request.files: | ||||
|         return jsonify({"error": "No file part"}), 400 | ||||
|  | ||||
|     file = request.files["image"]  # get the image from the packet | ||||
|  | ||||
|     if file.filename == "" or not file.filename: | ||||
|         return jsonify({"error": "No selected file"}), 400 | ||||
|  | ||||
|     # Check if image ends in .jpg | ||||
|     if file.filename.lower().endswith(".jpg"): | ||||
|         filepath = os.path.join(UPLOAD_FOLDER, file.filename) | ||||
|         file.save(filepath) | ||||
|         print(asyncio.run(process_image(filepath))) | ||||
|         return jsonify( | ||||
|             { | ||||
|                 "message": "File uploaded successfully", | ||||
|                 "filename": file.filename, | ||||
|                 "status": True, | ||||
|             } | ||||
|         ) | ||||
|  | ||||
|     return jsonify({"error": "Only JPEG files allowed"}), 400 | ||||
|  | ||||
|  | ||||
| async def process_image(file: str): | ||||
|     anpr = ANPR() | ||||
|     plates = await anpr.detect(file) | ||||
|     return plates | ||||
|  | ||||
|  | ||||
| if __name__ == "__main__": | ||||
|     app.run(host="192.168.137.1", port=2222, debug=True) | ||||
|   | ||||
							
								
								
									
										
											BIN
										
									
								
								uploads/image.jpg
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										
											BIN
										
									
								
								uploads/image.jpg
									
									
									
									
									
										Normal file
									
								
							
										
											Binary file not shown.
										
									
								
							| After Width: | Height: | Size: 33 KiB | 
		Reference in New Issue
	
	Block a user