Skip to content
Snippets Groups Projects
Commit a306deaf authored by Iiro Rastas's avatar Iiro Rastas
Browse files

Add 2D video recording

Adds 2D video recording option to the GUI.
parent d3e66259
No related branches found
No related tags found
1 merge request!179Feature/219/gui record options
Pipeline #16353 passed
......@@ -137,6 +137,7 @@ ftl::gui::Camera::Camera(ftl::gui::Screen *screen, ftl::rgbd::Source *src) : scr
sdepth_ = false;
ftime_ = (float)glfwGetTime();
pause_ = false;
videowriter_ = std::nullopt;
channel_ = Channel::Left;
......@@ -488,6 +489,12 @@ const GLTexture &ftl::gui::Camera::captureFrame() {
//imageSize = Vector2f(rgb.cols,rgb.rows);
texture1_.update(im1_);
}
if (videowriter_) {
cv::Mat image;
cv::flip(im1_, image, 0);
videowriter_.value().write(image);
}
}
return texture1_;
......@@ -503,6 +510,21 @@ void ftl::gui::Camera::snapshot() {
cv::imwrite(std::string(timestamp) + ".png", image);
}
void ftl::gui::Camera::toggleVideoRecording() {
if (videowriter_) {
videowriter_.value().release();
videowriter_ = std::nullopt;
} else {
char timestamp[18];
std::time_t t = std::time(NULL);
std::strftime(timestamp, sizeof(timestamp), "%F-%H%M%S", std::localtime(&t));
videowriter_ = std::optional<cv::VideoWriter>(cv::VideoWriter(std::string(timestamp) + ".avi",
cv::VideoWriter::fourcc('M','J','P','G'),
screen_->root()->value("fps", 20),
cv::Size(width(), height())));
}
}
nlohmann::json ftl::gui::Camera::getMetaData() {
return nlohmann::json();
}
......@@ -53,6 +53,8 @@ class Camera {
void snapshot();
void toggleVideoRecording();
nlohmann::json getMetaData();
StatisticsImage *stats_ = nullptr;
......@@ -87,6 +89,7 @@ class Camera {
ftl::codecs::Channels channels_;
cv::Mat im1_; // first channel (left)
cv::Mat im2_; // second channel ("right")
std::optional<cv::VideoWriter> videowriter_;
MUTEX mutex_;
......
......@@ -47,6 +47,15 @@ MediaPanel::MediaPanel(ftl::gui::Screen *screen) : nanogui::Window(screen, ""),
screen_->activeCamera()->snapshot();
});
itembutton = new Button(recordpopup, "2D video recording");
itembutton->setFlags(Button::ToggleButton);
itembutton->setChangeCallback([this,recordbutton](bool state) {
screen_->activeCamera()->toggleVideoRecording();
if (state) {
recordbutton->setTextColor(nanogui::Color(1.0f,0.1f,0.1f,1.0f));
} else {
recordbutton->setTextColor(nanogui::Color(1.0f,1.0f,1.0f,1.0f));
}
});
itembutton = new Button(recordpopup, "Depth video recording");
itembutton->setFlags(Button::ToggleButton);
itembutton->setChangeCallback([this,recordbutton](bool state) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment