reenabled parallel capture

pull/3471/head
kallaballa 2 years ago
parent 7a1497524f
commit dca04428ec
  1. 24
      modules/v4d/src/v4d.cpp

@ -247,7 +247,11 @@ static void do_frame(void* void_fn_ptr) {
static bool first_run = true; static bool first_run = true;
void V4D::run(std::function<bool(cv::Ptr<V4D>)> fn, size_t workers) { void V4D::run(std::function<bool(cv::Ptr<V4D>)> fn
#ifndef __EMSCRIPTEN__
, size_t workers
#endif
) {
#ifndef __EMSCRIPTEN__ #ifndef __EMSCRIPTEN__
numWorkers_ = workers; numWorkers_ = workers;
std::vector<std::thread*> threads; std::vector<std::thread*> threads;
@ -345,7 +349,6 @@ void V4D::feed(cv::InputArray in) {
#ifndef __EMSCRIPTEN__ #ifndef __EMSCRIPTEN__
CLExecScope_t scope(fbCtx().getCLExecContext()); CLExecScope_t scope(fbCtx().getCLExecContext());
#endif #endif
TimeTracker::getInstance()->execute("feed", [this, &in](){ TimeTracker::getInstance()->execute("feed", [this, &in](){
cv::UMat frame; cv::UMat frame;
clvaCtx().capture([&](cv::UMat& videoFrame) { clvaCtx().capture([&](cv::UMat& videoFrame) {
@ -384,12 +387,14 @@ bool V4D::capture() {
} }
return false; return false;
#else #else
this->capture([this](cv::UMat& videoFrame) {
if(source_ && source_->isReady()) { if(source_ && source_->isReady()) {
auto p = source_->operator()(); auto p = source_->operator()();
currentSeqNr_ = p.first; currentSeqNr_ = p.first;
} }
});
return true; return true;
#endif #endif
} }
@ -398,37 +403,26 @@ bool V4D::capture(std::function<void(cv::UMat&)> fn) {
TimeTracker::getInstance()->execute("capture", [this, fn, &res](){ TimeTracker::getInstance()->execute("capture", [this, fn, &res](){
CV_UNUSED(res); CV_UNUSED(res);
if (!source_ || !source_->isReady() || !source_->isOpen()) { if (!source_ || !source_->isReady() || !source_->isOpen()) {
#ifndef __EMSCRIPTEN__
res = false; res = false;
#endif
return; return;
} }
if (futureReader_.valid()) { if (futureReader_.valid()) {
if (!futureReader_.get()) { if (!futureReader_.get()) {
#ifndef __EMSCRIPTEN__
res = false; res = false;
#endif
return; return;
} }
} }
if(nextReaderFrame_.empty()) { if(nextReaderFrame_.empty()) {
if (!clvaCtx().capture(fn, nextReaderFrame_)) { if (!clvaCtx().capture(fn, nextReaderFrame_)) {
#ifndef __EMSCRIPTEN__
res = false; res = false;
#endif
return; return;
} }
} }
nextReaderFrame_.copyTo(currentReaderFrame_); nextReaderFrame_.copyTo(currentReaderFrame_);
futureReader_ = thread_pool_.enqueue( futureReader_ = thread_pool_.enqueue(
[](V4D* v, std::function<void(UMat&)> func, cv::UMat& frame) { [](V4D* v, std::function<void(UMat&)> func, cv::UMat& frame) {
#ifndef __EMSCRIPTEN__ return v->clvaCtx().capture(func, frame);
return v->clvaCtx().capture(func, frame);
#else
v->clvaCtx().capture(func, frame);
return true;
#endif
}, this, fn, nextReaderFrame_); }, this, fn, nextReaderFrame_);
fb([this](cv::UMat& frameBuffer){ fb([this](cv::UMat& frameBuffer){

Loading…
Cancel
Save