Skip to content
Snippets Groups Projects
Commit 087ed62a authored by Nicolas Pope's avatar Nicolas Pope
Browse files

Add context menu snapshot

parent 562a2e02
No related branches found
No related tags found
1 merge request!316Resolves #343 GUI and Frame Refactor
Pipeline #28520 failed
...@@ -5,6 +5,10 @@ ...@@ -5,6 +5,10 @@
#include <ftl/rgbd/capabilities.hpp> #include <ftl/rgbd/capabilities.hpp>
#include <chrono> #include <chrono>
#include <opencv2/imgproc.hpp>
#include <opencv2/imgcodecs.hpp>
#include <opencv2/cudaarithm.hpp>
#include <loguru.hpp> #include <loguru.hpp>
using ftl::gui2::Camera; using ftl::gui2::Camera;
...@@ -341,6 +345,19 @@ void Camera::startStreaming(const std::unordered_set<ftl::codecs::Channel> &chan ...@@ -341,6 +345,19 @@ void Camera::startStreaming(const std::unordered_set<ftl::codecs::Channel> &chan
io->feed()->startStreaming(filter); io->feed()->startStreaming(filter);
} }
void Camera::snapshot(const std::string &filename) {
auto ptr = std::atomic_load(&latest_);
if (ptr) {
auto &frame = ptr->frames[frame_idx];
if (frame.hasChannel(channel)) {
const auto &snap = frame.get<cv::Mat>(channel);
cv::Mat output;
cv::cvtColor(snap, output, cv::COLOR_BGRA2BGR);
cv::imwrite(filename, output);
}
}
}
ftl::cuda::TextureObject<uchar4>& Camera::getFrame() { ftl::cuda::TextureObject<uchar4>& Camera::getFrame() {
if (std::atomic_load(&current_fs_)) { if (std::atomic_load(&current_fs_)) {
auto& frame = current_fs_->frames[frame_idx].cast<ftl::rgbd::Frame>(); auto& frame = current_fs_->frames[frame_idx].cast<ftl::rgbd::Frame>();
......
...@@ -61,6 +61,8 @@ public: ...@@ -61,6 +61,8 @@ public:
void startRecording(const std::string &filename, const std::unordered_set<ftl::codecs::Channel> &channels); void startRecording(const std::string &filename, const std::unordered_set<ftl::codecs::Channel> &channels);
void startStreaming(const std::unordered_set<ftl::codecs::Channel> &channels); void startStreaming(const std::unordered_set<ftl::codecs::Channel> &channels);
void snapshot(const std::string &filename);
private: private:
int frame_idx = -1; int frame_idx = -1;
ftl::data::FrameID frame_id_; ftl::data::FrameID frame_id_;
......
...@@ -377,6 +377,29 @@ CameraView::CameraView(ftl::gui2::Screen* parent, ftl::gui2::Camera* ctrl) : ...@@ -377,6 +377,29 @@ CameraView::CameraView(ftl::gui2::Screen* parent, ftl::gui2::Camera* ctrl) :
imview_->setCursor(nanogui::Cursor::Crosshair); imview_->setCursor(nanogui::Cursor::Crosshair);
mod->setCursor(nanogui::Cursor::Crosshair); mod->setCursor(nanogui::Cursor::Crosshair);
} }
auto theme = dynamic_cast<ftl::gui2::Screen*>(screen())->getTheme("toolbutton");
//this->setTheme(theme);
context_menu_ = new nanogui::Window(parent, "");
context_menu_->setVisible(false);
context_menu_->setLayout(new nanogui::BoxLayout(nanogui::Orientation::Vertical));
context_menu_->setTheme(theme);
auto *button = new nanogui::Button(context_menu_, "Capture Image");
button->setCallback([this]() {
char timestamp[18];
std::time_t t=std::time(NULL);
std::strftime(timestamp, sizeof(timestamp), "%F-%H%M%S", std::localtime(&t));
context_menu_->setVisible(false);
ctrl_->snapshot(std::string(timestamp)+std::string(".png"));
});
button = new nanogui::Button(context_menu_, "Settings");
button->setCallback([this, button]() {
context_menu_->setVisible(false);
ctrl_->screen->getModule<ftl::gui2::ConfigCtrl>()->show(ctrl_->getID());
});
} }
CameraView::~CameraView() { CameraView::~CameraView() {
...@@ -385,6 +408,11 @@ CameraView::~CameraView() { ...@@ -385,6 +408,11 @@ CameraView::~CameraView() {
// should be fixed in nanogui // should be fixed in nanogui
panel_->dispose(); panel_->dispose();
} }
if (context_menu_->parent()->getRefCount() > 0) {
context_menu_->setVisible(false);
context_menu_->dispose();
}
} }
void CameraView::refresh() { void CameraView::refresh() {
...@@ -434,8 +462,17 @@ bool CameraView::mouseButtonEvent(const Eigen::Vector2i &p, int button, bool dow ...@@ -434,8 +462,17 @@ bool CameraView::mouseButtonEvent(const Eigen::Vector2i &p, int button, bool dow
if (pos.x() >= 0.0f && pos.y() >= 0.0f) { if (pos.x() >= 0.0f && pos.y() >= 0.0f) {
ctrl_->touch(0, ftl::codecs::TouchType::MOUSE_LEFT, pos.x(), pos.y(), 0.0f, (down) ? 255 : 0); ctrl_->touch(0, ftl::codecs::TouchType::MOUSE_LEFT, pos.x(), pos.y(), 0.0f, (down) ? 255 : 0);
} }
context_menu_->setVisible(false);
return true;
} else if (button == 1) {
if (!down) {
context_menu_->setPosition(p - mPos);
context_menu_->setVisible(true);
return true; return true;
} }
} else {
context_menu_->setVisible(false);
}
return false; return false;
} }
......
...@@ -34,6 +34,7 @@ protected: ...@@ -34,6 +34,7 @@ protected:
Camera* ctrl_; Camera* ctrl_;
MediaPanel* panel_; MediaPanel* panel_;
FTLImageView* imview_; FTLImageView* imview_;
nanogui::Window *context_menu_;
public: public:
EIGEN_MAKE_ALIGNED_OPERATOR_NEW EIGEN_MAKE_ALIGNED_OPERATOR_NEW
......
...@@ -65,8 +65,7 @@ bool CameraView3D::keyboardEvent(int key, int scancode, int action, int modifier ...@@ -65,8 +65,7 @@ bool CameraView3D::keyboardEvent(int key, int scancode, int action, int modifier
} }
bool CameraView3D::mouseButtonEvent(const Eigen::Vector2i &p, int button, bool down, int modifiers) { bool CameraView3D::mouseButtonEvent(const Eigen::Vector2i &p, int button, bool down, int modifiers) {
LOG(INFO) << "mouseButtonEvent: " << p; return CameraView::mouseButtonEvent(p, button, down, modifiers);
return true;
} }
bool CameraView3D::mouseMotionEvent(const Eigen::Vector2i &p, const Eigen::Vector2i &rel, int button, int modifiers) { bool CameraView3D::mouseMotionEvent(const Eigen::Vector2i &p, const Eigen::Vector2i &rel, int button, int modifiers) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment