1
0
mirror of https://github.com/opencv/opencv.git synced 2026-07-29 15:23:05 +04:00

Merge pull request #23595 from TolyaTalamanov:at/implement-openvino-backend

[G-API] Implement OpenVINO 2.0 backend #23595

### Pull Request Readiness Checklist

Implemented basic functionality for `OpenVINO` 2.0 G-API backend.

#### Overview
- [x] Implement `Infer` kernel with some of essential configurable parameters + IR/Blob models format support.
- [ ] Implement the rest of kernels: `InferList`, `InferROI`, `Infer2` + other configurable params (e.g reshape)
- [x] Asyncrhonous execution support
- [ ] Remote context support

See details at https://github.com/opencv/opencv/wiki/How_to_contribute#making-a-good-pull-request

- [x] I agree to contribute to the project under Apache 2 License.
- [x] To the best of my knowledge, the proposed patch is not based on a code under GPL or another license that is incompatible with OpenCV
- [ ] The PR is proposed to the proper branch
- [ ] There is a reference to the original bug report and related work
- [x] There is accuracy test, performance test and test data in opencv_extra repository, if applicable
      Patch to opencv_extra has the same branch name.
- [x] The feature is well documented and sample code can be built with the project CMake
This commit is contained in:
Anatoliy Talamanov
2023-06-02 13:31:03 +02:00
committed by GitHub
parent 36d6ca529d
commit 5330112f05
15 changed files with 2933 additions and 4 deletions
+34
View File
@@ -6,6 +6,8 @@
#include "cv2_numpy.hpp"
#include <vector>
#include <string>
#include <unordered_map>
#include <map>
#include <type_traits> // std::enable_if
extern PyTypeObject* pyopencv_Mat_TypePtr;
@@ -263,6 +265,38 @@ PyObject* pyopencv_from(const std::vector<Tp>& value)
return pyopencvVecConverter<Tp>::from(value);
}
template<typename K, typename V>
bool pyopencv_to(PyObject *obj, std::map<K,V> &map, const ArgInfo& info)
{
PyObject* py_key = nullptr;
PyObject* py_value = nullptr;
Py_ssize_t pos = 0;
if (!PyDict_Check(obj)) {
failmsg("Can't parse '%s'. Input argument isn't dict or"
" an instance of subtype of the dict type", info.name);
return false;
}
while(PyDict_Next(obj, &pos, &py_key, &py_value))
{
K cpp_key;
if (!pyopencv_to(py_key, cpp_key, ArgInfo("key", false))) {
failmsg("Can't parse dict key. Key on position %lu has a wrong type", pos);
return false;
}
V cpp_value;
if (!pyopencv_to(py_value, cpp_value, ArgInfo("value", false))) {
failmsg("Can't parse dict value. Value on position %lu has a wrong type", pos);
return false;
}
map.emplace(cpp_key, cpp_value);
}
return true;
}
template <typename Tp>
static bool pyopencv_to_generic_vec(PyObject* obj, std::vector<Tp>& value, const ArgInfo& info)
{
@@ -190,6 +190,14 @@ _PREDEFINED_TYPES = (
PrimitiveTypeNode.float_(),
PrimitiveTypeNode.str_())
), export_name="SearchParams"),
AliasTypeNode.dict_("map_string_and_string", PrimitiveTypeNode.str_("map_string_and_string::key"),
PrimitiveTypeNode.str_("map_string_and_string::key::value")),
AliasTypeNode.dict_("map_string_and_int", PrimitiveTypeNode.str_("map_string_and_int::key"),
PrimitiveTypeNode.int_("map_string_and_int::key::value")),
AliasTypeNode.dict_("map_string_and_vector_size_t", PrimitiveTypeNode.str_("map_string_and_vector_size_t::key"),
SequenceTypeNode("map_string_and_vector_size_t::key::value", PrimitiveTypeNode.int_("size_t"))),
AliasTypeNode.dict_("map_string_and_vector_float", PrimitiveTypeNode.str_("map_string_and_vector_float::key"),
SequenceTypeNode("map_string_and_vector_float::key::value", PrimitiveTypeNode.float_())),
)
PREDEFINED_TYPES = dict(zip((t.ctype_name for t in _PREDEFINED_TYPES), _PREDEFINED_TYPES))