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
7 Commits
976840c6b2
...
main
Author | SHA1 | Date | |
---|---|---|---|
1431d2c164 | |||
0a8b96a45a | |||
69eba455f9 | |||
e262325565 | |||
|
f493665275 | ||
|
899aa94b40 | ||
|
d5524d7890 |
@@ -30,7 +30,7 @@ This project is a kobuki that drives around in dangerous areas and detects objec
|
|||||||
|
|
||||||
3. **Install the required packages**
|
3. **Install the required packages**
|
||||||
- Install the following packages on the server: "docker docker-buildx mosquitto nginx"
|
- Install the following packages on the server: "docker docker-buildx mosquitto nginx"
|
||||||
- Install the following packages on the Raspberry Pi: "g++ make cmake", https://github.com/eclipse-paho/paho.mqtt.c, https://github.com/eclipse-paho/paho.mqtt.cpp
|
- Install the following packages on the Raspberry Pi: "g++ make cmake libopencv-dev libssl-dev", https://github.com/eclipse-paho/paho.mqtt.c, https://github.com/eclipse-paho/paho.mqtt.cpp
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@@ -407,6 +407,7 @@ std::string serializeKobukiData(const TKobukiData &data)
|
|||||||
json += "]}";
|
json += "]}";
|
||||||
return json;
|
return json;
|
||||||
}
|
}
|
||||||
|
|
||||||
// create extra function to send the message every 100ms
|
// create extra function to send the message every 100ms
|
||||||
// needed it so it can be threaded
|
// needed it so it can be threaded
|
||||||
void sendKobukiData(TKobukiData &data)
|
void sendKobukiData(TKobukiData &data)
|
||||||
@@ -420,7 +421,8 @@ void sendKobukiData(TKobukiData &data)
|
|||||||
}
|
}
|
||||||
|
|
||||||
void CapnSend() {
|
void CapnSend() {
|
||||||
VideoCapture cap(0);
|
int COMPRESSION_LEVEL = 90;
|
||||||
|
VideoCapture cap(0); // Open the camera
|
||||||
if (!cap.isOpened()) {
|
if (!cap.isOpened()) {
|
||||||
cerr << "Error: Could not open camera" << endl;
|
cerr << "Error: Could not open camera" << endl;
|
||||||
return;
|
return;
|
||||||
@@ -444,14 +446,21 @@ void CapnSend() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Convert the image to a byte array
|
|
||||||
vector<uchar> buf;
|
|
||||||
imencode(".jpg", frame, buf);
|
|
||||||
auto *enc_msg = reinterpret_cast<unsigned char *>(buf.data());
|
|
||||||
|
|
||||||
// Publish the image data
|
vector<uchar> imgbuf;
|
||||||
client.publishMessage("kobuki/cam", string(enc_msg, enc_msg + buf.size()));
|
vector<int> compression_params;
|
||||||
cout << "Sent image" << endl;
|
compression_params.push_back(IMWRITE_JPEG_QUALITY); // Set JPEG quality
|
||||||
|
compression_params.push_back(COMPRESSION_LEVEL); // Adjust the quality level (0-100, lower = more compression)
|
||||||
|
|
||||||
|
// Encode the image into the byte buffer with the specified compression parameters
|
||||||
|
imencode(".jpg", frame, imgbuf, compression_params);
|
||||||
|
|
||||||
|
// Convert the vector<uchar> buffer to a string (no casting)
|
||||||
|
string enc_msg(imgbuf.begin(), imgbuf.end());
|
||||||
|
|
||||||
|
// Publish the compressed image data (MQTT, in this case)
|
||||||
|
client.publishMessage("kobuki/cam", enc_msg);
|
||||||
|
cout << "Sent compressed image" << endl;
|
||||||
|
|
||||||
std::this_thread::sleep_for(std::chrono::milliseconds(200)); // Send image every 200ms
|
std::this_thread::sleep_for(std::chrono::milliseconds(200)); // Send image every 200ms
|
||||||
}
|
}
|
||||||
|
@@ -85,6 +85,7 @@ def index():
|
|||||||
@app.route('/control', methods=["GET", "POST"])
|
@app.route('/control', methods=["GET", "POST"])
|
||||||
def control():
|
def control():
|
||||||
if request.authorization and request.authorization.username == 'ishak' and request.authorization.password == 'kobuki':
|
if request.authorization and request.authorization.username == 'ishak' and request.authorization.password == 'kobuki':
|
||||||
|
yolo_results_db()
|
||||||
return render_template('control.html')
|
return render_template('control.html')
|
||||||
else:
|
else:
|
||||||
return ('Unauthorized', 401, {'WWW-Authenticate': 'Basic realm="Login Required"'})
|
return ('Unauthorized', 401, {'WWW-Authenticate': 'Basic realm="Login Required"'})
|
||||||
@@ -158,8 +159,12 @@ def image():
|
|||||||
return "No image available", 404
|
return "No image available", 404
|
||||||
|
|
||||||
|
|
||||||
@app.route('/yolo_results', methods=['GET', 'POST'])
|
@app.route('/yolo_results', methods=['GET'])
|
||||||
def yolo_results_endpoint():
|
def yolo_results_endpoint():
|
||||||
|
global yolo_results
|
||||||
|
return jsonify(yolo_results)
|
||||||
|
|
||||||
|
def yolo_results_db():
|
||||||
global yolo_results
|
global yolo_results
|
||||||
with lock:
|
with lock:
|
||||||
try:
|
try:
|
||||||
@@ -176,7 +181,5 @@ def yolo_results_endpoint():
|
|||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(f"Unexpected error: {e}")
|
print(f"Unexpected error: {e}")
|
||||||
|
|
||||||
return jsonify(yolo_results)
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
app.run(debug=True, port=5000)
|
app.run(debug=True, port=5000)
|
Reference in New Issue
Block a user