mirror of
https://gitlab.fdmci.hva.nl/technische-informatica-sm3/ti-projectten/rooziinuubii79.git
synced 2025-08-05 12:54:57 +00:00
Compare commits
11 Commits
c3d575ccf1
...
5e01e25d9c
Author | SHA1 | Date | |
---|---|---|---|
5e01e25d9c | |||
0d184261fd | |||
ccaa722973 | |||
7d1b878c30 | |||
228c508012 | |||
7845feb9f8 | |||
20d6d8799d | |||
9c7c774030 | |||
0832da0d3b | |||
a59b9c8714 | |||
4a05ec5efc |
1
src/Python/flask/.dockerignore
Normal file
1
src/Python/flask/.dockerignore
Normal file
@@ -0,0 +1 @@
|
||||
__pycache__
|
18
src/Python/flask/Dockerfile
Normal file
18
src/Python/flask/Dockerfile
Normal file
@@ -0,0 +1,18 @@
|
||||
FROM python:3.9
|
||||
|
||||
WORKDIR /app
|
||||
|
||||
COPY . .
|
||||
|
||||
RUN apt-get update && apt-get install -y libgl1
|
||||
|
||||
|
||||
RUN pip install -r requirements.txt
|
||||
|
||||
EXPOSE 5000
|
||||
|
||||
CMD ["python", "web/app.py"]
|
||||
|
||||
#build instruction: sudo docker buildx build -t flaskapp:latest .
|
||||
#run instruction: sudo docker run --network="host" flaskapp:latest
|
||||
# need to use network host to connect to the host's mqtt server
|
5
src/Python/flask/requirements.txt
Normal file
5
src/Python/flask/requirements.txt
Normal file
@@ -0,0 +1,5 @@
|
||||
Flask==3.1.0
|
||||
paho-mqtt==1.6.1
|
||||
ultralytics==8.3.58
|
||||
opencv-python-headless==4.6.0.66
|
||||
numpy==1.23.4
|
@@ -13,6 +13,9 @@ kobuki_message = ""
|
||||
latest_image = None
|
||||
yolo_results = []
|
||||
|
||||
# https://medium.com/@Mert.A/how-to-segment-objects-with-yolov11-68593eb49fa8
|
||||
yolo_classes = list(model.names.values())
|
||||
|
||||
def on_message(client, userdata, message):
|
||||
global kobuki_message, latest_image, yolo_results
|
||||
if message.topic == "kobuki/data":
|
||||
@@ -25,20 +28,22 @@ def on_message(client, userdata, message):
|
||||
yolo_results = []
|
||||
for result in results:
|
||||
for box in result.boxes:
|
||||
class_id = int(box.cls.item()) # Convert to integer
|
||||
class_name = yolo_classes[class_id]
|
||||
yolo_results.append({
|
||||
"class": box.cls,
|
||||
"confidence": box.conf,
|
||||
"class": class_name,
|
||||
"confidence": box.conf.item(),
|
||||
"bbox": box.xyxy.tolist()
|
||||
})
|
||||
# Draw bounding box on the image
|
||||
x1, y1, x2, y2 = map(int, box.xyxy)
|
||||
x1, y1, x2, y2 = map(int, box.xyxy[0])
|
||||
cv2.rectangle(latest_image, (x1, y1), (x2, y2), (0, 255, 0), 2)
|
||||
cv2.putText(latest_image, f"{box.cls} {box.conf:.2f}", (x1, y1 - 10), cv2.FONT_HERSHEY_SIMPLEX, 0.9, (0, 255, 0), 2)
|
||||
cv2.putText(latest_image, f"{class_name} {box.conf.item():.2f}", (x1, y1 - 10), cv2.FONT_HERSHEY_SIMPLEX, 0.9, (0, 255, 0), 2)
|
||||
|
||||
# Create an MQTT client instance
|
||||
mqtt_client = mqtt.Client()
|
||||
mqtt_client.username_pw_set("server", "serverwachtwoordofzo")
|
||||
mqtt_client.connect("localhost", 1883, 60)
|
||||
mqtt_client.connect("localhost", 1884, 60)
|
||||
mqtt_client.loop_start()
|
||||
mqtt_client.subscribe("kobuki/data")
|
||||
mqtt_client.subscribe("kobuki/cam")
|
||||
|
@@ -7,3 +7,7 @@ User=user1
|
||||
WorkingDirectory=/home/user1/rooziinuubii79/src/C++/Driver/
|
||||
ExecStart=/home/user1/rooziinuubii79/src/C++/Driver/kobuki_control
|
||||
Restart=always
|
||||
RestartSec=5
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
Reference in New Issue
Block a user