diff --git a/modules/v4d/src/detail/clvacontext.cpp b/modules/v4d/src/detail/clvacontext.cpp index 439daba32..d552b2077 100644 --- a/modules/v4d/src/detail/clvacontext.cpp +++ b/modules/v4d/src/detail/clvacontext.cpp @@ -16,27 +16,33 @@ CLVAContext::CLVAContext(FrameBufferContext& mainFbContext) : mainFbContext_(mai bool CLVAContext::capture(std::function fn, cv::UMat& output) { cv::Size fbSize = mainFbContext_.size(); #ifndef __EMSCRIPTEN__ - if (!context_.empty()) { - CLExecScope_t scope(context_); + if (hasContext()) { + CLExecScope_t scope(getCLExecContext()); #endif fn(readFrame_); + if (readFrame_.empty()) + return false; + resizePreserveAspectRatio(readFrame_, readRGBBuffer_, mainFbContext_.size()); + cv::cvtColor(readRGBBuffer_, output, cv::COLOR_RGB2BGRA); #ifndef __EMSCRIPTEN__ } else { + CLExecScope_t scope(mainFbContext_.getCLExecContext()); + readFrame_ = cv::UMat(); fn(readFrame_); + if (readFrame_.empty()) + return false; + resizePreserveAspectRatio(readFrame_, readRGBBuffer_, mainFbContext_.size()); + cv::cvtColor(readRGBBuffer_, output, cv::COLOR_RGB2BGRA); } #endif - if (readFrame_.empty()) - return false; - resizePreserveAspectRatio(readFrame_, readRGBBuffer_, mainFbContext_.size()); - cv::cvtColor(readRGBBuffer_, output, cv::COLOR_RGB2BGRA); return true; } void CLVAContext::write(std::function fn, cv::UMat& input) { #ifndef __EMSCRIPTEN__ - if (!context_.empty()) { - CLExecScope_t scope(context_); + if (hasContext()) { + CLExecScope_t scope(getCLExecContext()); #endif cv::cvtColor(input, writeRGBBuffer_, cv::COLOR_BGRA2RGB); fn(writeRGBBuffer_);