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

Merge branch 4.x

This commit is contained in:
Alexander Alekhin
2021-04-09 10:30:38 +00:00
1114 changed files with 64039 additions and 14611 deletions
+2 -2
View File
@@ -34,8 +34,8 @@ def load_tests(loader, tests, pattern):
else:
print('WARNING: OpenCV tests config file ({}) is missing, running subset of tests'.format(config_file))
tests_pattern = os.environ.get('OPENCV_PYTEST_FILTER', 'test_') + '*.py'
if tests_pattern != 'test_*py':
tests_pattern = os.environ.get('OPENCV_PYTEST_FILTER', 'test_*') + '.py'
if tests_pattern != 'test_*.py':
print('Tests filter: {}'.format(tests_pattern))
processed = set()
+2
View File
@@ -33,6 +33,8 @@ class cuda_test(NewOpenCVTests):
self.assertTrue(cuMat.cudaPtr() != 0)
stream = cv.cuda_Stream()
self.assertTrue(stream.cudaPtr() != 0)
asyncstream = cv.cuda_Stream(1) # cudaStreamNonBlocking
self.assertTrue(asyncstream.cudaPtr() != 0)
if __name__ == '__main__':
NewOpenCVTests.bootstrap()
View File
+41
View File
@@ -0,0 +1,41 @@
# Python 2/3 compatibility
from __future__ import print_function
import numpy as np
import cv2 as cv
import os
import datetime
from tests_common import NewOpenCVTests
class get_cache_dir_test(NewOpenCVTests):
def test_get_cache_dir(self):
#New binding
path = cv.utils.fs.getCacheDirectoryForDownloads()
self.assertTrue(os.path.exists(path))
self.assertTrue(os.path.isdir(path))
def get_cache_dir_imread_interop(self, ext):
path = cv.utils.fs.getCacheDirectoryForDownloads()
gold_image = np.ones((16, 16, 3), np.uint8)
read_from_file = np.zeros((16, 16, 3), np.uint8)
test_file_name = os.path.join(path, "test." + ext)
try:
cv.imwrite(test_file_name, gold_image)
read_from_file = cv.imread(test_file_name)
finally:
os.remove(test_file_name)
self.assertEqual(cv.norm(gold_image, read_from_file), 0)
def test_get_cache_dir_imread_interop_png(self):
self.get_cache_dir_imread_interop("png")
def test_get_cache_dir_imread_interop_jpeg(self):
self.get_cache_dir_imread_interop("jpg")
def test_get_cache_dir_imread_interop_tiff(self):
self.get_cache_dir_imread_interop("tif")
if __name__ == '__main__':
NewOpenCVTests.bootstrap()
+3
View File
@@ -64,6 +64,9 @@ class houghlines_test(NewOpenCVTests):
self.assertGreater(float(matches_counter) / len(testLines), .7)
lines_acc = cv.HoughLinesWithAccumulator(dst, rho=1, theta=np.pi / 180, threshold=150, srn=0, stn=0)
self.assertEqual(lines_acc[0,0,2], 192.0)
self.assertEqual(lines_acc[1,0,2], 187.0)
if __name__ == '__main__':
NewOpenCVTests.bootstrap()
View File
+1 -1
View File
@@ -76,7 +76,7 @@ class Hackathon244Tests(NewOpenCVTests):
mc, mr = cv.minEnclosingCircle(a)
be0 = ((150.2511749267578, 150.77322387695312), (158.024658203125, 197.57696533203125), 37.57804489135742)
br0 = ((161.2974090576172, 154.41793823242188), (199.2301483154297, 207.7177734375), -9.164555549621582)
br0 = ((161.2974090576172, 154.41793823242188), (207.7177734375, 199.2301483154297), 80.83544921875)
mc0, mr0 = (160.41790771484375, 144.55152893066406), 136.713500977
self.check_close_boxes(be, be0, 5, 15)
Executable → Regular
+139 -1
View File
@@ -3,6 +3,7 @@ from __future__ import print_function
import ctypes
from functools import partial
from collections import namedtuple
import numpy as np
import cv2 as cv
@@ -46,6 +47,12 @@ class Bindings(NewOpenCVTests):
boost.getMaxDepth() # from ml::DTrees
boost.isClassifier() # from ml::StatModel
def test_raiseGeneralException(self):
with self.assertRaises((cv.error,),
msg='C++ exception is not propagated to Python in the right way') as cm:
cv.utils.testRaiseGeneralException()
self.assertEqual(str(cm.exception), 'exception text')
def test_redirectError(self):
try:
cv.imshow("", None) # This causes an assert
@@ -73,6 +80,45 @@ class Bindings(NewOpenCVTests):
except cv.error as _e:
pass
def test_overload_resolution_can_choose_correct_overload(self):
val = 123
point = (51, 165)
self.assertEqual(cv.utils.testOverloadResolution(val, point),
'overload (int={}, point=(x={}, y={}))'.format(val, *point),
"Can't select first overload if all arguments are provided as positional")
self.assertEqual(cv.utils.testOverloadResolution(val, point=point),
'overload (int={}, point=(x={}, y={}))'.format(val, *point),
"Can't select first overload if one of the arguments are provided as keyword")
self.assertEqual(cv.utils.testOverloadResolution(val),
'overload (int={}, point=(x=42, y=24))'.format(val),
"Can't select first overload if one of the arguments has default value")
rect = (1, 5, 10, 23)
self.assertEqual(cv.utils.testOverloadResolution(rect),
'overload (rect=(x={}, y={}, w={}, h={}))'.format(*rect),
"Can't select second overload if all arguments are provided")
def test_overload_resolution_fails(self):
def test_overload_resolution(msg, *args, **kwargs):
no_exception_msg = 'Overload resolution failed without any exception for: "{}"'.format(msg)
wrong_exception_msg = 'Overload resolution failed with wrong exception type for: "{}"'.format(msg)
with self.assertRaises((cv.error, Exception), msg=no_exception_msg) as cm:
res = cv.utils.testOverloadResolution(*args, **kwargs)
self.fail("Unexpected result for {}: '{}'".format(msg, res))
self.assertEqual(type(cm.exception), cv.error, wrong_exception_msg)
test_overload_resolution('wrong second arg type (keyword arg)', 5, point=(1, 2, 3))
test_overload_resolution('wrong second arg type', 5, 2)
test_overload_resolution('wrong first arg', 3.4, (12, 21))
test_overload_resolution('wrong first arg, no second arg', 4.5)
test_overload_resolution('wrong args number for first overload', 3, (12, 21), 123)
test_overload_resolution('wrong args number for second overload', (3, 12, 12, 1), (12, 21))
# One of the common problems
test_overload_resolution('rect with float coordinates', (4.5, 4, 2, 1))
test_overload_resolution('rect with wrong number of coordinates', (4, 4, 1))
class Arguments(NewOpenCVTests):
@@ -314,7 +360,7 @@ class Arguments(NewOpenCVTests):
def test_parse_to_cstring_convertible(self):
try_to_convert = partial(self._try_to_convert, cv.utils.dumpCString)
for convertible in ('s', 'str', str(123), ('char'), np.str('test1'), np.str_('test2')):
for convertible in ('', 's', 'str', str(123), ('char'), np.str('test1'), np.str_('test2')):
expected = 'string: ' + convertible
actual = try_to_convert(convertible)
self.assertEqual(expected, actual,
@@ -326,6 +372,98 @@ class Arguments(NewOpenCVTests):
with self.assertRaises((TypeError), msg=get_no_exception_msg(not_convertible)):
_ = cv.utils.dumpCString(not_convertible)
def test_parse_to_string_convertible(self):
try_to_convert = partial(self._try_to_convert, cv.utils.dumpString)
for convertible in (None, '', 's', 'str', str(123), np.str('test1'), np.str_('test2')):
expected = 'string: ' + (convertible if convertible else '')
actual = try_to_convert(convertible)
self.assertEqual(expected, actual,
msg=get_conversion_error_msg(convertible, expected, actual))
def test_parse_to_string_not_convertible(self):
for not_convertible in ((12,), ('t', 'e', 's', 't'), np.array(['123', ]),
np.array(['t', 'e', 's', 't']), 1, True, False):
with self.assertRaises((TypeError), msg=get_no_exception_msg(not_convertible)):
_ = cv.utils.dumpString(not_convertible)
def test_parse_to_rect_convertible(self):
Rect = namedtuple('Rect', ('x', 'y', 'w', 'h'))
try_to_convert = partial(self._try_to_convert, cv.utils.dumpRect)
for convertible in ((1, 2, 4, 5), [5, 3, 10, 20], np.array([10, 20, 23, 10]),
Rect(10, 30, 40, 55), tuple(np.array([40, 20, 24, 20])),
list(np.array([20, 40, 30, 35]))):
expected = 'rect: (x={}, y={}, w={}, h={})'.format(*convertible)
actual = try_to_convert(convertible)
self.assertEqual(expected, actual,
msg=get_conversion_error_msg(convertible, expected, actual))
def test_parse_to_rect_not_convertible(self):
for not_convertible in (np.empty(shape=(4, 1)), (), [], np.array([]), (12, ),
[3, 4, 5, 10, 123], {1: 2, 3:4, 5:10, 6:30},
'1234', np.array([1, 2, 3, 4], dtype=np.float32),
np.array([[1, 2], [3, 4], [5, 6], [6, 8]]), (1, 2, 5, 1.5)):
with self.assertRaises((TypeError), msg=get_no_exception_msg(not_convertible)):
_ = cv.utils.dumpRect(not_convertible)
def test_parse_to_rotated_rect_convertible(self):
RotatedRect = namedtuple('RotatedRect', ('center', 'size', 'angle'))
try_to_convert = partial(self._try_to_convert, cv.utils.dumpRotatedRect)
for convertible in (((2.5, 2.5), (10., 20.), 12.5), [[1.5, 10.5], (12.5, 51.5), 10],
RotatedRect((10, 40), np.array([10.5, 20.5]), 5),
np.array([[10, 6], [50, 50], 5.5], dtype=object)):
center, size, angle = convertible
expected = 'rotated_rect: (c_x={:.6f}, c_y={:.6f}, w={:.6f},' \
' h={:.6f}, a={:.6f})'.format(center[0], center[1],
size[0], size[1], angle)
actual = try_to_convert(convertible)
self.assertEqual(expected, actual,
msg=get_conversion_error_msg(convertible, expected, actual))
def test_parse_to_rotated_rect_not_convertible(self):
for not_convertible in ([], (), np.array([]), (123, (45, 34), 1), {1: 2, 3: 4}, 123,
np.array([[123, 123, 14], [1, 3], 56], dtype=object), '123'):
with self.assertRaises((TypeError), msg=get_no_exception_msg(not_convertible)):
_ = cv.utils.dumpRotatedRect(not_convertible)
def test_parse_to_term_criteria_convertible(self):
TermCriteria = namedtuple('TermCriteria', ('type', 'max_count', 'epsilon'))
try_to_convert = partial(self._try_to_convert, cv.utils.dumpTermCriteria)
for convertible in ((1, 10, 1e-3), [2, 30, 1e-1], np.array([10, 20, 0.5], dtype=object),
TermCriteria(0, 5, 0.1)):
expected = 'term_criteria: (type={}, max_count={}, epsilon={:.6f}'.format(*convertible)
actual = try_to_convert(convertible)
self.assertEqual(expected, actual,
msg=get_conversion_error_msg(convertible, expected, actual))
def test_parse_to_term_criteria_not_convertible(self):
for not_convertible in ([], (), np.array([]), [1, 4], (10,), (1.5, 34, 0.1),
{1: 5, 3: 5, 10: 10}, '145'):
with self.assertRaises((TypeError), msg=get_no_exception_msg(not_convertible)):
_ = cv.utils.dumpTermCriteria(not_convertible)
def test_parse_to_range_convertible_to_all(self):
try_to_convert = partial(self._try_to_convert, cv.utils.dumpRange)
for convertible in ((), [], np.array([])):
expected = 'range: all'
actual = try_to_convert(convertible)
self.assertEqual(expected, actual,
msg=get_conversion_error_msg(convertible, expected, actual))
def test_parse_to_range_convertible(self):
Range = namedtuple('Range', ('start', 'end'))
try_to_convert = partial(self._try_to_convert, cv.utils.dumpRange)
for convertible in ((10, 20), [-1, 3], np.array([10, 24]), Range(-4, 6)):
expected = 'range: (s={}, e={})'.format(*convertible)
actual = try_to_convert(convertible)
self.assertEqual(expected, actual,
msg=get_conversion_error_msg(convertible, expected, actual))
def test_parse_to_range_not_convertible(self):
for not_convertible in ((1, ), [40, ], np.array([1, 4, 6]), {'a': 1, 'b': 40},
(1.5, 13.5), [3, 6.7], np.array([6.3, 2.1]), '14, 4'):
with self.assertRaises((TypeError), msg=get_no_exception_msg(not_convertible)):
_ = cv.utils.dumpRange(not_convertible)
class SamplesFindFile(NewOpenCVTests):