Minor clarity changes

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

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

Loading…
Cancel
Save