Add python tests for dnn module

This commit is contained in:
Dmitry Kurtaev
2018-09-13 16:31:31 +03:00
parent 347e09cd07
commit d259eb28bb
2 changed files with 194 additions and 14 deletions
+15 -14
View File
@@ -26,23 +26,24 @@ class NewOpenCVTests(unittest.TestCase):
# github repository url
repoUrl = 'https://raw.github.com/opencv/opencv/master'
def find_file(self, filename, searchPaths=[]):
searchPaths = searchPaths if searchPaths else [self.repoPath, self.extraTestDataPath]
for path in searchPaths:
if path is not None:
candidate = path + '/' + filename
if os.path.isfile(candidate):
return candidate
self.fail('File ' + filename + ' not found')
return None
def get_sample(self, filename, iscolor = None):
if iscolor is None:
iscolor = cv.IMREAD_COLOR
if not filename in self.image_cache:
filedata = None
if NewOpenCVTests.repoPath is not None:
candidate = NewOpenCVTests.repoPath + '/' + filename
if os.path.isfile(candidate):
with open(candidate, 'rb') as f:
filedata = f.read()
if NewOpenCVTests.extraTestDataPath is not None:
candidate = NewOpenCVTests.extraTestDataPath + '/' + filename
if os.path.isfile(candidate):
with open(candidate, 'rb') as f:
filedata = f.read()
if filedata is None:
return None#filedata = urlopen(NewOpenCVTests.repoUrl + '/' + filename).read()
filepath = self.find_file(filename)
with open(filepath, 'rb') as f:
filedata = f.read()
self.image_cache[filename] = cv.imdecode(np.fromstring(filedata, dtype=np.uint8), iscolor)
return self.image_cache[filename]
@@ -102,4 +103,4 @@ def isPointInRect(p, rect):
if rect[0] <= p[0] and rect[1] <=p[1] and p[0] <= rect[2] and p[1] <= rect[3]:
return True
else:
return False
return False