mirror of
https://github.com/opencv/opencv.git
synced 2026-07-30 07:43:03 +04:00
Merge pull request #21658 from sivanov-work:vpp_core_add_roi
G-API: Add ROI processing in VPP preproc * Add ROI in VPP prepro * Apply comments
This commit is contained in:
@@ -34,6 +34,21 @@ bool FrameInfoComparator::equal_to(const mfxFrameInfo& lhs, const mfxFrameInfo&
|
||||
return lhs == rhs;
|
||||
}
|
||||
|
||||
void apply_roi(mfxFrameSurface1* surface_handle,
|
||||
const cv::util::optional<cv::Rect> &opt_roi) {
|
||||
if (opt_roi.has_value()) {
|
||||
const cv::Rect &roi = opt_roi.value();
|
||||
surface_handle->Info.CropX = static_cast<mfxU16>(roi.x);
|
||||
surface_handle->Info.CropY = static_cast<mfxU16>(roi.y);
|
||||
surface_handle->Info.CropW = static_cast<mfxU16>(roi.width);
|
||||
surface_handle->Info.CropH = static_cast<mfxU16>(roi.height);
|
||||
GAPI_LOG_DEBUG(nullptr, "applied ROI {" << surface_handle->Info.CropX <<
|
||||
", " << surface_handle->Info.CropY << "}, "
|
||||
"{ " << surface_handle->Info.CropX + surface_handle->Info.CropW <<
|
||||
", " << surface_handle->Info.CropY + surface_handle->Info.CropH << "}");
|
||||
}
|
||||
}
|
||||
|
||||
VPPPreprocEngine::VPPPreprocEngine(std::unique_ptr<VPLAccelerationPolicy>&& accel) :
|
||||
ProcessingEngineBase(std::move(accel)) {
|
||||
GAPI_LOG_INFO(nullptr, "Create VPP preprocessing engine");
|
||||
@@ -57,31 +72,25 @@ VPPPreprocEngine::VPPPreprocEngine(std::unique_ptr<VPLAccelerationPolicy>&& acce
|
||||
my_sess.sync_in_queue.pop();
|
||||
auto *vpp_suface = my_sess.processing_surface_ptr.lock()->get_handle();
|
||||
|
||||
/* TODO: consider CROP/ROI here
|
||||
static int x_offset = 0;
|
||||
static int y_offset = 0;
|
||||
dec_surface->Info.CropX = x_offset;
|
||||
dec_surface->Info.CropY = y_offset;
|
||||
dec_surface->Info.CropW = 100 + x_offset++;
|
||||
dec_surface->Info.CropH = 100 + y_offset++;
|
||||
*/
|
||||
session_type::outgoing_task vpp_pending_op {pending_op.sync_handle, nullptr};
|
||||
apply_roi(pending_op.decoded_surface_ptr, pending_op.roi);
|
||||
|
||||
mfxSyncPoint vpp_sync_handle{};
|
||||
my_sess.last_status = MFXVideoVPP_RunFrameVPPAsync(my_sess.session,
|
||||
pending_op.decoded_surface_ptr,
|
||||
vpp_suface,
|
||||
nullptr, &vpp_pending_op.sync_handle);
|
||||
vpp_pending_op.vpp_surface_ptr = vpp_suface;
|
||||
|
||||
nullptr, &vpp_sync_handle);
|
||||
session_type::outgoing_task vpp_pending_op {vpp_sync_handle,
|
||||
vpp_suface,
|
||||
std::move(pending_op) };
|
||||
GAPI_LOG_DEBUG(nullptr, "Got VPP async operation" <<
|
||||
", sync id: " <<
|
||||
vpp_pending_op.sync_handle <<
|
||||
", dec surface: " <<
|
||||
pending_op.decoded_surface_ptr <<
|
||||
vpp_pending_op.original_surface_ptr <<
|
||||
", trans surface: " <<
|
||||
vpp_pending_op.vpp_surface_ptr <<
|
||||
", status: " <<
|
||||
mfxstatus_to_string(my_sess.last_status));
|
||||
|
||||
// NB: process status
|
||||
if (my_sess.last_status == MFX_ERR_MORE_SURFACE ||
|
||||
my_sess.last_status == MFX_ERR_NONE) {
|
||||
@@ -131,6 +140,7 @@ VPPPreprocEngine::VPPPreprocEngine(std::unique_ptr<VPLAccelerationPolicy>&& acce
|
||||
|
||||
// put frames in ready queue on success
|
||||
if (MFX_ERR_NONE == sess.last_status) {
|
||||
pending_op.release_frame();
|
||||
on_frame_ready(my_sess, pending_op.vpp_surface_ptr);
|
||||
}
|
||||
}
|
||||
@@ -327,8 +337,8 @@ VPPPreprocEngine::initialize_session(mfxSession,
|
||||
return {};
|
||||
}
|
||||
|
||||
cv::MediaFrame VPPPreprocEngine::run_sync(const pp_session& sess, const cv::MediaFrame& in_frame) {
|
||||
|
||||
cv::MediaFrame VPPPreprocEngine::run_sync(const pp_session& sess, const cv::MediaFrame& in_frame,
|
||||
const cv::util::optional<cv::Rect> &roi) {
|
||||
std::shared_ptr<EngineSession> pp_sess_impl = sess.get<EngineSession>();
|
||||
if (!pp_sess_impl) {
|
||||
// bypass case
|
||||
@@ -347,8 +357,10 @@ cv::MediaFrame VPPPreprocEngine::run_sync(const pp_session& sess, const cv::Medi
|
||||
|
||||
// schedule decoded surface into preproc queue
|
||||
session_type::incoming_task in_preproc_request {nullptr,
|
||||
vpl_adapter->get_surface()->get_handle(),
|
||||
in_frame};
|
||||
vpl_adapter->get_surface()->get_handle(),
|
||||
vpl_adapter->get_surface()->get_info(),
|
||||
in_frame,
|
||||
roi};
|
||||
s->sync_in_queue.emplace(in_preproc_request);
|
||||
|
||||
// invoke pipeline to transform decoded surface into preprocessed surface
|
||||
|
||||
@@ -47,7 +47,8 @@ public:
|
||||
const GFrameDesc& required_frame_descr) override;
|
||||
|
||||
cv::MediaFrame run_sync(const pp_session &session_handle,
|
||||
const cv::MediaFrame& in_frame) override;
|
||||
const cv::MediaFrame& in_frame,
|
||||
const cv::util::optional<cv::Rect> &opt_roi) override;
|
||||
|
||||
private:
|
||||
std::map<mfxFrameInfo, session_ptr_type, FrameInfoComparator> preproc_session_map;
|
||||
|
||||
@@ -60,6 +60,24 @@ void VPPPreprocSession::init_surface_pool(VPLAccelerationPolicy::pool_key_t key)
|
||||
const mfxFrameInfo& VPPPreprocSession::get_video_param() const {
|
||||
return mfx_vpp_out_param.vpp.Out;
|
||||
}
|
||||
|
||||
VPPPreprocSession::outgoing_task::outgoing_task(mfxSyncPoint acquired_sync_handle,
|
||||
mfxFrameSurface1* acquired_surface_ptr,
|
||||
VPPPreprocSession::incoming_task &&in) :
|
||||
sync_handle(acquired_sync_handle),
|
||||
vpp_surface_ptr(acquired_surface_ptr),
|
||||
original_surface_ptr(in.decoded_surface_ptr),
|
||||
original_frame_info(std::move(in.decoded_frame_info)),
|
||||
original_frame(in.decoded_frame_copy) {
|
||||
}
|
||||
|
||||
void VPPPreprocSession::outgoing_task::release_frame() {
|
||||
// restore initial surface params
|
||||
memcpy(&(original_surface_ptr->Info),
|
||||
&original_frame_info, sizeof(Surface::info_t));
|
||||
// release references on frame adapter
|
||||
original_frame = cv::MediaFrame();
|
||||
}
|
||||
} // namespace onevpl
|
||||
} // namespace wip
|
||||
} // namespace gapi
|
||||
|
||||
@@ -41,12 +41,24 @@ private:
|
||||
struct incoming_task {
|
||||
mfxSyncPoint sync_handle;
|
||||
mfxFrameSurface1* decoded_surface_ptr;
|
||||
Surface::info_t decoded_frame_info;
|
||||
cv::MediaFrame decoded_frame_copy;
|
||||
cv::util::optional<cv::Rect> roi;
|
||||
};
|
||||
|
||||
struct outgoing_task {
|
||||
outgoing_task() = default;
|
||||
outgoing_task(mfxSyncPoint acquired_sync_handle,
|
||||
mfxFrameSurface1* acquired_surface_ptr,
|
||||
incoming_task &&in);
|
||||
mfxSyncPoint sync_handle;
|
||||
mfxFrameSurface1* vpp_surface_ptr;
|
||||
|
||||
mfxFrameSurface1* original_surface_ptr;
|
||||
void release_frame();
|
||||
private:
|
||||
Surface::info_t original_frame_info;
|
||||
cv::MediaFrame original_frame;
|
||||
};
|
||||
|
||||
std::queue<incoming_task> sync_in_queue;
|
||||
|
||||
@@ -27,7 +27,8 @@ struct IPreprocEngine {
|
||||
initialize_preproc(const pp_params& initial_frame_param,
|
||||
const GFrameDesc& required_frame_descr) = 0;
|
||||
virtual cv::MediaFrame
|
||||
run_sync(const pp_session &sess, const cv::MediaFrame& in_frame) = 0;
|
||||
run_sync(const pp_session &sess, const cv::MediaFrame& in_frame,
|
||||
const cv::util::optional<cv::Rect> &opt_roi = {}) = 0;
|
||||
};
|
||||
} // namespace wip
|
||||
} // namespace gapi
|
||||
|
||||
Reference in New Issue
Block a user