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

Merge branch 4.x

This commit is contained in:
Alexander Smorkalov
2024-07-16 10:11:21 +03:00
102 changed files with 3618 additions and 2171 deletions
+4 -1
View File
@@ -46,19 +46,22 @@ private:
static const uint32_t arg_outputarg_flag = 0x1;
static const uint32_t arg_arithm_op_src_flag = 0x2;
static const uint32_t arg_pathlike_flag = 0x4;
static const uint32_t arg_nd_mat_flag = 0x8;
public:
const char* name;
bool outputarg;
bool arithm_op_src;
bool pathlike;
bool nd_mat;
// more fields may be added if necessary
ArgInfo(const char* name_, uint32_t arg_) :
name(name_),
outputarg((arg_ & arg_outputarg_flag) != 0),
arithm_op_src((arg_ & arg_arithm_op_src_flag) != 0),
pathlike((arg_ & arg_pathlike_flag) != 0) {}
pathlike((arg_ & arg_pathlike_flag) != 0),
nd_mat((arg_ & arg_nd_mat_flag) != 0) {}
private:
ArgInfo(const ArgInfo&) = delete;
+1 -1
View File
@@ -173,7 +173,7 @@ bool pyopencv_to(PyObject* o, Mat& m, const ArgInfo& info)
CV_LOG_DEBUG(NULL, "Incoming ndarray '" << info.name << "': ndims=" << ndims << " _sizes=" << pycv_dumpArray(_sizes, ndims) << " _strides=" << pycv_dumpArray(_strides, ndims));
bool ismultichannel = ndims == 3 && _sizes[2] <= CV_CN_MAX;
bool ismultichannel = ndims == 3 && _sizes[2] <= CV_CN_MAX && !info.nd_mat;
if (pyopencv_Mat_TypePtr && PyObject_TypeCheck(o, pyopencv_Mat_TypePtr))
{
bool wrapChannels = false;
+27 -11
View File
@@ -340,22 +340,38 @@ static bool pyopencv_to_generic_vec(PyObject* obj, std::vector<Tp>& value, const
{
return true;
}
if (!PySequence_Check(obj))
if (info.nd_mat && PyArray_Check(obj))
{
failmsg("Can't parse '%s'. Input argument doesn't provide sequence protocol", info.name);
return false;
}
const size_t n = static_cast<size_t>(PySequence_Size(obj));
value.resize(n);
for (size_t i = 0; i < n; i++)
{
SafeSeqItem item_wrap(obj, i);
if (!pyopencv_to(item_wrap.item, value[i], info))
/*
If obj is marked as nd mat and of array type, it is parsed to a single
mat in the target vector to avoid being split into multiple mats
*/
value.resize(1);
if (!pyopencv_to(obj, value.front(), info))
{
failmsg("Can't parse '%s'. Sequence item with index %lu has a wrong type", info.name, i);
failmsg("Can't parse '%s'. Array item has a wrong type", info.name);
return false;
}
}
else // parse as sequence
{
if (!PySequence_Check(obj))
{
failmsg("Can't parse '%s'. Input argument doesn't provide sequence protocol", info.name);
return false;
}
const size_t n = static_cast<size_t>(PySequence_Size(obj));
value.resize(n);
for (size_t i = 0; i < n; i++)
{
SafeSeqItem item_wrap(obj, i);
if (!pyopencv_to(item_wrap.item, value[i], info))
{
failmsg("Can't parse '%s'. Sequence item with index %lu has a wrong type", info.name, i);
return false;
}
}
}
return true;
}
+5
View File
@@ -488,6 +488,10 @@ class ArgInfo(object):
return self.name + '_'
return self.name
@property
def nd_mat(self):
return '/ND' in self._modifiers
@property
def inputarg(self):
return '/O' not in self._modifiers
@@ -528,6 +532,7 @@ class ArgInfo(object):
arg = 0x01 if self.outputarg else 0x0
arg += 0x02 if self.arithm_op_src_arg else 0x0
arg += 0x04 if self.pathlike else 0x0
arg += 0x08 if self.nd_mat else 0x0
return "ArgInfo(\"%s\", %d)" % (self.name, arg)
+4
View File
@@ -84,6 +84,10 @@ class CppHeaderParser(object):
modlist = []
# pass 0: extracts the modifiers
if "CV_ND" in arg_str:
modlist.append("/ND")
arg_str = arg_str.replace("CV_ND", "")
if "CV_OUT" in arg_str:
modlist.append("/O")
arg_str = arg_str.replace("CV_OUT", "")
+4
View File
@@ -972,6 +972,10 @@ class SamplesFindFile(NewOpenCVTests):
except cv.error as _e:
pass
class AlgorithmImplHit(NewOpenCVTests):
def test_callable(self):
res = cv.getDefaultAlgorithmHint()
self.assertTrue(res is not None)
if __name__ == '__main__':
NewOpenCVTests.bootstrap()