Skip to content

Commit 7825abd

Browse files
committed
python: handle errors in Rect conversions
1 parent cd59516 commit 7825abd

File tree

3 files changed

+18
-4
lines changed

3 files changed

+18
-4
lines changed

modules/dnn/misc/python/test/test_dnn.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ def test_model(self):
177177
cv.rectangle(frame, box, (0, 255, 0))
178178
cv.rectangle(frame, np.array(box), (0, 255, 0))
179179
cv.rectangle(frame, tuple(box), (0, 255, 0))
180-
cv.rectangle(frame, list(box), (0, 255, 0))
180+
# FIXIT never properly work: cv.rectangle(frame, list(box), (0, 255, 0))
181181

182182

183183
def test_classification_model(self):

modules/python/src2/cv2.cpp

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1552,8 +1552,13 @@ template<typename _Tp> struct pyopencvVecConverter
15521552
break;
15531553
}
15541554
}
1555+
if (i != n)
1556+
{
1557+
failmsg("Can't convert vector element for '%s', index=%d", info.name, i);
1558+
}
15551559
return i == n;
15561560
}
1561+
failmsg("Can't convert object to vector for '%s', unsupported type", info.name);
15571562
return false;
15581563
}
15591564

@@ -1772,7 +1777,15 @@ bool pyopencv_to(PyObject* obj, Rect& r, const ArgInfo& info)
17721777
else
17731778
{
17741779
std::vector<int> value(4);
1775-
pyopencvVecConverter<int>::to(obj, value, info);
1780+
if (!pyopencvVecConverter<int>::to(obj, value, info))
1781+
{
1782+
return false;
1783+
}
1784+
if (value.size() != 4)
1785+
{
1786+
failmsg("Expected 4 values for '%s', got %d", info.name, (int)value.size());
1787+
return false;
1788+
}
17761789
r = Rect(value[0], value[1], value[2], value[3]);
17771790
return true;
17781791
}

modules/python/test/test_misc.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,13 +98,14 @@ def test_overload_resolution(msg, *args, **kwargs):
9898
no_exception_msg = 'Overload resolution failed without any exception for: "{}"'.format(msg)
9999
wrong_exception_msg = 'Overload resolution failed with wrong exception type for: "{}"'.format(msg)
100100
with self.assertRaises((cv.error, Exception), msg=no_exception_msg) as cm:
101-
cv.utils.testOverloadResolution(*args, **kwargs)
101+
res = cv.utils.testOverloadResolution(*args, **kwargs)
102+
self.fail("Unexpected result for {}: '{}'".format(msg, res))
102103
self.assertEqual(type(cm.exception), cv.error, wrong_exception_msg)
103104

104105
test_overload_resolution('wrong second arg type (keyword arg)', 5, point=(1, 2, 3))
105106
test_overload_resolution('wrong second arg type', 5, 2)
106107
test_overload_resolution('wrong first arg', 3.4, (12, 21))
107-
# FIXIT: test_overload_resolution('wrong first arg, no second arg', 4.5)
108+
test_overload_resolution('wrong first arg, no second arg', 4.5)
108109
test_overload_resolution('wrong args number for first overload', 3, (12, 21), 123)
109110
test_overload_resolution('wrong args number for second overload', (3, 12, 12, 1), (12, 21))
110111
# One of the common problems

0 commit comments

Comments
 (0)