1
0
mirror of https://github.com/opencv/opencv.git synced 2026-07-30 07:43:03 +04:00

Merge branch 4.x

This commit is contained in:
Alexander Smorkalov
2024-01-15 17:23:10 +03:00
531 changed files with 20900 additions and 12934 deletions
@@ -0,0 +1,29 @@
// This file is part of OpenCV project.
// It is subject to the license terms in the LICENSE file found in the top-level directory
// of this distribution and at http://opencv.org/license.html.
//
// Copyright (C) 2018 Intel Corporation
#ifndef OPENCV_GAPI_CPU_OT_API_HPP
#define OPENCV_GAPI_CPU_OT_API_HPP
#include <opencv2/core/cvdef.h> // GAPI_EXPORTS
#include <opencv2/gapi/gkernel.hpp> // GKernelPackage
namespace cv {
namespace gapi {
/**
* @brief This namespace contains G-API Operation Types for
* VAS Object Tracking module functionality.
*/
namespace ot {
namespace cpu {
GAPI_EXPORTS_W GKernelPackage kernels();
} // namespace cpu
} // namespace ot
} // namespace gapi
} // namespace cv
#endif // OPENCV_GAPI_CPU_OT_API_HPP
@@ -39,6 +39,9 @@ public:
GAPI_WRAP
PyParams& cfgAddExecutionProvider(ep::DirectML ep);
GAPI_WRAP
PyParams& cfgAddExecutionProvider(ep::CoreML ep);
GAPI_WRAP
PyParams& cfgAddExecutionProvider(ep::CUDA ep);
@@ -32,6 +32,65 @@ namespace onnx {
*/
namespace ep {
/**
* @brief This structure provides functions
* that fill inference options for ONNX CoreML Execution Provider.
* Please follow https://onnxruntime.ai/docs/execution-providers/CoreML-ExecutionProvider.html#coreml-execution-provider
*/
struct GAPI_EXPORTS_W_SIMPLE CoreML {
/** @brief Class constructor.
Constructs CoreML parameters.
*/
GAPI_WRAP
CoreML() = default;
/** @brief Limit CoreML Execution Provider to run on CPU only.
This function is used to limit CoreML to run on CPU only.
Please follow: https://onnxruntime.ai/docs/execution-providers/CoreML-ExecutionProvider.html#coreml_flag_use_cpu_only
@return reference to this parameter structure.
*/
GAPI_WRAP
CoreML& cfgUseCPUOnly() {
use_cpu_only = true;
return *this;
}
/** @brief Enable CoreML EP to run on a subgraph in the body of a control flow ONNX operator (i.e. a Loop, Scan or If operator).
This function is used to enable CoreML EP to run on
a subgraph of a control flow of ONNX operation.
Please follow: https://onnxruntime.ai/docs/execution-providers/CoreML-ExecutionProvider.html#coreml_flag_enable_on_subgraph
@return reference to this parameter structure.
*/
GAPI_WRAP
CoreML& cfgEnableOnSubgraph() {
enable_on_subgraph = true;
return *this;
}
/** @brief Enable CoreML EP to run only on Apple Neural Engine.
This function is used to enable CoreML EP to run only on Apple Neural Engine.
Please follow: https://onnxruntime.ai/docs/execution-providers/CoreML-ExecutionProvider.html#coreml_flag_only_enable_device_with_ane
@return reference to this parameter structure.
*/
GAPI_WRAP
CoreML& cfgEnableOnlyNeuralEngine() {
enable_only_ane = true;
return *this;
}
bool use_cpu_only = false;
bool enable_on_subgraph = false;
bool enable_only_ane = false;
};
/**
* @brief This structure provides functions
* that fill inference options for CUDA Execution Provider.
@@ -189,13 +248,23 @@ public:
GAPI_WRAP
explicit DirectML(const int device_id) : ddesc(device_id) { };
using DeviceDesc = cv::util::variant<int>;
/** @brief Class constructor.
Constructs DirectML parameters based on adapter name.
@param adapter_name Target adapter_name to use.
*/
GAPI_WRAP
explicit DirectML(const std::string &adapter_name) : ddesc(adapter_name) { };
using DeviceDesc = cv::util::variant<int, std::string>;
DeviceDesc ddesc;
};
using EP = cv::util::variant< cv::util::monostate
, OpenVINO
, DirectML
, CoreML
, CUDA
, TensorRT>;
@@ -487,6 +556,20 @@ public:
/** @brief Adds execution provider for runtime.
The function is used to add ONNX Runtime CoreML Execution Provider options.
@param ep CoreML Execution Provider options.
@see cv::gapi::onnx::ep::CoreML.
@return the reference on modified object.
*/
Params<Net>& cfgAddExecutionProvider(ep::CoreML&& ep) {
desc.execution_providers.emplace_back(std::move(ep));
return *this;
}
/** @brief Adds execution provider for runtime.
The function is used to add ONNX Runtime CUDA Execution Provider options.
@param ep CUDA Execution Provider options.
@@ -573,6 +656,11 @@ public:
desc.execution_providers.emplace_back(std::move(ep));
}
/** @see onnx::Params::cfgAddExecutionProvider. */
void cfgAddExecutionProvider(ep::CoreML&& ep) {
desc.execution_providers.emplace_back(std::move(ep));
}
/** @see onnx::Params::cfgAddExecutionProvider. */
void cfgAddExecutionProvider(ep::CUDA&& ep) {
desc.execution_providers.emplace_back(std::move(ep));
@@ -679,7 +679,32 @@ protected:
};
} // namespace ov
namespace wip { namespace ov {
/**
* @brief Ask G-API OpenVINO backend to run only inference of model provided.
*
* G-API OpenVINO backend will perform only the inference of the model provided
* without populating input and copying back output data.
* This mode is used to evaluate the pure inference performance of the model without
* taking into account the i/o data transfer.
*/
struct benchmark_mode { };
/** @} */
} // namespace ov
} // namespace wip
} // namespace gapi
namespace detail
{
template<> struct CompileArgTag<cv::gapi::wip::ov::benchmark_mode>
{
static const char* tag() { return "gapi.wip.ov.benchmark_mode"; }
};
}
} // namespace cv
#endif // OPENCV_GAPI_INFER_OV_HPP
+194
View File
@@ -0,0 +1,194 @@
// This file is part of OpenCV project.
// It is subject to the license terms in the LICENSE file found in the top-level directory
// of this distribution and at http://opencv.org/license.html.
//
// Copyright (C) 2023 Intel Corporation
#ifndef OPENCV_GAPI_OT_HPP
#define OPENCV_GAPI_OT_HPP
#include <opencv2/gapi.hpp>
#include <opencv2/gapi/s11n.hpp>
#include <opencv2/gapi/gkernel.hpp>
namespace cv {
namespace gapi {
/**
* @brief This namespace contains G-API Operation Types for
* VAS Object Tracking module functionality.
*/
namespace ot {
/**
* @enum TrackingStatus
*
* Tracking status twin for vas::ot::TrackingStatus
*/
enum TrackingStatus
{
NEW = 0, /**< The object is newly added. */
TRACKED, /**< The object is being tracked. */
LOST /**< The object gets lost now. The object can be tracked again
by specifying detected object manually. */
};
struct GAPI_EXPORTS_W_SIMPLE ObjectTrackerParams
{
/**
* Maximum number of trackable objects in a frame.
* Valid range: 1 <= max_num_objects. Or it can be -1 if there is no limitation
* of maximum number in X86. KMB/TBH has limitation up to 1024.
* Default value is -1 which means there is no limitation in X86. KMB/TBH is -1 means 200.
*/
GAPI_PROP_RW int32_t max_num_objects = -1;
/**
* Input color format. Supports 0(BGR), 1(NV12), 2(BGRX) and 4(I420)
*/
GAPI_PROP_RW int32_t input_image_format = 0;
/**
* Specifies whether tracker to use detection class for keeping id of an object.
* If it is true, new detection will be associated from previous tracking only when
* those two have same class.
* class id of an object is fixed across video frames.
* If it is false, new detection can be associated across different-class objects.
* In this case, the class id of an object may change across video frames depending on the tracker input.
* It is recommended to turn this option off when it is likely that detector confuses the class of object.
* For example, when detector confuses bicycle and motorbike. Turning this option off will increase
* the tracking reliability as tracker will ignore the class label of detector.
* @n
* Default value is true.
*/
GAPI_PROP_RW bool tracking_per_class = true;
bool operator==(const ObjectTrackerParams& other) const
{
return max_num_objects == other.max_num_objects
&& input_image_format == other.input_image_format
&& tracking_per_class == other.tracking_per_class;
}
};
using GTrackedInfo = std::tuple<cv::GArray<cv::Rect>, cv::GArray<int32_t>, cv::GArray<uint64_t>, cv::GArray<int>>;
G_API_OP(GTrackFromMat, <GTrackedInfo(cv::GMat, cv::GArray<cv::Rect>, cv::GArray<int32_t>, float)>, "com.intel.track_from_mat")
{
static std::tuple<cv::GArrayDesc, cv::GArrayDesc,
cv::GArrayDesc, cv::GArrayDesc> outMeta(cv::GMatDesc, cv::GArrayDesc, cv::GArrayDesc, float)
{
return std::make_tuple(cv::empty_array_desc(), cv::empty_array_desc(),
cv::empty_array_desc(), cv::empty_array_desc());
}
};
G_API_OP(GTrackFromFrame, <GTrackedInfo(cv::GFrame, cv::GArray<cv::Rect>, cv::GArray<int32_t>, float)>, "com.intel.track_from_frame")
{
static std::tuple<cv::GArrayDesc, cv::GArrayDesc,
cv::GArrayDesc, cv::GArrayDesc> outMeta(cv::GFrameDesc, cv::GArrayDesc, cv::GArrayDesc, float)
{
return std::make_tuple(cv::empty_array_desc(), cv::empty_array_desc(),
cv::empty_array_desc(), cv::empty_array_desc());
}
};
/**
* @brief Tracks objects with video frames.
* If a detected object is overlapped enough with one of tracked object, the tracked object's
* informationis updated with the input detected object.
* On the other hand, if a detected object is overlapped with none of tracked objects,
* the detected object is newly added and ObjectTracker starts to track the object.
* In zero term tracking type, ObjectTracker clears tracked objects in case that empty
* list of detected objects is passed in.
*
* @param mat Input frame.
* @param detected_rects Detected objects rectangles in the input frame.
* @param detected_class_labels Detected objects class labels in the input frame.
* @param delta Frame_delta_t Delta time between two consecutive tracking in seconds.
* The valid range is [0.005 ~ 0.5].
* @return Tracking results of target objects.
* cv::GArray<cv::Rect> Array of rectangles for tracked objects.
* cv::GArray<int32_t> Array of detected objects labels.
* cv::GArray<uint64_t> Array of tracking IDs for objects.
* Numbering sequence starts from 1.
* The value 0 means the tracking ID of this object has
* not been assigned.
* cv::GArray<int> Array of tracking statuses for objects.
*/
GAPI_EXPORTS_W std::tuple<cv::GArray<cv::Rect>,
cv::GArray<int>,
cv::GArray<uint64_t>,
cv::GArray<int>>
track(const cv::GMat& mat,
const cv::GArray<cv::Rect>& detected_rects,
const cv::GArray<int>& detected_class_labels,
float delta);
/**
@overload
* @brief Tracks objects with video frames. Overload of track(...) for frame as GFrame.
*
* @param frame Input frame.
* @param detected_rects Detected objects rectangles in the input frame.
* @param detected_class_labels Detected objects class labels in the input frame.
* @param delta Frame_delta_t Delta time between two consecutive tracking in seconds.
* The valid range is [0.005 ~ 0.5].
* @return Tracking results of target objects.
* @return Tracking results of target objects.
* cv::GArray<cv::Rect> Array of rectangles for tracked objects.
* cv::GArray<int32_t> Array of detected objects labels.
* cv::GArray<uint64_t> Array of tracking IDs for objects.
* Numbering sequence starts from 1.
* The value 0 means the tracking ID of this object has
* not been assigned.
* cv::GArray<int> Array of tracking statuses for objects.
*/
GAPI_EXPORTS_W std::tuple<cv::GArray<cv::Rect>,
cv::GArray<int>,
cv::GArray<uint64_t>,
cv::GArray<int>>
track(const cv::GFrame& frame,
const cv::GArray<cv::Rect>& detected_rects,
const cv::GArray<int>& detected_class_labels,
float delta);
} // namespace ot
} // namespace gapi
} // namespace cv
// FIXME: move to a separate file?
namespace cv
{
namespace detail
{
template<> struct CompileArgTag<cv::gapi::ot::ObjectTrackerParams>
{
static const char* tag()
{
return "cv.gapi.ot.object_tracker_params";
}
};
} // namespace detail
namespace gapi
{
namespace s11n
{
namespace detail
{
template<> struct S11N<cv::gapi::ot::ObjectTrackerParams> {
static void serialize(IOStream &os, const cv::gapi::ot::ObjectTrackerParams &p) {
os << p. max_num_objects << p.input_image_format << p.tracking_per_class;
}
static cv::gapi::ot::ObjectTrackerParams deserialize(IIStream &is) {
cv::gapi::ot::ObjectTrackerParams p;
is >> p. max_num_objects >> p.input_image_format >> p.tracking_per_class;
return p;
}
};
} // namespace detail
} // namespace s11n
} // namespace gapi
} // namespace cv
#endif // OPENCV_GAPI_OT_HPP