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

Docs and tidy

parent c30c86e6
No related branches found
No related tags found
1 merge request!312Support new basler cameras
...@@ -3,7 +3,6 @@ ...@@ -3,7 +3,6 @@
#include <Eigen/Eigen> #include <Eigen/Eigen>
#include <ftl/cuda_util.hpp> #include <ftl/cuda_util.hpp>
//#include <opencv2/opencv.hpp>
#include <ftl/rgbd/camera.hpp> #include <ftl/rgbd/camera.hpp>
#include <ftl/rgbd/frame.hpp> #include <ftl/rgbd/frame.hpp>
...@@ -12,8 +11,20 @@ namespace rgbd { ...@@ -12,8 +11,20 @@ namespace rgbd {
class Source; class Source;
/**
* Base class for source device implementations. Each device provides a capture
* and retrieve functionality. `capture` is called with a high resolution timer
* at a precise timestamp to ensure synchronisation. In another thread the
* `retrieve` function is called after `capture` to download any data into the
* provided frame object. The frame object is then dispatched for further
* processing, such as disparity calculation, or is discarded if a previous
* processing dispatch is still on going.
*
* @see ftl::rgbd::Group
*/
class BaseSourceImpl { class BaseSourceImpl {
public: public:
// TODO: Remove this
friend class ftl::rgbd::Source; friend class ftl::rgbd::Source;
public: public:
...@@ -21,12 +32,15 @@ class BaseSourceImpl { ...@@ -21,12 +32,15 @@ class BaseSourceImpl {
virtual ~BaseSourceImpl() {} virtual ~BaseSourceImpl() {}
/** /**
* Perform hardware data capture. This should be low latency. * Perform hardware data capture. This should be low latency (<1ms).
*/ */
virtual bool capture(int64_t ts)=0; virtual bool capture(int64_t ts)=0;
/** /**
* Perform slow IO operation to get the data into the given frame object. * Perform slow IO operation to get the data into the given frame object.
* This can take up to 1 fps (eg. ~40ms), but should be faster. It occurs
* in a different thread to the `capture` call but will never occur at the
* same time as `capture`. If `capture` fails then this will not be called.
*/ */
virtual bool retrieve(ftl::rgbd::Frame &frame)=0; virtual bool retrieve(ftl::rgbd::Frame &frame)=0;
...@@ -35,6 +49,7 @@ class BaseSourceImpl { ...@@ -35,6 +49,7 @@ class BaseSourceImpl {
*/ */
virtual bool isReady() { return false; }; virtual bool isReady() { return false; };
// These should be accessed via the state object in a frame.
[[deprecated]] virtual void setPose(const Eigen::Matrix4d &pose) { state_.setPose(pose); }; [[deprecated]] virtual void setPose(const Eigen::Matrix4d &pose) { state_.setPose(pose); };
[[deprecated]] virtual Camera parameters(ftl::codecs::Channel) { return params_; }; [[deprecated]] virtual Camera parameters(ftl::codecs::Channel) { return params_; };
...@@ -43,7 +58,7 @@ class BaseSourceImpl { ...@@ -43,7 +58,7 @@ class BaseSourceImpl {
protected: protected:
ftl::rgbd::FrameState state_; ftl::rgbd::FrameState state_;
capability_t capabilities_; capability_t capabilities_; // To be deprecated
ftl::rgbd::Source *host_; ftl::rgbd::Source *host_;
ftl::rgbd::Camera &params_; ftl::rgbd::Camera &params_;
}; };
......
...@@ -25,3 +25,25 @@ cv::Mat Camera::getCameraMatrix() const { ...@@ -25,3 +25,25 @@ cv::Mat Camera::getCameraMatrix() const {
K.at<double>(1,2) = -cy; K.at<double>(1,2) = -cy;
return K; return K;
} }
/*
* Scale camera parameters to match resolution.
*/
Camera Camera::scaled(int width, int height) const {
const auto &cam = *this;
float scaleX = (float)width / (float)cam.width;
float scaleY = (float)height / (float)cam.height;
//CHECK( abs(scaleX - scaleY) < 0.00000001f );
Camera newcam = cam;
newcam.width = width;
newcam.height = height;
newcam.fx *= scaleX;
newcam.fy *= scaleY;
newcam.cx *= scaleX;
newcam.cy *= scaleY;
newcam.doffs *= scaleX;
return newcam;
}
...@@ -97,10 +97,6 @@ int Group::streamID(const ftl::rgbd::Source *s) const { ...@@ -97,10 +97,6 @@ int Group::streamID(const ftl::rgbd::Source *s) const {
} }
void Group::onFrameSet(const ftl::rgbd::VideoCallback &cb) { void Group::onFrameSet(const ftl::rgbd::VideoCallback &cb) {
//if (latency_ == 0) {
// callback_ = cb;
//}
// 1. Capture camera frames with high precision // 1. Capture camera frames with high precision
cap_id_ = ftl::timer::add(ftl::timer::kTimerHighPrecision, [this](int64_t ts) { cap_id_ = ftl::timer::add(ftl::timer::kTimerHighPrecision, [this](int64_t ts) {
skip_ = jobs_ != 0; // Last frame not finished so skip all steps skip_ = jobs_ != 0; // Last frame not finished so skip all steps
...@@ -108,42 +104,25 @@ void Group::onFrameSet(const ftl::rgbd::VideoCallback &cb) { ...@@ -108,42 +104,25 @@ void Group::onFrameSet(const ftl::rgbd::VideoCallback &cb) {
if (skip_) return true; if (skip_) return true;
for (auto s : sources_) { for (auto s : sources_) {
s->capture(ts); skip_ &= s->capture(ts);
} }
return true; return true;
}); });
// 2. After capture, swap any internal source double buffers // 2. Issue IO retrieve ad compute jobs before finding a valid
/*swap_id_ = ftl::timer::add(ftl::timer::kTimerSwap, [this](int64_t ts) {
if (skip_) return true;
for (auto s : sources_) {
s->swap();
}
return true;
});*/
// 3. Issue IO retrieve ad compute jobs before finding a valid
// frame at required latency to pass to callback. // frame at required latency to pass to callback.
main_id_ = ftl::timer::add(ftl::timer::kTimerMain, [this,cb](int64_t ts) { main_id_ = ftl::timer::add(ftl::timer::kTimerMain, [this,cb](int64_t ts) {
//if (skip_) LOG(ERROR) << "SKIPPING TIMER JOB " << ts;
if (skip_) return true; if (skip_) return true;
//jobs_++;
for (auto s : sources_) { for (auto s : sources_) {
jobs_++; // += 2; jobs_++;
ftl::pool.push([this,s,ts](int id) { ftl::pool.push([this,s,ts](int id) {
_retrieveJob(s); _retrieveJob(s);
--jobs_; --jobs_;
//if (jobs_ == 0) LOG(INFO) << "LAST JOB = Retrieve";
_dispatchJob(s, ts); _dispatchJob(s, ts);
}); });
/*ftl::pool.push([this,s](int id) {
_computeJob(s);
//if (jobs_ == 0) LOG(INFO) << "LAST JOB = Compute";
--jobs_;
});*/
} }
return true; return true;
}); });
...@@ -154,12 +133,6 @@ void Group::onFrameSet(const ftl::rgbd::VideoCallback &cb) { ...@@ -154,12 +133,6 @@ void Group::onFrameSet(const ftl::rgbd::VideoCallback &cb) {
}); });
} }
/*void Group::removeRawCallback(const std::function<void(ftl::rgbd::Source*, const ftl::codecs::StreamPacket &spkt, const ftl::codecs::Packet &pkt)> &f) {
for (auto s : sources_) {
s->removeRawCallback(f);
}
}*/
void Group::setName(const std::string &name) { void Group::setName(const std::string &name) {
name_ = name; name_ = name;
builder_.setName(name); builder_.setName(name);
......
...@@ -133,7 +133,7 @@ static ftl::rgbd::BaseSourceImpl *createFileImpl(const ftl::URI &uri, Source *ho ...@@ -133,7 +133,7 @@ static ftl::rgbd::BaseSourceImpl *createFileImpl(const ftl::URI &uri, Source *ho
} }
static ftl::rgbd::BaseSourceImpl *createDeviceImpl(const ftl::URI &uri, Source *host) { static ftl::rgbd::BaseSourceImpl *createDeviceImpl(const ftl::URI &uri, Source *host) {
if (uri.getPathSegment(0) == "video") { if (uri.getPathSegment(0) == "video" || uri.getPathSegment(0) == "camera") {
return new StereoVideoSource(host); return new StereoVideoSource(host);
} else if (uri.getPathSegment(0) == "pylon") { } else if (uri.getPathSegment(0) == "pylon") {
#ifdef HAVE_PYLON #ifdef HAVE_PYLON
...@@ -149,17 +149,6 @@ static ftl::rgbd::BaseSourceImpl *createDeviceImpl(const ftl::URI &uri, Source * ...@@ -149,17 +149,6 @@ static ftl::rgbd::BaseSourceImpl *createDeviceImpl(const ftl::URI &uri, Source *
#endif #endif
} else if (uri.getPathSegment(0) == "screen") { } else if (uri.getPathSegment(0) == "screen") {
return new ScreenCapture(host); return new ScreenCapture(host);
} else {
/*params_.width = value("width", 1280);
params_.height = value("height", 720);
params_.fx = value("focal", 700.0f);
params_.fy = params_.fx;
params_.cx = -(double)params_.width / 2.0;
params_.cy = -(double)params_.height / 2.0;
params_.minDepth = value("minDepth", 0.1f);
params_.maxDepth = value("maxDepth", 20.0f);
params_.doffs = 0;
params_.baseline = value("baseline", 0.0f);*/
} }
return nullptr; return nullptr;
} }
...@@ -253,25 +242,4 @@ void Source::setCallback(const FrameCallback &cb) { ...@@ -253,25 +242,4 @@ void Source::setCallback(const FrameCallback &cb) {
callback_ = cb; callback_ = cb;
} }
/*
* Scale camera parameters to match resolution.
*/
Camera Camera::scaled(int width, int height) const {
const auto &cam = *this;
float scaleX = (float)width / (float)cam.width;
float scaleY = (float)height / (float)cam.height;
//CHECK( abs(scaleX - scaleY) < 0.00000001f );
Camera newcam = cam;
newcam.width = width;
newcam.height = height;
newcam.fx *= scaleX;
newcam.fy *= scaleY;
newcam.cx *= scaleX;
newcam.cy *= scaleY;
newcam.doffs *= scaleX;
return newcam;
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment