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
5 Commits
2fa8fb2926
...
b48243f831
Author | SHA1 | Date | |
---|---|---|---|
|
b48243f831 | ||
317731ec87 | |||
441ca19578 | |||
7f807d0031 | |||
c0ec6901c4 |
@@ -3,3 +3,4 @@ paho-mqtt==1.6.1
|
|||||||
ultralytics==8.3.58
|
ultralytics==8.3.58
|
||||||
opencv-python-headless==4.6.0.66
|
opencv-python-headless==4.6.0.66
|
||||||
numpy==1.23.4
|
numpy==1.23.4
|
||||||
|
mysql-connector-python==9.1.0
|
@@ -1,4 +1,4 @@
|
|||||||
from flask import Flask, Response, request, render_template, jsonify
|
from flask import Flask, Response, request, render_template, jsonify, g
|
||||||
import paho.mqtt.client as mqtt
|
import paho.mqtt.client as mqtt
|
||||||
from ultralytics import YOLO
|
from ultralytics import YOLO
|
||||||
import cv2
|
import cv2
|
||||||
@@ -49,18 +49,6 @@ def on_message(client, userdata, message):
|
|||||||
cv2.rectangle(processed_image, (x1, y1), (x2, y2), (0, 255, 0), 2)
|
cv2.rectangle(processed_image, (x1, y1), (x2, y2), (0, 255, 0), 2)
|
||||||
cv2.putText(processed_image, f"{class_name} {box.conf.item():.2f}", (x1, y1 - 10), cv2.FONT_HERSHEY_SIMPLEX, 0.9, (0, 255, 0), 2)
|
cv2.putText(processed_image, f"{class_name} {box.conf.item():.2f}", (x1, y1 - 10), cv2.FONT_HERSHEY_SIMPLEX, 0.9, (0, 255, 0), 2)
|
||||||
|
|
||||||
|
|
||||||
# Globale MQTT setup
|
|
||||||
def on_message(client,userdata, message):
|
|
||||||
global kobuki_message, latest_image
|
|
||||||
if message.topic == "kobuki/data":
|
|
||||||
kobuki_message = str(message.payload.decode("utf-8"))
|
|
||||||
with app.app_context():
|
|
||||||
sensor_data(kobuki_message) # Sla de data op in de database
|
|
||||||
elif message.topic == "kobuki/cam":
|
|
||||||
latest_image = message.payload
|
|
||||||
|
|
||||||
|
|
||||||
# Create an MQTT client instance
|
# Create an MQTT client instance
|
||||||
mqtt_client = mqtt.Client()
|
mqtt_client = mqtt.Client()
|
||||||
mqtt_client.username_pw_set("server", "serverwachtwoordofzo")
|
mqtt_client.username_pw_set("server", "serverwachtwoordofzo")
|
||||||
@@ -131,8 +119,10 @@ def database():
|
|||||||
rows = cursor.fetchall()
|
rows = cursor.fetchall()
|
||||||
cursor.close()
|
cursor.close()
|
||||||
return str(rows)
|
return str(rows)
|
||||||
|
|
||||||
|
|
||||||
def sensor_data(kobuki_message):
|
@app.route('/data', methods=['GET'])
|
||||||
|
def data():
|
||||||
try:
|
try:
|
||||||
# Parse de JSON-string naar een Python-dictionary
|
# Parse de JSON-string naar een Python-dictionary
|
||||||
data = json.loads(kobuki_message)
|
data = json.loads(kobuki_message)
|
||||||
@@ -165,10 +155,8 @@ def sensor_data(kobuki_message):
|
|||||||
print(f"JSON decode error: {e}")
|
print(f"JSON decode error: {e}")
|
||||||
except mysql.connector.Error as err:
|
except mysql.connector.Error as err:
|
||||||
print(f"Database error: {err}")
|
print(f"Database error: {err}")
|
||||||
|
|
||||||
@app.route('/data', methods=['GET'])
|
|
||||||
def data():
|
|
||||||
return kobuki_message
|
return kobuki_message
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@app.route('/image')
|
@app.route('/image')
|
||||||
|
@@ -34,7 +34,8 @@ document.addEventListener("DOMContentLoaded", function() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Parse the data and show it on the website
|
// Parse the data and show it on the website
|
||||||
|
async function parseData() {
|
||||||
const data = await fetchData();
|
const data = await fetchData();
|
||||||
const sensorDataContainer = document.getElementById("sensor-data");
|
const sensorDataContainer = document.getElementById("sensor-data");
|
||||||
sensorDataContainer.innerHTML = ""; // Clear previous data
|
sensorDataContainer.innerHTML = ""; // Clear previous data
|
||||||
@@ -57,5 +58,4 @@ document.addEventListener("DOMContentLoaded", function() {
|
|||||||
|
|
||||||
// Update the image every 200 milliseconds
|
// Update the image every 200 milliseconds
|
||||||
setInterval(updateImage, 100);
|
setInterval(updateImage, 100);
|
||||||
});
|
});
|
||||||
|
|
Reference in New Issue
Block a user