Minor clarity changes

master
Benjamin Ruesink 2 months ago
parent 2ec5e2fe24
commit 8034f52dfe

@ -39,11 +39,11 @@
#include "../../../utils/httplib.h"
enum FrameType {
TYPE_ORIGINAL,
TYPE_OUTLINE,
TYPE_PROCESSED,
TYPE_MAX
enum StreamType {
ST_ORIGINAL,
ST_MASKED,
ST_PROCESSED, // testing
ST_MAX
};
struct FrameQueue {
@ -51,7 +51,7 @@ struct FrameQueue {
std::mutex frameMutex;
};
std::vector<FrameQueue> frameQueues(TYPE_MAX);
std::vector<FrameQueue> frameQueues(ST_MAX);
// Convert cv::Mat to JPEG buffer
std::vector<uchar> matToBytes(const cv::Mat& img) {
@ -1029,16 +1029,15 @@ FXApp::Err FXApp::processMovie(const char *inFile, const char *outFile) {
}
}
pushToFrameQueue(0, originalImg);
pushToFrameQueue(1, result);
pushToFrameQueue(2, outlineResult);
pushToFrameQueue(ST_ORIGINAL, originalImg);
pushToFrameQueue(ST_MASKED, result);
pushToFrameQueue(ST_PROCESSED, outlineResult);
// Display the results
cv::imshow("Original", originalImg);
cv::imshow("Overlay", result);
cv::imshow("OutlineTest", outlineResult);
int key = cv::waitKey(1);
if (key > 0) {
appErr = processKey(key);
@ -1093,18 +1092,18 @@ bool isCompModeEnumValid(const FXApp::CompMode& mode)
void startHttpServer() {
httplib::Server svr;
auto streamHandler = [](FrameType frameType) {
return [frameType](const httplib::Request&, httplib::Response& res) {
auto streamHandler = [](StreamType streamType) {
return [streamType](const httplib::Request&, httplib::Response& res) {
res.set_content_provider(
"multipart/x-mixed-replace; boundary=frame",
[frameType](size_t offset, httplib::DataSink& sink) {
[streamType](size_t offset, httplib::DataSink& sink) {
while (true) {
cv::Mat frame;
{
std::lock_guard<std::mutex> lock(frameQueues[frameType].frameMutex);
if (!frameQueues[frameType].frameQueue.empty()) {
frame = frameQueues[frameType].frameQueue.front();
frameQueues[frameType].frameQueue.pop();
std::lock_guard<std::mutex> lock(frameQueues[streamType].frameMutex);
if (!frameQueues[streamType].frameQueue.empty()) {
frame = frameQueues[streamType].frameQueue.front();
frameQueues[streamType].frameQueue.pop();
}
}
@ -1128,15 +1127,16 @@ void startHttpServer() {
};
};
// Array of route names corresponding to FrameType enum
const std::array<std::string, TYPE_MAX> routeNames = {
"original", "outline", "processed"
// Array of route names corresponding to StreamType enum
const std::array<std::string, ST_MAX> routeNames = {
"original", "masked", "processed"
};
// Set up routes for each frame type
for (int i = 0; i < TYPE_MAX; ++i) {
for (int i = 0; i < ST_MAX; ++i) {
std::string route = "/video_" + routeNames[i];
svr.Get(route, streamHandler(static_cast<FrameType>(i)));
svr.Get(route, streamHandler((StreamType)i));
printf("Streaming %s at http://localhost:8080%s\n", routeNames[i].c_str(), route.c_str());
}
svr.listen("0.0.0.0", 8080); // Start server on port 8080

Loading…
Cancel
Save