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

Merge branch 4.x

This commit is contained in:
Alexander Alekhin
2023-01-09 11:08:02 +00:00
880 changed files with 83958 additions and 9368 deletions
+24
View File
@@ -444,6 +444,30 @@ PyObject* pyopencv_from(const int& value)
// --- int64
template<>
bool pyopencv_to(PyObject* obj, int64& value, const ArgInfo& info)
{
if (!obj || obj == Py_None)
{
return true;
}
if (isBool(obj))
{
failmsg("Argument '%s' must be integer, not bool", info.name);
return false;
}
if (PyArray_IsIntegerScalar(obj))
{
value = PyLong_AsLongLong(obj);
}
else
{
failmsg("Argument '%s' is required to be an integer", info.name);
return false;
}
return !CV_HAS_CONVERSION_ERROR(value);
}
template<>
PyObject* pyopencv_from(const int64& value)
{
+5
View File
@@ -62,6 +62,10 @@ PyObject* pyopencv_from(const T& src) { return PyOpenCV_Converter<T>::from(src);
template<typename _Tp, int m, int n>
bool pyopencv_to(PyObject* o, cv::Matx<_Tp, m, n>& mx, const ArgInfo& info)
{
if (!o || o == Py_None) {
return true;
}
cv::Mat tmp;
if (!pyopencv_to(o, tmp, info)) {
return false;
@@ -121,6 +125,7 @@ template<> bool pyopencv_to(PyObject* obj, int& value, const ArgInfo& info);
template<> PyObject* pyopencv_from(const int& value);
// --- int64
template<> bool pyopencv_to(PyObject* obj, int64& value, const ArgInfo& info);
template<> PyObject* pyopencv_from(const int64& value);
// There is conflict between "size_t" and "unsigned int".
+4 -4
View File
@@ -51,13 +51,13 @@ NPY_TYPES asNumpyType<bool>()
return NPY_U##dst; \
}
CV_GENERATE_INTEGRAL_TYPE_NPY_CONVERSION(int8_t, INT8);
CV_GENERATE_INTEGRAL_TYPE_NPY_CONVERSION(int8_t, INT8)
CV_GENERATE_INTEGRAL_TYPE_NPY_CONVERSION(int16_t, INT16);
CV_GENERATE_INTEGRAL_TYPE_NPY_CONVERSION(int16_t, INT16)
CV_GENERATE_INTEGRAL_TYPE_NPY_CONVERSION(int32_t, INT32);
CV_GENERATE_INTEGRAL_TYPE_NPY_CONVERSION(int32_t, INT32)
CV_GENERATE_INTEGRAL_TYPE_NPY_CONVERSION(int64_t, INT64);
CV_GENERATE_INTEGRAL_TYPE_NPY_CONVERSION(int64_t, INT64)
#undef CV_GENERATE_INTEGRAL_TYPE_NPY_CONVERSION
+1 -1
View File
@@ -12,7 +12,7 @@
bool isPythonBindingsDebugEnabled();
void emit_failmsg(PyObject * exc, const char *msg);
int failmsg(const char *fmt, ...);
PyObject* failmsgp(const char *fmt, ...);;
PyObject* failmsgp(const char *fmt, ...);
//======================================================================================================================
+29 -5
View File
@@ -169,10 +169,10 @@ static int pyopencv_${name}_set_${member}(pyopencv_${name}_t* p, PyObject *value
gen_template_prop_init = Template("""
{(char*)"${member}", (getter)pyopencv_${name}_get_${member}, NULL, (char*)"${member}", NULL},""")
{(char*)"${export_member_name}", (getter)pyopencv_${name}_get_${member}, NULL, (char*)"${export_member_name}", NULL},""")
gen_template_rw_prop_init = Template("""
{(char*)"${member}", (getter)pyopencv_${name}_get_${member}, (setter)pyopencv_${name}_set_${member}, (char*)"${member}", NULL},""")
{(char*)"${export_member_name}", (getter)pyopencv_${name}_get_${member}, (setter)pyopencv_${name}_set_${member}, (char*)"${export_member_name}", NULL},""")
gen_template_overloaded_function_call = Template("""
{
@@ -212,6 +212,7 @@ simple_argtype_mapping = {
"c_string": ArgTypeInfo("char*", FormatStrings.string, '(char*)""'),
"string": ArgTypeInfo("std::string", FormatStrings.object, None, True),
"Stream": ArgTypeInfo("Stream", FormatStrings.object, 'Stream::Null()', True),
"UMat": ArgTypeInfo("UMat", FormatStrings.object, 'UMat()', True), # FIXIT: switch to CV_EXPORTS_W_SIMPLE as UMat is already a some kind of smart pointer
}
# Set of reserved keywords for Python. Can be acquired via the following call
@@ -245,6 +246,13 @@ class ClassProp(object):
if "/RW" in decl[3]:
self.readonly = False
@property
def export_name(self):
if self.name in python_reserved_keywords:
return self.name + "_"
return self.name
class ClassInfo(object):
def __init__(self, name, decl=None, codegen=None):
# Scope name can be a module or other class e.g. cv::SimpleBlobDetector::Params
@@ -296,6 +304,7 @@ class ClassInfo(object):
self.issimple = True
elif m == "/Params":
self.isparams = True
self.issimple = True # TODO: rework 'params' generation/handling (see #19156 and #22934)
self.props = [ClassProp(p) for p in decl[3]]
if not self.has_export_alias and self.original_name.startswith("Cv"):
@@ -359,13 +368,13 @@ class ClassInfo(object):
else:
getset_code.write(gen_template_get_prop.substitute(name=self.name, member=pname, membertype=p.tp, access=access_op))
if p.readonly:
getset_inits.write(gen_template_prop_init.substitute(name=self.name, member=pname))
getset_inits.write(gen_template_prop_init.substitute(name=self.name, member=pname, export_member_name=p.export_name))
else:
if self.isalgorithm:
getset_code.write(gen_template_set_prop_algo.substitute(name=self.name, cname=self.cname, member=pname, membertype=p.tp, access=access_op))
else:
getset_code.write(gen_template_set_prop.substitute(name=self.name, member=pname, membertype=p.tp, access=access_op))
getset_inits.write(gen_template_rw_prop_init.substitute(name=self.name, member=pname))
getset_inits.write(gen_template_rw_prop_init.substitute(name=self.name, member=pname, export_member_name=p.export_name))
methods_code = StringIO()
methods_inits = StringIO()
@@ -436,6 +445,7 @@ class ArgInfo(object):
self.name += "_"
self.defval = arg_tuple[2]
self.isarray = False
self.is_smart_ptr = self.tp.startswith('Ptr<') # FIXIT: handle through modifiers - need to modify parser
self.arraylen = 0
self.arraycvt = None
self.inputarg = True
@@ -746,7 +756,21 @@ class FuncInfo(object):
if any(tp in codegen.enums.keys() for tp in tp_candidates):
defval0 = "static_cast<%s>(%d)" % (a.tp, 0)
arg_type_info = simple_argtype_mapping.get(tp, ArgTypeInfo(tp, FormatStrings.object, defval0, True))
if tp in simple_argtype_mapping:
arg_type_info = simple_argtype_mapping[tp]
else:
if tp in all_classes:
tp_classinfo = all_classes[tp]
cname_of_value = tp_classinfo.cname if tp_classinfo.issimple else "Ptr<{}>".format(tp_classinfo.cname)
arg_type_info = ArgTypeInfo(cname_of_value, FormatStrings.object, defval0, True)
assert not (a.is_smart_ptr and tp_classinfo.issimple), "Can't pass 'simple' type as Ptr<>"
if not a.is_smart_ptr and not tp_classinfo.issimple:
assert amp == ''
amp = '*'
else:
# FIXIT: Ptr_ / vector_ / enums / nested types
arg_type_info = ArgTypeInfo(tp, FormatStrings.object, defval0, True)
parse_name = a.name
if a.py_inputarg:
if arg_type_info.strict_conversion: