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

Implements #112 thumbnails

parent ef3bdb15
No related branches found
No related tags found
No related merge requests found
Showing
with 246 additions and 61 deletions
...@@ -12,6 +12,7 @@ set(GUISRC ...@@ -12,6 +12,7 @@ set(GUISRC
src/gltexture.cpp src/gltexture.cpp
src/camera.cpp src/camera.cpp
src/media_panel.cpp src/media_panel.cpp
src/thumbview.cpp
) )
add_executable(ftl-gui ${GUISRC}) add_executable(ftl-gui ${GUISRC})
......
...@@ -14,20 +14,21 @@ GLTexture::~GLTexture() { ...@@ -14,20 +14,21 @@ GLTexture::~GLTexture() {
} }
void GLTexture::update(cv::Mat &m) { void GLTexture::update(cv::Mat &m) {
if (m.rows == 0) return;
if (glid_ == std::numeric_limits<unsigned int>::max()) { if (glid_ == std::numeric_limits<unsigned int>::max()) {
glGenTextures(1, &glid_); glGenTextures(1, &glid_);
glBindTexture(GL_TEXTURE_2D, glid_); glBindTexture(GL_TEXTURE_2D, glid_);
cv::Mat m(cv::Size(100,100), CV_8UC3); //cv::Mat m(cv::Size(100,100), CV_8UC3);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB8, m.cols, m.rows, 0, GL_RGB, GL_UNSIGNED_BYTE, m.data); glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB8, m.cols, m.rows, 0, GL_BGR, GL_UNSIGNED_BYTE, m.data);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
} else {
glBindTexture(GL_TEXTURE_2D, glid_);
// TODO Allow for other formats
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB8, m.cols, m.rows, 0, GL_BGR, GL_UNSIGNED_BYTE, m.data);
} }
if (m.rows == 0) return;
glBindTexture(GL_TEXTURE_2D, glid_);
// TODO Allow for other formats
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB8, m.cols, m.rows, 0, GL_BGR, GL_UNSIGNED_BYTE, m.data);
auto err = glGetError(); auto err = glGetError();
if (err != 0) LOG(ERROR) << "OpenGL Texture error: " << err; if (err != 0) LOG(ERROR) << "OpenGL Texture error: " << err;
} }
...@@ -13,6 +13,7 @@ class GLTexture { ...@@ -13,6 +13,7 @@ class GLTexture {
void update(cv::Mat &m); void update(cv::Mat &m);
unsigned int texture() const { return glid_; } unsigned int texture() const { return glid_; }
bool isValid() const { return glid_ != std::numeric_limits<unsigned int>::max(); }
private: private:
unsigned int glid_; unsigned int glid_;
......
...@@ -26,25 +26,6 @@ MediaPanel::MediaPanel(ftl::gui::Screen *screen) : nanogui::Window(screen, ""), ...@@ -26,25 +26,6 @@ MediaPanel::MediaPanel(ftl::gui::Screen *screen) : nanogui::Window(screen, ""),
//setFixedSize(size); //setFixedSize(size);
setPosition(Vector2i(screen->width() / 2 - size[0]/2, screen->height() - 30 - size[1])); setPosition(Vector2i(screen->width() / 2 - size[0]/2, screen->height() - 30 - size[1]));
Theme *mediatheme = new Theme(*theme());
mediatheme->mIconScale = 1.2f;
mediatheme->mWindowDropShadowSize = 0;
mediatheme->mWindowFillFocused = nanogui::Color(45, 150);
mediatheme->mWindowFillUnfocused = nanogui::Color(45, 80);
mediatheme->mButtonGradientTopUnfocused = nanogui::Color(0,0);
mediatheme->mButtonGradientBotUnfocused = nanogui::Color(0,0);
mediatheme->mButtonGradientTopFocused = nanogui::Color(80,230);
mediatheme->mButtonGradientBotFocused = nanogui::Color(80,230);
mediatheme->mIconColor = nanogui::Color(255,255);
mediatheme->mTextColor = nanogui::Color(1.0f,1.0f,1.0f,1.0f);
mediatheme->mBorderDark = nanogui::Color(0,0);
mediatheme->mBorderMedium = nanogui::Color(0,0);
mediatheme->mBorderLight = nanogui::Color(0,0);
mediatheme->mDropShadow = nanogui::Color(0,0);
mediatheme->mButtonFontSize = 30;
setTheme(mediatheme);
auto button = new Button(this, "", ENTYPO_ICON_EDIT); auto button = new Button(this, "", ENTYPO_ICON_EDIT);
button->setTooltip("Edit camera properties"); button->setTooltip("Edit camera properties");
button->setCallback([this]() { button->setCallback([this]() {
......
...@@ -72,6 +72,24 @@ ftl::gui::Screen::Screen(ftl::Configurable *proot, ftl::net::Universe *pnet, ftl ...@@ -72,6 +72,24 @@ ftl::gui::Screen::Screen(ftl::Configurable *proot, ftl::net::Universe *pnet, ftl
toolbuttheme->mButtonGradientTopPushed = nanogui::Color(60,180); toolbuttheme->mButtonGradientTopPushed = nanogui::Color(60,180);
toolbuttheme->mButtonGradientBotPushed = nanogui::Color(60,180); toolbuttheme->mButtonGradientBotPushed = nanogui::Color(60,180);
Theme *mediatheme = new Theme(*theme());
mediatheme->mIconScale = 1.2f;
mediatheme->mWindowDropShadowSize = 0;
mediatheme->mWindowFillFocused = nanogui::Color(45, 150);
mediatheme->mWindowFillUnfocused = nanogui::Color(45, 80);
mediatheme->mButtonGradientTopUnfocused = nanogui::Color(0,0);
mediatheme->mButtonGradientBotUnfocused = nanogui::Color(0,0);
mediatheme->mButtonGradientTopFocused = nanogui::Color(80,230);
mediatheme->mButtonGradientBotFocused = nanogui::Color(80,230);
mediatheme->mIconColor = nanogui::Color(255,255);
mediatheme->mTextColor = nanogui::Color(1.0f,1.0f,1.0f,1.0f);
mediatheme->mBorderDark = nanogui::Color(0,0);
mediatheme->mBorderMedium = nanogui::Color(0,0);
mediatheme->mBorderLight = nanogui::Color(0,0);
mediatheme->mDropShadow = nanogui::Color(0,0);
mediatheme->mButtonFontSize = 30;
mediatheme->mStandardFontSize = 20;
windowtheme = new Theme(*theme()); windowtheme = new Theme(*theme());
windowtheme->mWindowFillFocused = nanogui::Color(220, 200); windowtheme->mWindowFillFocused = nanogui::Color(220, 200);
windowtheme->mWindowFillUnfocused = nanogui::Color(220, 200); windowtheme->mWindowFillUnfocused = nanogui::Color(220, 200);
...@@ -196,6 +214,7 @@ ftl::gui::Screen::Screen(ftl::Configurable *proot, ftl::net::Universe *pnet, ftl ...@@ -196,6 +214,7 @@ ftl::gui::Screen::Screen(ftl::Configurable *proot, ftl::net::Universe *pnet, ftl
swindow_ = new ftl::gui::SourceWindow(this); swindow_ = new ftl::gui::SourceWindow(this);
mwindow_ = new ftl::gui::MediaPanel(this); mwindow_ = new ftl::gui::MediaPanel(this);
mwindow_->setVisible(false); mwindow_->setVisible(false);
mwindow_->setTheme(mediatheme);
cwindow_->setPosition(Eigen::Vector2i(80, 20)); cwindow_->setPosition(Eigen::Vector2i(80, 20));
//swindow_->setPosition(Eigen::Vector2i(80, 400)); //swindow_->setPosition(Eigen::Vector2i(80, 400));
...@@ -203,7 +222,7 @@ ftl::gui::Screen::Screen(ftl::Configurable *proot, ftl::net::Universe *pnet, ftl ...@@ -203,7 +222,7 @@ ftl::gui::Screen::Screen(ftl::Configurable *proot, ftl::net::Universe *pnet, ftl
swindow_->setVisible(true); swindow_->setVisible(true);
swindow_->center(); swindow_->center();
cwindow_->setTheme(windowtheme); cwindow_->setTheme(windowtheme);
swindow_->setTheme(windowtheme); swindow_->setTheme(mediatheme);
mShader.init("RGBDShader", defaultImageViewVertexShader, mShader.init("RGBDShader", defaultImageViewVertexShader,
defaultImageViewFragmentShader); defaultImageViewFragmentShader);
......
...@@ -12,11 +12,14 @@ ...@@ -12,11 +12,14 @@
#include <nanogui/glutil.h> #include <nanogui/glutil.h>
#include <nanogui/screen.h> #include <nanogui/screen.h>
#include <nanogui/layout.h> #include <nanogui/layout.h>
#include <nanogui/vscrollpanel.h>
#ifdef HAVE_LIBARCHIVE #ifdef HAVE_LIBARCHIVE
#include "ftl/rgbd/snapshot.hpp" #include "ftl/rgbd/snapshot.hpp"
#endif #endif
#include "thumbview.hpp"
using ftl::gui::SourceWindow; using ftl::gui::SourceWindow;
using ftl::gui::Screen; using ftl::gui::Screen;
using ftl::rgbd::Source; using ftl::rgbd::Source;
...@@ -25,7 +28,7 @@ using ftl::config::json_t; ...@@ -25,7 +28,7 @@ using ftl::config::json_t;
SourceWindow::SourceWindow(ftl::gui::Screen *screen) SourceWindow::SourceWindow(ftl::gui::Screen *screen)
: nanogui::Window(screen, ""), screen_(screen) { : nanogui::Window(screen, ""), screen_(screen) {
setLayout(new nanogui::GroupLayout()); setLayout(new nanogui::BoxLayout(nanogui::Orientation::Vertical, nanogui::Alignment::Fill, 20, 5));
using namespace nanogui; using namespace nanogui;
...@@ -39,24 +42,33 @@ SourceWindow::SourceWindow(ftl::gui::Screen *screen) ...@@ -39,24 +42,33 @@ SourceWindow::SourceWindow(ftl::gui::Screen *screen)
// tools->setLayout(new BoxLayout(Orientation::Horizontal, // tools->setLayout(new BoxLayout(Orientation::Horizontal,
// Alignment::Middle, 0, 6)); // Alignment::Middle, 0, 6));
new Label(this, "Select source","sans-bold"); auto label = new Label(this, "Select Camera","sans-bold",20);
available_ = screen_->control()->getNet()->findAll<string>("list_streams"); available_ = screen_->control()->getNet()->findAll<string>("list_streams");
auto select = new ComboBox(this, available_); //auto select = new ComboBox(this, available_);
select->setCallback([this,select](int ix) { //select->setCallback([this,select](int ix) {
//src_->set("uri", available_[ix]); //src_->set("uri", available_[ix]);
// TODO(Nick) Check camera exists first // TODO(Nick) Check camera exists first
screen_->setActiveCamera(cameras_[available_[ix]]); // screen_->setActiveCamera(cameras_[available_[ix]]);
LOG(INFO) << "Change source: " << ix; // LOG(INFO) << "Change source: " << ix;
}); //});
_updateCameras(); auto vscroll = new VScrollPanel(this);
ipanel_ = new Widget(vscroll);
ipanel_->setLayout(new GridLayout(nanogui::Orientation::Horizontal, 2,
nanogui::Alignment::Middle, 0, 5));
//ipanel_ = new ImageView(vscroll, 0);
screen->net()->onConnect([this,select](ftl::net::Peer *p) { screen->net()->onConnect([this](ftl::net::Peer *p) {
UNIQUE_LOCK(mutex_, lk);
available_ = screen_->net()->findAll<string>("list_streams"); available_ = screen_->net()->findAll<string>("list_streams");
select->setItems(available_); //select->setItems(available_);
_updateCameras(); _updateCameras();
}); });
UNIQUE_LOCK(mutex_, lk);
_updateCameras();
/*new Label(this, "Source Options","sans-bold"); /*new Label(this, "Source Options","sans-bold");
auto tools = new Widget(this); auto tools = new Widget(this);
...@@ -118,6 +130,11 @@ SourceWindow::SourceWindow(ftl::gui::Screen *screen) ...@@ -118,6 +130,11 @@ SourceWindow::SourceWindow(ftl::gui::Screen *screen)
} }
void SourceWindow::_updateCameras() { void SourceWindow::_updateCameras() {
refresh_thumbs_ = true;
if (thumbs_.size() != available_.size()) {
thumbs_.resize(available_.size());
}
for (auto s : available_) { for (auto s : available_) {
if (cameras_.find(s) == cameras_.end()) { if (cameras_.find(s) == cameras_.end()) {
json_t srcjson; json_t srcjson;
...@@ -126,6 +143,8 @@ void SourceWindow::_updateCameras() { ...@@ -126,6 +143,8 @@ void SourceWindow::_updateCameras() {
std::vector<ftl::rgbd::Source*> srcs = ftl::createArray<ftl::rgbd::Source>(screen_->root(), "sources", screen_->net()); std::vector<ftl::rgbd::Source*> srcs = ftl::createArray<ftl::rgbd::Source>(screen_->root(), "sources", screen_->net());
auto *src = srcs[srcs.size()-1]; auto *src = srcs[srcs.size()-1];
LOG(INFO) << "Making camera: " << src->getURI();
auto *cam = new ftl::gui::Camera(screen_, src); auto *cam = new ftl::gui::Camera(screen_, src);
cameras_[s] = cam; cameras_[s] = cam;
} else { } else {
...@@ -137,3 +156,33 @@ void SourceWindow::_updateCameras() { ...@@ -137,3 +156,33 @@ void SourceWindow::_updateCameras() {
SourceWindow::~SourceWindow() { SourceWindow::~SourceWindow() {
} }
void SourceWindow::draw(NVGcontext *ctx) {
if (refresh_thumbs_) {
UNIQUE_LOCK(mutex_, lk);
//refresh_thumbs_ = false;
for (size_t i=0; i<thumbs_.size(); ++i) {
cv::Mat t;
auto *cam = cameras_[available_[i]];
if (cam) {
if (cam->source()->thumbnail(t)) {
thumbs_[i].update(t);
} else {
refresh_thumbs_ = true;
}
}
if (ipanel_->childCount() < i+1) {
new ftl::gui::ThumbView(ipanel_, screen_, cam);
}
if (thumbs_[i].isValid()) dynamic_cast<nanogui::ImageView*>(ipanel_->childAt(i))->bindImage(thumbs_[i].texture());
}
// TODO(Nick) remove excess image views
center();
}
nanogui::Window::draw(ctx);
}
...@@ -2,12 +2,15 @@ ...@@ -2,12 +2,15 @@
#define _FTL_GUI_SRCWINDOW_HPP_ #define _FTL_GUI_SRCWINDOW_HPP_
#include <nanogui/window.h> #include <nanogui/window.h>
#include <nanogui/imageview.h>
#include <ftl/master.hpp> #include <ftl/master.hpp>
#include <ftl/uuid.hpp> #include <ftl/uuid.hpp>
#include <ftl/rgbd/source.hpp> #include <ftl/rgbd/source.hpp>
#include <ftl/threads.hpp>
#include <vector> #include <vector>
#include <map> #include <map>
#include <string> #include <string>
#include "gltexture.hpp"
class VirtualCameraView; class VirtualCameraView;
...@@ -24,10 +27,16 @@ class SourceWindow : public nanogui::Window { ...@@ -24,10 +27,16 @@ class SourceWindow : public nanogui::Window {
const std::vector<ftl::gui::Camera*> &getCameras(); const std::vector<ftl::gui::Camera*> &getCameras();
virtual void draw(NVGcontext *ctx);
private: private:
ftl::gui::Screen *screen_; ftl::gui::Screen *screen_;
std::map<std::string, ftl::gui::Camera*> cameras_; std::map<std::string, ftl::gui::Camera*> cameras_;
std::vector<std::string> available_; std::vector<std::string> available_;
std::vector<GLTexture> thumbs_;
bool refresh_thumbs_;
nanogui::Widget *ipanel_;
std::mutex mutex_;
void _updateCameras(); void _updateCameras();
......
#include "thumbview.hpp"
#include "screen.hpp"
#include "camera.hpp"
using ftl::gui::ThumbView;
using ftl::gui::Screen;
using ftl::gui::Camera;
ThumbView::ThumbView(nanogui::Widget *parent, ftl::gui::Screen *screen, ftl::gui::Camera *cam)
: ImageView(parent, 0), screen_(screen), cam_(cam) {
setCursor(nanogui::Cursor::Hand);
}
ThumbView::~ThumbView() {
}
bool ThumbView::mouseButtonEvent(const nanogui::Vector2i &p, int button, bool down, int modifiers) {
if (button == 0 && !down) {
screen_->setActiveCamera(cam_);
}
}
void ThumbView::draw(NVGcontext *ctx) {
ImageView::draw(ctx);
nvgScissor(ctx, mPos.x(), mPos.y(), mSize.x(), mSize.y());
nvgFontSize(ctx, 14);
nvgFontFace(ctx, "sans-bold");
nvgText(ctx, mPos.x() + 10, mPos.y()+mSize.y() - 10, cam_->source()->getURI().c_str(), NULL);
nvgResetScissor(ctx);
}
#ifndef _FTL_GUI_THUMBVIEW_HPP_
#define _FTL_GUI_THUMBVIEW_HPP_
#include <nanogui/imageview.h>
namespace ftl {
namespace gui {
class Screen;
class Camera;
class ThumbView : public nanogui::ImageView {
public:
ThumbView(nanogui::Widget *parent, ftl::gui::Screen *screen, ftl::gui::Camera *cam);
~ThumbView();
bool mouseButtonEvent(const nanogui::Vector2i &p, int button, bool down, int modifiers);
void draw(NVGcontext *ctx);
private:
Screen *screen_;
Camera *cam_;
};
}
}
#endif // _FTL_GUI_THUMBVIEW_HPP_
...@@ -26,7 +26,7 @@ class VirtualSource : public ftl::rgbd::detail::Source { ...@@ -26,7 +26,7 @@ class VirtualSource : public ftl::rgbd::detail::Source {
void setScene(ftl::voxhash::SceneRep *); void setScene(ftl::voxhash::SceneRep *);
bool grab(); bool grab(int n, int b);
//void getRGBD(cv::Mat &rgb, cv::Mat &depth); //void getRGBD(cv::Mat &rgb, cv::Mat &depth);
bool isReady(); bool isReady();
......
...@@ -53,7 +53,7 @@ void VirtualSource::setScene(ftl::voxhash::SceneRep *scene) { ...@@ -53,7 +53,7 @@ void VirtualSource::setScene(ftl::voxhash::SceneRep *scene) {
scene_ = scene; scene_ = scene;
} }
bool VirtualSource::grab() { bool VirtualSource::grab(int n, int b) {
if (scene_) { if (scene_) {
// Ensure this host thread is using correct GPU. // Ensure this host thread is using correct GPU.
......
...@@ -27,7 +27,11 @@ class Source { ...@@ -27,7 +27,11 @@ class Source {
explicit Source(ftl::rgbd::Source *host) : capabilities_(0), host_(host), params_({0}) { } explicit Source(ftl::rgbd::Source *host) : capabilities_(0), host_(host), params_({0}) { }
virtual ~Source() {} virtual ~Source() {}
virtual bool grab()=0; /**
* @param n Number of frames to request in batch. Default -1 means automatic (10)
* @param b Bit rate setting. -1 = automatic, 0 = best quality, 9 = lowest quality
*/
virtual bool grab(int n, int b)=0;
virtual bool isReady() { return false; }; virtual bool isReady() { return false; };
virtual void setPose(const Eigen::Matrix4d &pose) { }; virtual void setPose(const Eigen::Matrix4d &pose) { };
......
...@@ -173,6 +173,7 @@ class Source : public ftl::Configurable { ...@@ -173,6 +173,7 @@ class Source : public ftl::Configurable {
detail::Source *impl_; detail::Source *impl_;
cv::Mat rgb_; cv::Mat rgb_;
cv::Mat depth_; cv::Mat depth_;
cv::Mat thumb_;
Camera params_; // TODO Find better solution Camera params_; // TODO Find better solution
Eigen::Matrix4d pose_; Eigen::Matrix4d pose_;
ftl::net::Universe *net_; ftl::net::Universe *net_;
......
...@@ -17,14 +17,15 @@ namespace ftl { ...@@ -17,14 +17,15 @@ namespace ftl {
namespace rgbd { namespace rgbd {
static const int kChunkDim = 4; static const int kChunkDim = 4;
static constexpr int kChunkCount = kChunkDim * kChunkDim;
namespace detail { namespace detail {
struct StreamClient { struct StreamClient {
std::string uri; std::string uri;
ftl::UUID peerid; ftl::UUID peerid;
int txcount; // Frames sent since last request std::atomic<int> txcount; // Frames sent since last request
int txmax; // Frames to send in request int txmax; // Frames to send in request
}; };
static const unsigned int kGrabbed = 0x1; static const unsigned int kGrabbed = 0x1;
...@@ -34,11 +35,12 @@ static const unsigned int kDepth = 0x4; ...@@ -34,11 +35,12 @@ static const unsigned int kDepth = 0x4;
struct StreamSource { struct StreamSource {
ftl::rgbd::Source *src; ftl::rgbd::Source *src;
std::atomic<unsigned int> jobs; // Busy or ready to swap? std::atomic<unsigned int> jobs; // Busy or ready to swap?
std::atomic<unsigned int> clientCount;
cv::Mat rgb; // Tx buffer cv::Mat rgb; // Tx buffer
cv::Mat depth; // Tx buffer cv::Mat depth; // Tx buffer
cv::Mat prev_rgb; cv::Mat prev_rgb;
cv::Mat prev_depth; cv::Mat prev_depth;
std::vector<detail::StreamClient> clients[10]; // One list per bitrate std::list<detail::StreamClient> clients[10]; // One list per bitrate
std::shared_mutex mutex; std::shared_mutex mutex;
unsigned long long frame; unsigned long long frame;
}; };
......
#ifndef _FTL_RGBD_BITRATESETTINGS_HPP_
#define _FTL_RGBD_BITRATESETTINGS_HPP_
namespace ftl {
namespace rgbd {
namespace detail {
struct BitrateSetting {
int width;
int height;
int jpg_quality;
int png_compression;
};
static const BitrateSetting bitrate_settings[] = {
1280, 720, 95, 1,
1280, 720, 95, 1,
1280, 720, 95, 1,
1280, 720, 75, 1,
640, 360, 95, 1,
640, 360, 75, 5,
640, 360, 50, 5,
320, 160, 95, 5,
320, 160, 75, 5,
320, 160, 50, 9
};
}
}
}
#endif // _FTL_RGBD_BITRATESETTINGS_HPP_
...@@ -14,7 +14,7 @@ class ImageSource : public ftl::rgbd::detail::Source { ...@@ -14,7 +14,7 @@ class ImageSource : public ftl::rgbd::detail::Source {
} }
bool grab() { return false; }; bool grab(int n, int b) { return false; };
bool isReady() { return false; }; bool isReady() { return false; };
}; };
......
...@@ -150,7 +150,7 @@ void MiddleburySource::_performDisparity() { ...@@ -150,7 +150,7 @@ void MiddleburySource::_performDisparity() {
stream_.waitForCompletion(); stream_.waitForCompletion();
} }
bool MiddleburySource::grab() { bool MiddleburySource::grab(int n, int b) {
//_performDisparity(); //_performDisparity();
return true; return true;
} }
......
...@@ -19,7 +19,7 @@ class MiddleburySource : public detail::Source { ...@@ -19,7 +19,7 @@ class MiddleburySource : public detail::Source {
MiddleburySource(ftl::rgbd::Source *, const std::string &dir); MiddleburySource(ftl::rgbd::Source *, const std::string &dir);
~MiddleburySource() {}; ~MiddleburySource() {};
bool grab(); bool grab(int n, int b);
bool isReady() { return ready_; } bool isReady() { return ready_; }
private: private:
......
...@@ -56,7 +56,7 @@ bool NetSource::_getCalibration(Universe &net, const UUID &peer, const string &s ...@@ -56,7 +56,7 @@ bool NetSource::_getCalibration(Universe &net, const UUID &peer, const string &s
} }
NetSource::NetSource(ftl::rgbd::Source *host) NetSource::NetSource(ftl::rgbd::Source *host)
: ftl::rgbd::detail::Source(host), active_(false) { : ftl::rgbd::detail::Source(host), active_(false), minB_(9), maxN_(1) {
gamma_ = host->value("gamma", 1.0f); gamma_ = host->value("gamma", 1.0f);
temperature_ = host->value("temperature", 6500); temperature_ = host->value("temperature", 6500);
...@@ -120,9 +120,20 @@ void NetSource::_recvChunk(int frame, int chunk, bool delta, const vector<unsign ...@@ -120,9 +120,20 @@ void NetSource::_recvChunk(int frame, int chunk, bool delta, const vector<unsign
cv::Mat chunkRGB = rgb_(roi); cv::Mat chunkRGB = rgb_(roi);
cv::Mat chunkDepth = depth_(roi); cv::Mat chunkDepth = depth_(roi);
tmp_rgb.copyTo(chunkRGB); // Original size so just copy
tmp_depth.convertTo(chunkDepth, CV_32FC1, 1.0f/1000.0f); //(16.0f*10.0f)); if (tmp_rgb.cols == chunkRGB.cols) {
if (chunk == 0) N_--; tmp_rgb.copyTo(chunkRGB);
tmp_depth.convertTo(chunkDepth, CV_32FC1, 1.0f/1000.0f); //(16.0f*10.0f));
// Downsized so needs a scale up
} else {
cv::resize(tmp_rgb, chunkRGB, chunkRGB.size());
tmp_depth.convertTo(tmp_depth, CV_32FC1, 1.0f/1000.0f);
cv::resize(tmp_depth, chunkDepth, chunkDepth.size());
}
if (chunk == 0) {
N_--;
}
} }
void NetSource::setPose(const Eigen::Matrix4d &pose) { void NetSource::setPose(const Eigen::Matrix4d &pose) {
...@@ -162,14 +173,14 @@ void NetSource::_updateURI() { ...@@ -162,14 +173,14 @@ void NetSource::_updateURI() {
_recvChunk(frame, chunk, delta, jpg, d); _recvChunk(frame, chunk, delta, jpg, d);
}); });
N_ = 1; N_ = 0;
// Initiate stream with request for first 10 frames // Initiate stream with request for first 10 frames
try { //try {
host_->getNet()->send(peer_, "get_stream", *uri, N_, 0, host_->getNet()->id(), *uri); // host_->getNet()->send(peer_, "get_stream", *uri, N_, 0, host_->getNet()->id(), *uri);
} catch(...) { //} catch(...) {
LOG(ERROR) << "Could not connect to stream " << *uri; // LOG(ERROR) << "Could not connect to stream " << *uri;
} //}
// Update chunk details // Update chunk details
chunks_dim_ = ftl::rgbd::kChunkDim; chunks_dim_ = ftl::rgbd::kChunkDim;
...@@ -188,13 +199,24 @@ void NetSource::_updateURI() { ...@@ -188,13 +199,24 @@ void NetSource::_updateURI() {
} }
} }
bool NetSource::grab() { bool NetSource::grab(int n, int b) {
// Send one frame before end to prevent unwanted pause // Choose highest requested number of frames
if (N_ <= 2) { maxN_ = std::max(maxN_,(n == -1) ? 10 : n);
N_ = 10;
if (!host_->getNet()->send(peer_, "get_stream", *host_->get<string>("uri"), N_, 0, host_->getNet()->id(), *host_->get<string>("uri"))) { // Choose best requested quality
minB_ = std::min(minB_,(b == -1) ? 0 : b);
// Send k frames before end to prevent unwanted pause
// Unless only a single frame is requested
if ((N_ <= 2 && maxN_ > 1) || N_ == 0) {
N_ = maxN_;
if (!host_->getNet()->send(peer_, "get_stream", *host_->get<string>("uri"), N_, minB_, host_->getNet()->id(), *host_->get<string>("uri"))) {
active_ = false; active_ = false;
} }
maxN_ = 1; // Reset to single frame
minB_ = 9; // Reset to worst quality
} }
return true; return true;
} }
......
...@@ -22,7 +22,7 @@ class NetSource : public detail::Source { ...@@ -22,7 +22,7 @@ class NetSource : public detail::Source {
explicit NetSource(ftl::rgbd::Source *); explicit NetSource(ftl::rgbd::Source *);
~NetSource(); ~NetSource();
bool grab(); bool grab(int n, int b);
bool isReady(); bool isReady();
void setPose(const Eigen::Matrix4d &pose); void setPose(const Eigen::Matrix4d &pose);
...@@ -43,6 +43,8 @@ class NetSource : public detail::Source { ...@@ -43,6 +43,8 @@ class NetSource : public detail::Source {
cv::Mat idepth_; cv::Mat idepth_;
float gamma_; float gamma_;
int temperature_; int temperature_;
int minB_;
int maxN_;
bool _getCalibration(ftl::net::Universe &net, const ftl::UUID &peer, const std::string &src, ftl::rgbd::Camera &p); bool _getCalibration(ftl::net::Universe &net, const ftl::UUID &peer, const std::string &src, ftl::rgbd::Camera &p);
void _recv(const std::vector<unsigned char> &jpg, const std::vector<unsigned char> &d); void _recv(const std::vector<unsigned char> &jpg, const std::vector<unsigned char> &d);
......
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