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

Reduce buffer copies by swapping

parent 78c5ed3c
No related branches found
No related tags found
1 merge request!80Make capture and compute parallel
Pipeline #12600 passed
......@@ -68,15 +68,27 @@ class Source : public ftl::Configurable {
channel_t getChannel() const { return channel_; }
/**
* Perform the hardware or virtual frame grab operation.
*/
bool capture();
/**
* Between frames, do any required buffer swaps.
*/
void swap() { if (impl_) impl_->swap(); }
/**
* Perform the hardware or virtual frame grab operation.
* Do any post-grab processing. This function
* may take considerable time to return, especially for sources requiring
* software stereo correspondance.
*/
bool compute(int N=-1, int B=-1);
/**
* Wrapper grab that performs capture, swap and computation steps in one.
* It is more optimal to perform capture and compute in parallel.
*/
bool grab(int N=-1, int B=-1) {
bool c = capture();
swap();
......@@ -84,16 +96,9 @@ class Source : public ftl::Configurable {
}
/**
* Do any post-grab processing. This function
* may take considerable time to return, especially for sources requiring
* software stereo correspondance. If `process` is not called manually
* after a `grab` and before a `get`, then it will be called automatically
* on first `get`.
*/
//void process();
/**
* Get a copy of both colour and depth frames.
* Get a copy of both colour and depth frames. Note that this does a buffer
* swap rather than a copy, so the parameters should be persistent buffers for
* best performance.
*/
void getFrames(cv::Mat &c, cv::Mat &d);
......
......@@ -167,8 +167,16 @@ void Source::getFrames(cv::Mat &rgb, cv::Mat &depth) {
SHARED_LOCK(mutex_,lk);
//rgb_.copyTo(rgb);
//depth_.copyTo(depth);
//rgb = rgb_;
//depth = depth_;
cv::Mat tmp;
tmp = rgb;
rgb = rgb_;
rgb_ = tmp;
tmp = depth;
depth = depth_;
depth_ = tmp;
}
Eigen::Vector4d Source::point(uint ux, uint uy) {
......@@ -236,7 +244,7 @@ bool Source::compute(int N, int B) {
return true;
} else if (impl_ && impl_->compute(N,B)) {
timestamp_ = impl_->timestamp_;
/*cv::Mat tmp;
cv::Mat tmp;
rgb_.create(impl_->rgb_.size(), impl_->rgb_.type());
depth_.create(impl_->depth_.size(), impl_->depth_.type());
tmp = rgb_;
......@@ -244,9 +252,10 @@ bool Source::compute(int N, int B) {
impl_->rgb_ = tmp;
tmp = depth_;
depth_ = impl_->depth_;
impl_->depth_ = tmp;*/
impl_->rgb_.copyTo(rgb_);
impl_->depth_.copyTo(depth_);
impl_->depth_ = tmp;
//impl_->rgb_.copyTo(rgb_);
//impl_->depth_.copyTo(depth_);
return true;
}
return false;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment