mirror of
https://github.com/opencv/opencv.git
synced 2024-11-29 13:47:32 +08:00
Merge remote-tracking branch 'Itseez/2.4' into fix_bug_5599
This commit is contained in:
commit
a20a273982
@ -794,8 +794,42 @@ double cv::fisheye::calibrate(InputArrayOfArrays objectPoints, InputArrayOfArray
|
|||||||
|
|
||||||
if (K.needed()) cv::Mat(_K).convertTo(K, K.empty() ? CV_64FC1 : K.type());
|
if (K.needed()) cv::Mat(_K).convertTo(K, K.empty() ? CV_64FC1 : K.type());
|
||||||
if (D.needed()) cv::Mat(finalParam.k).convertTo(D, D.empty() ? CV_64FC1 : D.type());
|
if (D.needed()) cv::Mat(finalParam.k).convertTo(D, D.empty() ? CV_64FC1 : D.type());
|
||||||
if (rvecs.needed()) cv::Mat(omc).convertTo(rvecs, rvecs.empty() ? CV_64FC3 : rvecs.type());
|
|
||||||
if (tvecs.needed()) cv::Mat(Tc).convertTo(tvecs, tvecs.empty() ? CV_64FC3 : tvecs.type());
|
if (rvecs.needed())
|
||||||
|
{
|
||||||
|
if( rvecs.kind() == _InputArray::STD_VECTOR_MAT )
|
||||||
|
{
|
||||||
|
rvecs.create((int)objectPoints.total(), 1, CV_64FC3);
|
||||||
|
for( int i = 0; i < (int)objectPoints.total(); i++ )
|
||||||
|
{
|
||||||
|
rvecs.create(3, 1, CV_64F, i, true);
|
||||||
|
Mat rv = rvecs.getMat(i);
|
||||||
|
*rv.ptr<Vec3d>(0) = omc[i];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
cv::Mat(omc).convertTo(rvecs, rvecs.fixedType() ? rvecs.type() : CV_64FC3);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (tvecs.needed())
|
||||||
|
{
|
||||||
|
if( tvecs.kind() == _InputArray::STD_VECTOR_MAT )
|
||||||
|
{
|
||||||
|
tvecs.create((int)objectPoints.total(), 1, CV_64FC3);
|
||||||
|
for( int i = 0; i < (int)objectPoints.total(); i++ )
|
||||||
|
{
|
||||||
|
tvecs.create(3, 1, CV_64F, i, true);
|
||||||
|
Mat tv = tvecs.getMat(i);
|
||||||
|
*tv.ptr<Vec3d>(0) = Tc[i];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
cv::Mat(Tc).convertTo(tvecs, tvecs.fixedType() ? tvecs.type() : CV_64FC3);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return rms;
|
return rms;
|
||||||
}
|
}
|
||||||
|
File diff suppressed because it is too large
Load Diff
197
modules/ts/misc/run_android.py
Normal file
197
modules/ts/misc/run_android.py
Normal file
@ -0,0 +1,197 @@
|
|||||||
|
#!/usr/bin/env python
|
||||||
|
|
||||||
|
import sys
|
||||||
|
from run_utils import *
|
||||||
|
from run_suite import TestSuite
|
||||||
|
|
||||||
|
def exe(program):
|
||||||
|
return program + ".exe" if hostos == 'nt' else program
|
||||||
|
|
||||||
|
class ApkInfo:
|
||||||
|
def __init__(self):
|
||||||
|
self.pkg_name = None
|
||||||
|
self.pkg_target = None
|
||||||
|
self.pkg_runner = None
|
||||||
|
|
||||||
|
def forcePackage(self, package):
|
||||||
|
if package:
|
||||||
|
if package.startswith("."):
|
||||||
|
self.pkg_target += package
|
||||||
|
else:
|
||||||
|
self.pkg_target = package
|
||||||
|
|
||||||
|
#==============================================================================
|
||||||
|
|
||||||
|
class Tool:
|
||||||
|
def __init__(self):
|
||||||
|
self.cmd = []
|
||||||
|
|
||||||
|
def run(self, args = [], silent = False):
|
||||||
|
cmd = self.cmd[:]
|
||||||
|
cmd.extend(args)
|
||||||
|
return execute(self.cmd + args, silent)
|
||||||
|
|
||||||
|
|
||||||
|
#==============================================================================
|
||||||
|
|
||||||
|
class Adb(Tool):
|
||||||
|
def __init__(self, sdk_dir):
|
||||||
|
Tool.__init__(self)
|
||||||
|
exe_path = os.path.join(sdk_dir, exe("platform-tools/adb"))
|
||||||
|
if not os.path.isfile(exe_path) or not os.access(exe_path, os.X_OK):
|
||||||
|
exe_path = None
|
||||||
|
# fix adb tool location
|
||||||
|
if not exe_path:
|
||||||
|
exe_path = getRunningProcessExePathByName("adb")
|
||||||
|
if not exe_path:
|
||||||
|
exe_path = "adb"
|
||||||
|
self.cmd = [exe_path]
|
||||||
|
self.cpuinfo = ""
|
||||||
|
|
||||||
|
def init(self, serial):
|
||||||
|
# remember current device serial. Needed if another device is connected while this script runs
|
||||||
|
if not serial:
|
||||||
|
serial = self.detectSerial()
|
||||||
|
if serial:
|
||||||
|
self.cmd.extend(["-s", serial])
|
||||||
|
# read device cpuinfo
|
||||||
|
self.cpuinfo = self.run(["shell", "cat /proc/cpuinfo"], silent = True)
|
||||||
|
if not self.cpuinfo:
|
||||||
|
raise Err("Can not get cpuinfo from Android device")
|
||||||
|
|
||||||
|
def detectSerial(self):
|
||||||
|
adb_res = self.run(["devices"], silent = True)
|
||||||
|
# assume here that device name may consists of any characters except newline
|
||||||
|
connected_devices = re.findall(r"^[^\n]+[ \t]+device\r?$", adb_res, re.MULTILINE)
|
||||||
|
if not connected_devices:
|
||||||
|
raise Err("Can not find Android device")
|
||||||
|
elif len(connected_devices) != 1:
|
||||||
|
raise Err("Too many (%s) devices are connected. Please specify single device using --serial option:\n\n%s", len(connected_devices), adb_res)
|
||||||
|
else:
|
||||||
|
return connected_devices[0].split("\t")[0]
|
||||||
|
|
||||||
|
def getOSIdentifier(self):
|
||||||
|
return "Android" + self.run(["shell", "getprop ro.build.version.release"], silent = True).strip()
|
||||||
|
|
||||||
|
def getHardware(self):
|
||||||
|
hw = re.search(r"^Hardware[ \t]*:[ \t]*(.*?)$", self.cpuinfo, re.MULTILINE)
|
||||||
|
if hw:
|
||||||
|
return hw.group(1).strip()
|
||||||
|
|
||||||
|
def checkArmHardware(self, expected_abi):
|
||||||
|
if expected_abi and "armeabi-v7a" in expected_abi:
|
||||||
|
if "ARMv7" not in self.cpuinfo:
|
||||||
|
raise Err("Android device does not support ARMv7 commands, but tests are built for armeabi-v7a")
|
||||||
|
if "NEON" in expected_abi and "neon" not in self.cpuinfo:
|
||||||
|
raise Err("Android device has no NEON, but tests are built for %s", expected_abi)
|
||||||
|
|
||||||
|
|
||||||
|
#==============================================================================
|
||||||
|
|
||||||
|
class Aapt(Tool):
|
||||||
|
def __init__(self, sdk_dir):
|
||||||
|
Tool.__init__(self)
|
||||||
|
aapt_fn = exe("aapt")
|
||||||
|
aapt = None
|
||||||
|
for r, ds, fs in os.walk( os.path.join(sdk_dir, 'build-tools') ):
|
||||||
|
if aapt_fn in fs:
|
||||||
|
aapt = os.path.join(r, aapt_fn)
|
||||||
|
break
|
||||||
|
if not aapt:
|
||||||
|
raise Err("Can not find aapt tool: %s", aapt_fn)
|
||||||
|
self.cmd = [aapt]
|
||||||
|
|
||||||
|
def dump(self, exe):
|
||||||
|
res = ApkInfo()
|
||||||
|
output = self.run(["dump", "xmltree", exe, "AndroidManifest.xml"], silent = True)
|
||||||
|
if not output:
|
||||||
|
raise Err("Can not dump manifest from %s", exe)
|
||||||
|
tags = re.split(r"[ ]+E: ", output)
|
||||||
|
# get package name
|
||||||
|
manifest_tag = [t for t in tags if t.startswith("manifest ")]
|
||||||
|
if not manifest_tag:
|
||||||
|
raise Err("Can not read package name from: %s", exe)
|
||||||
|
res.pkg_name = re.search(r"^[ ]+A: package=\"(?P<pkg>.*?)\" \(Raw: \"(?P=pkg)\"\)\r?$", manifest_tag[0], flags=re.MULTILINE).group("pkg")
|
||||||
|
# get test instrumentation info
|
||||||
|
instrumentation_tag = [t for t in tags if t.startswith("instrumentation ")]
|
||||||
|
if not instrumentation_tag:
|
||||||
|
raise Err("Can not find instrumentation detials in: %s", exe)
|
||||||
|
res.pkg_runner = re.search(r"^[ ]+A: android:name\(0x[0-9a-f]{8}\)=\"(?P<runner>.*?)\" \(Raw: \"(?P=runner)\"\)\r?$", instrumentation_tag[0], flags=re.MULTILINE).group("runner")
|
||||||
|
res.pkg_target = re.search(r"^[ ]+A: android:targetPackage\(0x[0-9a-f]{8}\)=\"(?P<pkg>.*?)\" \(Raw: \"(?P=pkg)\"\)\r?$", instrumentation_tag[0], flags=re.MULTILINE).group("pkg")
|
||||||
|
if not res.pkg_name or not res.pkg_runner or not res.pkg_target:
|
||||||
|
raise Err("Can not find instrumentation detials in: %s", exe)
|
||||||
|
return res
|
||||||
|
|
||||||
|
#===================================================================================================
|
||||||
|
|
||||||
|
class AndroidTestSuite(TestSuite):
|
||||||
|
def __init__(self, options, cache, android_env = {}):
|
||||||
|
TestSuite.__init__(self, options, cache)
|
||||||
|
sdk_dir = options.android_sdk or os.environ.get("ANDROID_SDK", False) or os.path.dirname(os.path.dirname(self.cache.android_executable))
|
||||||
|
log.debug("Detecting Android tools in directory: %s", sdk_dir)
|
||||||
|
self.adb = Adb(sdk_dir)
|
||||||
|
self.aapt = Aapt(sdk_dir)
|
||||||
|
self.env = android_env
|
||||||
|
|
||||||
|
def isTest(self, fullpath):
|
||||||
|
if os.path.isfile(fullpath):
|
||||||
|
if fullpath.endswith(".apk") or os.access(fullpath, os.X_OK):
|
||||||
|
return True
|
||||||
|
return False
|
||||||
|
|
||||||
|
def getOS(self):
|
||||||
|
return self.adb.getOSIdentifier()
|
||||||
|
|
||||||
|
def getHardware(self):
|
||||||
|
return [self.adb.getHardware()]
|
||||||
|
|
||||||
|
def checkPrerequisites(self):
|
||||||
|
self.adb.init(self.options.serial)
|
||||||
|
self.adb.checkArmHardware(self.cache.android_abi)
|
||||||
|
|
||||||
|
def runTest(self, path, logfile, workingDir, args = []):
|
||||||
|
args = args[:]
|
||||||
|
exe = os.path.abspath(path)
|
||||||
|
|
||||||
|
if exe.endswith(".apk"):
|
||||||
|
info = self.aapt.dump(exe)
|
||||||
|
if not info:
|
||||||
|
raise Err("Can not read info from test package: %s", exe)
|
||||||
|
info.forcePackage(self.options.package)
|
||||||
|
self.adb.run(["uninstall", info.pkg_name])
|
||||||
|
|
||||||
|
output = self.adb.run(["install", exe], silent = True)
|
||||||
|
if not (output and "Success" in output):
|
||||||
|
raise Err("Can not install package: %s", exe)
|
||||||
|
|
||||||
|
params = ["-e package %s" % info.pkg_target]
|
||||||
|
ret = self.adb.run(["shell", "am instrument -w %s %s/%s" % (" ".join(params), info.pkg_name, info.pkg_runner)])
|
||||||
|
return None, ret
|
||||||
|
else:
|
||||||
|
device_dir = getpass.getuser().replace(" ","") + "_" + self.options.mode +"/"
|
||||||
|
if isColorEnabled(args):
|
||||||
|
args.append("--gtest_color=yes")
|
||||||
|
tempdir = "/data/local/tmp/"
|
||||||
|
android_dir = tempdir + device_dir
|
||||||
|
exename = os.path.basename(exe)
|
||||||
|
android_exe = android_dir + exename
|
||||||
|
self.adb.run(["push", exe, android_exe])
|
||||||
|
self.adb.run(["shell", "chmod 777 " + android_exe])
|
||||||
|
env_pieces = ["export %s=%s" % (a,b) for a,b in self.env.items()]
|
||||||
|
pieces = ["cd %s" % android_dir, "./%s %s" % (exename, " ".join(args))]
|
||||||
|
log.warning("Run: %s" % " && ".join(pieces))
|
||||||
|
ret = self.adb.run(["shell", " && ".join(env_pieces + pieces)])
|
||||||
|
# try get log
|
||||||
|
hostlogpath = os.path.join(workingDir, logfile)
|
||||||
|
self.adb.run(["pull", android_dir + logfile, hostlogpath])
|
||||||
|
# cleanup
|
||||||
|
self.adb.run(["shell", "rm " + android_dir + logfile])
|
||||||
|
self.adb.run(["shell", "rm " + tempdir + "__opencv_temp.*"], silent = True)
|
||||||
|
if os.path.isfile(hostlogpath):
|
||||||
|
return hostlogpath, ret
|
||||||
|
return None, ret
|
||||||
|
|
||||||
|
#===================================================================================================
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
log.error("This is utility file, please execute run.py script")
|
164
modules/ts/misc/run_suite.py
Normal file
164
modules/ts/misc/run_suite.py
Normal file
@ -0,0 +1,164 @@
|
|||||||
|
#!/usr/bin/env python
|
||||||
|
|
||||||
|
import datetime
|
||||||
|
from run_utils import *
|
||||||
|
|
||||||
|
class TestSuite(object):
|
||||||
|
def __init__(self, options, cache):
|
||||||
|
self.options = options
|
||||||
|
self.cache = cache
|
||||||
|
self.nameprefix = "opencv_" + self.options.mode + "_"
|
||||||
|
self.tests = self.cache.gatherTests(self.nameprefix + "*", self.isTest)
|
||||||
|
|
||||||
|
def getOS(self):
|
||||||
|
return getPlatformVersion() or self.cache.getOS()
|
||||||
|
|
||||||
|
def getHardware(self):
|
||||||
|
res = []
|
||||||
|
if self.cache.getArch() in ["x86", "x64"] and self.cache.withCuda():
|
||||||
|
res.append("CUDA")
|
||||||
|
return res
|
||||||
|
|
||||||
|
def getLogName(self, app, timestamp):
|
||||||
|
app = self.getAlias(app)
|
||||||
|
rev = self.cache.getGitVersion()
|
||||||
|
if isinstance(timestamp, datetime.datetime):
|
||||||
|
timestamp = timestamp.strftime("%Y%m%d-%H%M%S")
|
||||||
|
if self.options.longname:
|
||||||
|
small_pieces = [self.getOS(), self.cache.getArch()] + self.cache.getDependencies() + self.getHardware() + [self.cache.getSIMDFeatures()]
|
||||||
|
big_pieces = [app, str(rev), timestamp, "_".join([p for p in small_pieces if p])]
|
||||||
|
l = "__".join(big_pieces)
|
||||||
|
else:
|
||||||
|
pieces = [app, self.cache.getOS(), self.cache.getArch()] + self.getHardware() + [rev, timestamp]
|
||||||
|
lname = "_".join([p for p in pieces if p])
|
||||||
|
lname = re.sub(r'[\(\)\[\]\s,]', '_', lname)
|
||||||
|
l = re.sub(r'_+', '_', lname)
|
||||||
|
return l + ".xml"
|
||||||
|
|
||||||
|
def listTests(self, short = False, main = False):
|
||||||
|
if len(self.tests) == 0:
|
||||||
|
raise Err("No tests found")
|
||||||
|
for t in self.tests:
|
||||||
|
if short:
|
||||||
|
t = self.getAlias(t)
|
||||||
|
if not main or self.cache.isMainModule(t):
|
||||||
|
log.info("%s", t)
|
||||||
|
|
||||||
|
def getAlias(self, fname):
|
||||||
|
return sorted(self.getAliases(fname), key = len)[0]
|
||||||
|
|
||||||
|
def getAliases(self, fname):
|
||||||
|
# input is full path ('/home/.../bin/opencv_test_core') or 'java'
|
||||||
|
res = [fname]
|
||||||
|
fname = os.path.basename(fname)
|
||||||
|
res.append(fname) # filename (opencv_test_core.exe)
|
||||||
|
noext = re.sub(r"\.(exe|apk)$", '', fname)
|
||||||
|
res.append(noext) # filename w/o extension (opencv_test_core)
|
||||||
|
nopref = None
|
||||||
|
if fname.startswith(self.nameprefix):
|
||||||
|
nopref = fname[len(self.nameprefix):]
|
||||||
|
res.append(nopref) # filename w/o prefix (core)
|
||||||
|
if noext.startswith(self.nameprefix):
|
||||||
|
res.append(noext[len(self.nameprefix):])
|
||||||
|
if self.options.configuration == "Debug":
|
||||||
|
res.append(re.sub(r"d$", '', noext)) # MSVC debug config, remove 'd' suffix
|
||||||
|
if nopref:
|
||||||
|
res.append(re.sub(r"d$", '', nopref)) # MSVC debug config, remove 'd' suffix
|
||||||
|
return set(res)
|
||||||
|
|
||||||
|
def getTest(self, name):
|
||||||
|
# return stored test name by provided alias
|
||||||
|
for t in self.tests:
|
||||||
|
if name in self.getAliases(t):
|
||||||
|
return t
|
||||||
|
raise Err("Can not find test: %s", name)
|
||||||
|
|
||||||
|
def getTestList(self, white, black):
|
||||||
|
res = [t for t in white or self.tests if self.getAlias(t) not in black]
|
||||||
|
if len(res) == 0:
|
||||||
|
raise Err("No tests found")
|
||||||
|
return set(res)
|
||||||
|
|
||||||
|
def isTest(self, fullpath):
|
||||||
|
if fullpath == "java":
|
||||||
|
return True
|
||||||
|
if not os.path.isfile(fullpath):
|
||||||
|
return False
|
||||||
|
if self.cache.getOS() == "nt" and not fullpath.endswith(".exe"):
|
||||||
|
return False
|
||||||
|
return os.access(fullpath, os.X_OK)
|
||||||
|
|
||||||
|
def wrapInValgrind(self, cmd = []):
|
||||||
|
if self.options.valgrind:
|
||||||
|
res = ['valgrind']
|
||||||
|
if self.options.valgrind_supp:
|
||||||
|
res.append("--suppressions=%s" % self.options.valgrind_supp)
|
||||||
|
res.extend(self.options.valgrind_opt)
|
||||||
|
return res + cmd
|
||||||
|
return cmd
|
||||||
|
|
||||||
|
def runTest(self, path, logfile, workingDir, args = []):
|
||||||
|
args = args[:]
|
||||||
|
exe = os.path.abspath(path)
|
||||||
|
if path == "java":
|
||||||
|
cfg = self.cache.build_type
|
||||||
|
if self.options.configuration:
|
||||||
|
cfg = self.options.configuration
|
||||||
|
cmd = [self.cache.ant_executable, "-Dopencv.build.type=%s" % cfg, "buildAndTest"]
|
||||||
|
ret = execute(cmd, cwd = self.cache.java_test_binary_dir + "/.build")
|
||||||
|
return None, ret
|
||||||
|
else:
|
||||||
|
if isColorEnabled(args):
|
||||||
|
args.append("--gtest_color=yes")
|
||||||
|
cmd = self.wrapInValgrind([exe] + args)
|
||||||
|
tempDir = TempEnvDir('OPENCV_TEMP_PATH', "__opencv_temp.")
|
||||||
|
tempDir.init()
|
||||||
|
log.warning("Run: %s" % " ".join(cmd))
|
||||||
|
ret = execute(cmd, cwd = workingDir)
|
||||||
|
tempDir.clean()
|
||||||
|
hostlogpath = os.path.join(workingDir, logfile)
|
||||||
|
if os.path.isfile(hostlogpath):
|
||||||
|
return hostlogpath, ret
|
||||||
|
return None, ret
|
||||||
|
|
||||||
|
def checkPrerequisites(self):
|
||||||
|
if self.cache.getArch() == "x64" and hostmachine == "x86":
|
||||||
|
raise Err("Target architecture is incompatible with current platform")
|
||||||
|
|
||||||
|
def runTests(self, tests, black, workingDir, args = []):
|
||||||
|
self.checkPrerequisites()
|
||||||
|
args = args[:]
|
||||||
|
logs = []
|
||||||
|
test_list = self.getTestList(tests, black)
|
||||||
|
date = datetime.datetime.now()
|
||||||
|
if len(test_list) != 1:
|
||||||
|
args = [a for a in args if not a.startswith("--gtest_output=")]
|
||||||
|
ret = 0
|
||||||
|
for test in test_list:
|
||||||
|
more_args = []
|
||||||
|
exe = self.getTest(test)
|
||||||
|
|
||||||
|
userlog = [a for a in args if a.startswith("--gtest_output=")]
|
||||||
|
if len(userlog) == 0:
|
||||||
|
logname = self.getLogName(exe, date)
|
||||||
|
more_args.append("--gtest_output=xml:" + logname)
|
||||||
|
else:
|
||||||
|
logname = userlog[0][userlog[0].find(":")+1:]
|
||||||
|
|
||||||
|
log.debug("Running the test: %s (%s) ==> %s in %s", exe, args + more_args, logname, workingDir)
|
||||||
|
if self.options.dry_run:
|
||||||
|
logfile, r = None, 0
|
||||||
|
else:
|
||||||
|
logfile, r = self.runTest(exe, logname, workingDir, args + more_args)
|
||||||
|
log.debug("Test returned: %s ==> %s", r, logfile)
|
||||||
|
|
||||||
|
if r != 0:
|
||||||
|
ret = r
|
||||||
|
if logfile:
|
||||||
|
logs.append(os.path.relpath(logfile, workingDir))
|
||||||
|
return logs, ret
|
||||||
|
|
||||||
|
#===================================================================================================
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
log.error("This is utility file, please execute run.py script")
|
447
modules/ts/misc/run_utils.py
Normal file
447
modules/ts/misc/run_utils.py
Normal file
@ -0,0 +1,447 @@
|
|||||||
|
#!/usr/bin/env python
|
||||||
|
|
||||||
|
import sys, os, platform, re, tempfile, glob, getpass, logging
|
||||||
|
from subprocess import check_call, check_output, CalledProcessError, STDOUT
|
||||||
|
|
||||||
|
hostos = os.name # 'nt', 'posix'
|
||||||
|
hostmachine = platform.machine() # 'x86', 'AMD64', 'x86_64'
|
||||||
|
|
||||||
|
def initLogger():
|
||||||
|
l = logging.getLogger("run.py")
|
||||||
|
l.setLevel(logging.DEBUG)
|
||||||
|
ch = logging.StreamHandler(sys.stderr)
|
||||||
|
ch.setFormatter(logging.Formatter("%(message)s"))
|
||||||
|
l.addHandler(ch)
|
||||||
|
return l
|
||||||
|
|
||||||
|
log = initLogger()
|
||||||
|
|
||||||
|
#===================================================================================================
|
||||||
|
|
||||||
|
class Err(Exception):
|
||||||
|
def __init__(self, msg, *args):
|
||||||
|
self.msg = msg % args
|
||||||
|
|
||||||
|
def execute(cmd, silent = False, cwd = "."):
|
||||||
|
try:
|
||||||
|
log.debug("Run: %s", cmd)
|
||||||
|
if silent:
|
||||||
|
return check_output(cmd, stderr = STDOUT, cwd = cwd).decode("latin-1")
|
||||||
|
else:
|
||||||
|
return check_call(cmd, cwd = cwd)
|
||||||
|
except CalledProcessError as e:
|
||||||
|
if silent:
|
||||||
|
log.debug("Process returned: %d", e.returncode)
|
||||||
|
return e.output.decode("latin-1")
|
||||||
|
else:
|
||||||
|
log.error("Process returned: %d", e.returncode)
|
||||||
|
return e.returncode
|
||||||
|
|
||||||
|
def isColorEnabled(args):
|
||||||
|
usercolor = [a for a in args if a.startswith("--gtest_color=")]
|
||||||
|
return len(usercolor) == 0 and sys.stdout.isatty() and hostos != "nt"
|
||||||
|
|
||||||
|
#===================================================================================================
|
||||||
|
|
||||||
|
def getPlatformVersion():
|
||||||
|
mv = platform.mac_ver()
|
||||||
|
if mv[0]:
|
||||||
|
return "Darwin" + mv[0]
|
||||||
|
else:
|
||||||
|
wv = platform.win32_ver()
|
||||||
|
if wv[0]:
|
||||||
|
return "Windows" + wv[0]
|
||||||
|
else:
|
||||||
|
lv = platform.linux_distribution()
|
||||||
|
if lv[0]:
|
||||||
|
return lv[0] + lv[1]
|
||||||
|
return None
|
||||||
|
|
||||||
|
def readGitVersion(git, path):
|
||||||
|
if not path or not git or not os.path.isdir(os.path.join(path, ".git")):
|
||||||
|
return None
|
||||||
|
try:
|
||||||
|
output = execute([git, "-C", path, "rev-parse", "--short", "HEAD"], silent = True)
|
||||||
|
return output.strip()
|
||||||
|
except OSError:
|
||||||
|
log.warning("Git version read failed")
|
||||||
|
return None
|
||||||
|
|
||||||
|
SIMD_DETECTION_PROGRAM="""
|
||||||
|
#if __SSE5__
|
||||||
|
# error SSE5
|
||||||
|
#endif
|
||||||
|
#if __AVX2__
|
||||||
|
# error AVX2
|
||||||
|
#endif
|
||||||
|
#if __AVX__
|
||||||
|
# error AVX
|
||||||
|
#endif
|
||||||
|
#if __SSE4_2__
|
||||||
|
# error SSE4.2
|
||||||
|
#endif
|
||||||
|
#if __SSE4_1__
|
||||||
|
# error SSE4.1
|
||||||
|
#endif
|
||||||
|
#if __SSSE3__
|
||||||
|
# error SSSE3
|
||||||
|
#endif
|
||||||
|
#if __SSE3__
|
||||||
|
# error SSE3
|
||||||
|
#endif
|
||||||
|
#if __AES__
|
||||||
|
# error AES
|
||||||
|
#endif
|
||||||
|
#if __SSE2__
|
||||||
|
# error SSE2
|
||||||
|
#endif
|
||||||
|
#if __SSE__
|
||||||
|
# error SSE
|
||||||
|
#endif
|
||||||
|
#if __3dNOW__
|
||||||
|
# error 3dNOW
|
||||||
|
#endif
|
||||||
|
#if __MMX__
|
||||||
|
# error MMX
|
||||||
|
#endif
|
||||||
|
#if __ARM_NEON__
|
||||||
|
# error NEON
|
||||||
|
#endif
|
||||||
|
#error NOSIMD
|
||||||
|
"""
|
||||||
|
|
||||||
|
def testSIMD(compiler, cxx_flags, compiler_arg = None):
|
||||||
|
if not compiler:
|
||||||
|
return None
|
||||||
|
compiler_output = ""
|
||||||
|
try:
|
||||||
|
_, tmpfile = tempfile.mkstemp(suffix=".cpp", text = True)
|
||||||
|
with open(tmpfile, "w+") as fd:
|
||||||
|
fd.write(SIMD_DETECTION_PROGRAM)
|
||||||
|
options = [compiler]
|
||||||
|
if compiler_arg:
|
||||||
|
options.append(compiler_arg)
|
||||||
|
|
||||||
|
prev_option = None
|
||||||
|
for opt in " ".join(cxx_flags).split():
|
||||||
|
if opt.count('\"') % 2 == 1:
|
||||||
|
if prev_option is None:
|
||||||
|
prev_option = opt
|
||||||
|
else:
|
||||||
|
options.append(prev_option + " " + opt)
|
||||||
|
prev_option = None
|
||||||
|
elif prev_option is None:
|
||||||
|
options.append(opt)
|
||||||
|
else:
|
||||||
|
prev_option = prev_option + " " + opt
|
||||||
|
options.append(tmpfile)
|
||||||
|
compiler_output = execute(options, silent = True)
|
||||||
|
os.remove(tmpfile)
|
||||||
|
m = re.search("#error\W+(\w+)", compiler_output)
|
||||||
|
if m:
|
||||||
|
return m.group(1)
|
||||||
|
except OSError:
|
||||||
|
pass
|
||||||
|
log.debug("SIMD detection failed")
|
||||||
|
return None
|
||||||
|
|
||||||
|
#==============================================================================
|
||||||
|
|
||||||
|
parse_patterns = (
|
||||||
|
{'name': "cmake_home", 'default': None, 'pattern': re.compile(r"^CMAKE_HOME_DIRECTORY:INTERNAL=(.+)$")},
|
||||||
|
{'name': "opencv_home", 'default': None, 'pattern': re.compile(r"^OpenCV_SOURCE_DIR:STATIC=(.+)$")},
|
||||||
|
{'name': "opencv_build", 'default': None, 'pattern': re.compile(r"^OpenCV_BINARY_DIR:STATIC=(.+)$")},
|
||||||
|
{'name': "tests_dir", 'default': None, 'pattern': re.compile(r"^EXECUTABLE_OUTPUT_PATH:PATH=(.+)$")},
|
||||||
|
{'name': "build_type", 'default': "Release", 'pattern': re.compile(r"^CMAKE_BUILD_TYPE:STRING=(.*)$")},
|
||||||
|
{'name': "git_executable", 'default': None, 'pattern': re.compile(r"^GIT_EXECUTABLE:FILEPATH=(.*)$")},
|
||||||
|
{'name': "cxx_flags", 'default': "", 'pattern': re.compile(r"^CMAKE_CXX_FLAGS:STRING=(.*)$")},
|
||||||
|
{'name': "cxx_flags_debug", 'default': "", 'pattern': re.compile(r"^CMAKE_CXX_FLAGS_DEBUG:STRING=(.*)$")},
|
||||||
|
{'name': "cxx_flags_release", 'default': "", 'pattern': re.compile(r"^CMAKE_CXX_FLAGS_RELEASE:STRING=(.*)$")},
|
||||||
|
{'name': "opencv_cxx_flags", 'default': "", 'pattern': re.compile(r"^OPENCV_EXTRA_C_FLAGS:INTERNAL=(.*)$")},
|
||||||
|
{'name': "cxx_flags_android", 'default': None, 'pattern': re.compile(r"^ANDROID_CXX_FLAGS:INTERNAL=(.*)$")},
|
||||||
|
{'name': "android_abi", 'default': None, 'pattern': re.compile(r"^ANDROID_ABI:STRING=(.*)$")},
|
||||||
|
{'name': "android_executable", 'default': None, 'pattern': re.compile(r"^ANDROID_EXECUTABLE:FILEPATH=(.*android.*)$")},
|
||||||
|
{'name': "ant_executable", 'default': None, 'pattern': re.compile(r"^ANT_EXECUTABLE:FILEPATH=(.*ant.*)$")},
|
||||||
|
{'name': "java_test_binary_dir", 'default': None, 'pattern': re.compile(r"^opencv_test_java_BINARY_DIR:STATIC=(.*)$")},
|
||||||
|
{'name': "is_x64", 'default': "OFF", 'pattern': re.compile(r"^CUDA_64_BIT_DEVICE_CODE:BOOL=(ON)$")},#ugly(
|
||||||
|
{'name': "cmake_generator", 'default': None, 'pattern': re.compile(r"^CMAKE_GENERATOR:INTERNAL=(.+)$")},
|
||||||
|
{'name': "cxx_compiler", 'default': None, 'pattern': re.compile(r"^CMAKE_CXX_COMPILER:\w*PATH=(.+)$")},
|
||||||
|
{'name': "cxx_compiler_arg1", 'default': None, 'pattern': re.compile(r"^CMAKE_CXX_COMPILER_ARG1:[A-Z]+=(.+)$")},
|
||||||
|
{'name': "with_cuda", 'default': "OFF", 'pattern': re.compile(r"^WITH_CUDA:BOOL=(ON)$")},
|
||||||
|
{'name': "cuda_library", 'default': None, 'pattern': re.compile(r"^CUDA_CUDA_LIBRARY:FILEPATH=(.+)$")},
|
||||||
|
{'name': "cuda_version", 'default': None, 'pattern': re.compile(r"^CUDA_VERSION:STRING=(.+)$")},
|
||||||
|
{'name': "core_dependencies", 'default': None, 'pattern': re.compile(r"^opencv_core_LIB_DEPENDS:STATIC=(.+)$")},
|
||||||
|
)
|
||||||
|
|
||||||
|
class CMakeCache:
|
||||||
|
def __init__(self):
|
||||||
|
self.setDefaultAttrs()
|
||||||
|
self.cmake_home_vcver = None
|
||||||
|
self.opencv_home_vcver = None
|
||||||
|
self.featuresSIMD = None
|
||||||
|
self.main_modules = []
|
||||||
|
|
||||||
|
def setDummy(self, path):
|
||||||
|
self.tests_dir = os.path.normpath(path)
|
||||||
|
|
||||||
|
def read(self, path, fname, cfg):
|
||||||
|
rx = re.compile(r'^opencv_(\w+)_SOURCE_DIR:STATIC=(.*)$')
|
||||||
|
module_paths = {} # name -> path
|
||||||
|
with open(fname, "rt") as cachefile:
|
||||||
|
for l in cachefile.readlines():
|
||||||
|
ll = l.strip()
|
||||||
|
if not ll or ll.startswith("#"):
|
||||||
|
continue
|
||||||
|
for p in parse_patterns:
|
||||||
|
match = p["pattern"].match(ll)
|
||||||
|
if match:
|
||||||
|
value = match.groups()[0]
|
||||||
|
if value and not value.endswith("-NOTFOUND"):
|
||||||
|
setattr(self, p["name"], value)
|
||||||
|
# log.debug("cache value: %s = %s", p["name"], value)
|
||||||
|
|
||||||
|
match = rx.search(ll)
|
||||||
|
if match:
|
||||||
|
module_paths[match.group(1)] = match.group(2)
|
||||||
|
|
||||||
|
if not self.tests_dir:
|
||||||
|
self.tests_dir = path
|
||||||
|
else:
|
||||||
|
rel = os.path.relpath(self.tests_dir, self.opencv_build)
|
||||||
|
self.tests_dir = os.path.join(path, rel)
|
||||||
|
self.tests_dir = os.path.normpath(self.tests_dir)
|
||||||
|
|
||||||
|
# fix VS test binary path (add Debug or Release)
|
||||||
|
if "Visual Studio" in self.cmake_generator:
|
||||||
|
if cfg:
|
||||||
|
self.tests_dir = os.path.join(self.tests_dir, self.options.configuration)
|
||||||
|
else:
|
||||||
|
self.tests_dir = os.path.join(self.tests_dir, self.build_type)
|
||||||
|
|
||||||
|
self.cmake_home_vcver = readGitVersion(self.git_executable, self.cmake_home)
|
||||||
|
if self.opencv_home == self.cmake_home:
|
||||||
|
self.opencv_home_vcver = self.cmake_home_vcver
|
||||||
|
else:
|
||||||
|
self.opencv_home_vcver = readGitVersion(self.git_executable, self.opencv_home)
|
||||||
|
|
||||||
|
for module,path in module_paths.items():
|
||||||
|
rel = os.path.relpath(path, self.opencv_home)
|
||||||
|
if not ".." in rel:
|
||||||
|
self.main_modules.append(module)
|
||||||
|
|
||||||
|
self.flags = [
|
||||||
|
self.cxx_flags_android,
|
||||||
|
self.cxx_flags,
|
||||||
|
self.cxx_flags_release,
|
||||||
|
self.opencv_cxx_flags,
|
||||||
|
self.cxx_flags_release]
|
||||||
|
self.flags = [f for f in self.flags if f]
|
||||||
|
self.featuresSIMD = testSIMD(self.cxx_compiler, self.flags, self.cxx_compiler_arg1)
|
||||||
|
|
||||||
|
def setDefaultAttrs(self):
|
||||||
|
for p in parse_patterns:
|
||||||
|
setattr(self, p["name"], p["default"])
|
||||||
|
|
||||||
|
def gatherTests(self, mask, isGood = None):
|
||||||
|
if self.tests_dir and os.path.isdir(self.tests_dir):
|
||||||
|
d = os.path.abspath(self.tests_dir)
|
||||||
|
files = glob.glob(os.path.join(d, mask))
|
||||||
|
if not self.getOS() == "android" and self.withJava():
|
||||||
|
files.append("java")
|
||||||
|
return [f for f in files if isGood(f)]
|
||||||
|
return []
|
||||||
|
|
||||||
|
def isMainModule(self, name):
|
||||||
|
return name in self.main_modules
|
||||||
|
|
||||||
|
def withCuda(self):
|
||||||
|
return self.cuda_version and self.with_cuda == "ON" and self.cuda_library and not self.cuda_library.endswith("-NOTFOUND")
|
||||||
|
|
||||||
|
def withJava(self):
|
||||||
|
return self.ant_executable and self.java_test_binary_dir
|
||||||
|
|
||||||
|
def getGitVersion(self):
|
||||||
|
if self.cmake_home_vcver:
|
||||||
|
if self.cmake_home_vcver == self.opencv_home_vcver:
|
||||||
|
rev = self.cmake_home_vcver
|
||||||
|
elif self.opencv_home_vcver:
|
||||||
|
rev = self.cmake_home_vcver + "-" + self.opencv_home_vcver
|
||||||
|
else:
|
||||||
|
rev = self.cmake_home_vcver
|
||||||
|
else:
|
||||||
|
rev = None
|
||||||
|
if rev:
|
||||||
|
rev = rev.replace(":","to")
|
||||||
|
else:
|
||||||
|
rev = ""
|
||||||
|
return rev
|
||||||
|
|
||||||
|
def getTestFullName(self, shortname):
|
||||||
|
return os.path.join(self.tests_dir, shortname)
|
||||||
|
|
||||||
|
def getSIMDFeatures(self):
|
||||||
|
return self.featuresSIMD
|
||||||
|
|
||||||
|
def getOS(self):
|
||||||
|
if self.android_executable:
|
||||||
|
return "android"
|
||||||
|
else:
|
||||||
|
return hostos
|
||||||
|
|
||||||
|
def getArch(self):
|
||||||
|
arch = "unknown"
|
||||||
|
if self.getOS() == "android":
|
||||||
|
if "armeabi-v7a" in self.android_abi:
|
||||||
|
arch = "armv7a"
|
||||||
|
elif "armeabi-v6" in self.android_abi:
|
||||||
|
arch = "armv6"
|
||||||
|
elif "armeabi" in self.android_abi:
|
||||||
|
arch = "armv5te"
|
||||||
|
elif "x86" in self.android_abi:
|
||||||
|
arch = "x86"
|
||||||
|
elif "mips" in self.android_abi:
|
||||||
|
arch = "mips"
|
||||||
|
else:
|
||||||
|
arch = "ARM"
|
||||||
|
elif self.is_x64 and hostmachine in ["AMD64", "x86_64"]:
|
||||||
|
arch = "x64"
|
||||||
|
elif hostmachine in ["x86", "AMD64", "x86_64"]:
|
||||||
|
arch = "x86"
|
||||||
|
return arch
|
||||||
|
|
||||||
|
def getDependencies(self):
|
||||||
|
if self.core_dependencies:
|
||||||
|
candidates = ["tbb", "ippicv", "ipp", "pthreads"]
|
||||||
|
return [a for a in self.core_dependencies.split(";") if a and a in candidates]
|
||||||
|
return []
|
||||||
|
|
||||||
|
|
||||||
|
#==============================================================================
|
||||||
|
|
||||||
|
def getRunningProcessExePathByName_win32(name):
|
||||||
|
from ctypes import windll, POINTER, pointer, Structure, sizeof
|
||||||
|
from ctypes import c_long , c_int , c_uint , c_char , c_ubyte , c_char_p , c_void_p
|
||||||
|
|
||||||
|
class PROCESSENTRY32(Structure):
|
||||||
|
_fields_ = [ ( 'dwSize' , c_uint ) ,
|
||||||
|
( 'cntUsage' , c_uint) ,
|
||||||
|
( 'th32ProcessID' , c_uint) ,
|
||||||
|
( 'th32DefaultHeapID' , c_uint) ,
|
||||||
|
( 'th32ModuleID' , c_uint) ,
|
||||||
|
( 'cntThreads' , c_uint) ,
|
||||||
|
( 'th32ParentProcessID' , c_uint) ,
|
||||||
|
( 'pcPriClassBase' , c_long) ,
|
||||||
|
( 'dwFlags' , c_uint) ,
|
||||||
|
( 'szExeFile' , c_char * 260 ) ,
|
||||||
|
( 'th32MemoryBase' , c_long) ,
|
||||||
|
( 'th32AccessKey' , c_long ) ]
|
||||||
|
|
||||||
|
class MODULEENTRY32(Structure):
|
||||||
|
_fields_ = [ ( 'dwSize' , c_long ) ,
|
||||||
|
( 'th32ModuleID' , c_long ),
|
||||||
|
( 'th32ProcessID' , c_long ),
|
||||||
|
( 'GlblcntUsage' , c_long ),
|
||||||
|
( 'ProccntUsage' , c_long ) ,
|
||||||
|
( 'modBaseAddr' , c_long ) ,
|
||||||
|
( 'modBaseSize' , c_long ) ,
|
||||||
|
( 'hModule' , c_void_p ) ,
|
||||||
|
( 'szModule' , c_char * 256 ),
|
||||||
|
( 'szExePath' , c_char * 260 ) ]
|
||||||
|
|
||||||
|
TH32CS_SNAPPROCESS = 2
|
||||||
|
TH32CS_SNAPMODULE = 0x00000008
|
||||||
|
|
||||||
|
## CreateToolhelp32Snapshot
|
||||||
|
CreateToolhelp32Snapshot= windll.kernel32.CreateToolhelp32Snapshot
|
||||||
|
CreateToolhelp32Snapshot.reltype = c_long
|
||||||
|
CreateToolhelp32Snapshot.argtypes = [ c_int , c_int ]
|
||||||
|
## Process32First
|
||||||
|
Process32First = windll.kernel32.Process32First
|
||||||
|
Process32First.argtypes = [ c_void_p , POINTER( PROCESSENTRY32 ) ]
|
||||||
|
Process32First.rettype = c_int
|
||||||
|
## Process32Next
|
||||||
|
Process32Next = windll.kernel32.Process32Next
|
||||||
|
Process32Next.argtypes = [ c_void_p , POINTER(PROCESSENTRY32) ]
|
||||||
|
Process32Next.rettype = c_int
|
||||||
|
## CloseHandle
|
||||||
|
CloseHandle = windll.kernel32.CloseHandle
|
||||||
|
CloseHandle.argtypes = [ c_void_p ]
|
||||||
|
CloseHandle.rettype = c_int
|
||||||
|
## Module32First
|
||||||
|
Module32First = windll.kernel32.Module32First
|
||||||
|
Module32First.argtypes = [ c_void_p , POINTER(MODULEENTRY32) ]
|
||||||
|
Module32First.rettype = c_int
|
||||||
|
|
||||||
|
hProcessSnap = c_void_p(0)
|
||||||
|
hProcessSnap = CreateToolhelp32Snapshot( TH32CS_SNAPPROCESS , 0 )
|
||||||
|
|
||||||
|
pe32 = PROCESSENTRY32()
|
||||||
|
pe32.dwSize = sizeof( PROCESSENTRY32 )
|
||||||
|
ret = Process32First( hProcessSnap , pointer( pe32 ) )
|
||||||
|
path = None
|
||||||
|
|
||||||
|
while ret :
|
||||||
|
if name + ".exe" == pe32.szExeFile:
|
||||||
|
hModuleSnap = c_void_p(0)
|
||||||
|
me32 = MODULEENTRY32()
|
||||||
|
me32.dwSize = sizeof( MODULEENTRY32 )
|
||||||
|
hModuleSnap = CreateToolhelp32Snapshot( TH32CS_SNAPMODULE, pe32.th32ProcessID )
|
||||||
|
|
||||||
|
ret = Module32First( hModuleSnap, pointer(me32) )
|
||||||
|
path = me32.szExePath
|
||||||
|
CloseHandle( hModuleSnap )
|
||||||
|
if path:
|
||||||
|
break
|
||||||
|
ret = Process32Next( hProcessSnap, pointer(pe32) )
|
||||||
|
CloseHandle( hProcessSnap )
|
||||||
|
return path
|
||||||
|
|
||||||
|
|
||||||
|
def getRunningProcessExePathByName_posix(name):
|
||||||
|
pids= [pid for pid in os.listdir('/proc') if pid.isdigit()]
|
||||||
|
for pid in pids:
|
||||||
|
try:
|
||||||
|
path = os.readlink(os.path.join('/proc', pid, 'exe'))
|
||||||
|
if path and path.endswith(name):
|
||||||
|
return path
|
||||||
|
except:
|
||||||
|
pass
|
||||||
|
|
||||||
|
def getRunningProcessExePathByName(name):
|
||||||
|
try:
|
||||||
|
if hostos == "nt":
|
||||||
|
return getRunningProcessExePathByName_win32(name)
|
||||||
|
elif hostos == "posix":
|
||||||
|
return getRunningProcessExePathByName_posix(name)
|
||||||
|
else:
|
||||||
|
return None
|
||||||
|
except:
|
||||||
|
return None
|
||||||
|
|
||||||
|
|
||||||
|
class TempEnvDir:
|
||||||
|
def __init__(self, envname, prefix):
|
||||||
|
self.envname = envname
|
||||||
|
self.prefix = prefix
|
||||||
|
self.saved_name = None
|
||||||
|
self.new_name = None
|
||||||
|
|
||||||
|
def init(self):
|
||||||
|
self.saved_name = os.environ.get(self.envname)
|
||||||
|
self.new_name = tempfile.mkdtemp(prefix=self.prefix, dir=self.saved_name or None)
|
||||||
|
os.environ[self.envname] = self.new_name
|
||||||
|
|
||||||
|
def clean(self):
|
||||||
|
if self.saved_name:
|
||||||
|
os.environ[self.envname] = self.saved_name
|
||||||
|
else:
|
||||||
|
del os.environ[self.envname]
|
||||||
|
try:
|
||||||
|
shutil.rmtree(self.new_name)
|
||||||
|
except:
|
||||||
|
pass
|
||||||
|
|
||||||
|
#===================================================================================================
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
log.error("This is utility file, please execute run.py script")
|
6
platforms/scripts/valgrind.supp
Normal file
6
platforms/scripts/valgrind.supp
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
{
|
||||||
|
IPP static init
|
||||||
|
Memcheck:Cond
|
||||||
|
fun:ippicvGetCpuFeatures
|
||||||
|
fun:ippicvStaticInit
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user