mirror of
https://github.com/zebrajr/opencv.git
synced 2025-12-06 12:19:50 +01:00
Merge pull request #20196 from TolyaTalamanov:at/support-vaargs-compile-args
G-API: Support vaargs for cv.compile_args * Support cv.compile_args to work with variadic number of inputs * Disable python2.x G-API * Move compile_args to gapi pkg
This commit is contained in:
parent
f30f1afd47
commit
53eca2ff5b
|
|
@ -11,6 +11,11 @@ def register(mname):
|
||||||
return parameterized
|
return parameterized
|
||||||
|
|
||||||
|
|
||||||
|
@register('cv2.gapi')
|
||||||
|
def compile_args(*args):
|
||||||
|
return list(map(cv.GCompileArg, args))
|
||||||
|
|
||||||
|
|
||||||
@register('cv2')
|
@register('cv2')
|
||||||
class GOpaque():
|
class GOpaque():
|
||||||
# NB: Inheritance from c++ class cause segfault.
|
# NB: Inheritance from c++ class cause segfault.
|
||||||
|
|
|
||||||
|
|
@ -3,11 +3,10 @@
|
||||||
|
|
||||||
namespace cv
|
namespace cv
|
||||||
{
|
{
|
||||||
struct GAPI_EXPORTS_W_SIMPLE GCompileArg { };
|
struct GAPI_EXPORTS_W_SIMPLE GCompileArg {
|
||||||
|
GAPI_WRAP GCompileArg(gapi::GKernelPackage pkg);
|
||||||
GAPI_EXPORTS_W GCompileArgs compile_args(gapi::GKernelPackage pkg);
|
GAPI_WRAP GCompileArg(gapi::GNetPackage pkg);
|
||||||
GAPI_EXPORTS_W GCompileArgs compile_args(gapi::GNetPackage pkg);
|
};
|
||||||
GAPI_EXPORTS_W GCompileArgs compile_args(gapi::GKernelPackage kernels, gapi::GNetPackage nets);
|
|
||||||
|
|
||||||
// NB: This classes doesn't exist in *.so
|
// NB: This classes doesn't exist in *.so
|
||||||
// HACK: Mark them as a class to force python wrapper generate code for this entities
|
// HACK: Mark them as a class to force python wrapper generate code for this entities
|
||||||
|
|
|
||||||
|
|
@ -3,187 +3,209 @@
|
||||||
import numpy as np
|
import numpy as np
|
||||||
import cv2 as cv
|
import cv2 as cv
|
||||||
import os
|
import os
|
||||||
|
import sys
|
||||||
|
import unittest
|
||||||
|
|
||||||
from tests_common import NewOpenCVTests
|
from tests_common import NewOpenCVTests
|
||||||
|
|
||||||
|
|
||||||
# Plaidml is an optional backend
|
try:
|
||||||
pkgs = [
|
|
||||||
('ocl' , cv.gapi.core.ocl.kernels()),
|
if sys.version_info[:2] < (3, 0):
|
||||||
('cpu' , cv.gapi.core.cpu.kernels()),
|
raise unittest.SkipTest('Python 2.x is not supported')
|
||||||
('fluid' , cv.gapi.core.fluid.kernels())
|
|
||||||
# ('plaidml', cv.gapi.core.plaidml.kernels())
|
# Plaidml is an optional backend
|
||||||
]
|
pkgs = [
|
||||||
|
('ocl' , cv.gapi.core.ocl.kernels()),
|
||||||
|
('cpu' , cv.gapi.core.cpu.kernels()),
|
||||||
|
('fluid' , cv.gapi.core.fluid.kernels())
|
||||||
|
# ('plaidml', cv.gapi.core.plaidml.kernels())
|
||||||
|
]
|
||||||
|
|
||||||
|
|
||||||
class gapi_core_test(NewOpenCVTests):
|
class gapi_core_test(NewOpenCVTests):
|
||||||
|
|
||||||
def test_add(self):
|
def test_add(self):
|
||||||
# TODO: Extend to use any type and size here
|
# TODO: Extend to use any type and size here
|
||||||
sz = (720, 1280)
|
sz = (720, 1280)
|
||||||
in1 = np.full(sz, 100)
|
in1 = np.full(sz, 100)
|
||||||
in2 = np.full(sz, 50)
|
in2 = np.full(sz, 50)
|
||||||
|
|
||||||
# OpenCV
|
# OpenCV
|
||||||
expected = cv.add(in1, in2)
|
expected = cv.add(in1, in2)
|
||||||
|
|
||||||
# G-API
|
# G-API
|
||||||
g_in1 = cv.GMat()
|
g_in1 = cv.GMat()
|
||||||
g_in2 = cv.GMat()
|
g_in2 = cv.GMat()
|
||||||
g_out = cv.gapi.add(g_in1, g_in2)
|
g_out = cv.gapi.add(g_in1, g_in2)
|
||||||
comp = cv.GComputation(cv.GIn(g_in1, g_in2), cv.GOut(g_out))
|
comp = cv.GComputation(cv.GIn(g_in1, g_in2), cv.GOut(g_out))
|
||||||
|
|
||||||
for pkg_name, pkg in pkgs:
|
for pkg_name, pkg in pkgs:
|
||||||
actual = comp.apply(cv.gin(in1, in2), args=cv.compile_args(pkg))
|
actual = comp.apply(cv.gin(in1, in2), args=cv.gapi.compile_args(pkg))
|
||||||
# Comparison
|
# Comparison
|
||||||
self.assertEqual(0.0, cv.norm(expected, actual, cv.NORM_INF),
|
self.assertEqual(0.0, cv.norm(expected, actual, cv.NORM_INF),
|
||||||
'Failed on ' + pkg_name + ' backend')
|
|
||||||
self.assertEqual(expected.dtype, actual.dtype, 'Failed on ' + pkg_name + ' backend')
|
|
||||||
|
|
||||||
|
|
||||||
def test_add_uint8(self):
|
|
||||||
sz = (720, 1280)
|
|
||||||
in1 = np.full(sz, 100, dtype=np.uint8)
|
|
||||||
in2 = np.full(sz, 50 , dtype=np.uint8)
|
|
||||||
|
|
||||||
# OpenCV
|
|
||||||
expected = cv.add(in1, in2)
|
|
||||||
|
|
||||||
# G-API
|
|
||||||
g_in1 = cv.GMat()
|
|
||||||
g_in2 = cv.GMat()
|
|
||||||
g_out = cv.gapi.add(g_in1, g_in2)
|
|
||||||
comp = cv.GComputation(cv.GIn(g_in1, g_in2), cv.GOut(g_out))
|
|
||||||
|
|
||||||
for pkg_name, pkg in pkgs:
|
|
||||||
actual = comp.apply(cv.gin(in1, in2), args=cv.compile_args(pkg))
|
|
||||||
# Comparison
|
|
||||||
self.assertEqual(0.0, cv.norm(expected, actual, cv.NORM_INF),
|
|
||||||
'Failed on ' + pkg_name + ' backend')
|
|
||||||
self.assertEqual(expected.dtype, actual.dtype, 'Failed on ' + pkg_name + ' backend')
|
|
||||||
|
|
||||||
|
|
||||||
def test_mean(self):
|
|
||||||
img_path = self.find_file('cv/face/david2.jpg', [os.environ.get('OPENCV_TEST_DATA_PATH')])
|
|
||||||
in_mat = cv.imread(img_path)
|
|
||||||
|
|
||||||
# OpenCV
|
|
||||||
expected = cv.mean(in_mat)
|
|
||||||
|
|
||||||
# G-API
|
|
||||||
g_in = cv.GMat()
|
|
||||||
g_out = cv.gapi.mean(g_in)
|
|
||||||
comp = cv.GComputation(g_in, g_out)
|
|
||||||
|
|
||||||
for pkg_name, pkg in pkgs:
|
|
||||||
actual = comp.apply(cv.gin(in_mat), args=cv.compile_args(pkg))
|
|
||||||
# Comparison
|
|
||||||
self.assertEqual(0.0, cv.norm(expected, actual, cv.NORM_INF),
|
|
||||||
'Failed on ' + pkg_name + ' backend')
|
|
||||||
|
|
||||||
|
|
||||||
def test_split3(self):
|
|
||||||
img_path = self.find_file('cv/face/david2.jpg', [os.environ.get('OPENCV_TEST_DATA_PATH')])
|
|
||||||
in_mat = cv.imread(img_path)
|
|
||||||
|
|
||||||
# OpenCV
|
|
||||||
expected = cv.split(in_mat)
|
|
||||||
|
|
||||||
# G-API
|
|
||||||
g_in = cv.GMat()
|
|
||||||
b, g, r = cv.gapi.split3(g_in)
|
|
||||||
comp = cv.GComputation(cv.GIn(g_in), cv.GOut(b, g, r))
|
|
||||||
|
|
||||||
for pkg_name, pkg in pkgs:
|
|
||||||
actual = comp.apply(cv.gin(in_mat), args=cv.compile_args(pkg))
|
|
||||||
# Comparison
|
|
||||||
for e, a in zip(expected, actual):
|
|
||||||
self.assertEqual(0.0, cv.norm(e, a, cv.NORM_INF),
|
|
||||||
'Failed on ' + pkg_name + ' backend')
|
'Failed on ' + pkg_name + ' backend')
|
||||||
self.assertEqual(e.dtype, a.dtype, 'Failed on ' + pkg_name + ' backend')
|
self.assertEqual(expected.dtype, actual.dtype, 'Failed on ' + pkg_name + ' backend')
|
||||||
|
|
||||||
|
|
||||||
def test_threshold(self):
|
def test_add_uint8(self):
|
||||||
img_path = self.find_file('cv/face/david2.jpg', [os.environ.get('OPENCV_TEST_DATA_PATH')])
|
sz = (720, 1280)
|
||||||
in_mat = cv.cvtColor(cv.imread(img_path), cv.COLOR_RGB2GRAY)
|
in1 = np.full(sz, 100, dtype=np.uint8)
|
||||||
maxv = (30, 30)
|
in2 = np.full(sz, 50 , dtype=np.uint8)
|
||||||
|
|
||||||
# OpenCV
|
# OpenCV
|
||||||
expected_thresh, expected_mat = cv.threshold(in_mat, maxv[0], maxv[0], cv.THRESH_TRIANGLE)
|
expected = cv.add(in1, in2)
|
||||||
|
|
||||||
# G-API
|
# G-API
|
||||||
g_in = cv.GMat()
|
g_in1 = cv.GMat()
|
||||||
g_sc = cv.GScalar()
|
g_in2 = cv.GMat()
|
||||||
mat, threshold = cv.gapi.threshold(g_in, g_sc, cv.THRESH_TRIANGLE)
|
g_out = cv.gapi.add(g_in1, g_in2)
|
||||||
comp = cv.GComputation(cv.GIn(g_in, g_sc), cv.GOut(mat, threshold))
|
comp = cv.GComputation(cv.GIn(g_in1, g_in2), cv.GOut(g_out))
|
||||||
|
|
||||||
for pkg_name, pkg in pkgs:
|
for pkg_name, pkg in pkgs:
|
||||||
actual_mat, actual_thresh = comp.apply(cv.gin(in_mat, maxv), args=cv.compile_args(pkg))
|
actual = comp.apply(cv.gin(in1, in2), args=cv.gapi.compile_args(pkg))
|
||||||
# Comparison
|
# Comparison
|
||||||
self.assertEqual(0.0, cv.norm(expected_mat, actual_mat, cv.NORM_INF),
|
self.assertEqual(0.0, cv.norm(expected, actual, cv.NORM_INF),
|
||||||
'Failed on ' + pkg_name + ' backend')
|
'Failed on ' + pkg_name + ' backend')
|
||||||
self.assertEqual(expected_mat.dtype, actual_mat.dtype,
|
self.assertEqual(expected.dtype, actual.dtype, 'Failed on ' + pkg_name + ' backend')
|
||||||
'Failed on ' + pkg_name + ' backend')
|
|
||||||
self.assertEqual(expected_thresh, actual_thresh[0],
|
|
||||||
'Failed on ' + pkg_name + ' backend')
|
|
||||||
|
|
||||||
def test_kmeans(self):
|
|
||||||
# K-means params
|
|
||||||
count = 100
|
|
||||||
sz = (count, 2)
|
|
||||||
in_mat = np.random.random(sz).astype(np.float32)
|
|
||||||
K = 5
|
|
||||||
flags = cv.KMEANS_RANDOM_CENTERS
|
|
||||||
attempts = 1;
|
|
||||||
criteria = (cv.TERM_CRITERIA_MAX_ITER + cv.TERM_CRITERIA_EPS, 30, 0)
|
|
||||||
|
|
||||||
# G-API
|
|
||||||
g_in = cv.GMat()
|
|
||||||
compactness, out_labels, centers = cv.gapi.kmeans(g_in, K, criteria, attempts, flags)
|
|
||||||
comp = cv.GComputation(cv.GIn(g_in), cv.GOut(compactness, out_labels, centers))
|
|
||||||
|
|
||||||
compact, labels, centers = comp.apply(cv.gin(in_mat))
|
|
||||||
|
|
||||||
# Assert
|
|
||||||
self.assertTrue(compact >= 0)
|
|
||||||
self.assertEqual(sz[0], labels.shape[0])
|
|
||||||
self.assertEqual(1, labels.shape[1])
|
|
||||||
self.assertTrue(labels.size != 0)
|
|
||||||
self.assertEqual(centers.shape[1], sz[1]);
|
|
||||||
self.assertEqual(centers.shape[0], K);
|
|
||||||
self.assertTrue(centers.size != 0);
|
|
||||||
|
|
||||||
|
|
||||||
def generate_random_points(self, sz):
|
def test_mean(self):
|
||||||
arr = np.random.random(sz).astype(np.float32).T
|
img_path = self.find_file('cv/face/david2.jpg', [os.environ.get('OPENCV_TEST_DATA_PATH')])
|
||||||
return list(zip(arr[0], arr[1]))
|
in_mat = cv.imread(img_path)
|
||||||
|
|
||||||
|
# OpenCV
|
||||||
|
expected = cv.mean(in_mat)
|
||||||
|
|
||||||
|
# G-API
|
||||||
|
g_in = cv.GMat()
|
||||||
|
g_out = cv.gapi.mean(g_in)
|
||||||
|
comp = cv.GComputation(g_in, g_out)
|
||||||
|
|
||||||
|
for pkg_name, pkg in pkgs:
|
||||||
|
actual = comp.apply(cv.gin(in_mat), args=cv.gapi.compile_args(pkg))
|
||||||
|
# Comparison
|
||||||
|
self.assertEqual(0.0, cv.norm(expected, actual, cv.NORM_INF),
|
||||||
|
'Failed on ' + pkg_name + ' backend')
|
||||||
|
|
||||||
|
|
||||||
def test_kmeans_2d(self):
|
def test_split3(self):
|
||||||
# K-means 2D params
|
img_path = self.find_file('cv/face/david2.jpg', [os.environ.get('OPENCV_TEST_DATA_PATH')])
|
||||||
count = 100
|
in_mat = cv.imread(img_path)
|
||||||
sz = (count, 2)
|
|
||||||
amount = sz[0]
|
|
||||||
K = 5
|
|
||||||
flags = cv.KMEANS_RANDOM_CENTERS
|
|
||||||
attempts = 1;
|
|
||||||
criteria = (cv.TERM_CRITERIA_MAX_ITER + cv.TERM_CRITERIA_EPS, 30, 0);
|
|
||||||
in_vector = self.generate_random_points(sz)
|
|
||||||
in_labels = []
|
|
||||||
|
|
||||||
# G-API
|
# OpenCV
|
||||||
data = cv.GArrayT(cv.gapi.CV_POINT2F)
|
expected = cv.split(in_mat)
|
||||||
best_labels = cv.GArrayT(cv.gapi.CV_INT)
|
|
||||||
|
|
||||||
compactness, out_labels, centers = cv.gapi.kmeans(data, K, best_labels, criteria, attempts, flags);
|
# G-API
|
||||||
comp = cv.GComputation(cv.GIn(data, best_labels), cv.GOut(compactness, out_labels, centers));
|
g_in = cv.GMat()
|
||||||
|
b, g, r = cv.gapi.split3(g_in)
|
||||||
|
comp = cv.GComputation(cv.GIn(g_in), cv.GOut(b, g, r))
|
||||||
|
|
||||||
compact, labels, centers = comp.apply(cv.gin(in_vector, in_labels));
|
for pkg_name, pkg in pkgs:
|
||||||
|
actual = comp.apply(cv.gin(in_mat), args=cv.gapi.compile_args(pkg))
|
||||||
|
# Comparison
|
||||||
|
for e, a in zip(expected, actual):
|
||||||
|
self.assertEqual(0.0, cv.norm(e, a, cv.NORM_INF),
|
||||||
|
'Failed on ' + pkg_name + ' backend')
|
||||||
|
self.assertEqual(e.dtype, a.dtype, 'Failed on ' + pkg_name + ' backend')
|
||||||
|
|
||||||
# Assert
|
|
||||||
self.assertTrue(compact >= 0)
|
def test_threshold(self):
|
||||||
self.assertEqual(amount, len(labels))
|
img_path = self.find_file('cv/face/david2.jpg', [os.environ.get('OPENCV_TEST_DATA_PATH')])
|
||||||
self.assertEqual(K, len(centers))
|
in_mat = cv.cvtColor(cv.imread(img_path), cv.COLOR_RGB2GRAY)
|
||||||
|
maxv = (30, 30)
|
||||||
|
|
||||||
|
# OpenCV
|
||||||
|
expected_thresh, expected_mat = cv.threshold(in_mat, maxv[0], maxv[0], cv.THRESH_TRIANGLE)
|
||||||
|
|
||||||
|
# G-API
|
||||||
|
g_in = cv.GMat()
|
||||||
|
g_sc = cv.GScalar()
|
||||||
|
mat, threshold = cv.gapi.threshold(g_in, g_sc, cv.THRESH_TRIANGLE)
|
||||||
|
comp = cv.GComputation(cv.GIn(g_in, g_sc), cv.GOut(mat, threshold))
|
||||||
|
|
||||||
|
for pkg_name, pkg in pkgs:
|
||||||
|
actual_mat, actual_thresh = comp.apply(cv.gin(in_mat, maxv), args=cv.gapi.compile_args(pkg))
|
||||||
|
# Comparison
|
||||||
|
self.assertEqual(0.0, cv.norm(expected_mat, actual_mat, cv.NORM_INF),
|
||||||
|
'Failed on ' + pkg_name + ' backend')
|
||||||
|
self.assertEqual(expected_mat.dtype, actual_mat.dtype,
|
||||||
|
'Failed on ' + pkg_name + ' backend')
|
||||||
|
self.assertEqual(expected_thresh, actual_thresh[0],
|
||||||
|
'Failed on ' + pkg_name + ' backend')
|
||||||
|
|
||||||
|
|
||||||
|
def test_kmeans(self):
|
||||||
|
# K-means params
|
||||||
|
count = 100
|
||||||
|
sz = (count, 2)
|
||||||
|
in_mat = np.random.random(sz).astype(np.float32)
|
||||||
|
K = 5
|
||||||
|
flags = cv.KMEANS_RANDOM_CENTERS
|
||||||
|
attempts = 1
|
||||||
|
criteria = (cv.TERM_CRITERIA_MAX_ITER + cv.TERM_CRITERIA_EPS, 30, 0)
|
||||||
|
|
||||||
|
# G-API
|
||||||
|
g_in = cv.GMat()
|
||||||
|
compactness, out_labels, centers = cv.gapi.kmeans(g_in, K, criteria, attempts, flags)
|
||||||
|
comp = cv.GComputation(cv.GIn(g_in), cv.GOut(compactness, out_labels, centers))
|
||||||
|
|
||||||
|
compact, labels, centers = comp.apply(cv.gin(in_mat))
|
||||||
|
|
||||||
|
# Assert
|
||||||
|
self.assertTrue(compact >= 0)
|
||||||
|
self.assertEqual(sz[0], labels.shape[0])
|
||||||
|
self.assertEqual(1, labels.shape[1])
|
||||||
|
self.assertTrue(labels.size != 0)
|
||||||
|
self.assertEqual(centers.shape[1], sz[1])
|
||||||
|
self.assertEqual(centers.shape[0], K)
|
||||||
|
self.assertTrue(centers.size != 0)
|
||||||
|
|
||||||
|
|
||||||
|
def generate_random_points(self, sz):
|
||||||
|
arr = np.random.random(sz).astype(np.float32).T
|
||||||
|
return list(zip(arr[0], arr[1]))
|
||||||
|
|
||||||
|
|
||||||
|
def test_kmeans_2d(self):
|
||||||
|
# K-means 2D params
|
||||||
|
count = 100
|
||||||
|
sz = (count, 2)
|
||||||
|
amount = sz[0]
|
||||||
|
K = 5
|
||||||
|
flags = cv.KMEANS_RANDOM_CENTERS
|
||||||
|
attempts = 1
|
||||||
|
criteria = (cv.TERM_CRITERIA_MAX_ITER + cv.TERM_CRITERIA_EPS, 30, 0)
|
||||||
|
in_vector = self.generate_random_points(sz)
|
||||||
|
in_labels = []
|
||||||
|
|
||||||
|
# G-API
|
||||||
|
data = cv.GArrayT(cv.gapi.CV_POINT2F)
|
||||||
|
best_labels = cv.GArrayT(cv.gapi.CV_INT)
|
||||||
|
|
||||||
|
compactness, out_labels, centers = cv.gapi.kmeans(data, K, best_labels, criteria, attempts, flags)
|
||||||
|
comp = cv.GComputation(cv.GIn(data, best_labels), cv.GOut(compactness, out_labels, centers))
|
||||||
|
|
||||||
|
compact, labels, centers = comp.apply(cv.gin(in_vector, in_labels))
|
||||||
|
|
||||||
|
# Assert
|
||||||
|
self.assertTrue(compact >= 0)
|
||||||
|
self.assertEqual(amount, len(labels))
|
||||||
|
self.assertEqual(K, len(centers))
|
||||||
|
|
||||||
|
|
||||||
|
except unittest.SkipTest as e:
|
||||||
|
|
||||||
|
message = str(e)
|
||||||
|
|
||||||
|
class TestSkip(unittest.TestCase):
|
||||||
|
def setUp(self):
|
||||||
|
self.skipTest('Skip tests: ' + message)
|
||||||
|
|
||||||
|
def test_skip():
|
||||||
|
pass
|
||||||
|
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
|
|
||||||
|
|
@ -3,103 +3,124 @@
|
||||||
import numpy as np
|
import numpy as np
|
||||||
import cv2 as cv
|
import cv2 as cv
|
||||||
import os
|
import os
|
||||||
|
import sys
|
||||||
|
import unittest
|
||||||
|
|
||||||
from tests_common import NewOpenCVTests
|
from tests_common import NewOpenCVTests
|
||||||
|
|
||||||
|
|
||||||
# Plaidml is an optional backend
|
try:
|
||||||
pkgs = [
|
|
||||||
('ocl' , cv.gapi.core.ocl.kernels()),
|
if sys.version_info[:2] < (3, 0):
|
||||||
('cpu' , cv.gapi.core.cpu.kernels()),
|
raise unittest.SkipTest('Python 2.x is not supported')
|
||||||
('fluid' , cv.gapi.core.fluid.kernels())
|
|
||||||
# ('plaidml', cv.gapi.core.plaidml.kernels())
|
# Plaidml is an optional backend
|
||||||
]
|
pkgs = [
|
||||||
|
('ocl' , cv.gapi.core.ocl.kernels()),
|
||||||
|
('cpu' , cv.gapi.core.cpu.kernels()),
|
||||||
|
('fluid' , cv.gapi.core.fluid.kernels())
|
||||||
|
# ('plaidml', cv.gapi.core.plaidml.kernels())
|
||||||
|
]
|
||||||
|
|
||||||
|
|
||||||
class gapi_imgproc_test(NewOpenCVTests):
|
class gapi_imgproc_test(NewOpenCVTests):
|
||||||
|
|
||||||
def test_good_features_to_track(self):
|
def test_good_features_to_track(self):
|
||||||
# TODO: Extend to use any type and size here
|
# TODO: Extend to use any type and size here
|
||||||
img_path = self.find_file('cv/face/david2.jpg', [os.environ.get('OPENCV_TEST_DATA_PATH')])
|
img_path = self.find_file('cv/face/david2.jpg', [os.environ.get('OPENCV_TEST_DATA_PATH')])
|
||||||
in1 = cv.cvtColor(cv.imread(img_path), cv.COLOR_RGB2GRAY)
|
in1 = cv.cvtColor(cv.imread(img_path), cv.COLOR_RGB2GRAY)
|
||||||
|
|
||||||
# NB: goodFeaturesToTrack configuration
|
# NB: goodFeaturesToTrack configuration
|
||||||
max_corners = 50
|
max_corners = 50
|
||||||
quality_lvl = 0.01
|
quality_lvl = 0.01
|
||||||
min_distance = 10
|
min_distance = 10
|
||||||
block_sz = 3
|
block_sz = 3
|
||||||
use_harris_detector = True
|
use_harris_detector = True
|
||||||
k = 0.04
|
k = 0.04
|
||||||
mask = None
|
mask = None
|
||||||
|
|
||||||
# OpenCV
|
# OpenCV
|
||||||
expected = cv.goodFeaturesToTrack(in1, max_corners, quality_lvl,
|
expected = cv.goodFeaturesToTrack(in1, max_corners, quality_lvl,
|
||||||
min_distance, mask=mask,
|
min_distance, mask=mask,
|
||||||
blockSize=block_sz, useHarrisDetector=use_harris_detector, k=k)
|
blockSize=block_sz, useHarrisDetector=use_harris_detector, k=k)
|
||||||
|
|
||||||
# G-API
|
# G-API
|
||||||
g_in = cv.GMat()
|
g_in = cv.GMat()
|
||||||
g_out = cv.gapi.goodFeaturesToTrack(g_in, max_corners, quality_lvl,
|
g_out = cv.gapi.goodFeaturesToTrack(g_in, max_corners, quality_lvl,
|
||||||
min_distance, mask, block_sz, use_harris_detector, k)
|
min_distance, mask, block_sz, use_harris_detector, k)
|
||||||
|
|
||||||
comp = cv.GComputation(cv.GIn(g_in), cv.GOut(g_out))
|
comp = cv.GComputation(cv.GIn(g_in), cv.GOut(g_out))
|
||||||
|
|
||||||
for pkg_name, pkg in pkgs:
|
for pkg_name, pkg in pkgs:
|
||||||
actual = comp.apply(cv.gin(in1), args=cv.compile_args(pkg))
|
actual = comp.apply(cv.gin(in1), args=cv.gapi.compile_args(pkg))
|
||||||
# NB: OpenCV & G-API have different output shapes:
|
# NB: OpenCV & G-API have different output shapes:
|
||||||
# OpenCV - (num_points, 1, 2)
|
# OpenCV - (num_points, 1, 2)
|
||||||
# G-API - (num_points, 2)
|
# G-API - (num_points, 2)
|
||||||
# Comparison
|
# Comparison
|
||||||
self.assertEqual(0.0, cv.norm(expected.flatten(),
|
self.assertEqual(0.0, cv.norm(expected.flatten(),
|
||||||
np.array(actual, dtype=np.float32).flatten(),
|
np.array(actual, dtype=np.float32).flatten(),
|
||||||
cv.NORM_INF),
|
cv.NORM_INF),
|
||||||
'Failed on ' + pkg_name + ' backend')
|
'Failed on ' + pkg_name + ' backend')
|
||||||
|
|
||||||
|
|
||||||
def test_rgb2gray(self):
|
def test_rgb2gray(self):
|
||||||
# TODO: Extend to use any type and size here
|
# TODO: Extend to use any type and size here
|
||||||
img_path = self.find_file('cv/face/david2.jpg', [os.environ.get('OPENCV_TEST_DATA_PATH')])
|
img_path = self.find_file('cv/face/david2.jpg', [os.environ.get('OPENCV_TEST_DATA_PATH')])
|
||||||
in1 = cv.imread(img_path)
|
in1 = cv.imread(img_path)
|
||||||
|
|
||||||
# OpenCV
|
# OpenCV
|
||||||
expected = cv.cvtColor(in1, cv.COLOR_RGB2GRAY)
|
expected = cv.cvtColor(in1, cv.COLOR_RGB2GRAY)
|
||||||
|
|
||||||
# G-API
|
# G-API
|
||||||
g_in = cv.GMat()
|
g_in = cv.GMat()
|
||||||
g_out = cv.gapi.RGB2Gray(g_in)
|
g_out = cv.gapi.RGB2Gray(g_in)
|
||||||
|
|
||||||
comp = cv.GComputation(cv.GIn(g_in), cv.GOut(g_out))
|
comp = cv.GComputation(cv.GIn(g_in), cv.GOut(g_out))
|
||||||
|
|
||||||
for pkg_name, pkg in pkgs:
|
for pkg_name, pkg in pkgs:
|
||||||
actual = comp.apply(cv.gin(in1), args=cv.compile_args(pkg))
|
actual = comp.apply(cv.gin(in1), args=cv.gapi.compile_args(pkg))
|
||||||
# Comparison
|
# Comparison
|
||||||
self.assertEqual(0.0, cv.norm(expected, actual, cv.NORM_INF),
|
self.assertEqual(0.0, cv.norm(expected, actual, cv.NORM_INF),
|
||||||
'Failed on ' + pkg_name + ' backend')
|
'Failed on ' + pkg_name + ' backend')
|
||||||
|
|
||||||
|
|
||||||
def test_bounding_rect(self):
|
def test_bounding_rect(self):
|
||||||
sz = 1280
|
sz = 1280
|
||||||
fscale = 256
|
fscale = 256
|
||||||
|
|
||||||
def sample_value(fscale):
|
def sample_value(fscale):
|
||||||
return np.random.uniform(0, 255 * fscale) / fscale
|
return np.random.uniform(0, 255 * fscale) / fscale
|
||||||
|
|
||||||
points = np.array([(sample_value(fscale), sample_value(fscale)) for _ in range(1280)], np.float32)
|
points = np.array([(sample_value(fscale), sample_value(fscale)) for _ in range(1280)], np.float32)
|
||||||
|
|
||||||
# OpenCV
|
# OpenCV
|
||||||
expected = cv.boundingRect(points)
|
expected = cv.boundingRect(points)
|
||||||
|
|
||||||
# G-API
|
# G-API
|
||||||
g_in = cv.GMat()
|
g_in = cv.GMat()
|
||||||
g_out = cv.gapi.boundingRect(g_in)
|
g_out = cv.gapi.boundingRect(g_in)
|
||||||
|
|
||||||
comp = cv.GComputation(cv.GIn(g_in), cv.GOut(g_out))
|
comp = cv.GComputation(cv.GIn(g_in), cv.GOut(g_out))
|
||||||
|
|
||||||
for pkg_name, pkg in pkgs:
|
for pkg_name, pkg in pkgs:
|
||||||
actual = comp.apply(cv.gin(points), args=cv.compile_args(pkg))
|
actual = comp.apply(cv.gin(points), args=cv.gapi.compile_args(pkg))
|
||||||
# Comparison
|
# Comparison
|
||||||
self.assertEqual(0.0, cv.norm(expected, actual, cv.NORM_INF),
|
self.assertEqual(0.0, cv.norm(expected, actual, cv.NORM_INF),
|
||||||
'Failed on ' + pkg_name + ' backend')
|
'Failed on ' + pkg_name + ' backend')
|
||||||
|
|
||||||
|
|
||||||
|
except unittest.SkipTest as e:
|
||||||
|
|
||||||
|
message = str(e)
|
||||||
|
|
||||||
|
class TestSkip(unittest.TestCase):
|
||||||
|
def setUp(self):
|
||||||
|
self.skipTest('Skip tests: ' + message)
|
||||||
|
|
||||||
|
def test_skip():
|
||||||
|
pass
|
||||||
|
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
|
|
||||||
|
|
@ -3,318 +3,338 @@
|
||||||
import numpy as np
|
import numpy as np
|
||||||
import cv2 as cv
|
import cv2 as cv
|
||||||
import os
|
import os
|
||||||
|
import sys
|
||||||
|
import unittest
|
||||||
|
|
||||||
from tests_common import NewOpenCVTests
|
from tests_common import NewOpenCVTests
|
||||||
|
|
||||||
|
|
||||||
class test_gapi_infer(NewOpenCVTests):
|
try:
|
||||||
|
|
||||||
def infer_reference_network(self, model_path, weights_path, img):
|
if sys.version_info[:2] < (3, 0):
|
||||||
net = cv.dnn.readNetFromModelOptimizer(model_path, weights_path)
|
raise unittest.SkipTest('Python 2.x is not supported')
|
||||||
net.setPreferableBackend(cv.dnn.DNN_BACKEND_INFERENCE_ENGINE)
|
|
||||||
net.setPreferableTarget(cv.dnn.DNN_TARGET_CPU)
|
|
||||||
|
|
||||||
blob = cv.dnn.blobFromImage(img)
|
|
||||||
|
|
||||||
net.setInput(blob)
|
|
||||||
return net.forward(net.getUnconnectedOutLayersNames())
|
|
||||||
|
|
||||||
|
|
||||||
def make_roi(self, img, roi):
|
class test_gapi_infer(NewOpenCVTests):
|
||||||
return img[roi[1]:roi[1] + roi[3], roi[0]:roi[0] + roi[2], ...]
|
|
||||||
|
def infer_reference_network(self, model_path, weights_path, img):
|
||||||
|
net = cv.dnn.readNetFromModelOptimizer(model_path, weights_path)
|
||||||
|
net.setPreferableBackend(cv.dnn.DNN_BACKEND_INFERENCE_ENGINE)
|
||||||
|
net.setPreferableTarget(cv.dnn.DNN_TARGET_CPU)
|
||||||
|
|
||||||
|
blob = cv.dnn.blobFromImage(img)
|
||||||
|
|
||||||
|
net.setInput(blob)
|
||||||
|
return net.forward(net.getUnconnectedOutLayersNames())
|
||||||
|
|
||||||
|
|
||||||
def test_age_gender_infer(self):
|
def make_roi(self, img, roi):
|
||||||
# NB: Check IE
|
return img[roi[1]:roi[1] + roi[3], roi[0]:roi[0] + roi[2], ...]
|
||||||
if not cv.dnn.DNN_TARGET_CPU in cv.dnn.getAvailableTargets(cv.dnn.DNN_BACKEND_INFERENCE_ENGINE):
|
|
||||||
return
|
|
||||||
|
|
||||||
root_path = '/omz_intel_models/intel/age-gender-recognition-retail-0013/FP32/age-gender-recognition-retail-0013'
|
|
||||||
model_path = self.find_file(root_path + '.xml', [os.environ.get('OPENCV_DNN_TEST_DATA_PATH')])
|
|
||||||
weights_path = self.find_file(root_path + '.bin', [os.environ.get('OPENCV_DNN_TEST_DATA_PATH')])
|
|
||||||
device_id = 'CPU'
|
|
||||||
|
|
||||||
img_path = self.find_file('cv/face/david2.jpg', [os.environ.get('OPENCV_TEST_DATA_PATH')])
|
|
||||||
img = cv.resize(cv.imread(img_path), (62,62))
|
|
||||||
|
|
||||||
# OpenCV DNN
|
|
||||||
dnn_age, dnn_gender = self.infer_reference_network(model_path, weights_path, img)
|
|
||||||
|
|
||||||
# OpenCV G-API
|
|
||||||
g_in = cv.GMat()
|
|
||||||
inputs = cv.GInferInputs()
|
|
||||||
inputs.setInput('data', g_in)
|
|
||||||
|
|
||||||
outputs = cv.gapi.infer("net", inputs)
|
|
||||||
age_g = outputs.at("age_conv3")
|
|
||||||
gender_g = outputs.at("prob")
|
|
||||||
|
|
||||||
comp = cv.GComputation(cv.GIn(g_in), cv.GOut(age_g, gender_g))
|
|
||||||
pp = cv.gapi.ie.params("net", model_path, weights_path, device_id)
|
|
||||||
|
|
||||||
gapi_age, gapi_gender = comp.apply(cv.gin(img), args=cv.compile_args(cv.gapi.networks(pp)))
|
|
||||||
|
|
||||||
# Check
|
|
||||||
self.assertEqual(0.0, cv.norm(dnn_gender, gapi_gender, cv.NORM_INF))
|
|
||||||
self.assertEqual(0.0, cv.norm(dnn_age, gapi_age, cv.NORM_INF))
|
|
||||||
|
|
||||||
|
|
||||||
def test_age_gender_infer_roi(self):
|
def test_age_gender_infer(self):
|
||||||
# NB: Check IE
|
# NB: Check IE
|
||||||
if not cv.dnn.DNN_TARGET_CPU in cv.dnn.getAvailableTargets(cv.dnn.DNN_BACKEND_INFERENCE_ENGINE):
|
if not cv.dnn.DNN_TARGET_CPU in cv.dnn.getAvailableTargets(cv.dnn.DNN_BACKEND_INFERENCE_ENGINE):
|
||||||
return
|
return
|
||||||
|
|
||||||
root_path = '/omz_intel_models/intel/age-gender-recognition-retail-0013/FP32/age-gender-recognition-retail-0013'
|
root_path = '/omz_intel_models/intel/age-gender-recognition-retail-0013/FP32/age-gender-recognition-retail-0013'
|
||||||
model_path = self.find_file(root_path + '.xml', [os.environ.get('OPENCV_DNN_TEST_DATA_PATH')])
|
model_path = self.find_file(root_path + '.xml', [os.environ.get('OPENCV_DNN_TEST_DATA_PATH')])
|
||||||
weights_path = self.find_file(root_path + '.bin', [os.environ.get('OPENCV_DNN_TEST_DATA_PATH')])
|
weights_path = self.find_file(root_path + '.bin', [os.environ.get('OPENCV_DNN_TEST_DATA_PATH')])
|
||||||
device_id = 'CPU'
|
device_id = 'CPU'
|
||||||
|
|
||||||
img_path = self.find_file('cv/face/david2.jpg', [os.environ.get('OPENCV_TEST_DATA_PATH')])
|
img_path = self.find_file('cv/face/david2.jpg', [os.environ.get('OPENCV_TEST_DATA_PATH')])
|
||||||
img = cv.imread(img_path)
|
img = cv.resize(cv.imread(img_path), (62,62))
|
||||||
roi = (10, 10, 62, 62)
|
|
||||||
|
|
||||||
# OpenCV DNN
|
# OpenCV DNN
|
||||||
dnn_age, dnn_gender = self.infer_reference_network(model_path,
|
dnn_age, dnn_gender = self.infer_reference_network(model_path, weights_path, img)
|
||||||
|
|
||||||
|
# OpenCV G-API
|
||||||
|
g_in = cv.GMat()
|
||||||
|
inputs = cv.GInferInputs()
|
||||||
|
inputs.setInput('data', g_in)
|
||||||
|
|
||||||
|
outputs = cv.gapi.infer("net", inputs)
|
||||||
|
age_g = outputs.at("age_conv3")
|
||||||
|
gender_g = outputs.at("prob")
|
||||||
|
|
||||||
|
comp = cv.GComputation(cv.GIn(g_in), cv.GOut(age_g, gender_g))
|
||||||
|
pp = cv.gapi.ie.params("net", model_path, weights_path, device_id)
|
||||||
|
|
||||||
|
gapi_age, gapi_gender = comp.apply(cv.gin(img), args=cv.gapi.compile_args(cv.gapi.networks(pp)))
|
||||||
|
|
||||||
|
# Check
|
||||||
|
self.assertEqual(0.0, cv.norm(dnn_gender, gapi_gender, cv.NORM_INF))
|
||||||
|
self.assertEqual(0.0, cv.norm(dnn_age, gapi_age, cv.NORM_INF))
|
||||||
|
|
||||||
|
|
||||||
|
def test_age_gender_infer_roi(self):
|
||||||
|
# NB: Check IE
|
||||||
|
if not cv.dnn.DNN_TARGET_CPU in cv.dnn.getAvailableTargets(cv.dnn.DNN_BACKEND_INFERENCE_ENGINE):
|
||||||
|
return
|
||||||
|
|
||||||
|
root_path = '/omz_intel_models/intel/age-gender-recognition-retail-0013/FP32/age-gender-recognition-retail-0013'
|
||||||
|
model_path = self.find_file(root_path + '.xml', [os.environ.get('OPENCV_DNN_TEST_DATA_PATH')])
|
||||||
|
weights_path = self.find_file(root_path + '.bin', [os.environ.get('OPENCV_DNN_TEST_DATA_PATH')])
|
||||||
|
device_id = 'CPU'
|
||||||
|
|
||||||
|
img_path = self.find_file('cv/face/david2.jpg', [os.environ.get('OPENCV_TEST_DATA_PATH')])
|
||||||
|
img = cv.imread(img_path)
|
||||||
|
roi = (10, 10, 62, 62)
|
||||||
|
|
||||||
|
# OpenCV DNN
|
||||||
|
dnn_age, dnn_gender = self.infer_reference_network(model_path,
|
||||||
|
weights_path,
|
||||||
|
self.make_roi(img, roi))
|
||||||
|
|
||||||
|
# OpenCV G-API
|
||||||
|
g_in = cv.GMat()
|
||||||
|
g_roi = cv.GOpaqueT(cv.gapi.CV_RECT)
|
||||||
|
inputs = cv.GInferInputs()
|
||||||
|
inputs.setInput('data', g_in)
|
||||||
|
|
||||||
|
outputs = cv.gapi.infer("net", g_roi, inputs)
|
||||||
|
age_g = outputs.at("age_conv3")
|
||||||
|
gender_g = outputs.at("prob")
|
||||||
|
|
||||||
|
comp = cv.GComputation(cv.GIn(g_in, g_roi), cv.GOut(age_g, gender_g))
|
||||||
|
pp = cv.gapi.ie.params("net", model_path, weights_path, device_id)
|
||||||
|
|
||||||
|
gapi_age, gapi_gender = comp.apply(cv.gin(img, roi), args=cv.gapi.compile_args(cv.gapi.networks(pp)))
|
||||||
|
|
||||||
|
# Check
|
||||||
|
self.assertEqual(0.0, cv.norm(dnn_gender, gapi_gender, cv.NORM_INF))
|
||||||
|
self.assertEqual(0.0, cv.norm(dnn_age, gapi_age, cv.NORM_INF))
|
||||||
|
|
||||||
|
|
||||||
|
def test_age_gender_infer_roi_list(self):
|
||||||
|
# NB: Check IE
|
||||||
|
if not cv.dnn.DNN_TARGET_CPU in cv.dnn.getAvailableTargets(cv.dnn.DNN_BACKEND_INFERENCE_ENGINE):
|
||||||
|
return
|
||||||
|
|
||||||
|
root_path = '/omz_intel_models/intel/age-gender-recognition-retail-0013/FP32/age-gender-recognition-retail-0013'
|
||||||
|
model_path = self.find_file(root_path + '.xml', [os.environ.get('OPENCV_DNN_TEST_DATA_PATH')])
|
||||||
|
weights_path = self.find_file(root_path + '.bin', [os.environ.get('OPENCV_DNN_TEST_DATA_PATH')])
|
||||||
|
device_id = 'CPU'
|
||||||
|
|
||||||
|
rois = [(10, 15, 62, 62), (23, 50, 62, 62), (14, 100, 62, 62), (80, 50, 62, 62)]
|
||||||
|
img_path = self.find_file('cv/face/david2.jpg', [os.environ.get('OPENCV_TEST_DATA_PATH')])
|
||||||
|
img = cv.imread(img_path)
|
||||||
|
|
||||||
|
# OpenCV DNN
|
||||||
|
dnn_age_list = []
|
||||||
|
dnn_gender_list = []
|
||||||
|
for roi in rois:
|
||||||
|
age, gender = self.infer_reference_network(model_path,
|
||||||
weights_path,
|
weights_path,
|
||||||
self.make_roi(img, roi))
|
self.make_roi(img, roi))
|
||||||
|
dnn_age_list.append(age)
|
||||||
|
dnn_gender_list.append(gender)
|
||||||
|
|
||||||
# OpenCV G-API
|
# OpenCV G-API
|
||||||
g_in = cv.GMat()
|
g_in = cv.GMat()
|
||||||
g_roi = cv.GOpaqueT(cv.gapi.CV_RECT)
|
g_rois = cv.GArrayT(cv.gapi.CV_RECT)
|
||||||
inputs = cv.GInferInputs()
|
inputs = cv.GInferInputs()
|
||||||
inputs.setInput('data', g_in)
|
inputs.setInput('data', g_in)
|
||||||
|
|
||||||
outputs = cv.gapi.infer("net", g_roi, inputs)
|
outputs = cv.gapi.infer("net", g_rois, inputs)
|
||||||
age_g = outputs.at("age_conv3")
|
age_g = outputs.at("age_conv3")
|
||||||
gender_g = outputs.at("prob")
|
gender_g = outputs.at("prob")
|
||||||
|
|
||||||
comp = cv.GComputation(cv.GIn(g_in, g_roi), cv.GOut(age_g, gender_g))
|
comp = cv.GComputation(cv.GIn(g_in, g_rois), cv.GOut(age_g, gender_g))
|
||||||
pp = cv.gapi.ie.params("net", model_path, weights_path, device_id)
|
pp = cv.gapi.ie.params("net", model_path, weights_path, device_id)
|
||||||
|
|
||||||
gapi_age, gapi_gender = comp.apply(cv.gin(img, roi), args=cv.compile_args(cv.gapi.networks(pp)))
|
gapi_age_list, gapi_gender_list = comp.apply(cv.gin(img, rois),
|
||||||
|
args=cv.gapi.compile_args(cv.gapi.networks(pp)))
|
||||||
|
|
||||||
# Check
|
# Check
|
||||||
self.assertEqual(0.0, cv.norm(dnn_gender, gapi_gender, cv.NORM_INF))
|
for gapi_age, gapi_gender, dnn_age, dnn_gender in zip(gapi_age_list,
|
||||||
self.assertEqual(0.0, cv.norm(dnn_age, gapi_age, cv.NORM_INF))
|
gapi_gender_list,
|
||||||
|
dnn_age_list,
|
||||||
|
dnn_gender_list):
|
||||||
|
self.assertEqual(0.0, cv.norm(dnn_gender, gapi_gender, cv.NORM_INF))
|
||||||
|
self.assertEqual(0.0, cv.norm(dnn_age, gapi_age, cv.NORM_INF))
|
||||||
|
|
||||||
|
|
||||||
def test_age_gender_infer_roi_list(self):
|
def test_age_gender_infer2_roi(self):
|
||||||
# NB: Check IE
|
# NB: Check IE
|
||||||
if not cv.dnn.DNN_TARGET_CPU in cv.dnn.getAvailableTargets(cv.dnn.DNN_BACKEND_INFERENCE_ENGINE):
|
if not cv.dnn.DNN_TARGET_CPU in cv.dnn.getAvailableTargets(cv.dnn.DNN_BACKEND_INFERENCE_ENGINE):
|
||||||
return
|
return
|
||||||
|
|
||||||
root_path = '/omz_intel_models/intel/age-gender-recognition-retail-0013/FP32/age-gender-recognition-retail-0013'
|
root_path = '/omz_intel_models/intel/age-gender-recognition-retail-0013/FP32/age-gender-recognition-retail-0013'
|
||||||
model_path = self.find_file(root_path + '.xml', [os.environ.get('OPENCV_DNN_TEST_DATA_PATH')])
|
model_path = self.find_file(root_path + '.xml', [os.environ.get('OPENCV_DNN_TEST_DATA_PATH')])
|
||||||
weights_path = self.find_file(root_path + '.bin', [os.environ.get('OPENCV_DNN_TEST_DATA_PATH')])
|
weights_path = self.find_file(root_path + '.bin', [os.environ.get('OPENCV_DNN_TEST_DATA_PATH')])
|
||||||
device_id = 'CPU'
|
device_id = 'CPU'
|
||||||
|
|
||||||
rois = [(10, 15, 62, 62), (23, 50, 62, 62), (14, 100, 62, 62), (80, 50, 62, 62)]
|
rois = [(10, 15, 62, 62), (23, 50, 62, 62), (14, 100, 62, 62), (80, 50, 62, 62)]
|
||||||
img_path = self.find_file('cv/face/david2.jpg', [os.environ.get('OPENCV_TEST_DATA_PATH')])
|
img_path = self.find_file('cv/face/david2.jpg', [os.environ.get('OPENCV_TEST_DATA_PATH')])
|
||||||
img = cv.imread(img_path)
|
img = cv.imread(img_path)
|
||||||
|
|
||||||
# OpenCV DNN
|
# OpenCV DNN
|
||||||
dnn_age_list = []
|
dnn_age_list = []
|
||||||
dnn_gender_list = []
|
dnn_gender_list = []
|
||||||
for roi in rois:
|
for roi in rois:
|
||||||
age, gender = self.infer_reference_network(model_path,
|
age, gender = self.infer_reference_network(model_path,
|
||||||
weights_path,
|
weights_path,
|
||||||
self.make_roi(img, roi))
|
self.make_roi(img, roi))
|
||||||
dnn_age_list.append(age)
|
dnn_age_list.append(age)
|
||||||
dnn_gender_list.append(gender)
|
dnn_gender_list.append(gender)
|
||||||
|
|
||||||
# OpenCV G-API
|
# OpenCV G-API
|
||||||
g_in = cv.GMat()
|
g_in = cv.GMat()
|
||||||
g_rois = cv.GArrayT(cv.gapi.CV_RECT)
|
g_rois = cv.GArrayT(cv.gapi.CV_RECT)
|
||||||
inputs = cv.GInferInputs()
|
inputs = cv.GInferListInputs()
|
||||||
inputs.setInput('data', g_in)
|
inputs.setInput('data', g_rois)
|
||||||
|
|
||||||
outputs = cv.gapi.infer("net", g_rois, inputs)
|
outputs = cv.gapi.infer2("net", g_in, inputs)
|
||||||
age_g = outputs.at("age_conv3")
|
age_g = outputs.at("age_conv3")
|
||||||
gender_g = outputs.at("prob")
|
gender_g = outputs.at("prob")
|
||||||
|
|
||||||
comp = cv.GComputation(cv.GIn(g_in, g_rois), cv.GOut(age_g, gender_g))
|
comp = cv.GComputation(cv.GIn(g_in, g_rois), cv.GOut(age_g, gender_g))
|
||||||
pp = cv.gapi.ie.params("net", model_path, weights_path, device_id)
|
pp = cv.gapi.ie.params("net", model_path, weights_path, device_id)
|
||||||
|
|
||||||
gapi_age_list, gapi_gender_list = comp.apply(cv.gin(img, rois),
|
gapi_age_list, gapi_gender_list = comp.apply(cv.gin(img, rois),
|
||||||
args=cv.compile_args(cv.gapi.networks(pp)))
|
args=cv.gapi.compile_args(cv.gapi.networks(pp)))
|
||||||
|
|
||||||
# Check
|
# Check
|
||||||
for gapi_age, gapi_gender, dnn_age, dnn_gender in zip(gapi_age_list,
|
for gapi_age, gapi_gender, dnn_age, dnn_gender in zip(gapi_age_list,
|
||||||
gapi_gender_list,
|
gapi_gender_list,
|
||||||
dnn_age_list,
|
dnn_age_list,
|
||||||
dnn_gender_list):
|
dnn_gender_list):
|
||||||
self.assertEqual(0.0, cv.norm(dnn_gender, gapi_gender, cv.NORM_INF))
|
self.assertEqual(0.0, cv.norm(dnn_gender, gapi_gender, cv.NORM_INF))
|
||||||
self.assertEqual(0.0, cv.norm(dnn_age, gapi_age, cv.NORM_INF))
|
self.assertEqual(0.0, cv.norm(dnn_age, gapi_age, cv.NORM_INF))
|
||||||
|
|
||||||
|
|
||||||
def test_age_gender_infer2_roi(self):
|
|
||||||
# NB: Check IE
|
|
||||||
if not cv.dnn.DNN_TARGET_CPU in cv.dnn.getAvailableTargets(cv.dnn.DNN_BACKEND_INFERENCE_ENGINE):
|
|
||||||
return
|
|
||||||
|
|
||||||
root_path = '/omz_intel_models/intel/age-gender-recognition-retail-0013/FP32/age-gender-recognition-retail-0013'
|
|
||||||
model_path = self.find_file(root_path + '.xml', [os.environ.get('OPENCV_DNN_TEST_DATA_PATH')])
|
|
||||||
weights_path = self.find_file(root_path + '.bin', [os.environ.get('OPENCV_DNN_TEST_DATA_PATH')])
|
|
||||||
device_id = 'CPU'
|
|
||||||
|
|
||||||
rois = [(10, 15, 62, 62), (23, 50, 62, 62), (14, 100, 62, 62), (80, 50, 62, 62)]
|
|
||||||
img_path = self.find_file('cv/face/david2.jpg', [os.environ.get('OPENCV_TEST_DATA_PATH')])
|
|
||||||
img = cv.imread(img_path)
|
|
||||||
|
|
||||||
# OpenCV DNN
|
|
||||||
dnn_age_list = []
|
|
||||||
dnn_gender_list = []
|
|
||||||
for roi in rois:
|
|
||||||
age, gender = self.infer_reference_network(model_path,
|
|
||||||
weights_path,
|
|
||||||
self.make_roi(img, roi))
|
|
||||||
dnn_age_list.append(age)
|
|
||||||
dnn_gender_list.append(gender)
|
|
||||||
|
|
||||||
# OpenCV G-API
|
|
||||||
g_in = cv.GMat()
|
|
||||||
g_rois = cv.GArrayT(cv.gapi.CV_RECT)
|
|
||||||
inputs = cv.GInferListInputs()
|
|
||||||
inputs.setInput('data', g_rois)
|
|
||||||
|
|
||||||
outputs = cv.gapi.infer2("net", g_in, inputs)
|
|
||||||
age_g = outputs.at("age_conv3")
|
|
||||||
gender_g = outputs.at("prob")
|
|
||||||
|
|
||||||
comp = cv.GComputation(cv.GIn(g_in, g_rois), cv.GOut(age_g, gender_g))
|
|
||||||
pp = cv.gapi.ie.params("net", model_path, weights_path, device_id)
|
|
||||||
|
|
||||||
gapi_age_list, gapi_gender_list = comp.apply(cv.gin(img, rois),
|
|
||||||
args=cv.compile_args(cv.gapi.networks(pp)))
|
|
||||||
|
|
||||||
# Check
|
|
||||||
for gapi_age, gapi_gender, dnn_age, dnn_gender in zip(gapi_age_list,
|
|
||||||
gapi_gender_list,
|
|
||||||
dnn_age_list,
|
|
||||||
dnn_gender_list):
|
|
||||||
self.assertEqual(0.0, cv.norm(dnn_gender, gapi_gender, cv.NORM_INF))
|
|
||||||
self.assertEqual(0.0, cv.norm(dnn_age, gapi_age, cv.NORM_INF))
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def test_person_detection_retail_0013(self):
|
def test_person_detection_retail_0013(self):
|
||||||
# NB: Check IE
|
# NB: Check IE
|
||||||
if not cv.dnn.DNN_TARGET_CPU in cv.dnn.getAvailableTargets(cv.dnn.DNN_BACKEND_INFERENCE_ENGINE):
|
if not cv.dnn.DNN_TARGET_CPU in cv.dnn.getAvailableTargets(cv.dnn.DNN_BACKEND_INFERENCE_ENGINE):
|
||||||
return
|
return
|
||||||
|
|
||||||
root_path = '/omz_intel_models/intel/person-detection-retail-0013/FP32/person-detection-retail-0013'
|
root_path = '/omz_intel_models/intel/person-detection-retail-0013/FP32/person-detection-retail-0013'
|
||||||
model_path = self.find_file(root_path + '.xml', [os.environ.get('OPENCV_DNN_TEST_DATA_PATH')])
|
model_path = self.find_file(root_path + '.xml', [os.environ.get('OPENCV_DNN_TEST_DATA_PATH')])
|
||||||
weights_path = self.find_file(root_path + '.bin', [os.environ.get('OPENCV_DNN_TEST_DATA_PATH')])
|
weights_path = self.find_file(root_path + '.bin', [os.environ.get('OPENCV_DNN_TEST_DATA_PATH')])
|
||||||
img_path = self.find_file('gpu/lbpcascade/er.png', [os.environ.get('OPENCV_TEST_DATA_PATH')])
|
img_path = self.find_file('gpu/lbpcascade/er.png', [os.environ.get('OPENCV_TEST_DATA_PATH')])
|
||||||
device_id = 'CPU'
|
device_id = 'CPU'
|
||||||
img = cv.resize(cv.imread(img_path), (544, 320))
|
img = cv.resize(cv.imread(img_path), (544, 320))
|
||||||
|
|
||||||
# OpenCV DNN
|
# OpenCV DNN
|
||||||
net = cv.dnn.readNetFromModelOptimizer(model_path, weights_path)
|
net = cv.dnn.readNetFromModelOptimizer(model_path, weights_path)
|
||||||
net.setPreferableBackend(cv.dnn.DNN_BACKEND_INFERENCE_ENGINE)
|
net.setPreferableBackend(cv.dnn.DNN_BACKEND_INFERENCE_ENGINE)
|
||||||
net.setPreferableTarget(cv.dnn.DNN_TARGET_CPU)
|
net.setPreferableTarget(cv.dnn.DNN_TARGET_CPU)
|
||||||
|
|
||||||
blob = cv.dnn.blobFromImage(img)
|
blob = cv.dnn.blobFromImage(img)
|
||||||
|
|
||||||
def parseSSD(detections, size):
|
def parseSSD(detections, size):
|
||||||
h, w = size
|
h, w = size
|
||||||
bboxes = []
|
bboxes = []
|
||||||
detections = detections.reshape(-1, 7)
|
detections = detections.reshape(-1, 7)
|
||||||
for sample_id, class_id, confidence, xmin, ymin, xmax, ymax in detections:
|
for sample_id, class_id, confidence, xmin, ymin, xmax, ymax in detections:
|
||||||
if confidence >= 0.5:
|
if confidence >= 0.5:
|
||||||
x = int(xmin * w)
|
x = int(xmin * w)
|
||||||
y = int(ymin * h)
|
y = int(ymin * h)
|
||||||
width = int(xmax * w - x)
|
width = int(xmax * w - x)
|
||||||
height = int(ymax * h - y)
|
height = int(ymax * h - y)
|
||||||
bboxes.append((x, y, width, height))
|
bboxes.append((x, y, width, height))
|
||||||
|
|
||||||
return bboxes
|
return bboxes
|
||||||
|
|
||||||
net.setInput(blob)
|
net.setInput(blob)
|
||||||
dnn_detections = net.forward()
|
dnn_detections = net.forward()
|
||||||
dnn_boxes = parseSSD(np.array(dnn_detections), img.shape[:2])
|
dnn_boxes = parseSSD(np.array(dnn_detections), img.shape[:2])
|
||||||
|
|
||||||
# OpenCV G-API
|
# OpenCV G-API
|
||||||
g_in = cv.GMat()
|
g_in = cv.GMat()
|
||||||
inputs = cv.GInferInputs()
|
inputs = cv.GInferInputs()
|
||||||
inputs.setInput('data', g_in)
|
inputs.setInput('data', g_in)
|
||||||
|
|
||||||
g_sz = cv.gapi.streaming.size(g_in)
|
g_sz = cv.gapi.streaming.size(g_in)
|
||||||
outputs = cv.gapi.infer("net", inputs)
|
outputs = cv.gapi.infer("net", inputs)
|
||||||
detections = outputs.at("detection_out")
|
detections = outputs.at("detection_out")
|
||||||
bboxes = cv.gapi.parseSSD(detections, g_sz, 0.5, False, False)
|
bboxes = cv.gapi.parseSSD(detections, g_sz, 0.5, False, False)
|
||||||
|
|
||||||
comp = cv.GComputation(cv.GIn(g_in), cv.GOut(bboxes))
|
comp = cv.GComputation(cv.GIn(g_in), cv.GOut(bboxes))
|
||||||
pp = cv.gapi.ie.params("net", model_path, weights_path, device_id)
|
pp = cv.gapi.ie.params("net", model_path, weights_path, device_id)
|
||||||
|
|
||||||
gapi_age, gapi_gender = comp.apply(cv.gin(img), args=cv.compile_args(cv.gapi.networks(pp)))
|
gapi_boxes = comp.apply(cv.gin(img.astype(np.float32)),
|
||||||
|
args=cv.gapi.compile_args(cv.gapi.networks(pp)))
|
||||||
|
|
||||||
gapi_boxes = comp.apply(cv.gin(img.astype(np.float32)),
|
# Comparison
|
||||||
args=cv.compile_args(cv.gapi.networks(pp)))
|
self.assertEqual(0.0, cv.norm(np.array(dnn_boxes).flatten(),
|
||||||
|
np.array(gapi_boxes).flatten(),
|
||||||
# Comparison
|
cv.NORM_INF))
|
||||||
self.assertEqual(0.0, cv.norm(np.array(dnn_boxes).flatten(),
|
|
||||||
np.array(gapi_boxes).flatten(),
|
|
||||||
cv.NORM_INF))
|
|
||||||
|
|
||||||
|
|
||||||
def test_person_detection_retail_0013(self):
|
def test_person_detection_retail_0013(self):
|
||||||
# NB: Check IE
|
# NB: Check IE
|
||||||
if not cv.dnn.DNN_TARGET_CPU in cv.dnn.getAvailableTargets(cv.dnn.DNN_BACKEND_INFERENCE_ENGINE):
|
if not cv.dnn.DNN_TARGET_CPU in cv.dnn.getAvailableTargets(cv.dnn.DNN_BACKEND_INFERENCE_ENGINE):
|
||||||
return
|
return
|
||||||
|
|
||||||
root_path = '/omz_intel_models/intel/person-detection-retail-0013/FP32/person-detection-retail-0013'
|
root_path = '/omz_intel_models/intel/person-detection-retail-0013/FP32/person-detection-retail-0013'
|
||||||
model_path = self.find_file(root_path + '.xml', [os.environ.get('OPENCV_DNN_TEST_DATA_PATH')])
|
model_path = self.find_file(root_path + '.xml', [os.environ.get('OPENCV_DNN_TEST_DATA_PATH')])
|
||||||
weights_path = self.find_file(root_path + '.bin', [os.environ.get('OPENCV_DNN_TEST_DATA_PATH')])
|
weights_path = self.find_file(root_path + '.bin', [os.environ.get('OPENCV_DNN_TEST_DATA_PATH')])
|
||||||
img_path = self.find_file('gpu/lbpcascade/er.png', [os.environ.get('OPENCV_TEST_DATA_PATH')])
|
img_path = self.find_file('gpu/lbpcascade/er.png', [os.environ.get('OPENCV_TEST_DATA_PATH')])
|
||||||
device_id = 'CPU'
|
device_id = 'CPU'
|
||||||
img = cv.resize(cv.imread(img_path), (544, 320))
|
img = cv.resize(cv.imread(img_path), (544, 320))
|
||||||
|
|
||||||
# OpenCV DNN
|
# OpenCV DNN
|
||||||
net = cv.dnn.readNetFromModelOptimizer(model_path, weights_path)
|
net = cv.dnn.readNetFromModelOptimizer(model_path, weights_path)
|
||||||
net.setPreferableBackend(cv.dnn.DNN_BACKEND_INFERENCE_ENGINE)
|
net.setPreferableBackend(cv.dnn.DNN_BACKEND_INFERENCE_ENGINE)
|
||||||
net.setPreferableTarget(cv.dnn.DNN_TARGET_CPU)
|
net.setPreferableTarget(cv.dnn.DNN_TARGET_CPU)
|
||||||
|
|
||||||
blob = cv.dnn.blobFromImage(img)
|
blob = cv.dnn.blobFromImage(img)
|
||||||
|
|
||||||
def parseSSD(detections, size):
|
def parseSSD(detections, size):
|
||||||
h, w = size
|
h, w = size
|
||||||
bboxes = []
|
bboxes = []
|
||||||
detections = detections.reshape(-1, 7)
|
detections = detections.reshape(-1, 7)
|
||||||
for sample_id, class_id, confidence, xmin, ymin, xmax, ymax in detections:
|
for sample_id, class_id, confidence, xmin, ymin, xmax, ymax in detections:
|
||||||
if confidence >= 0.5:
|
if confidence >= 0.5:
|
||||||
x = int(xmin * w)
|
x = int(xmin * w)
|
||||||
y = int(ymin * h)
|
y = int(ymin * h)
|
||||||
width = int(xmax * w - x)
|
width = int(xmax * w - x)
|
||||||
height = int(ymax * h - y)
|
height = int(ymax * h - y)
|
||||||
bboxes.append((x, y, width, height))
|
bboxes.append((x, y, width, height))
|
||||||
|
|
||||||
return bboxes
|
return bboxes
|
||||||
|
|
||||||
net.setInput(blob)
|
net.setInput(blob)
|
||||||
dnn_detections = net.forward()
|
dnn_detections = net.forward()
|
||||||
dnn_boxes = parseSSD(np.array(dnn_detections), img.shape[:2])
|
dnn_boxes = parseSSD(np.array(dnn_detections), img.shape[:2])
|
||||||
|
|
||||||
# OpenCV G-API
|
# OpenCV G-API
|
||||||
g_in = cv.GMat()
|
g_in = cv.GMat()
|
||||||
inputs = cv.GInferInputs()
|
inputs = cv.GInferInputs()
|
||||||
inputs.setInput('data', g_in)
|
inputs.setInput('data', g_in)
|
||||||
|
|
||||||
g_sz = cv.gapi.streaming.size(g_in)
|
g_sz = cv.gapi.streaming.size(g_in)
|
||||||
outputs = cv.gapi.infer("net", inputs)
|
outputs = cv.gapi.infer("net", inputs)
|
||||||
detections = outputs.at("detection_out")
|
detections = outputs.at("detection_out")
|
||||||
bboxes = cv.gapi.parseSSD(detections, g_sz, 0.5, False, False)
|
bboxes = cv.gapi.parseSSD(detections, g_sz, 0.5, False, False)
|
||||||
|
|
||||||
comp = cv.GComputation(cv.GIn(g_in), cv.GOut(bboxes))
|
comp = cv.GComputation(cv.GIn(g_in), cv.GOut(bboxes))
|
||||||
pp = cv.gapi.ie.params("net", model_path, weights_path, device_id)
|
pp = cv.gapi.ie.params("net", model_path, weights_path, device_id)
|
||||||
|
|
||||||
gapi_boxes = comp.apply(cv.gin(img.astype(np.float32)),
|
gapi_boxes = comp.apply(cv.gin(img.astype(np.float32)),
|
||||||
args=cv.compile_args(cv.gapi.networks(pp)))
|
args=cv.gapi.compile_args(cv.gapi.networks(pp)))
|
||||||
|
|
||||||
# Comparison
|
# Comparison
|
||||||
self.assertEqual(0.0, cv.norm(np.array(dnn_boxes).flatten(),
|
self.assertEqual(0.0, cv.norm(np.array(dnn_boxes).flatten(),
|
||||||
np.array(gapi_boxes).flatten(),
|
np.array(gapi_boxes).flatten(),
|
||||||
cv.NORM_INF))
|
cv.NORM_INF))
|
||||||
|
|
||||||
|
|
||||||
|
except unittest.SkipTest as e:
|
||||||
|
|
||||||
|
message = str(e)
|
||||||
|
|
||||||
|
class TestSkip(unittest.TestCase):
|
||||||
|
def setUp(self):
|
||||||
|
self.skipTest('Skip tests: ' + message)
|
||||||
|
|
||||||
|
def test_skip():
|
||||||
|
pass
|
||||||
|
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
|
|
||||||
|
|
@ -225,7 +225,7 @@ try:
|
||||||
comp = cv.GComputation(cv.GIn(g_in1, g_in2), cv.GOut(g_out))
|
comp = cv.GComputation(cv.GIn(g_in1, g_in2), cv.GOut(g_out))
|
||||||
|
|
||||||
pkg = cv.gapi.kernels(GAddImpl)
|
pkg = cv.gapi.kernels(GAddImpl)
|
||||||
actual = comp.apply(cv.gin(in_mat1, in_mat2), args=cv.compile_args(pkg))
|
actual = comp.apply(cv.gin(in_mat1, in_mat2), args=cv.gapi.compile_args(pkg))
|
||||||
|
|
||||||
self.assertEqual(0.0, cv.norm(expected, actual, cv.NORM_INF))
|
self.assertEqual(0.0, cv.norm(expected, actual, cv.NORM_INF))
|
||||||
|
|
||||||
|
|
@ -245,7 +245,7 @@ try:
|
||||||
comp = cv.GComputation(cv.GIn(g_in), cv.GOut(g_ch1, g_ch2, g_ch3))
|
comp = cv.GComputation(cv.GIn(g_in), cv.GOut(g_ch1, g_ch2, g_ch3))
|
||||||
|
|
||||||
pkg = cv.gapi.kernels(GSplit3Impl)
|
pkg = cv.gapi.kernels(GSplit3Impl)
|
||||||
ch1, ch2, ch3 = comp.apply(cv.gin(in_mat), args=cv.compile_args(pkg))
|
ch1, ch2, ch3 = comp.apply(cv.gin(in_mat), args=cv.gapi.compile_args(pkg))
|
||||||
|
|
||||||
self.assertEqual(0.0, cv.norm(in_ch1, ch1, cv.NORM_INF))
|
self.assertEqual(0.0, cv.norm(in_ch1, ch1, cv.NORM_INF))
|
||||||
self.assertEqual(0.0, cv.norm(in_ch2, ch2, cv.NORM_INF))
|
self.assertEqual(0.0, cv.norm(in_ch2, ch2, cv.NORM_INF))
|
||||||
|
|
@ -266,7 +266,7 @@ try:
|
||||||
comp = cv.GComputation(g_in, g_out)
|
comp = cv.GComputation(g_in, g_out)
|
||||||
|
|
||||||
pkg = cv.gapi.kernels(GMeanImpl)
|
pkg = cv.gapi.kernels(GMeanImpl)
|
||||||
actual = comp.apply(cv.gin(in_mat), args=cv.compile_args(pkg))
|
actual = comp.apply(cv.gin(in_mat), args=cv.gapi.compile_args(pkg))
|
||||||
|
|
||||||
# Comparison
|
# Comparison
|
||||||
self.assertEqual(expected, actual)
|
self.assertEqual(expected, actual)
|
||||||
|
|
@ -287,7 +287,7 @@ try:
|
||||||
comp = cv.GComputation(cv.GIn(g_in, g_sc), cv.GOut(g_out))
|
comp = cv.GComputation(cv.GIn(g_in, g_sc), cv.GOut(g_out))
|
||||||
|
|
||||||
pkg = cv.gapi.kernels(GAddCImpl)
|
pkg = cv.gapi.kernels(GAddCImpl)
|
||||||
actual = comp.apply(cv.gin(in_mat, sc), args=cv.compile_args(pkg))
|
actual = comp.apply(cv.gin(in_mat, sc), args=cv.gapi.compile_args(pkg))
|
||||||
|
|
||||||
self.assertEqual(0.0, cv.norm(expected, actual, cv.NORM_INF))
|
self.assertEqual(0.0, cv.norm(expected, actual, cv.NORM_INF))
|
||||||
|
|
||||||
|
|
@ -305,7 +305,7 @@ try:
|
||||||
comp = cv.GComputation(cv.GIn(g_in), cv.GOut(g_sz))
|
comp = cv.GComputation(cv.GIn(g_in), cv.GOut(g_sz))
|
||||||
|
|
||||||
pkg = cv.gapi.kernels(GSizeImpl)
|
pkg = cv.gapi.kernels(GSizeImpl)
|
||||||
actual = comp.apply(cv.gin(in_mat), args=cv.compile_args(pkg))
|
actual = comp.apply(cv.gin(in_mat), args=cv.gapi.compile_args(pkg))
|
||||||
|
|
||||||
self.assertEqual(0.0, cv.norm(expected, actual, cv.NORM_INF))
|
self.assertEqual(0.0, cv.norm(expected, actual, cv.NORM_INF))
|
||||||
|
|
||||||
|
|
@ -322,7 +322,7 @@ try:
|
||||||
comp = cv.GComputation(cv.GIn(g_r), cv.GOut(g_sz))
|
comp = cv.GComputation(cv.GIn(g_r), cv.GOut(g_sz))
|
||||||
|
|
||||||
pkg = cv.gapi.kernels(GSizeRImpl)
|
pkg = cv.gapi.kernels(GSizeRImpl)
|
||||||
actual = comp.apply(cv.gin(roi), args=cv.compile_args(pkg))
|
actual = comp.apply(cv.gin(roi), args=cv.gapi.compile_args(pkg))
|
||||||
|
|
||||||
# cv.norm works with tuples ?
|
# cv.norm works with tuples ?
|
||||||
self.assertEqual(0.0, cv.norm(expected, actual, cv.NORM_INF))
|
self.assertEqual(0.0, cv.norm(expected, actual, cv.NORM_INF))
|
||||||
|
|
@ -340,7 +340,7 @@ try:
|
||||||
comp = cv.GComputation(cv.GIn(g_pts), cv.GOut(g_br))
|
comp = cv.GComputation(cv.GIn(g_pts), cv.GOut(g_br))
|
||||||
|
|
||||||
pkg = cv.gapi.kernels(GBoundingRectImpl)
|
pkg = cv.gapi.kernels(GBoundingRectImpl)
|
||||||
actual = comp.apply(cv.gin(points), args=cv.compile_args(pkg))
|
actual = comp.apply(cv.gin(points), args=cv.gapi.compile_args(pkg))
|
||||||
|
|
||||||
# cv.norm works with tuples ?
|
# cv.norm works with tuples ?
|
||||||
self.assertEqual(0.0, cv.norm(expected, actual, cv.NORM_INF))
|
self.assertEqual(0.0, cv.norm(expected, actual, cv.NORM_INF))
|
||||||
|
|
@ -371,7 +371,7 @@ try:
|
||||||
|
|
||||||
comp = cv.GComputation(cv.GIn(g_in), cv.GOut(g_out))
|
comp = cv.GComputation(cv.GIn(g_in), cv.GOut(g_out))
|
||||||
pkg = cv.gapi.kernels(GGoodFeaturesImpl)
|
pkg = cv.gapi.kernels(GGoodFeaturesImpl)
|
||||||
actual = comp.apply(cv.gin(in_mat), args=cv.compile_args(pkg))
|
actual = comp.apply(cv.gin(in_mat), args=cv.gapi.compile_args(pkg))
|
||||||
|
|
||||||
# NB: OpenCV & G-API have different output types.
|
# NB: OpenCV & G-API have different output types.
|
||||||
# OpenCV - numpy array with shape (num_points, 1, 2)
|
# OpenCV - numpy array with shape (num_points, 1, 2)
|
||||||
|
|
@ -453,10 +453,10 @@ try:
|
||||||
g_in = cv.GArray.Int()
|
g_in = cv.GArray.Int()
|
||||||
comp = cv.GComputation(cv.GIn(g_in), cv.GOut(GSum.on(g_in)))
|
comp = cv.GComputation(cv.GIn(g_in), cv.GOut(GSum.on(g_in)))
|
||||||
|
|
||||||
s = comp.apply(cv.gin([1, 2, 3, 4]), args=cv.compile_args(cv.gapi.kernels(GSumImpl)))
|
s = comp.apply(cv.gin([1, 2, 3, 4]), args=cv.gapi.compile_args(cv.gapi.kernels(GSumImpl)))
|
||||||
self.assertEqual(10, s)
|
self.assertEqual(10, s)
|
||||||
|
|
||||||
s = comp.apply(cv.gin([1, 2, 8, 7]), args=cv.compile_args(cv.gapi.kernels(GSumImpl)))
|
s = comp.apply(cv.gin([1, 2, 8, 7]), args=cv.gapi.compile_args(cv.gapi.kernels(GSumImpl)))
|
||||||
self.assertEqual(18, s)
|
self.assertEqual(18, s)
|
||||||
|
|
||||||
self.assertEqual(18, GSumImpl.last_result)
|
self.assertEqual(18, GSumImpl.last_result)
|
||||||
|
|
@ -488,13 +488,13 @@ try:
|
||||||
'tuple': (42, 42)
|
'tuple': (42, 42)
|
||||||
}
|
}
|
||||||
|
|
||||||
out = comp.apply(cv.gin(table, 'int'), args=cv.compile_args(cv.gapi.kernels(GLookUpImpl)))
|
out = comp.apply(cv.gin(table, 'int'), args=cv.gapi.compile_args(cv.gapi.kernels(GLookUpImpl)))
|
||||||
self.assertEqual(42, out)
|
self.assertEqual(42, out)
|
||||||
|
|
||||||
out = comp.apply(cv.gin(table, 'str'), args=cv.compile_args(cv.gapi.kernels(GLookUpImpl)))
|
out = comp.apply(cv.gin(table, 'str'), args=cv.gapi.compile_args(cv.gapi.kernels(GLookUpImpl)))
|
||||||
self.assertEqual('hello, world!', out)
|
self.assertEqual('hello, world!', out)
|
||||||
|
|
||||||
out = comp.apply(cv.gin(table, 'tuple'), args=cv.compile_args(cv.gapi.kernels(GLookUpImpl)))
|
out = comp.apply(cv.gin(table, 'tuple'), args=cv.gapi.compile_args(cv.gapi.kernels(GLookUpImpl)))
|
||||||
self.assertEqual((42, 42), out)
|
self.assertEqual((42, 42), out)
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -521,7 +521,7 @@ try:
|
||||||
arr1 = [3, 'str']
|
arr1 = [3, 'str']
|
||||||
|
|
||||||
out = comp.apply(cv.gin(arr0, arr1),
|
out = comp.apply(cv.gin(arr0, arr1),
|
||||||
args=cv.compile_args(cv.gapi.kernels(GConcatImpl)))
|
args=cv.gapi.compile_args(cv.gapi.kernels(GConcatImpl)))
|
||||||
|
|
||||||
self.assertEqual(arr0 + arr1, out)
|
self.assertEqual(arr0 + arr1, out)
|
||||||
|
|
||||||
|
|
@ -550,7 +550,7 @@ try:
|
||||||
img1 = np.array([1, 2, 3])
|
img1 = np.array([1, 2, 3])
|
||||||
|
|
||||||
with self.assertRaises(Exception): comp.apply(cv.gin(img0, img1),
|
with self.assertRaises(Exception): comp.apply(cv.gin(img0, img1),
|
||||||
args=cv.compile_args(
|
args=cv.gapi.compile_args(
|
||||||
cv.gapi.kernels(GAddImpl)))
|
cv.gapi.kernels(GAddImpl)))
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -577,7 +577,7 @@ try:
|
||||||
img1 = np.array([1, 2, 3])
|
img1 = np.array([1, 2, 3])
|
||||||
|
|
||||||
with self.assertRaises(Exception): comp.apply(cv.gin(img0, img1),
|
with self.assertRaises(Exception): comp.apply(cv.gin(img0, img1),
|
||||||
args=cv.compile_args(
|
args=cv.gapi.compile_args(
|
||||||
cv.gapi.kernels(GAddImpl)))
|
cv.gapi.kernels(GAddImpl)))
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -607,7 +607,7 @@ try:
|
||||||
# FIXME: Cause Bad variant access.
|
# FIXME: Cause Bad variant access.
|
||||||
# Need to provide more descriptive error messsage.
|
# Need to provide more descriptive error messsage.
|
||||||
with self.assertRaises(Exception): comp.apply(cv.gin(img0, img1),
|
with self.assertRaises(Exception): comp.apply(cv.gin(img0, img1),
|
||||||
args=cv.compile_args(
|
args=cv.gapi.compile_args(
|
||||||
cv.gapi.kernels(GAddImpl)))
|
cv.gapi.kernels(GAddImpl)))
|
||||||
|
|
||||||
def test_pipeline_with_custom_kernels(self):
|
def test_pipeline_with_custom_kernels(self):
|
||||||
|
|
@ -657,7 +657,7 @@ try:
|
||||||
g_mean = cv.gapi.mean(g_transposed)
|
g_mean = cv.gapi.mean(g_transposed)
|
||||||
|
|
||||||
comp = cv.GComputation(cv.GIn(g_bgr), cv.GOut(g_mean))
|
comp = cv.GComputation(cv.GIn(g_bgr), cv.GOut(g_mean))
|
||||||
actual = comp.apply(cv.gin(img), args=cv.compile_args(
|
actual = comp.apply(cv.gin(img), args=cv.gapi.compile_args(
|
||||||
cv.gapi.kernels(GResizeImpl, GTransposeImpl)))
|
cv.gapi.kernels(GResizeImpl, GTransposeImpl)))
|
||||||
|
|
||||||
self.assertEqual(0.0, cv.norm(expected, actual, cv.NORM_INF))
|
self.assertEqual(0.0, cv.norm(expected, actual, cv.NORM_INF))
|
||||||
|
|
|
||||||
|
|
@ -3,201 +3,225 @@
|
||||||
import numpy as np
|
import numpy as np
|
||||||
import cv2 as cv
|
import cv2 as cv
|
||||||
import os
|
import os
|
||||||
|
import sys
|
||||||
|
import unittest
|
||||||
|
|
||||||
from tests_common import NewOpenCVTests
|
from tests_common import NewOpenCVTests
|
||||||
|
|
||||||
class test_gapi_streaming(NewOpenCVTests):
|
|
||||||
|
|
||||||
def test_image_input(self):
|
try:
|
||||||
sz = (1280, 720)
|
|
||||||
in_mat = np.random.randint(0, 100, sz).astype(np.uint8)
|
|
||||||
|
|
||||||
# OpenCV
|
if sys.version_info[:2] < (3, 0):
|
||||||
expected = cv.medianBlur(in_mat, 3)
|
raise unittest.SkipTest('Python 2.x is not supported')
|
||||||
|
|
||||||
# G-API
|
|
||||||
g_in = cv.GMat()
|
|
||||||
g_out = cv.gapi.medianBlur(g_in, 3)
|
|
||||||
c = cv.GComputation(g_in, g_out)
|
|
||||||
ccomp = c.compileStreaming(cv.descr_of(in_mat))
|
|
||||||
ccomp.setSource(cv.gin(in_mat))
|
|
||||||
ccomp.start()
|
|
||||||
|
|
||||||
_, actual = ccomp.pull()
|
|
||||||
|
|
||||||
# Assert
|
|
||||||
self.assertEqual(0.0, cv.norm(expected, actual, cv.NORM_INF))
|
|
||||||
|
|
||||||
|
|
||||||
def test_video_input(self):
|
class test_gapi_streaming(NewOpenCVTests):
|
||||||
ksize = 3
|
|
||||||
path = self.find_file('cv/video/768x576.avi', [os.environ['OPENCV_TEST_DATA_PATH']])
|
|
||||||
|
|
||||||
# OpenCV
|
def test_image_input(self):
|
||||||
cap = cv.VideoCapture(path)
|
sz = (1280, 720)
|
||||||
|
in_mat = np.random.randint(0, 100, sz).astype(np.uint8)
|
||||||
# G-API
|
|
||||||
g_in = cv.GMat()
|
|
||||||
g_out = cv.gapi.medianBlur(g_in, ksize)
|
|
||||||
c = cv.GComputation(g_in, g_out)
|
|
||||||
|
|
||||||
ccomp = c.compileStreaming()
|
|
||||||
source = cv.gapi.wip.make_capture_src(path)
|
|
||||||
ccomp.setSource(source)
|
|
||||||
ccomp.start()
|
|
||||||
|
|
||||||
# Assert
|
|
||||||
max_num_frames = 10
|
|
||||||
proc_num_frames = 0
|
|
||||||
while cap.isOpened():
|
|
||||||
has_expected, expected = cap.read()
|
|
||||||
has_actual, actual = ccomp.pull()
|
|
||||||
|
|
||||||
self.assertEqual(has_expected, has_actual)
|
|
||||||
|
|
||||||
if not has_actual:
|
|
||||||
break
|
|
||||||
|
|
||||||
self.assertEqual(0.0, cv.norm(cv.medianBlur(expected, ksize), actual, cv.NORM_INF))
|
|
||||||
|
|
||||||
proc_num_frames += 1
|
|
||||||
if proc_num_frames == max_num_frames:
|
|
||||||
break;
|
|
||||||
|
|
||||||
|
|
||||||
def test_video_split3(self):
|
|
||||||
path = self.find_file('cv/video/768x576.avi', [os.environ['OPENCV_TEST_DATA_PATH']])
|
|
||||||
|
|
||||||
# OpenCV
|
|
||||||
cap = cv.VideoCapture(path)
|
|
||||||
|
|
||||||
# G-API
|
|
||||||
g_in = cv.GMat()
|
|
||||||
b, g, r = cv.gapi.split3(g_in)
|
|
||||||
c = cv.GComputation(cv.GIn(g_in), cv.GOut(b, g, r))
|
|
||||||
|
|
||||||
ccomp = c.compileStreaming()
|
|
||||||
source = cv.gapi.wip.make_capture_src(path)
|
|
||||||
ccomp.setSource(source)
|
|
||||||
ccomp.start()
|
|
||||||
|
|
||||||
# Assert
|
|
||||||
max_num_frames = 10
|
|
||||||
proc_num_frames = 0
|
|
||||||
while cap.isOpened():
|
|
||||||
has_expected, frame = cap.read()
|
|
||||||
has_actual, actual = ccomp.pull()
|
|
||||||
|
|
||||||
self.assertEqual(has_expected, has_actual)
|
|
||||||
|
|
||||||
if not has_actual:
|
|
||||||
break
|
|
||||||
|
|
||||||
expected = cv.split(frame)
|
|
||||||
for e, a in zip(expected, actual):
|
|
||||||
self.assertEqual(0.0, cv.norm(e, a, cv.NORM_INF))
|
|
||||||
|
|
||||||
proc_num_frames += 1
|
|
||||||
if proc_num_frames == max_num_frames:
|
|
||||||
break;
|
|
||||||
|
|
||||||
|
|
||||||
def test_video_add(self):
|
|
||||||
sz = (576, 768, 3)
|
|
||||||
in_mat = np.random.randint(0, 100, sz).astype(np.uint8)
|
|
||||||
|
|
||||||
path = self.find_file('cv/video/768x576.avi', [os.environ['OPENCV_TEST_DATA_PATH']])
|
|
||||||
|
|
||||||
# OpenCV
|
|
||||||
cap = cv.VideoCapture(path)
|
|
||||||
|
|
||||||
# G-API
|
|
||||||
g_in1 = cv.GMat()
|
|
||||||
g_in2 = cv.GMat()
|
|
||||||
out = cv.gapi.add(g_in1, g_in2)
|
|
||||||
c = cv.GComputation(cv.GIn(g_in1, g_in2), cv.GOut(out))
|
|
||||||
|
|
||||||
ccomp = c.compileStreaming()
|
|
||||||
source = cv.gapi.wip.make_capture_src(path)
|
|
||||||
ccomp.setSource(cv.gin(source, in_mat))
|
|
||||||
ccomp.start()
|
|
||||||
|
|
||||||
# Assert
|
|
||||||
max_num_frames = 10
|
|
||||||
proc_num_frames = 0
|
|
||||||
while cap.isOpened():
|
|
||||||
has_expected, frame = cap.read()
|
|
||||||
has_actual, actual = ccomp.pull()
|
|
||||||
|
|
||||||
self.assertEqual(has_expected, has_actual)
|
|
||||||
|
|
||||||
if not has_actual:
|
|
||||||
break
|
|
||||||
|
|
||||||
expected = cv.add(frame, in_mat)
|
|
||||||
self.assertEqual(0.0, cv.norm(expected, actual, cv.NORM_INF))
|
|
||||||
|
|
||||||
proc_num_frames += 1
|
|
||||||
if proc_num_frames == max_num_frames:
|
|
||||||
break;
|
|
||||||
|
|
||||||
|
|
||||||
def test_video_good_features_to_track(self):
|
|
||||||
path = self.find_file('cv/video/768x576.avi', [os.environ['OPENCV_TEST_DATA_PATH']])
|
|
||||||
|
|
||||||
# NB: goodFeaturesToTrack configuration
|
|
||||||
max_corners = 50
|
|
||||||
quality_lvl = 0.01
|
|
||||||
min_distance = 10
|
|
||||||
block_sz = 3
|
|
||||||
use_harris_detector = True
|
|
||||||
k = 0.04
|
|
||||||
mask = None
|
|
||||||
|
|
||||||
# OpenCV
|
|
||||||
cap = cv.VideoCapture(path)
|
|
||||||
|
|
||||||
# G-API
|
|
||||||
g_in = cv.GMat()
|
|
||||||
g_gray = cv.gapi.RGB2Gray(g_in)
|
|
||||||
g_out = cv.gapi.goodFeaturesToTrack(g_gray, max_corners, quality_lvl,
|
|
||||||
min_distance, mask, block_sz, use_harris_detector, k)
|
|
||||||
|
|
||||||
c = cv.GComputation(cv.GIn(g_in), cv.GOut(g_out))
|
|
||||||
|
|
||||||
ccomp = c.compileStreaming()
|
|
||||||
source = cv.gapi.wip.make_capture_src(path)
|
|
||||||
ccomp.setSource(source)
|
|
||||||
ccomp.start()
|
|
||||||
|
|
||||||
# Assert
|
|
||||||
max_num_frames = 10
|
|
||||||
proc_num_frames = 0
|
|
||||||
while cap.isOpened():
|
|
||||||
has_expected, frame = cap.read()
|
|
||||||
has_actual, actual = ccomp.pull()
|
|
||||||
|
|
||||||
self.assertEqual(has_expected, has_actual)
|
|
||||||
|
|
||||||
if not has_actual:
|
|
||||||
break
|
|
||||||
|
|
||||||
# OpenCV
|
# OpenCV
|
||||||
frame = cv.cvtColor(frame, cv.COLOR_RGB2GRAY)
|
expected = cv.medianBlur(in_mat, 3)
|
||||||
expected = cv.goodFeaturesToTrack(frame, max_corners, quality_lvl,
|
|
||||||
min_distance, mask=mask,
|
# G-API
|
||||||
blockSize=block_sz, useHarrisDetector=use_harris_detector, k=k)
|
g_in = cv.GMat()
|
||||||
for e, a in zip(expected, actual):
|
g_out = cv.gapi.medianBlur(g_in, 3)
|
||||||
# NB: OpenCV & G-API have different output shapes:
|
c = cv.GComputation(g_in, g_out)
|
||||||
# OpenCV - (num_points, 1, 2)
|
ccomp = c.compileStreaming(cv.descr_of(in_mat))
|
||||||
# G-API - (num_points, 2)
|
ccomp.setSource(cv.gin(in_mat))
|
||||||
self.assertEqual(0.0, cv.norm(e.flatten(),
|
ccomp.start()
|
||||||
np.array(a, np.float32).flatten(),
|
|
||||||
cv.NORM_INF))
|
_, actual = ccomp.pull()
|
||||||
|
|
||||||
|
# Assert
|
||||||
|
self.assertEqual(0.0, cv.norm(expected, actual, cv.NORM_INF))
|
||||||
|
|
||||||
|
|
||||||
|
def test_video_input(self):
|
||||||
|
ksize = 3
|
||||||
|
path = self.find_file('cv/video/768x576.avi', [os.environ['OPENCV_TEST_DATA_PATH']])
|
||||||
|
|
||||||
|
# OpenCV
|
||||||
|
cap = cv.VideoCapture(path)
|
||||||
|
|
||||||
|
# G-API
|
||||||
|
g_in = cv.GMat()
|
||||||
|
g_out = cv.gapi.medianBlur(g_in, ksize)
|
||||||
|
c = cv.GComputation(g_in, g_out)
|
||||||
|
|
||||||
|
ccomp = c.compileStreaming()
|
||||||
|
source = cv.gapi.wip.make_capture_src(path)
|
||||||
|
ccomp.setSource(source)
|
||||||
|
ccomp.start()
|
||||||
|
|
||||||
|
# Assert
|
||||||
|
max_num_frames = 10
|
||||||
|
proc_num_frames = 0
|
||||||
|
while cap.isOpened():
|
||||||
|
has_expected, expected = cap.read()
|
||||||
|
has_actual, actual = ccomp.pull()
|
||||||
|
|
||||||
|
self.assertEqual(has_expected, has_actual)
|
||||||
|
|
||||||
|
if not has_actual:
|
||||||
|
break
|
||||||
|
|
||||||
|
self.assertEqual(0.0, cv.norm(cv.medianBlur(expected, ksize), actual, cv.NORM_INF))
|
||||||
|
|
||||||
|
proc_num_frames += 1
|
||||||
|
if proc_num_frames == max_num_frames:
|
||||||
|
break
|
||||||
|
|
||||||
|
|
||||||
|
def test_video_split3(self):
|
||||||
|
path = self.find_file('cv/video/768x576.avi', [os.environ['OPENCV_TEST_DATA_PATH']])
|
||||||
|
|
||||||
|
# OpenCV
|
||||||
|
cap = cv.VideoCapture(path)
|
||||||
|
|
||||||
|
# G-API
|
||||||
|
g_in = cv.GMat()
|
||||||
|
b, g, r = cv.gapi.split3(g_in)
|
||||||
|
c = cv.GComputation(cv.GIn(g_in), cv.GOut(b, g, r))
|
||||||
|
|
||||||
|
ccomp = c.compileStreaming()
|
||||||
|
source = cv.gapi.wip.make_capture_src(path)
|
||||||
|
ccomp.setSource(source)
|
||||||
|
ccomp.start()
|
||||||
|
|
||||||
|
# Assert
|
||||||
|
max_num_frames = 10
|
||||||
|
proc_num_frames = 0
|
||||||
|
while cap.isOpened():
|
||||||
|
has_expected, frame = cap.read()
|
||||||
|
has_actual, actual = ccomp.pull()
|
||||||
|
|
||||||
|
self.assertEqual(has_expected, has_actual)
|
||||||
|
|
||||||
|
if not has_actual:
|
||||||
|
break
|
||||||
|
|
||||||
|
expected = cv.split(frame)
|
||||||
|
for e, a in zip(expected, actual):
|
||||||
|
self.assertEqual(0.0, cv.norm(e, a, cv.NORM_INF))
|
||||||
|
|
||||||
|
proc_num_frames += 1
|
||||||
|
if proc_num_frames == max_num_frames:
|
||||||
|
break
|
||||||
|
|
||||||
|
|
||||||
|
def test_video_add(self):
|
||||||
|
sz = (576, 768, 3)
|
||||||
|
in_mat = np.random.randint(0, 100, sz).astype(np.uint8)
|
||||||
|
|
||||||
|
path = self.find_file('cv/video/768x576.avi', [os.environ['OPENCV_TEST_DATA_PATH']])
|
||||||
|
|
||||||
|
# OpenCV
|
||||||
|
cap = cv.VideoCapture(path)
|
||||||
|
|
||||||
|
# G-API
|
||||||
|
g_in1 = cv.GMat()
|
||||||
|
g_in2 = cv.GMat()
|
||||||
|
out = cv.gapi.add(g_in1, g_in2)
|
||||||
|
c = cv.GComputation(cv.GIn(g_in1, g_in2), cv.GOut(out))
|
||||||
|
|
||||||
|
ccomp = c.compileStreaming()
|
||||||
|
source = cv.gapi.wip.make_capture_src(path)
|
||||||
|
ccomp.setSource(cv.gin(source, in_mat))
|
||||||
|
ccomp.start()
|
||||||
|
|
||||||
|
# Assert
|
||||||
|
max_num_frames = 10
|
||||||
|
proc_num_frames = 0
|
||||||
|
while cap.isOpened():
|
||||||
|
has_expected, frame = cap.read()
|
||||||
|
has_actual, actual = ccomp.pull()
|
||||||
|
|
||||||
|
self.assertEqual(has_expected, has_actual)
|
||||||
|
|
||||||
|
if not has_actual:
|
||||||
|
break
|
||||||
|
|
||||||
|
expected = cv.add(frame, in_mat)
|
||||||
|
self.assertEqual(0.0, cv.norm(expected, actual, cv.NORM_INF))
|
||||||
|
|
||||||
|
proc_num_frames += 1
|
||||||
|
if proc_num_frames == max_num_frames:
|
||||||
|
break;
|
||||||
|
|
||||||
|
|
||||||
|
def test_video_good_features_to_track(self):
|
||||||
|
path = self.find_file('cv/video/768x576.avi', [os.environ['OPENCV_TEST_DATA_PATH']])
|
||||||
|
|
||||||
|
# NB: goodFeaturesToTrack configuration
|
||||||
|
max_corners = 50
|
||||||
|
quality_lvl = 0.01
|
||||||
|
min_distance = 10
|
||||||
|
block_sz = 3
|
||||||
|
use_harris_detector = True
|
||||||
|
k = 0.04
|
||||||
|
mask = None
|
||||||
|
|
||||||
|
# OpenCV
|
||||||
|
cap = cv.VideoCapture(path)
|
||||||
|
|
||||||
|
# G-API
|
||||||
|
g_in = cv.GMat()
|
||||||
|
g_gray = cv.gapi.RGB2Gray(g_in)
|
||||||
|
g_out = cv.gapi.goodFeaturesToTrack(g_gray, max_corners, quality_lvl,
|
||||||
|
min_distance, mask, block_sz, use_harris_detector, k)
|
||||||
|
|
||||||
|
c = cv.GComputation(cv.GIn(g_in), cv.GOut(g_out))
|
||||||
|
|
||||||
|
ccomp = c.compileStreaming()
|
||||||
|
source = cv.gapi.wip.make_capture_src(path)
|
||||||
|
ccomp.setSource(source)
|
||||||
|
ccomp.start()
|
||||||
|
|
||||||
|
# Assert
|
||||||
|
max_num_frames = 10
|
||||||
|
proc_num_frames = 0
|
||||||
|
while cap.isOpened():
|
||||||
|
has_expected, frame = cap.read()
|
||||||
|
has_actual, actual = ccomp.pull()
|
||||||
|
|
||||||
|
self.assertEqual(has_expected, has_actual)
|
||||||
|
|
||||||
|
if not has_actual:
|
||||||
|
break
|
||||||
|
|
||||||
|
# OpenCV
|
||||||
|
frame = cv.cvtColor(frame, cv.COLOR_RGB2GRAY)
|
||||||
|
expected = cv.goodFeaturesToTrack(frame, max_corners, quality_lvl,
|
||||||
|
min_distance, mask=mask,
|
||||||
|
blockSize=block_sz, useHarrisDetector=use_harris_detector, k=k)
|
||||||
|
for e, a in zip(expected, actual):
|
||||||
|
# NB: OpenCV & G-API have different output shapes:
|
||||||
|
# OpenCV - (num_points, 1, 2)
|
||||||
|
# G-API - (num_points, 2)
|
||||||
|
self.assertEqual(0.0, cv.norm(e.flatten(),
|
||||||
|
np.array(a, np.float32).flatten(),
|
||||||
|
cv.NORM_INF))
|
||||||
|
|
||||||
|
proc_num_frames += 1
|
||||||
|
if proc_num_frames == max_num_frames:
|
||||||
|
break
|
||||||
|
|
||||||
|
|
||||||
|
except unittest.SkipTest as e:
|
||||||
|
|
||||||
|
message = str(e)
|
||||||
|
|
||||||
|
class TestSkip(unittest.TestCase):
|
||||||
|
def setUp(self):
|
||||||
|
self.skipTest('Skip tests: ' + message)
|
||||||
|
|
||||||
|
def test_skip():
|
||||||
|
pass
|
||||||
|
|
||||||
|
pass
|
||||||
|
|
||||||
proc_num_frames += 1
|
|
||||||
if proc_num_frames == max_num_frames:
|
|
||||||
break;
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
NewOpenCVTests.bootstrap()
|
NewOpenCVTests.bootstrap()
|
||||||
|
|
|
||||||
|
|
@ -3,29 +3,51 @@
|
||||||
import numpy as np
|
import numpy as np
|
||||||
import cv2 as cv
|
import cv2 as cv
|
||||||
import os
|
import os
|
||||||
|
import sys
|
||||||
|
import unittest
|
||||||
|
|
||||||
from tests_common import NewOpenCVTests
|
from tests_common import NewOpenCVTests
|
||||||
|
|
||||||
class gapi_types_test(NewOpenCVTests):
|
|
||||||
|
|
||||||
def test_garray_type(self):
|
try:
|
||||||
types = [cv.gapi.CV_BOOL , cv.gapi.CV_INT , cv.gapi.CV_DOUBLE , cv.gapi.CV_FLOAT,
|
|
||||||
cv.gapi.CV_STRING, cv.gapi.CV_POINT , cv.gapi.CV_POINT2F, cv.gapi.CV_SIZE ,
|
|
||||||
cv.gapi.CV_RECT , cv.gapi.CV_SCALAR, cv.gapi.CV_MAT , cv.gapi.CV_GMAT]
|
|
||||||
|
|
||||||
for t in types:
|
if sys.version_info[:2] < (3, 0):
|
||||||
g_array = cv.GArrayT(t)
|
raise unittest.SkipTest('Python 2.x is not supported')
|
||||||
self.assertEqual(t, g_array.type())
|
|
||||||
|
class gapi_types_test(NewOpenCVTests):
|
||||||
|
|
||||||
|
def test_garray_type(self):
|
||||||
|
types = [cv.gapi.CV_BOOL , cv.gapi.CV_INT , cv.gapi.CV_DOUBLE , cv.gapi.CV_FLOAT,
|
||||||
|
cv.gapi.CV_STRING, cv.gapi.CV_POINT , cv.gapi.CV_POINT2F, cv.gapi.CV_SIZE ,
|
||||||
|
cv.gapi.CV_RECT , cv.gapi.CV_SCALAR, cv.gapi.CV_MAT , cv.gapi.CV_GMAT]
|
||||||
|
|
||||||
|
for t in types:
|
||||||
|
g_array = cv.GArrayT(t)
|
||||||
|
self.assertEqual(t, g_array.type())
|
||||||
|
|
||||||
|
|
||||||
def test_gopaque_type(self):
|
def test_gopaque_type(self):
|
||||||
types = [cv.gapi.CV_BOOL , cv.gapi.CV_INT , cv.gapi.CV_DOUBLE , cv.gapi.CV_FLOAT,
|
types = [cv.gapi.CV_BOOL , cv.gapi.CV_INT , cv.gapi.CV_DOUBLE , cv.gapi.CV_FLOAT,
|
||||||
cv.gapi.CV_STRING, cv.gapi.CV_POINT , cv.gapi.CV_POINT2F, cv.gapi.CV_SIZE ,
|
cv.gapi.CV_STRING, cv.gapi.CV_POINT , cv.gapi.CV_POINT2F, cv.gapi.CV_SIZE ,
|
||||||
cv.gapi.CV_RECT]
|
cv.gapi.CV_RECT]
|
||||||
|
|
||||||
for t in types:
|
for t in types:
|
||||||
g_opaque = cv.GOpaqueT(t)
|
g_opaque = cv.GOpaqueT(t)
|
||||||
self.assertEqual(t, g_opaque.type())
|
self.assertEqual(t, g_opaque.type())
|
||||||
|
|
||||||
|
|
||||||
|
except unittest.SkipTest as e:
|
||||||
|
|
||||||
|
message = str(e)
|
||||||
|
|
||||||
|
class TestSkip(unittest.TestCase):
|
||||||
|
def setUp(self):
|
||||||
|
self.skipTest('Skip tests: ' + message)
|
||||||
|
|
||||||
|
def test_skip():
|
||||||
|
pass
|
||||||
|
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user