changing 'java' module layout
This commit is contained in:
2
modules/java/generator/config/core.filelist
Normal file
2
modules/java/generator/config/core.filelist
Normal file
@@ -0,0 +1,2 @@
|
||||
include/opencv2/core/core.hpp
|
||||
../java/generator/src/cpp/core_manual.hpp
|
1
modules/java/generator/config/features2d.filelist
Normal file
1
modules/java/generator/config/features2d.filelist
Normal file
@@ -0,0 +1 @@
|
||||
../java/generator/src/cpp/features2d_manual.hpp
|
0
modules/java/generator/config/nonfree.filelist
Normal file
0
modules/java/generator/config/nonfree.filelist
Normal file
1408
modules/java/generator/gen_java.py
Normal file
1408
modules/java/generator/gen_java.py
Normal file
File diff suppressed because it is too large
Load Diff
263
modules/java/generator/gen_javadoc.py
Normal file
263
modules/java/generator/gen_javadoc.py
Normal file
@@ -0,0 +1,263 @@
|
||||
import os, sys, re, string, glob
|
||||
allmodules = ["core", "flann", "imgproc", "ml", "highgui", "video", "features2d", "calib3d", "objdetect", "legacy", "contrib", "gpu", "androidcamera", "haartraining", "java", "python", "stitching", "traincascade", "ts", "photo", "videostab"]
|
||||
verbose = False
|
||||
show_warnings = True
|
||||
show_errors = True
|
||||
|
||||
class JavadocGenerator(object):
|
||||
def __init__(self, definitions = {}, javadoc_marker = "//javadoc:"):
|
||||
self.definitions = definitions
|
||||
self.javadoc_marker = javadoc_marker
|
||||
self.markers_processed = 0
|
||||
self.markers_documented = 0
|
||||
self.params_documented = 0
|
||||
self.params_undocumented = 0
|
||||
|
||||
def parceJavadocMarker(self, line):
|
||||
assert line.lstrip().startswith(self.javadoc_marker)
|
||||
offset = line[:line.find(self.javadoc_marker)]
|
||||
line = line.strip()[len(self.javadoc_marker):]
|
||||
args_start = line.rfind("(")
|
||||
args_end = line.rfind(")")
|
||||
assert args_start * args_end > 0
|
||||
if args_start >= 0:
|
||||
assert args_start < args_end
|
||||
name = line[:args_start].strip()
|
||||
if name.startswith("java"):
|
||||
name = name[4:]
|
||||
return (name, offset, filter(None, list(arg.strip() for arg in line[args_start+1:args_end].split(","))))
|
||||
name = line.strip()
|
||||
if name.startswith("java"):
|
||||
name = name[4:]
|
||||
return (name, offset, [])
|
||||
|
||||
def document(self, infile, outfile):
|
||||
inf = open(infile, "rt")
|
||||
outf = open(outfile, "wt")
|
||||
module = os.path.splitext(os.path.basename(infile))[0].split("+")[0]
|
||||
if module not in allmodules:
|
||||
module = "unknown"
|
||||
try:
|
||||
for l in inf.readlines():
|
||||
org = l
|
||||
l = l.replace(" ", "").replace("\t", "")#remove all whitespace
|
||||
if l.startswith(self.javadoc_marker):
|
||||
marker = self.parceJavadocMarker(l)
|
||||
self.markers_processed += 1
|
||||
decl = self.definitions.get(marker[0],None)
|
||||
if decl:
|
||||
javadoc = self.makeJavadoc(decl, marker[2])
|
||||
if verbose:
|
||||
print
|
||||
print "Javadoc for \"%s\" File: %s (line %s)" % (decl["name"], decl["file"], decl["line"])
|
||||
print javadoc
|
||||
for line in javadoc.split("\n"):
|
||||
outf.write(marker[1] + line + "\n")
|
||||
self.markers_documented += 1
|
||||
elif show_errors:
|
||||
print >> sys.stderr, "gen_javadoc error: could not find documentation for %s (module: %s)" % (l.lstrip()[len(self.javadoc_marker):-1].strip(), module)
|
||||
else:
|
||||
outf.write(org.replace("\t", " ").rstrip()+"\n")
|
||||
except:
|
||||
inf.close()
|
||||
outf.close()
|
||||
os.remove(outfile)
|
||||
raise
|
||||
else:
|
||||
inf.close()
|
||||
outf.close()
|
||||
|
||||
def FinishParagraph(self, text):
|
||||
return text[:-1] + "</p>\n"
|
||||
|
||||
def ReformatForJavadoc(self, s):
|
||||
out = ""
|
||||
in_paragraph = False
|
||||
in_list = False
|
||||
for term in s.split("\n"):
|
||||
in_list_item = False
|
||||
if term.startswith("*"):
|
||||
in_list_item = True
|
||||
if in_paragraph:
|
||||
out = self.FinishParagraph(out)
|
||||
in_paragraph = False
|
||||
if not in_list:
|
||||
out += " * <ul>\n"
|
||||
in_list = True
|
||||
term = " <li>" + term[1:]
|
||||
|
||||
if term.startswith("#."):
|
||||
in_list_item = True
|
||||
if in_paragraph:
|
||||
out = self.FinishParagraph(out)
|
||||
in_paragraph = False
|
||||
if not in_list:
|
||||
out += " * <ul>\n"
|
||||
in_list = True
|
||||
term = " <li>" + term[2:]
|
||||
|
||||
if not term:
|
||||
if in_paragraph:
|
||||
out = self.FinishParagraph(out)
|
||||
in_paragraph = False
|
||||
out += " *\n"
|
||||
else:
|
||||
if in_list and not in_list_item:
|
||||
in_list = False
|
||||
if out.endswith(" *\n"):
|
||||
out = out[:-3] + " * </ul>\n *\n"
|
||||
else:
|
||||
out += " * </ul>\n"
|
||||
pos_start = 0
|
||||
pos_end = min(77, len(term)-1)
|
||||
while pos_start < pos_end:
|
||||
if pos_end - pos_start == 77:
|
||||
while pos_end >= pos_start+60:
|
||||
if not term[pos_end].isspace():
|
||||
pos_end -= 1
|
||||
else:
|
||||
break
|
||||
if pos_end < pos_start+60:
|
||||
pos_end = min(pos_start + 77, len(term)-1)
|
||||
while pos_end < len(term):
|
||||
if not term[pos_end].isspace():
|
||||
pos_end += 1
|
||||
else:
|
||||
break
|
||||
if in_paragraph or term.startswith("@") or in_list_item:
|
||||
out += " * "
|
||||
else:
|
||||
in_paragraph = True
|
||||
out += " * <p>"
|
||||
out += term[pos_start:pos_end+1].rstrip() + "\n"
|
||||
pos_start = pos_end + 1
|
||||
pos_end = min(pos_start + 77, len(term)-1)
|
||||
|
||||
if in_paragraph:
|
||||
out = self.FinishParagraph(out)
|
||||
if in_list:
|
||||
out += " * </ul>\n"
|
||||
return out
|
||||
|
||||
def getJavaName(self, decl, methodSeparator = "."):
|
||||
name = "org.opencv."
|
||||
name += decl["module"]
|
||||
if "class" in decl:
|
||||
name += "." + decl["class"]
|
||||
else:
|
||||
name += "." + decl["module"].capitalize()
|
||||
if "method" in decl:
|
||||
name += methodSeparator + decl["method"]
|
||||
return name
|
||||
|
||||
def getDocURL(self, decl):
|
||||
url = "http://docs.opencv.org/modules/"
|
||||
url += decl["module"]
|
||||
url += "/doc/"
|
||||
url += os.path.basename(decl["file"]).replace(".rst",".html")
|
||||
url += "#" + decl["name"].replace("::","-").replace("()","").replace("=","").strip().rstrip("_").replace(" ","-").replace("_","-").lower()
|
||||
return url
|
||||
|
||||
def makeJavadoc(self, decl, args = None):
|
||||
doc = ""
|
||||
prefix = "/**\n"
|
||||
|
||||
if decl.get("isclass", False):
|
||||
decl_type = "class"
|
||||
elif decl.get("isstruct", False):
|
||||
decl_type = "struct"
|
||||
elif "class" in decl:
|
||||
decl_type = "method"
|
||||
else:
|
||||
decl_type = "function"
|
||||
|
||||
# brief goes first
|
||||
if "brief" in decl:
|
||||
doc += prefix + self.ReformatForJavadoc(decl["brief"])
|
||||
prefix = " *\n"
|
||||
elif "long" not in decl:
|
||||
if show_warnings:
|
||||
print >> sys.stderr, "gen_javadoc warning: no description for " + decl_type + " \"%s\" File: %s (line %s)" % (func["name"], func["file"], func["line"])
|
||||
doc += prefix + self.ReformatForJavadoc("This " + decl_type + " is undocumented")
|
||||
prefix = " *\n"
|
||||
|
||||
# long goes after brief
|
||||
if "long" in decl:
|
||||
doc += prefix + self.ReformatForJavadoc(decl["long"])
|
||||
prefix = " *\n"
|
||||
|
||||
# @param tags
|
||||
if args and (decl_type == "method" or decl_type == "function"):
|
||||
documented_params = decl.get("params",{})
|
||||
for arg in args:
|
||||
arg_doc = documented_params.get(arg, None)
|
||||
if not arg_doc:
|
||||
arg_doc = "a " + arg
|
||||
if show_warnings:
|
||||
print >> sys.stderr, "gen_javadoc warning: parameter \"%s\" of \"%s\" is undocumented. File: %s (line %s)" % (arg, decl["name"], decl["file"], decl["line"])
|
||||
self.params_undocumented += 1
|
||||
else:
|
||||
self.params_documented += 1
|
||||
doc += prefix + self.ReformatForJavadoc("@param " + arg + " " + arg_doc)
|
||||
prefix = ""
|
||||
prefix = " *\n"
|
||||
|
||||
# @see tags
|
||||
# always link to documentation
|
||||
doc += prefix + " * @see <a href=\"" + self.getDocURL(decl) + "\">" + self.getJavaName(decl) + "</a>\n"
|
||||
prefix = ""
|
||||
# other links
|
||||
if "seealso" in decl:
|
||||
for see in decl["seealso"]:
|
||||
seedecl = self.definitions.get(see,None)
|
||||
if seedecl:
|
||||
doc += prefix + " * @see " + self.getJavaName(seedecl, "#") + "\n"
|
||||
else:
|
||||
doc += prefix + " * @see " + see.replace("::",".") + "\n"
|
||||
prefix = " *\n"
|
||||
|
||||
#doc += prefix + " * File: " + decl["file"] + " (line " + str(decl["line"]) + ")\n"
|
||||
|
||||
return (doc + " */").replace("::",".")
|
||||
|
||||
def printSummary(self):
|
||||
print
|
||||
print "Javadoc Generator Summary:"
|
||||
print " Total markers: %s" % self.markers_processed
|
||||
print " Undocumented markers: %s" % (self.markers_processed - self.markers_documented)
|
||||
print " Generated comments: %s" % self.markers_documented
|
||||
|
||||
print
|
||||
print " Documented params: %s" % self.params_documented
|
||||
print " Undocumented params: %s" % self.params_undocumented
|
||||
print
|
||||
|
||||
if __name__ == "__main__":
|
||||
if len(sys.argv) < 2:
|
||||
print "Usage:\n", os.path.basename(sys.argv[0]), " <input dir1> [<input dir2> [...]]"
|
||||
exit(0)
|
||||
|
||||
selfpath = os.path.dirname(os.path.abspath(sys.argv[0]))
|
||||
hdr_parser_path = os.path.join(selfpath, "../../python/src2")
|
||||
|
||||
sys.path.append(selfpath)
|
||||
sys.path.append(hdr_parser_path)
|
||||
import hdr_parser
|
||||
import rst_parser
|
||||
|
||||
print "Parsing documentation..."
|
||||
parser = rst_parser.RstParser(hdr_parser.CppHeaderParser())
|
||||
for m in allmodules:
|
||||
parser.parse(m, os.path.join(selfpath, "../" + m))
|
||||
|
||||
parser.printSummary()
|
||||
|
||||
print "Generating javadoc comments..."
|
||||
generator = JavadocGenerator(parser.definitions)
|
||||
for i in range(1, len(sys.argv)):
|
||||
folder = os.path.abspath(sys.argv[i])
|
||||
for jfile in [f for f in glob.glob(os.path.join(folder,"*.java")) if not f.endswith("-jdoc.java")]:
|
||||
outfile = os.path.abspath(os.path.basename(jfile).replace(".java", "-jdoc.java"))
|
||||
generator.document(jfile, outfile)
|
||||
|
||||
generator.printSummary()
|
742
modules/java/generator/rst_parser.py
Normal file
742
modules/java/generator/rst_parser.py
Normal file
@@ -0,0 +1,742 @@
|
||||
import os, sys, re, string, glob
|
||||
allmodules = ["core", "flann", "imgproc", "ml", "highgui", "video", "features2d", "calib3d", "objdetect", "legacy", "contrib", "gpu", "androidcamera", "java", "python", "stitching", "ts", "photo", "nonfree", "videostab"]
|
||||
verbose = False
|
||||
show_warnings = True
|
||||
show_errors = True
|
||||
show_critical_errors = True
|
||||
|
||||
params_blacklist = {
|
||||
"fromarray" : ("object", "allowND"), # python only function
|
||||
"reprojectImageTo3D" : ("ddepth"), # python only argument
|
||||
"composeRT" : ("d*d*"), # wildchards in parameter names are not supported by this parser
|
||||
"CvSVM::train_auto" : ("\*Grid"), # wildchards in parameter names are not supported by this parser
|
||||
"error" : "args", # parameter of supporting macro
|
||||
"getConvertElem" : ("from", "cn", "to", "beta", "alpha"), # arguments of returned functions
|
||||
"gpu::swapChannels" : ("dstOrder") # parameter is not parsed correctly by the hdr_parser
|
||||
}
|
||||
|
||||
ERROR_001_SECTIONFAILURE = 1
|
||||
WARNING_002_HDRWHITESPACE = 2
|
||||
ERROR_003_PARENTHESES = 3
|
||||
WARNING_004_TABS = 4
|
||||
ERROR_005_REDEFENITIONPARAM = 5
|
||||
ERROR_006_REDEFENITIONFUNC = 6
|
||||
WARNING_007_UNDOCUMENTEDPARAM = 7
|
||||
WARNING_008_MISSINGPARAM = 8
|
||||
WARNING_009_HDRMISMATCH = 9
|
||||
ERROR_010_NOMODULE = 10
|
||||
ERROR_011_EOLEXPECTED = 11
|
||||
|
||||
params_mapping = {
|
||||
"composeRT" : {
|
||||
"dr3dr1" : "d*d*",
|
||||
"dr3dr2" : "d*d*",
|
||||
"dr3dt1" : "d*d*",
|
||||
"dr3dt2" : "d*d*",
|
||||
"dt3dr1" : "d*d*",
|
||||
"dt3dr2" : "d*d*",
|
||||
"dt3dt1" : "d*d*",
|
||||
"dt3dt2" : "d*d*"
|
||||
},
|
||||
"CvSVM::train_auto" : {
|
||||
"coeffGrid" : "\\*Grid",
|
||||
"degreeGrid" : "\\*Grid",
|
||||
"gammaGrid" : "\\*Grid",
|
||||
"nuGrid" : "\\*Grid",
|
||||
"pGrid" : "\\*Grid"
|
||||
}
|
||||
}
|
||||
|
||||
class DeclarationParser(object):
|
||||
def __init__(self, line=None):
|
||||
if line is None:
|
||||
self.fdecl = ""
|
||||
self.lang = ""
|
||||
self.balance = 0
|
||||
return
|
||||
self.lang = self.getLang(line)
|
||||
assert self.lang is not None
|
||||
self.fdecl = line[line.find("::")+2:].strip()
|
||||
self.balance = self.fdecl.count("(") - self.fdecl.count(")")
|
||||
assert self.balance >= 0
|
||||
|
||||
def append(self, line):
|
||||
self.fdecl += line
|
||||
self.balance = self.fdecl.count("(") - self.fdecl.count(")")
|
||||
|
||||
def isready(self):
|
||||
return self.balance == 0
|
||||
|
||||
def getLang(self, line):
|
||||
if line.startswith(".. ocv:function::"):
|
||||
return "C++"
|
||||
if line.startswith(".. ocv:cfunction::"):
|
||||
return "C"
|
||||
if line.startswith(".. ocv:pyfunction::"):
|
||||
return "Python2"
|
||||
if line.startswith(".. ocv:pyoldfunction::"):
|
||||
return "Python1"
|
||||
if line.startswith(".. ocv:jfunction::"):
|
||||
return "Java"
|
||||
return None
|
||||
|
||||
def hasDeclaration(self, line):
|
||||
return self.getLang(line) is not None
|
||||
|
||||
class ParamParser(object):
|
||||
def __init__(self, line=None):
|
||||
if line is None:
|
||||
self.prefix = ""
|
||||
self.name = ""
|
||||
self.comment = ""
|
||||
self.active = False
|
||||
return
|
||||
offset = line.find(":param")
|
||||
assert offset > 0
|
||||
self.prefix = line[:offset]
|
||||
assert self.prefix==" "*len(self.prefix), ":param definition should be prefixed with spaces"
|
||||
line = line[offset + 6:].lstrip()
|
||||
name_end = line.find(":")
|
||||
assert name_end > 0
|
||||
self.name = line[:name_end]
|
||||
self.comment = line[name_end+1:].lstrip()
|
||||
self.active = True
|
||||
|
||||
def append(self, line):
|
||||
assert self.active
|
||||
if (self.hasDeclaration(line)):
|
||||
self.active = False
|
||||
elif line.startswith(self.prefix) or not line:
|
||||
self.comment += "\n" + line.lstrip()
|
||||
else:
|
||||
self.active = False
|
||||
|
||||
def hasDeclaration(self, line):
|
||||
return line.lstrip().startswith(":param")
|
||||
|
||||
class RstParser(object):
|
||||
def __init__(self, cpp_parser):
|
||||
self.cpp_parser = cpp_parser
|
||||
self.definitions = {}
|
||||
self.sections_parsed = 0
|
||||
self.sections_total = 0
|
||||
self.sections_skipped = 0
|
||||
|
||||
def parse(self, module_name, module_path=None):
|
||||
if module_path is None:
|
||||
module_path = "../" + module_name
|
||||
doclist = glob.glob(os.path.join(module_path,"doc/*.rst"))
|
||||
for doc in doclist:
|
||||
self.parse_rst_file(module_name, doc)
|
||||
|
||||
def parse_section_safe(self, module_name, section_name, file_name, lineno, lines):
|
||||
try:
|
||||
self.parse_section(module_name, section_name, file_name, lineno, lines)
|
||||
except AssertionError, args:
|
||||
if show_errors:
|
||||
print >> sys.stderr, "RST parser error E%03d: assertion in \"%s\" at %s:%s" % (ERROR_001_SECTIONFAILURE, section_name, file_name, lineno)
|
||||
print >> sys.stderr, " Details: %s" % args
|
||||
|
||||
def parse_section(self, module_name, section_name, file_name, lineno, lines):
|
||||
self.sections_total += 1
|
||||
# skip sections having whitespace in name
|
||||
#if section_name.find(" ") >= 0 and section_name.find("::operator") < 0:
|
||||
if section_name.find(" ") >= 0 and not bool(re.match(r"(\w+::)*operator\s*(\w+|>>|<<|\(\)|->|\+\+|--|=|==|\+=|-=)", section_name)):
|
||||
if show_errors:
|
||||
print >> sys.stderr, "RST parser warning W%03d: SKIPPED: \"%s\" File: %s:%s" % (WARNING_002_HDRWHITESPACE, section_name, file_name, lineno)
|
||||
self.sections_skipped += 1
|
||||
return
|
||||
|
||||
func = {}
|
||||
func["name"] = section_name
|
||||
func["file"] = file_name
|
||||
func["line"] = lineno
|
||||
func["module"] = module_name
|
||||
|
||||
# parse section name
|
||||
section_name = self.parse_namespace(func, section_name)
|
||||
class_separator_idx = section_name.find("::")
|
||||
if class_separator_idx > 0:
|
||||
func["class"] = section_name[:class_separator_idx]
|
||||
func["method"] = section_name[class_separator_idx+2:]
|
||||
else:
|
||||
func["method"] = section_name
|
||||
|
||||
capturing_seealso = False
|
||||
skip_code_lines = False
|
||||
expected_brief = True
|
||||
fdecl = DeclarationParser()
|
||||
pdecl = ParamParser()
|
||||
|
||||
for l in lines:
|
||||
# read tail of function/method declaration if needed
|
||||
if not fdecl.isready():
|
||||
fdecl.append(ll)
|
||||
if fdecl.isready():
|
||||
self.add_new_fdecl(func, fdecl)
|
||||
continue
|
||||
|
||||
# continue capture seealso
|
||||
if capturing_seealso:
|
||||
if not l or l.startswith(" "):
|
||||
seealso = func.get("seealso",[])
|
||||
seealso.extend(l.split(","))
|
||||
func["seealso"] = seealso
|
||||
continue
|
||||
else:
|
||||
capturing_seealso = False
|
||||
|
||||
ll = l.strip()
|
||||
if ll == "..":
|
||||
expected_brief = False
|
||||
skip_code_lines = False
|
||||
continue
|
||||
|
||||
# skip lines if line-skipping mode is activated
|
||||
if skip_code_lines:
|
||||
if not l or l.startswith(" "):
|
||||
continue
|
||||
else:
|
||||
skip_code_lines = False
|
||||
|
||||
if ll.startswith(".. code-block::") or ll.startswith(".. image::"):
|
||||
skip_code_lines = True
|
||||
continue
|
||||
|
||||
# todo: parse structure members; skip them for now
|
||||
if ll.startswith(".. ocv:member::"):
|
||||
skip_code_lines = True
|
||||
continue
|
||||
|
||||
#ignore references (todo: collect them)
|
||||
if l.startswith(".. ["):
|
||||
continue
|
||||
|
||||
if ll.startswith(".. "):
|
||||
expected_brief = False
|
||||
elif ll.endswith("::"):
|
||||
# turn on line-skipping mode for code fragments
|
||||
skip_code_lines = True
|
||||
ll = ll[:len(ll)-2]
|
||||
|
||||
# continue param parsing (process params after processing .. at the beginning of the line and :: at the end)
|
||||
if pdecl.active:
|
||||
pdecl.append(l)
|
||||
if pdecl.active:
|
||||
continue
|
||||
else:
|
||||
self.add_new_pdecl(func, pdecl)
|
||||
# do not continue - current line can contain next parameter definition
|
||||
|
||||
# parse ".. seealso::" blocks
|
||||
if ll.startswith(".. seealso::"):
|
||||
if ll.endswith(".. seealso::"):
|
||||
capturing_seealso = True
|
||||
else:
|
||||
seealso = func.get("seealso",[])
|
||||
seealso.extend(ll[ll.find("::")+2:].split(","))
|
||||
func["seealso"] = seealso
|
||||
continue
|
||||
|
||||
# skip ".. index::"
|
||||
if ll.startswith(".. index::"):
|
||||
continue
|
||||
|
||||
# parse class & struct definitions
|
||||
if ll.startswith(".. ocv:class::"):
|
||||
func["class"] = ll[ll.find("::")+2:].strip()
|
||||
if "method" in func:
|
||||
del func["method"]
|
||||
func["isclass"] = True
|
||||
expected_brief = True
|
||||
continue
|
||||
|
||||
if ll.startswith(".. ocv:struct::"):
|
||||
func["class"] = ll[ll.find("::")+2:].strip()
|
||||
if "method" in func:
|
||||
del func["method"]
|
||||
func["isstruct"] = True
|
||||
expected_brief = True
|
||||
continue
|
||||
|
||||
# parse function/method definitions
|
||||
if fdecl.hasDeclaration(ll):
|
||||
fdecl = DeclarationParser(ll)
|
||||
if fdecl.isready():
|
||||
self.add_new_fdecl(func, fdecl)
|
||||
continue
|
||||
|
||||
# parse parameters
|
||||
if pdecl.hasDeclaration(l):
|
||||
pdecl = ParamParser(l)
|
||||
continue
|
||||
|
||||
# record brief description
|
||||
if expected_brief:
|
||||
func["brief"] = func.get("brief", "") + "\n" + ll
|
||||
if skip_code_lines:
|
||||
expected_brief = False # force end brief if code block begins
|
||||
continue
|
||||
|
||||
# record other lines as long description
|
||||
func["long"] = func.get("long", "") + "\n" + ll
|
||||
if skip_code_lines:
|
||||
func["long"] = func.get("long", "") + "\n"
|
||||
# endfor l in lines
|
||||
|
||||
if fdecl.balance != 0:
|
||||
if show_critical_errors:
|
||||
print >> sys.stderr, "RST parser error E%03d: invalid parentheses balance in \"%s\" at %s:%s" % (ERROR_003_PARENTHESES, section_name, file_name, lineno)
|
||||
return
|
||||
|
||||
# save last parameter if needed
|
||||
if pdecl.active:
|
||||
self.add_new_pdecl(func, pdecl)
|
||||
|
||||
# add definition to list
|
||||
func = self.normalize(func)
|
||||
if self.validate(func):
|
||||
self.definitions[func["name"]] = func
|
||||
self.sections_parsed += 1
|
||||
if verbose:
|
||||
self.print_info(func)
|
||||
elif func:
|
||||
if show_errors:
|
||||
self.print_info(func, True, sys.stderr)
|
||||
|
||||
def parse_rst_file(self, module_name, doc):
|
||||
doc = os.path.abspath(doc)
|
||||
lineno = 0
|
||||
whitespace_warnings = 0
|
||||
max_whitespace_warnings = 10
|
||||
|
||||
lines = []
|
||||
flineno = 0
|
||||
fname = ""
|
||||
prev_line = None
|
||||
|
||||
df = open(doc, "rt")
|
||||
for l in df.readlines():
|
||||
lineno += 1
|
||||
# handle tabs
|
||||
if l.find("\t") >= 0:
|
||||
whitespace_warnings += 1
|
||||
if whitespace_warnings <= max_whitespace_warnings and show_warnings:
|
||||
print >> sys.stderr, "RST parser warning W%03d: tab symbol instead of space is used at %s:%s" % (WARNING_004_TABS, doc, lineno)
|
||||
l = l.replace("\t", " ")
|
||||
|
||||
# handle first line
|
||||
if prev_line == None:
|
||||
prev_line = l.rstrip()
|
||||
continue
|
||||
|
||||
ll = l.rstrip()
|
||||
if len(prev_line) > 0 and len(ll) >= len(prev_line) and ll == "-" * len(ll):
|
||||
# new function candidate
|
||||
if len(lines) > 1:
|
||||
self.parse_section_safe(module_name, fname, doc, flineno, lines[:len(lines)-1])
|
||||
lines = []
|
||||
flineno = lineno-1
|
||||
fname = prev_line.strip()
|
||||
elif flineno > 0:
|
||||
lines.append(ll)
|
||||
prev_line = ll
|
||||
df.close()
|
||||
|
||||
# don't forget about the last function section in file!!!
|
||||
if len(lines) > 1:
|
||||
self.parse_section_safe(module_name, fname, doc, flineno, lines)
|
||||
|
||||
def parse_namespace(self, func, section_name):
|
||||
known_namespaces = ["cv", "gpu", "flann"]
|
||||
l = section_name.strip()
|
||||
for namespace in known_namespaces:
|
||||
if l.startswith(namespace + "::"):
|
||||
func["namespace"] = namespace
|
||||
return l[len(namespace)+2:]
|
||||
return section_name
|
||||
|
||||
def add_new_fdecl(self, func, decl):
|
||||
if decl.fdecl.endswith(";"):
|
||||
print >> sys.stderr, "RST parser error E%03d: unexpected semicolon at the end of declaration in \"%s\" at %s:%s" \
|
||||
% (ERROR_011_EOLEXPECTED, func["name"], func["file"], func["line"])
|
||||
decls = func.get("decls",[])
|
||||
if (decl.lang == "C++" or decl.lang == "C"):
|
||||
rst_decl = self.cpp_parser.parse_func_decl_no_wrap(decl.fdecl)
|
||||
decls.append( [decl.lang, decl.fdecl, rst_decl] )
|
||||
else:
|
||||
decls.append( [decl.lang, decl.fdecl] )
|
||||
func["decls"] = decls
|
||||
|
||||
def add_new_pdecl(self, func, decl):
|
||||
params = func.get("params",{})
|
||||
if decl.name in params:
|
||||
if show_errors:
|
||||
#check black_list
|
||||
if decl.name not in params_blacklist.get(func["name"], []):
|
||||
print >> sys.stderr, "RST parser error E%03d: redefinition of parameter \"%s\" in \"%s\" at %s:%s" \
|
||||
% (ERROR_005_REDEFENITIONPARAM, decl.name, func["name"], func["file"], func["line"])
|
||||
else:
|
||||
params[decl.name] = decl.comment
|
||||
func["params"] = params
|
||||
|
||||
def print_info(self, func, skipped=False, out = sys.stdout):
|
||||
print >> out
|
||||
if skipped:
|
||||
print >> out, "SKIPPED DEFINITION:"
|
||||
print >> out, "name: %s" % (func.get("name","~empty~"))
|
||||
print >> out, "file: %s:%s" % (func.get("file","~empty~"), func.get("line","~empty~"))
|
||||
print >> out, "is class: %s" % func.get("isclass",False)
|
||||
print >> out, "is struct: %s" % func.get("isstruct",False)
|
||||
print >> out, "module: %s" % func.get("module","~unknown~")
|
||||
print >> out, "namespace: %s" % func.get("namespace", "~empty~")
|
||||
print >> out, "class: %s" % (func.get("class","~empty~"))
|
||||
print >> out, "method: %s" % (func.get("method","~empty~"))
|
||||
print >> out, "brief: %s" % (func.get("brief","~empty~"))
|
||||
if "decls" in func:
|
||||
print >> out, "declarations:"
|
||||
for d in func["decls"]:
|
||||
print >> out, " %7s: %s" % (d[0], re.sub(r"[ ]+", " ", d[1]))
|
||||
if "seealso" in func:
|
||||
print >> out, "seealso: ", func["seealso"]
|
||||
if "params" in func:
|
||||
print >> out, "parameters:"
|
||||
for name, comment in func["params"].items():
|
||||
print >> out, "%23s: %s" % (name, comment)
|
||||
print >> out, "long: %s" % (func.get("long","~empty~"))
|
||||
print >> out
|
||||
|
||||
def validate(self, func):
|
||||
if func.get("decls",None) is None:
|
||||
if not func.get("isclass",False) and not func.get("isstruct",False):
|
||||
return False
|
||||
if func["name"] in self.definitions:
|
||||
if show_errors:
|
||||
print >> sys.stderr, "RST parser error E%03d: \"%s\" from: %s:%s is already documented at %s:%s" \
|
||||
% (ERROR_006_REDEFENITIONFUNC, func["name"], func["file"], func["line"], self.definitions[func["name"]]["file"], self.definitions[func["name"]]["line"])
|
||||
return False
|
||||
return self.validateParams(func)
|
||||
|
||||
def validateParams(self, func):
|
||||
documentedParams = func.get("params",{}).keys()
|
||||
params = []
|
||||
|
||||
for decl in func.get("decls", []):
|
||||
if len(decl) > 2:
|
||||
args = decl[2][3] # decl[2] -> [ funcname, return_ctype, [modifiers], [args] ]
|
||||
for arg in args:
|
||||
# arg -> [ ctype, name, def val, [mod], argno ]
|
||||
if arg[0] != "...":
|
||||
params.append(arg[1])
|
||||
params = list(set(params))#unique
|
||||
|
||||
# 1. all params are documented
|
||||
for p in params:
|
||||
if p not in documentedParams and show_warnings:
|
||||
print >> sys.stderr, "RST parser warning W%03d: parameter \"%s\" of \"%s\" is undocumented. %s:%s" % (WARNING_007_UNDOCUMENTEDPARAM, p, func["name"], func["file"], func["line"])
|
||||
|
||||
# 2. only real params are documented
|
||||
for p in documentedParams:
|
||||
if p not in params and show_warnings:
|
||||
if p not in params_blacklist.get(func["name"], []):
|
||||
print >> sys.stderr, "RST parser warning W%03d: unexisting parameter \"%s\" of \"%s\" is documented at %s:%s" % (WARNING_008_MISSINGPARAM, p, func["name"], func["file"], func["line"])
|
||||
return True
|
||||
|
||||
def normalize(self, func):
|
||||
if not func:
|
||||
return func
|
||||
fnname = func["name"]
|
||||
fnname = self.normalizeText(fnname)
|
||||
fnname = re.sub(r'_\?D$', "_nD", fnname) # tailing _?D can be mapped to _nD
|
||||
fnname = re.sub(r'\?D$', "ND", fnname) # tailing ?D can be mapped to ND
|
||||
fnname = re.sub(r'\(s\)$', "s", fnname) # tailing (s) can be mapped to s
|
||||
func["name"] = fnname
|
||||
if "method" in func:
|
||||
func["method"] = self.normalizeText(func["method"])
|
||||
if "class" in func:
|
||||
func["class"] = self.normalizeText(func["class"])
|
||||
if "brief" in func:
|
||||
func["brief"] = self.normalizeText(func.get("brief",None))
|
||||
if not func["brief"]:
|
||||
del func["brief"]
|
||||
if "long" in func:
|
||||
func["long"] = self.normalizeText(func.get("long",None))
|
||||
if not func["long"]:
|
||||
del func["long"]
|
||||
if "decls" in func:
|
||||
func["decls"].sort()
|
||||
if "params" in func:
|
||||
params = {}
|
||||
for name, comment in func["params"].items():
|
||||
cmt = self.normalizeText(comment)
|
||||
if cmt:
|
||||
params[name] = cmt
|
||||
# expand some wellknown params
|
||||
pmap = params_mapping.get(fnname)
|
||||
if pmap:
|
||||
for name, alias in pmap.items():
|
||||
params[name] = params[alias]
|
||||
func["params"] = params
|
||||
if "seealso" in func:
|
||||
seealso = []
|
||||
for see in func["seealso"]:
|
||||
item = self.normalizeText(see.rstrip(".")).strip("\"")
|
||||
if item and (item.find(" ") < 0 or item.find("::operator") > 0):
|
||||
seealso.append(item)
|
||||
func["seealso"] = list(set(seealso))
|
||||
if not func["seealso"]:
|
||||
del func["seealso"]
|
||||
|
||||
# special case for old C functions - section name should omit "cv" prefix
|
||||
if not func.get("isclass",False) and not func.get("isstruct",False):
|
||||
self.fixOldCFunctionName(func)
|
||||
return func
|
||||
|
||||
def fixOldCFunctionName(self, func):
|
||||
if not "decls" in func:
|
||||
return
|
||||
fname = None
|
||||
for decl in func["decls"]:
|
||||
if decl[0] != "C" and decl[0] != "Python1":
|
||||
return
|
||||
if decl[0] == "C":
|
||||
fname = decl[2][0]
|
||||
if fname is None:
|
||||
return
|
||||
|
||||
fname = fname.replace(".", "::")
|
||||
if fname.startswith("cv::cv"):
|
||||
if fname[6:] == func.get("name", "").replace("*", "_n"):
|
||||
func["name"] = fname[4:]
|
||||
func["method"] = fname[4:]
|
||||
elif show_warnings:
|
||||
print >> sys.stderr, "RST parser warning W%03d: \"%s\" - section name is \"%s\" instead of \"%s\" at %s:%s" % (WARNING_009_HDRMISMATCH, fname, func["name"], fname[6:], func["file"], func["line"])
|
||||
#self.print_info(func)
|
||||
|
||||
def normalizeText(self, s):
|
||||
if s is None:
|
||||
return s
|
||||
|
||||
s = re.sub(r"\.\. math::[ \r]*\n+((.|\n)*?)(\n[ \r]*\n|$)", mathReplace2, s)
|
||||
s = re.sub(r":math:`([^`]+?)`", mathReplace, s)
|
||||
s = re.sub(r" *:sup:", "^", s)
|
||||
|
||||
s = s.replace(":ocv:class:", "")
|
||||
s = s.replace(":ocv:struct:", "")
|
||||
s = s.replace(":ocv:func:", "")
|
||||
s = s.replace(":ocv:cfunc:","")
|
||||
s = s.replace(":c:type:", "")
|
||||
s = s.replace(":c:func:", "")
|
||||
s = s.replace(":ref:", "")
|
||||
s = s.replace(":math:", "")
|
||||
s = s.replace(":func:", "")
|
||||
|
||||
s = s.replace("]_", "]")
|
||||
s = s.replace(".. note::", "Note:")
|
||||
s = s.replace(".. table::", "")
|
||||
s = s.replace(".. ocv:function::", "")
|
||||
s = s.replace(".. ocv:cfunction::", "")
|
||||
|
||||
# remove ".. identifier:" lines
|
||||
s = re.sub(r"(^|\n)\.\. [a-zA-Z_0-9]+(::[a-zA-Z_0-9]+)?:(\n|$)", "\n ", s)
|
||||
# unwrap urls
|
||||
s = re.sub(r"`([^`<]+ )<(https?://[^>]+)>`_", "\\1(\\2)", s)
|
||||
# remove tailing ::
|
||||
s = re.sub(r"::(\n|$)", "\\1", s)
|
||||
|
||||
# normalize line endings
|
||||
s = re.sub(r"\r\n", "\n", s)
|
||||
# remove extra line breaks before/after _ or ,
|
||||
s = re.sub(r"\n[ ]*([_,])\n", r"\1 ", s)
|
||||
# remove extra line breaks after `
|
||||
#s = re.sub(r"`\n", "` ", s)
|
||||
# remove extra space after ( and before .,)
|
||||
s = re.sub(r"\([\n ]+", "(", s)
|
||||
s = re.sub(r"[\n ]+(\.|,|\))", "\\1", s)
|
||||
# remove extra line breaks after ".. note::"
|
||||
s = re.sub(r"\.\. note::\n+", ".. note:: ", s)
|
||||
# remove extra line breaks before *
|
||||
s = re.sub(r"\n+\*", "\n*", s)
|
||||
# remove extra line breaks after *
|
||||
s = re.sub(r"\n\*\n+", "\n* ", s)
|
||||
# remove extra line breaks before #.
|
||||
s = re.sub(r"\n+#\.", "\n#.", s)
|
||||
# remove extra line breaks after #.
|
||||
s = re.sub(r"\n#\.\n+", "\n#. ", s)
|
||||
# remove extra line breaks before `
|
||||
#s = re.sub(r"\n[ ]*`", " `", s)
|
||||
# remove trailing whitespaces
|
||||
s = re.sub(r"[ ]+$", "", s)
|
||||
# remove .. for references
|
||||
#s = re.sub(r"\.\. \[", "[", s)
|
||||
# unescape
|
||||
s = re.sub(r"\\(.)", "\\1", s)
|
||||
|
||||
# remove whitespace before .
|
||||
s = re.sub(r"[ ]+\.", ".", s)
|
||||
# remove tailing whitespace
|
||||
s = re.sub(r" +(\n|$)", "\\1", s)
|
||||
# remove leading whitespace
|
||||
s = re.sub(r"(^|\n) +", "\\1", s)
|
||||
# compress line breaks
|
||||
s = re.sub(r"\n\n+", "\n\n", s)
|
||||
# remove other newlines
|
||||
s = re.sub(r"([^.\n\\=])\n([^*#\n]|\*[^ ])", "\\1 \\2", s)
|
||||
# compress whitespace
|
||||
s = re.sub(r" +", " ", s)
|
||||
|
||||
# restore math
|
||||
s = re.sub(r" *<BR> *","\n", s)
|
||||
|
||||
# remove extra space before .
|
||||
s = re.sub(r"[\n ]+\.", ".", s)
|
||||
|
||||
s = s.replace("**", "")
|
||||
s = re.sub(r"``([^\n]+?)``", "<code>\\1</code>", s)
|
||||
s = s.replace("``", "\"")
|
||||
s = s.replace("`", "\"")
|
||||
s = s.replace("\"\"", "\"")
|
||||
|
||||
s = s.strip()
|
||||
return s
|
||||
|
||||
def printSummary(self):
|
||||
print
|
||||
print "RST Parser Summary:"
|
||||
print " Total sections: %s" % self.sections_total
|
||||
print " Skipped sections: %s" % self.sections_skipped
|
||||
print " Parsed sections: %s" % self.sections_parsed
|
||||
print " Invalid sections: %s" % (self.sections_total - self.sections_parsed - self.sections_skipped)
|
||||
|
||||
# statistic by language
|
||||
stat = {}
|
||||
classes = 0
|
||||
structs = 0
|
||||
for name, d in self.definitions.items():
|
||||
if d.get("isclass", False):
|
||||
classes += 1
|
||||
elif d.get("isstruct", False):
|
||||
structs += 1
|
||||
else:
|
||||
for decl in d.get("decls",[]):
|
||||
stat[decl[0]] = stat.get(decl[0],0) + 1
|
||||
|
||||
print
|
||||
print " classes documented: %s" % classes
|
||||
print " structs documented: %s" % structs
|
||||
for lang in sorted(stat.items()):
|
||||
print " %7s functions documented: %s" % lang
|
||||
print
|
||||
|
||||
def mathReplace2(match):
|
||||
m = mathReplace(match)
|
||||
#print "%s ===> %s" % (match.group(0), m)
|
||||
return "\n\n"+m+"<BR><BR>"
|
||||
|
||||
def hdotsforReplace(match):
|
||||
return '... '*int(match.group(1))
|
||||
|
||||
def matrixReplace(match):
|
||||
m = match.group(2)
|
||||
m = re.sub(r" *& *", " ", m)
|
||||
return m
|
||||
|
||||
def mathReplace(match):
|
||||
m = match.group(1)
|
||||
|
||||
m = m.replace("\n", "<BR>")
|
||||
m = re.sub(r"\\text(tt|rm)?{(.*?)}", "\\2", m)
|
||||
m = re.sub(r"\\mbox{(.*?)}", "\\1", m)
|
||||
m = re.sub(r"\\mathrm{(.*?)}", "\\1", m)
|
||||
m = re.sub(r"\\vecthree{(.*?)}{(.*?)}{(.*?)}", "[\\1 \\2 \\3]", m)
|
||||
m = re.sub(r"\\bar{(.*?)}", "\\1`", m)
|
||||
m = re.sub(r"\\sqrt\[(\d)*\]{(.*?)}", "sqrt\\1(\\2)", m)
|
||||
m = re.sub(r"\\sqrt{(.*?)}", "sqrt(\\1)", m)
|
||||
m = re.sub(r"\\frac{(.*?)}{(.*?)}", "(\\1)/(\\2)", m)
|
||||
m = re.sub(r"\\fork{(.*?)}{(.*?)}{(.*?)}{(.*?)}", "\\1 \\2; \\3 \\4", m)
|
||||
m = re.sub(r"\\forkthree{(.*?)}{(.*?)}{(.*?)}{(.*?)}{(.*?)}{(.*?)}", "\\1 \\2; \\3 \\4; \\5 \\6", m)
|
||||
m = re.sub(r"\\stackrel{(.*?)}{(.*?)}", "\\1 \\2", m)
|
||||
m = re.sub(r"\\sum _{(.*?)}", "sum{by: \\1}", m)
|
||||
|
||||
m = re.sub(r" +", " ", m)
|
||||
m = re.sub(r"\\begin{(?P<gtype>array|bmatrix)}(?:{[\|lcr\. ]+})? *(.*?)\\end{(?P=gtype)}", matrixReplace, m)
|
||||
m = re.sub(r"\\hdotsfor{(\d+)}", hdotsforReplace, m)
|
||||
m = re.sub(r"\\vecthreethree{(.*?)}{(.*?)}{(.*?)}{(.*?)}{(.*?)}{(.*?)}{(.*?)}{(.*?)}{(.*?)}", "<BR>|\\1 \\2 \\3|<BR>|\\4 \\5 \\6|<BR>|\\7 \\8 \\9|<BR>", m)
|
||||
|
||||
m = re.sub(r"\\left[ ]*\\lfloor[ ]*", "[", m)
|
||||
m = re.sub(r"[ ]*\\right[ ]*\\rfloor", "]", m)
|
||||
m = re.sub(r"\\left[ ]*\([ ]*", "(", m)
|
||||
m = re.sub(r"[ ]*\\right[ ]*\)", ")", m)
|
||||
m = re.sub(r"([^\\])\$", "\\1", m)
|
||||
|
||||
m = m.replace("\\times", "x")
|
||||
m = m.replace("\\pm", "+-")
|
||||
m = m.replace("\\cdot", "*")
|
||||
m = m.replace("\\sim", "~")
|
||||
m = m.replace("\\leftarrow", "<-")
|
||||
m = m.replace("\\rightarrow", "->")
|
||||
m = m.replace("\\leftrightarrow", "<->")
|
||||
m = re.sub(r" *\\neg *", " !", m)
|
||||
m = re.sub(r" *\\neq? *", " != ", m)
|
||||
m = re.sub(r" *\\geq? *", " >= ", m)
|
||||
m = re.sub(r" *\\leq? *", " <= ", m)
|
||||
m = re.sub(r" *\\vee *", " V ", m)
|
||||
m = re.sub(r" *\\oplus *", " (+) ", m)
|
||||
m = re.sub(r" *\\mod *", " mod ", m)
|
||||
m = re.sub(r"( *)\\partial *", "\\1d", m)
|
||||
|
||||
m = re.sub(r"( *)\\quad *", "\\1 ", m)
|
||||
m = m.replace("\\,", " ")
|
||||
m = m.replace("\\:", " ")
|
||||
m = m.replace("\\;", " ")
|
||||
m = m.replace("\\!", "")
|
||||
|
||||
m = m.replace("\\\\", "<BR>")
|
||||
m = m.replace("\\wedge", "/\\\\")
|
||||
m = re.sub(r"\\(.)", "\\1", m)
|
||||
|
||||
m = re.sub(r"\([ ]+", "(", m)
|
||||
m = re.sub(r"[ ]+(\.|,|\))(<BR>| |$)", "\\1\\2", m)
|
||||
m = re.sub(r" +\|[ ]+([a-zA-Z0-9_(])", " |\\1", m)
|
||||
m = re.sub(r"([a-zA-Z0-9_)}])[ ]+(\(|\|)", "\\1\\2", m)
|
||||
|
||||
m = re.sub(r"{\((-?[a-zA-Z0-9_]+)\)}", "\\1", m)
|
||||
m = re.sub(r"{(-?[a-zA-Z0-9_]+)}", "(\\1)", m)
|
||||
m = re.sub(r"\(([0-9]+)\)", "\\1", m)
|
||||
m = m.replace("{", "(")
|
||||
m = m.replace("}", ")")
|
||||
|
||||
#print "%s ===> %s" % (match.group(0), m)
|
||||
return "<em>" + m + "</em>"
|
||||
|
||||
if __name__ == "__main__":
|
||||
if len(sys.argv) < 2:
|
||||
print "Usage:\n", os.path.basename(sys.argv[0]), " <module path>"
|
||||
exit(0)
|
||||
|
||||
if len(sys.argv) >= 3:
|
||||
if sys.argv[2].lower() == "verbose":
|
||||
verbose = True
|
||||
|
||||
rst_parser_dir = os.path.dirname(os.path.abspath(sys.argv[0]))
|
||||
hdr_parser_path = os.path.join(rst_parser_dir, "../python/src2")
|
||||
|
||||
sys.path.append(hdr_parser_path)
|
||||
import hdr_parser
|
||||
|
||||
module = sys.argv[1]
|
||||
|
||||
if module != "all" and not os.path.isdir(os.path.join(rst_parser_dir, "../" + module)):
|
||||
print "RST parser error E%03d: module \"%s\" could not be found." % (ERROR_010_NOMODULE, module)
|
||||
exit(1)
|
||||
|
||||
parser = RstParser(hdr_parser.CppHeaderParser())
|
||||
|
||||
if module == "all":
|
||||
for m in allmodules:
|
||||
parser.parse(m, os.path.join(rst_parser_dir, "../" + m))
|
||||
else:
|
||||
parser.parse(module, os.path.join(rst_parser_dir, "../" + module))
|
||||
|
||||
# summary
|
||||
parser.printSummary()
|
2577
modules/java/generator/src/cpp/Mat.cpp
Normal file
2577
modules/java/generator/src/cpp/Mat.cpp
Normal file
File diff suppressed because it is too large
Load Diff
482
modules/java/generator/src/cpp/VideoCapture.cpp
Normal file
482
modules/java/generator/src/cpp/VideoCapture.cpp
Normal file
@@ -0,0 +1,482 @@
|
||||
#include <jni.h>
|
||||
|
||||
#ifdef DEBUG
|
||||
#include <android/log.h>
|
||||
#define MODULE_LOG_TAG "OpenCV.highgui"
|
||||
#define LOGD(...) ((void)__android_log_print(ANDROID_LOG_DEBUG, MODULE_LOG_TAG, __VA_ARGS__))
|
||||
#endif // DEBUG
|
||||
|
||||
#include "opencv2/opencv_modules.hpp"
|
||||
#ifdef HAVE_OPENCV_HIGHGUI
|
||||
|
||||
#include "opencv2/highgui/highgui_c.h"
|
||||
#include "opencv2/highgui/highgui.hpp"
|
||||
using namespace cv;
|
||||
|
||||
|
||||
extern "C" {
|
||||
|
||||
//
|
||||
// VideoCapture::VideoCapture()
|
||||
//
|
||||
|
||||
JNIEXPORT jlong JNICALL Java_org_opencv_highgui_VideoCapture_n_1VideoCapture__
|
||||
(JNIEnv* env, jclass);
|
||||
|
||||
JNIEXPORT jlong JNICALL Java_org_opencv_highgui_VideoCapture_n_1VideoCapture__
|
||||
(JNIEnv* env, jclass)
|
||||
{
|
||||
try {
|
||||
#ifdef DEBUG
|
||||
LOGD("highgui::VideoCapture_n_1VideoCapture__()");
|
||||
#endif // DEBUG
|
||||
|
||||
VideoCapture* _retval_ = new VideoCapture( );
|
||||
|
||||
return (jlong) _retval_;
|
||||
} catch(cv::Exception e) {
|
||||
#ifdef DEBUG
|
||||
LOGD("highgui::VideoCapture_n_1VideoCapture__() catched cv::Exception: %s", e.what());
|
||||
#endif // DEBUG
|
||||
jclass je = env->FindClass("org/opencv/core/CvException");
|
||||
if(!je) je = env->FindClass("java/lang/Exception");
|
||||
env->ThrowNew(je, e.what());
|
||||
return 0;
|
||||
} catch (...) {
|
||||
#ifdef DEBUG
|
||||
LOGD("highgui::VideoCapture_n_1VideoCapture__() catched unknown exception (...)");
|
||||
#endif // DEBUG
|
||||
jclass je = env->FindClass("java/lang/Exception");
|
||||
env->ThrowNew(je, "Unknown exception in JNI code {highgui::VideoCapture_n_1VideoCapture__()}");
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//
|
||||
// VideoCapture::VideoCapture(int device)
|
||||
//
|
||||
|
||||
JNIEXPORT jlong JNICALL Java_org_opencv_highgui_VideoCapture_n_1VideoCapture__I
|
||||
(JNIEnv* env, jclass, jint device);
|
||||
|
||||
JNIEXPORT jlong JNICALL Java_org_opencv_highgui_VideoCapture_n_1VideoCapture__I
|
||||
(JNIEnv* env, jclass, jint device)
|
||||
{
|
||||
try {
|
||||
#ifdef DEBUG
|
||||
LOGD("highgui::VideoCapture_n_1VideoCapture__I()");
|
||||
#endif // DEBUG
|
||||
|
||||
VideoCapture* _retval_ = new VideoCapture( device );
|
||||
|
||||
return (jlong) _retval_;
|
||||
} catch(cv::Exception e) {
|
||||
#ifdef DEBUG
|
||||
LOGD("highgui::VideoCapture_n_1VideoCapture__I() catched cv::Exception: %s", e.what());
|
||||
#endif // DEBUG
|
||||
jclass je = env->FindClass("org/opencv/core/CvException");
|
||||
if(!je) je = env->FindClass("java/lang/Exception");
|
||||
env->ThrowNew(je, e.what());
|
||||
return 0;
|
||||
} catch (...) {
|
||||
#ifdef DEBUG
|
||||
LOGD("highgui::VideoCapture_n_1VideoCapture__I() catched unknown exception (...)");
|
||||
#endif // DEBUG
|
||||
jclass je = env->FindClass("java/lang/Exception");
|
||||
env->ThrowNew(je, "Unknown exception in JNI code {highgui::VideoCapture_n_1VideoCapture__I()}");
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
//
|
||||
// double VideoCapture::get(int propId)
|
||||
//
|
||||
|
||||
JNIEXPORT jdouble JNICALL Java_org_opencv_highgui_VideoCapture_n_1get
|
||||
(JNIEnv* env, jclass, jlong self, jint propId);
|
||||
|
||||
JNIEXPORT jdouble JNICALL Java_org_opencv_highgui_VideoCapture_n_1get
|
||||
(JNIEnv* env, jclass, jlong self, jint propId)
|
||||
{
|
||||
try {
|
||||
#ifdef DEBUG
|
||||
LOGD("highgui::VideoCapture_n_1get()");
|
||||
#endif // DEBUG
|
||||
VideoCapture* me = (VideoCapture*) self; //TODO: check for NULL
|
||||
double _retval_ = me->get( propId );
|
||||
|
||||
return _retval_;
|
||||
} catch(cv::Exception e) {
|
||||
#ifdef DEBUG
|
||||
LOGD("highgui::VideoCapture_n_1get() catched cv::Exception: %s", e.what());
|
||||
#endif // DEBUG
|
||||
jclass je = env->FindClass("org/opencv/core/CvException");
|
||||
if(!je) je = env->FindClass("java/lang/Exception");
|
||||
env->ThrowNew(je, e.what());
|
||||
return 0;
|
||||
} catch (...) {
|
||||
#ifdef DEBUG
|
||||
LOGD("highgui::VideoCapture_n_1get() catched unknown exception (...)");
|
||||
#endif // DEBUG
|
||||
jclass je = env->FindClass("java/lang/Exception");
|
||||
env->ThrowNew(je, "Unknown exception in JNI code {highgui::VideoCapture_n_1get()}");
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
//
|
||||
// bool VideoCapture::grab()
|
||||
//
|
||||
|
||||
JNIEXPORT jboolean JNICALL Java_org_opencv_highgui_VideoCapture_n_1grab
|
||||
(JNIEnv* env, jclass, jlong self);
|
||||
|
||||
JNIEXPORT jboolean JNICALL Java_org_opencv_highgui_VideoCapture_n_1grab
|
||||
(JNIEnv* env, jclass, jlong self)
|
||||
{
|
||||
try {
|
||||
#ifdef DEBUG
|
||||
LOGD("highgui::VideoCapture_n_1grab()");
|
||||
#endif // DEBUG
|
||||
VideoCapture* me = (VideoCapture*) self; //TODO: check for NULL
|
||||
bool _retval_ = me->grab( );
|
||||
|
||||
return _retval_;
|
||||
} catch(cv::Exception e) {
|
||||
#ifdef DEBUG
|
||||
LOGD("highgui::VideoCapture_n_1grab() catched cv::Exception: %s", e.what());
|
||||
#endif // DEBUG
|
||||
jclass je = env->FindClass("org/opencv/core/CvException");
|
||||
if(!je) je = env->FindClass("java/lang/Exception");
|
||||
env->ThrowNew(je, e.what());
|
||||
return 0;
|
||||
} catch (...) {
|
||||
#ifdef DEBUG
|
||||
LOGD("highgui::VideoCapture_n_1grab() catched unknown exception (...)");
|
||||
#endif // DEBUG
|
||||
jclass je = env->FindClass("java/lang/Exception");
|
||||
env->ThrowNew(je, "Unknown exception in JNI code {highgui::VideoCapture_n_1grab()}");
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
//
|
||||
// bool VideoCapture::isOpened()
|
||||
//
|
||||
|
||||
JNIEXPORT jboolean JNICALL Java_org_opencv_highgui_VideoCapture_n_1isOpened
|
||||
(JNIEnv* env, jclass, jlong self);
|
||||
|
||||
JNIEXPORT jboolean JNICALL Java_org_opencv_highgui_VideoCapture_n_1isOpened
|
||||
(JNIEnv* env, jclass, jlong self)
|
||||
{
|
||||
try {
|
||||
#ifdef DEBUG
|
||||
LOGD("highgui::VideoCapture_n_1isOpened()");
|
||||
#endif // DEBUG
|
||||
VideoCapture* me = (VideoCapture*) self; //TODO: check for NULL
|
||||
bool _retval_ = me->isOpened( );
|
||||
|
||||
return _retval_;
|
||||
} catch(cv::Exception e) {
|
||||
#ifdef DEBUG
|
||||
LOGD("highgui::VideoCapture_n_1isOpened() catched cv::Exception: %s", e.what());
|
||||
#endif // DEBUG
|
||||
jclass je = env->FindClass("org/opencv/core/CvException");
|
||||
if(!je) je = env->FindClass("java/lang/Exception");
|
||||
env->ThrowNew(je, e.what());
|
||||
return 0;
|
||||
} catch (...) {
|
||||
#ifdef DEBUG
|
||||
LOGD("highgui::VideoCapture_n_1isOpened() catched unknown exception (...)");
|
||||
#endif // DEBUG
|
||||
jclass je = env->FindClass("java/lang/Exception");
|
||||
env->ThrowNew(je, "Unknown exception in JNI code {highgui::VideoCapture_n_1isOpened()}");
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//
|
||||
// bool VideoCapture::open(int device)
|
||||
//
|
||||
|
||||
JNIEXPORT jboolean JNICALL Java_org_opencv_highgui_VideoCapture_n_1open__JI
|
||||
(JNIEnv* env, jclass, jlong self, jint device);
|
||||
|
||||
JNIEXPORT jboolean JNICALL Java_org_opencv_highgui_VideoCapture_n_1open__JI
|
||||
(JNIEnv* env, jclass, jlong self, jint device)
|
||||
{
|
||||
try {
|
||||
#ifdef DEBUG
|
||||
LOGD("highgui::VideoCapture_n_1open__JI()");
|
||||
#endif // DEBUG
|
||||
VideoCapture* me = (VideoCapture*) self; //TODO: check for NULL
|
||||
bool _retval_ = me->open( device );
|
||||
|
||||
return _retval_;
|
||||
} catch(cv::Exception e) {
|
||||
#ifdef DEBUG
|
||||
LOGD("highgui::VideoCapture_n_1open__JI() catched cv::Exception: %s", e.what());
|
||||
#endif // DEBUG
|
||||
jclass je = env->FindClass("org/opencv/core/CvException");
|
||||
if(!je) je = env->FindClass("java/lang/Exception");
|
||||
env->ThrowNew(je, e.what());
|
||||
return 0;
|
||||
} catch (...) {
|
||||
#ifdef DEBUG
|
||||
LOGD("highgui::VideoCapture_n_1open__JI() catched unknown exception (...)");
|
||||
#endif // DEBUG
|
||||
jclass je = env->FindClass("java/lang/Exception");
|
||||
env->ThrowNew(je, "Unknown exception in JNI code {highgui::VideoCapture_n_1open__JI()}");
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
//
|
||||
// bool VideoCapture::read(Mat image)
|
||||
//
|
||||
|
||||
JNIEXPORT jboolean JNICALL Java_org_opencv_highgui_VideoCapture_n_1read
|
||||
(JNIEnv* env, jclass, jlong self, jlong image_nativeObj);
|
||||
|
||||
JNIEXPORT jboolean JNICALL Java_org_opencv_highgui_VideoCapture_n_1read
|
||||
(JNIEnv* env, jclass, jlong self, jlong image_nativeObj)
|
||||
{
|
||||
try {
|
||||
#ifdef DEBUG
|
||||
LOGD("highgui::VideoCapture_n_1read()");
|
||||
#endif // DEBUG
|
||||
VideoCapture* me = (VideoCapture*) self; //TODO: check for NULL
|
||||
Mat& image = *((Mat*)image_nativeObj);
|
||||
bool _retval_ = me->read( image );
|
||||
|
||||
return _retval_;
|
||||
} catch(cv::Exception e) {
|
||||
#ifdef DEBUG
|
||||
LOGD("highgui::VideoCapture_n_1read() catched cv::Exception: %s", e.what());
|
||||
#endif // DEBUG
|
||||
jclass je = env->FindClass("org/opencv/core/CvException");
|
||||
if(!je) je = env->FindClass("java/lang/Exception");
|
||||
env->ThrowNew(je, e.what());
|
||||
return 0;
|
||||
} catch (...) {
|
||||
#ifdef DEBUG
|
||||
LOGD("highgui::VideoCapture_n_1read() catched unknown exception (...)");
|
||||
#endif // DEBUG
|
||||
jclass je = env->FindClass("java/lang/Exception");
|
||||
env->ThrowNew(je, "Unknown exception in JNI code {highgui::VideoCapture_n_1read()}");
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
//
|
||||
// void VideoCapture::release()
|
||||
//
|
||||
|
||||
JNIEXPORT void JNICALL Java_org_opencv_highgui_VideoCapture_n_1release
|
||||
(JNIEnv* env, jclass, jlong self);
|
||||
|
||||
JNIEXPORT void JNICALL Java_org_opencv_highgui_VideoCapture_n_1release
|
||||
(JNIEnv* env, jclass, jlong self)
|
||||
{
|
||||
try {
|
||||
#ifdef DEBUG
|
||||
LOGD("highgui::VideoCapture_n_1release()");
|
||||
#endif // DEBUG
|
||||
VideoCapture* me = (VideoCapture*) self; //TODO: check for NULL
|
||||
me->release( );
|
||||
|
||||
return;
|
||||
} catch(cv::Exception e) {
|
||||
#ifdef DEBUG
|
||||
LOGD("highgui::VideoCapture_n_1release() catched cv::Exception: %s", e.what());
|
||||
#endif // DEBUG
|
||||
jclass je = env->FindClass("org/opencv/core/CvException");
|
||||
if(!je) je = env->FindClass("java/lang/Exception");
|
||||
env->ThrowNew(je, e.what());
|
||||
return;
|
||||
} catch (...) {
|
||||
#ifdef DEBUG
|
||||
LOGD("highgui::VideoCapture_n_1release() catched unknown exception (...)");
|
||||
#endif // DEBUG
|
||||
jclass je = env->FindClass("java/lang/Exception");
|
||||
env->ThrowNew(je, "Unknown exception in JNI code {highgui::VideoCapture_n_1release()}");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
//
|
||||
// bool VideoCapture::retrieve(Mat image, int channel = 0)
|
||||
//
|
||||
|
||||
JNIEXPORT jboolean JNICALL Java_org_opencv_highgui_VideoCapture_n_1retrieve__JJI
|
||||
(JNIEnv* env, jclass, jlong self, jlong image_nativeObj, jint channel);
|
||||
|
||||
JNIEXPORT jboolean JNICALL Java_org_opencv_highgui_VideoCapture_n_1retrieve__JJI
|
||||
(JNIEnv* env, jclass, jlong self, jlong image_nativeObj, jint channel)
|
||||
{
|
||||
try {
|
||||
#ifdef DEBUG
|
||||
LOGD("highgui::VideoCapture_n_1retrieve__JJI()");
|
||||
#endif // DEBUG
|
||||
VideoCapture* me = (VideoCapture*) self; //TODO: check for NULL
|
||||
Mat& image = *((Mat*)image_nativeObj);
|
||||
bool _retval_ = me->retrieve( image, channel );
|
||||
|
||||
return _retval_;
|
||||
} catch(cv::Exception e) {
|
||||
#ifdef DEBUG
|
||||
LOGD("highgui::VideoCapture_n_1retrieve__JJI() catched cv::Exception: %s", e.what());
|
||||
#endif // DEBUG
|
||||
jclass je = env->FindClass("org/opencv/core/CvException");
|
||||
if(!je) je = env->FindClass("java/lang/Exception");
|
||||
env->ThrowNew(je, e.what());
|
||||
return 0;
|
||||
} catch (...) {
|
||||
#ifdef DEBUG
|
||||
LOGD("highgui::VideoCapture_n_1retrieve__JJI() catched unknown exception (...)");
|
||||
#endif // DEBUG
|
||||
jclass je = env->FindClass("java/lang/Exception");
|
||||
env->ThrowNew(je, "Unknown exception in JNI code {highgui::VideoCapture_n_1retrieve__JJI()}");
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
JNIEXPORT jboolean JNICALL Java_org_opencv_highgui_VideoCapture_n_1retrieve__JJ
|
||||
(JNIEnv* env, jclass, jlong self, jlong image_nativeObj);
|
||||
|
||||
JNIEXPORT jboolean JNICALL Java_org_opencv_highgui_VideoCapture_n_1retrieve__JJ
|
||||
(JNIEnv* env, jclass, jlong self, jlong image_nativeObj)
|
||||
{
|
||||
try {
|
||||
#ifdef DEBUG
|
||||
LOGD("highgui::VideoCapture_n_1retrieve__JJ()");
|
||||
#endif // DEBUG
|
||||
VideoCapture* me = (VideoCapture*) self; //TODO: check for NULL
|
||||
Mat& image = *((Mat*)image_nativeObj);
|
||||
bool _retval_ = me->retrieve( image );
|
||||
|
||||
return _retval_;
|
||||
} catch(cv::Exception e) {
|
||||
#ifdef DEBUG
|
||||
LOGD("highgui::VideoCapture_n_1retrieve__JJ() catched cv::Exception: %s", e.what());
|
||||
#endif // DEBUG
|
||||
jclass je = env->FindClass("org/opencv/core/CvException");
|
||||
if(!je) je = env->FindClass("java/lang/Exception");
|
||||
env->ThrowNew(je, e.what());
|
||||
return 0;
|
||||
} catch (...) {
|
||||
#ifdef DEBUG
|
||||
LOGD("highgui::VideoCapture_n_1retrieve__JJ() catched unknown exception (...)");
|
||||
#endif // DEBUG
|
||||
jclass je = env->FindClass("java/lang/Exception");
|
||||
env->ThrowNew(je, "Unknown exception in JNI code {highgui::VideoCapture_n_1retrieve__JJ()}");
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
//
|
||||
// bool VideoCapture::set(int propId, double value)
|
||||
//
|
||||
|
||||
JNIEXPORT jboolean JNICALL Java_org_opencv_highgui_VideoCapture_n_1set
|
||||
(JNIEnv* env, jclass, jlong self, jint propId, jdouble value);
|
||||
|
||||
JNIEXPORT jboolean JNICALL Java_org_opencv_highgui_VideoCapture_n_1set
|
||||
(JNIEnv* env, jclass, jlong self, jint propId, jdouble value)
|
||||
{
|
||||
try {
|
||||
#ifdef DEBUG
|
||||
LOGD("highgui::VideoCapture_n_1set()");
|
||||
#endif // DEBUG
|
||||
VideoCapture* me = (VideoCapture*) self; //TODO: check for NULL
|
||||
bool _retval_ = me->set( propId, value );
|
||||
|
||||
return _retval_;
|
||||
} catch(cv::Exception e) {
|
||||
#ifdef DEBUG
|
||||
LOGD("highgui::VideoCapture_n_1set() catched cv::Exception: %s", e.what());
|
||||
#endif // DEBUG
|
||||
jclass je = env->FindClass("org/opencv/core/CvException");
|
||||
if(!je) je = env->FindClass("java/lang/Exception");
|
||||
env->ThrowNew(je, e.what());
|
||||
return 0;
|
||||
} catch (...) {
|
||||
#ifdef DEBUG
|
||||
LOGD("highgui::VideoCapture_n_1set() catched unknown exception (...)");
|
||||
#endif // DEBUG
|
||||
jclass je = env->FindClass("java/lang/Exception");
|
||||
env->ThrowNew(je, "Unknown exception in JNI code {highgui::VideoCapture_n_1set()}");
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
JNIEXPORT jstring JNICALL Java_org_opencv_highgui_VideoCapture_n_1getSupportedPreviewSizes
|
||||
(JNIEnv *env, jclass, jlong self);
|
||||
|
||||
JNIEXPORT jstring JNICALL Java_org_opencv_highgui_VideoCapture_n_1getSupportedPreviewSizes
|
||||
(JNIEnv *env, jclass, jlong self)
|
||||
{
|
||||
try {
|
||||
#ifdef DEBUG
|
||||
LOGD("highgui::VideoCapture_n_1set()");
|
||||
#endif // DEBUG
|
||||
VideoCapture* me = (VideoCapture*) self; //TODO: check for NULL
|
||||
union {double prop; const char* name;} u;
|
||||
u.prop = me->get(CV_CAP_PROP_SUPPORTED_PREVIEW_SIZES_STRING);
|
||||
return env->NewStringUTF(u.name);
|
||||
} catch(cv::Exception e) {
|
||||
#ifdef DEBUG
|
||||
LOGD("highgui::VideoCapture_n_1getSupportedPreviewSizes() catched cv::Exception: %s", e.what());
|
||||
#endif // DEBUG
|
||||
jclass je = env->FindClass("org/opencv/core/CvException");
|
||||
if(!je) je = env->FindClass("java/lang/Exception");
|
||||
env->ThrowNew(je, e.what());
|
||||
return env->NewStringUTF("");
|
||||
} catch (...) {
|
||||
#ifdef DEBUG
|
||||
LOGD("highgui::VideoCapture_n_1getSupportedPreviewSizes() catched unknown exception (...)");
|
||||
#endif // DEBUG
|
||||
jclass je = env->FindClass("java/lang/Exception");
|
||||
env->ThrowNew(je, "Unknown exception in JNI code {highgui::VideoCapture_n_1getSupportedPreviewSizes()}");
|
||||
return env->NewStringUTF("");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
//
|
||||
// native support for java finalize()
|
||||
// static void VideoCapture::n_delete( __int64 self )
|
||||
//
|
||||
|
||||
JNIEXPORT void JNICALL Java_org_opencv_highgui_VideoCapture_n_1delete
|
||||
(JNIEnv*, jclass, jlong self);
|
||||
|
||||
JNIEXPORT void JNICALL Java_org_opencv_highgui_VideoCapture_n_1delete
|
||||
(JNIEnv*, jclass, jlong self)
|
||||
{
|
||||
delete (VideoCapture*) self;
|
||||
}
|
||||
|
||||
} // extern "C"
|
||||
|
||||
#endif // HAVE_OPENCV_HIGHGUI
|
442
modules/java/generator/src/cpp/converters.cpp
Normal file
442
modules/java/generator/src/cpp/converters.cpp
Normal file
@@ -0,0 +1,442 @@
|
||||
#include "converters.h"
|
||||
|
||||
#ifdef DEBUG
|
||||
#include <android/log.h>
|
||||
#define MODULE_LOG_TAG "OpenCV.converters"
|
||||
#define LOGD(...) ((void)__android_log_print(ANDROID_LOG_DEBUG, MODULE_LOG_TAG, __VA_ARGS__))
|
||||
#else //DEBUG
|
||||
#define LOGD(...)
|
||||
#endif //DEBUG
|
||||
|
||||
using namespace cv;
|
||||
|
||||
#define CHECK_MAT(cond) if(!(cond)){ LOGD("FAILED: " #cond); return; }
|
||||
|
||||
|
||||
// vector_int
|
||||
|
||||
void Mat_to_vector_int(Mat& mat, vector<int>& v_int)
|
||||
{
|
||||
v_int.clear();
|
||||
CHECK_MAT(mat.type()==CV_32SC1 && mat.cols==1);
|
||||
v_int = (vector<int>) mat;
|
||||
}
|
||||
|
||||
void vector_int_to_Mat(vector<int>& v_int, Mat& mat)
|
||||
{
|
||||
mat = Mat(v_int, true);
|
||||
}
|
||||
|
||||
|
||||
//vector_double
|
||||
|
||||
void Mat_to_vector_double(Mat& mat, vector<double>& v_double)
|
||||
{
|
||||
v_double.clear();
|
||||
CHECK_MAT(mat.type()==CV_64FC1 && mat.cols==1);
|
||||
v_double = (vector<double>) mat;
|
||||
}
|
||||
|
||||
void vector_double_to_Mat(vector<double>& v_double, Mat& mat)
|
||||
{
|
||||
mat = Mat(v_double, true);
|
||||
}
|
||||
|
||||
|
||||
// vector_float
|
||||
|
||||
void Mat_to_vector_float(Mat& mat, vector<float>& v_float)
|
||||
{
|
||||
v_float.clear();
|
||||
CHECK_MAT(mat.type()==CV_32FC1 && mat.cols==1);
|
||||
v_float = (vector<float>) mat;
|
||||
}
|
||||
|
||||
void vector_float_to_Mat(vector<float>& v_float, Mat& mat)
|
||||
{
|
||||
mat = Mat(v_float, true);
|
||||
}
|
||||
|
||||
|
||||
//vector_uchar
|
||||
|
||||
void Mat_to_vector_uchar(Mat& mat, vector<uchar>& v_uchar)
|
||||
{
|
||||
v_uchar.clear();
|
||||
CHECK_MAT(mat.type()==CV_8UC1 && mat.cols==1);
|
||||
v_uchar = (vector<uchar>) mat;
|
||||
}
|
||||
|
||||
void vector_uchar_to_Mat(vector<uchar>& v_uchar, Mat& mat)
|
||||
{
|
||||
mat = Mat(v_uchar, true);
|
||||
}
|
||||
|
||||
void Mat_to_vector_char(Mat& mat, vector<char>& v_char)
|
||||
{
|
||||
v_char.clear();
|
||||
CHECK_MAT(mat.type()==CV_8SC1 && mat.cols==1);
|
||||
v_char = (vector<char>) mat;
|
||||
}
|
||||
|
||||
void vector_char_to_Mat(vector<char>& v_char, Mat& mat)
|
||||
{
|
||||
mat = Mat(v_char, true);
|
||||
}
|
||||
|
||||
|
||||
//vector_Rect
|
||||
|
||||
void Mat_to_vector_Rect(Mat& mat, vector<Rect>& v_rect)
|
||||
{
|
||||
v_rect.clear();
|
||||
CHECK_MAT(mat.type()==CV_32SC4 && mat.cols==1);
|
||||
v_rect = (vector<Rect>) mat;
|
||||
}
|
||||
|
||||
void vector_Rect_to_Mat(vector<Rect>& v_rect, Mat& mat)
|
||||
{
|
||||
mat = Mat(v_rect, true);
|
||||
}
|
||||
|
||||
|
||||
//vector_Point
|
||||
void Mat_to_vector_Point(Mat& mat, vector<Point>& v_point)
|
||||
{
|
||||
v_point.clear();
|
||||
CHECK_MAT(mat.type()==CV_32SC2 && mat.cols==1);
|
||||
v_point = (vector<Point>) mat;
|
||||
}
|
||||
|
||||
//vector_Point2f
|
||||
void Mat_to_vector_Point2f(Mat& mat, vector<Point2f>& v_point)
|
||||
{
|
||||
v_point.clear();
|
||||
CHECK_MAT(mat.type()==CV_32FC2 && mat.cols==1);
|
||||
v_point = (vector<Point2f>) mat;
|
||||
}
|
||||
|
||||
//vector_Point2d
|
||||
void Mat_to_vector_Point2d(Mat& mat, vector<Point2d>& v_point)
|
||||
{
|
||||
v_point.clear();
|
||||
CHECK_MAT(mat.type()==CV_64FC2 && mat.cols==1);
|
||||
v_point = (vector<Point2d>) mat;
|
||||
}
|
||||
|
||||
|
||||
//vector_Point3i
|
||||
void Mat_to_vector_Point3i(Mat& mat, vector<Point3i>& v_point)
|
||||
{
|
||||
v_point.clear();
|
||||
CHECK_MAT(mat.type()==CV_32SC3 && mat.cols==1);
|
||||
v_point = (vector<Point3i>) mat;
|
||||
}
|
||||
|
||||
//vector_Point3f
|
||||
void Mat_to_vector_Point3f(Mat& mat, vector<Point3f>& v_point)
|
||||
{
|
||||
v_point.clear();
|
||||
CHECK_MAT(mat.type()==CV_32FC3 && mat.cols==1);
|
||||
v_point = (vector<Point3f>) mat;
|
||||
}
|
||||
|
||||
//vector_Point3d
|
||||
void Mat_to_vector_Point3d(Mat& mat, vector<Point3d>& v_point)
|
||||
{
|
||||
v_point.clear();
|
||||
CHECK_MAT(mat.type()==CV_64FC3 && mat.cols==1);
|
||||
v_point = (vector<Point3d>) mat;
|
||||
}
|
||||
|
||||
|
||||
void vector_Point_to_Mat(vector<Point>& v_point, Mat& mat)
|
||||
{
|
||||
mat = Mat(v_point, true);
|
||||
}
|
||||
|
||||
void vector_Point2f_to_Mat(vector<Point2f>& v_point, Mat& mat)
|
||||
{
|
||||
mat = Mat(v_point, true);
|
||||
}
|
||||
|
||||
void vector_Point2d_to_Mat(vector<Point2d>& v_point, Mat& mat)
|
||||
{
|
||||
mat = Mat(v_point, true);
|
||||
}
|
||||
|
||||
void vector_Point3i_to_Mat(vector<Point3i>& v_point, Mat& mat)
|
||||
{
|
||||
mat = Mat(v_point, true);
|
||||
}
|
||||
|
||||
void vector_Point3f_to_Mat(vector<Point3f>& v_point, Mat& mat)
|
||||
{
|
||||
mat = Mat(v_point, true);
|
||||
}
|
||||
|
||||
void vector_Point3d_to_Mat(vector<Point3d>& v_point, Mat& mat)
|
||||
{
|
||||
mat = Mat(v_point, true);
|
||||
}
|
||||
|
||||
#ifdef HAVE_OPENCV_FEATURES2D
|
||||
//vector_KeyPoint
|
||||
void Mat_to_vector_KeyPoint(Mat& mat, vector<KeyPoint>& v_kp)
|
||||
{
|
||||
v_kp.clear();
|
||||
CHECK_MAT(mat.type()==CV_32FC(7) && mat.cols==1);
|
||||
for(int i=0; i<mat.rows; i++)
|
||||
{
|
||||
Vec<float, 7> v = mat.at< Vec<float, 7> >(i, 0);
|
||||
KeyPoint kp(v[0], v[1], v[2], v[3], v[4], (int)v[5], (int)v[6]);
|
||||
v_kp.push_back(kp);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
void vector_KeyPoint_to_Mat(vector<KeyPoint>& v_kp, Mat& mat)
|
||||
{
|
||||
int count = v_kp.size();
|
||||
mat.create(count, 1, CV_32FC(7));
|
||||
for(int i=0; i<count; i++)
|
||||
{
|
||||
KeyPoint kp = v_kp[i];
|
||||
mat.at< Vec<float, 7> >(i, 0) = Vec<float, 7>(kp.pt.x, kp.pt.y, kp.size, kp.angle, kp.response, kp.octave, kp.class_id);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
//vector_Mat
|
||||
void Mat_to_vector_Mat(cv::Mat& mat, std::vector<cv::Mat>& v_mat)
|
||||
{
|
||||
v_mat.clear();
|
||||
if(mat.type() == CV_32SC2 && mat.cols == 1)
|
||||
{
|
||||
v_mat.reserve(mat.rows);
|
||||
for(int i=0; i<mat.rows; i++)
|
||||
{
|
||||
Vec<int, 2> a = mat.at< Vec<int, 2> >(i, 0);
|
||||
long long addr = (((long long)a[0])<<32) | a[1];
|
||||
Mat& m = *( (Mat*) addr );
|
||||
v_mat.push_back(m);
|
||||
}
|
||||
} else {
|
||||
LOGD("Mat_to_vector_Mat() FAILED: mat.type() == CV_32SC2 && mat.cols == 1");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void vector_Mat_to_Mat(std::vector<cv::Mat>& v_mat, cv::Mat& mat)
|
||||
{
|
||||
int count = v_mat.size();
|
||||
mat.create(count, 1, CV_32SC2);
|
||||
for(int i=0; i<count; i++)
|
||||
{
|
||||
long long addr = (long long) new Mat(v_mat[i]);
|
||||
mat.at< Vec<int, 2> >(i, 0) = Vec<int, 2>(addr>>32, addr&0xffffffff);
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef HAVE_OPENCV_FEATURES2D
|
||||
//vector_DMatch
|
||||
void Mat_to_vector_DMatch(Mat& mat, vector<DMatch>& v_dm)
|
||||
{
|
||||
v_dm.clear();
|
||||
CHECK_MAT(mat.type()==CV_32FC4 && mat.cols==1);
|
||||
for(int i=0; i<mat.rows; i++)
|
||||
{
|
||||
Vec<float, 4> v = mat.at< Vec<float, 4> >(i, 0);
|
||||
DMatch dm((int)v[0], (int)v[1], (int)v[2], v[3]);
|
||||
v_dm.push_back(dm);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
void vector_DMatch_to_Mat(vector<DMatch>& v_dm, Mat& mat)
|
||||
{
|
||||
int count = v_dm.size();
|
||||
mat.create(count, 1, CV_32FC4);
|
||||
for(int i=0; i<count; i++)
|
||||
{
|
||||
DMatch dm = v_dm[i];
|
||||
mat.at< Vec<float, 4> >(i, 0) = Vec<float, 4>(dm.queryIdx, dm.trainIdx, dm.imgIdx, dm.distance);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
void Mat_to_vector_vector_Point(Mat& mat, vector< vector< Point > >& vv_pt)
|
||||
{
|
||||
vector<Mat> vm;
|
||||
vm.reserve( mat.rows );
|
||||
Mat_to_vector_Mat(mat, vm);
|
||||
for(size_t i=0; i<vm.size(); i++)
|
||||
{
|
||||
vector<Point> vpt;
|
||||
Mat_to_vector_Point(vm[i], vpt);
|
||||
vv_pt.push_back(vpt);
|
||||
}
|
||||
}
|
||||
|
||||
void Mat_to_vector_vector_Point2f(Mat& mat, vector< vector< Point2f > >& vv_pt)
|
||||
{
|
||||
vector<Mat> vm;
|
||||
vm.reserve( mat.rows );
|
||||
Mat_to_vector_Mat(mat, vm);
|
||||
for(size_t i=0; i<vm.size(); i++)
|
||||
{
|
||||
vector<Point2f> vpt;
|
||||
Mat_to_vector_Point2f(vm[i], vpt);
|
||||
vv_pt.push_back(vpt);
|
||||
}
|
||||
}
|
||||
|
||||
void Mat_to_vector_vector_Point3f(Mat& mat, vector< vector< Point3f > >& vv_pt)
|
||||
{
|
||||
vector<Mat> vm;
|
||||
vm.reserve( mat.rows );
|
||||
Mat_to_vector_Mat(mat, vm);
|
||||
for(size_t i=0; i<vm.size(); i++)
|
||||
{
|
||||
vector<Point3f> vpt;
|
||||
Mat_to_vector_Point3f(vm[i], vpt);
|
||||
vv_pt.push_back(vpt);
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef HAVE_OPENCV_FEATURES2D
|
||||
void Mat_to_vector_vector_KeyPoint(Mat& mat, vector< vector< KeyPoint > >& vv_kp)
|
||||
{
|
||||
vector<Mat> vm;
|
||||
vm.reserve( mat.rows );
|
||||
Mat_to_vector_Mat(mat, vm);
|
||||
for(size_t i=0; i<vm.size(); i++)
|
||||
{
|
||||
vector<KeyPoint> vkp;
|
||||
Mat_to_vector_KeyPoint(vm[i], vkp);
|
||||
vv_kp.push_back(vkp);
|
||||
}
|
||||
}
|
||||
|
||||
void vector_vector_KeyPoint_to_Mat(vector< vector< KeyPoint > >& vv_kp, Mat& mat)
|
||||
{
|
||||
vector<Mat> vm;
|
||||
vm.reserve( vv_kp.size() );
|
||||
for(size_t i=0; i<vv_kp.size(); i++)
|
||||
{
|
||||
Mat m;
|
||||
vector_KeyPoint_to_Mat(vv_kp[i], m);
|
||||
vm.push_back(m);
|
||||
}
|
||||
vector_Mat_to_Mat(vm, mat);
|
||||
}
|
||||
|
||||
void Mat_to_vector_vector_DMatch(Mat& mat, vector< vector< DMatch > >& vv_dm)
|
||||
{
|
||||
vector<Mat> vm;
|
||||
vm.reserve( mat.rows );
|
||||
Mat_to_vector_Mat(mat, vm);
|
||||
for(size_t i=0; i<vm.size(); i++)
|
||||
{
|
||||
vector<DMatch> vdm;
|
||||
Mat_to_vector_DMatch(vm[i], vdm);
|
||||
vv_dm.push_back(vdm);
|
||||
}
|
||||
}
|
||||
|
||||
void vector_vector_DMatch_to_Mat(vector< vector< DMatch > >& vv_dm, Mat& mat)
|
||||
{
|
||||
vector<Mat> vm;
|
||||
vm.reserve( vv_dm.size() );
|
||||
for(size_t i=0; i<vv_dm.size(); i++)
|
||||
{
|
||||
Mat m;
|
||||
vector_DMatch_to_Mat(vv_dm[i], m);
|
||||
vm.push_back(m);
|
||||
}
|
||||
vector_Mat_to_Mat(vm, mat);
|
||||
}
|
||||
#endif
|
||||
|
||||
void Mat_to_vector_vector_char(Mat& mat, vector< vector< char > >& vv_ch)
|
||||
{
|
||||
vector<Mat> vm;
|
||||
vm.reserve( mat.rows );
|
||||
Mat_to_vector_Mat(mat, vm);
|
||||
for(size_t i=0; i<vm.size(); i++)
|
||||
{
|
||||
vector<char> vch;
|
||||
Mat_to_vector_char(vm[i], vch);
|
||||
vv_ch.push_back(vch);
|
||||
}
|
||||
}
|
||||
|
||||
void vector_vector_char_to_Mat(vector< vector< char > >& vv_ch, Mat& mat)
|
||||
{
|
||||
vector<Mat> vm;
|
||||
vm.reserve( vv_ch.size() );
|
||||
for(size_t i=0; i<vv_ch.size(); i++)
|
||||
{
|
||||
Mat m;
|
||||
vector_char_to_Mat(vv_ch[i], m);
|
||||
vm.push_back(m);
|
||||
}
|
||||
vector_Mat_to_Mat(vm, mat);
|
||||
}
|
||||
|
||||
void vector_vector_Point_to_Mat(vector< vector< Point > >& vv_pt, Mat& mat)
|
||||
{
|
||||
vector<Mat> vm;
|
||||
vm.reserve( vv_pt.size() );
|
||||
for(size_t i=0; i<vv_pt.size(); i++)
|
||||
{
|
||||
Mat m;
|
||||
vector_Point_to_Mat(vv_pt[i], m);
|
||||
vm.push_back(m);
|
||||
}
|
||||
vector_Mat_to_Mat(vm, mat);
|
||||
}
|
||||
|
||||
void vector_vector_Point2f_to_Mat(vector< vector< Point2f > >& vv_pt, Mat& mat)
|
||||
{
|
||||
vector<Mat> vm;
|
||||
vm.reserve( vv_pt.size() );
|
||||
for(size_t i=0; i<vv_pt.size(); i++)
|
||||
{
|
||||
Mat m;
|
||||
vector_Point2f_to_Mat(vv_pt[i], m);
|
||||
vm.push_back(m);
|
||||
}
|
||||
vector_Mat_to_Mat(vm, mat);
|
||||
}
|
||||
|
||||
void vector_vector_Point3f_to_Mat(vector< vector< Point3f > >& vv_pt, Mat& mat)
|
||||
{
|
||||
vector<Mat> vm;
|
||||
vm.reserve( vv_pt.size() );
|
||||
for(size_t i=0; i<vv_pt.size(); i++)
|
||||
{
|
||||
Mat m;
|
||||
vector_Point3f_to_Mat(vv_pt[i], m);
|
||||
vm.push_back(m);
|
||||
}
|
||||
vector_Mat_to_Mat(vm, mat);
|
||||
}
|
||||
|
||||
void vector_Vec4i_to_Mat(vector<Vec4i>& v_vec, Mat& mat)
|
||||
{
|
||||
mat = Mat(v_vec, true);
|
||||
}
|
||||
|
||||
void vector_Vec4f_to_Mat(vector<Vec4f>& v_vec, Mat& mat)
|
||||
{
|
||||
mat = Mat(v_vec, true);
|
||||
}
|
||||
|
||||
void vector_Vec6f_to_Mat(vector<Vec6f>& v_vec, Mat& mat)
|
||||
{
|
||||
mat = Mat(v_vec, true);
|
||||
}
|
73
modules/java/generator/src/cpp/converters.h
Normal file
73
modules/java/generator/src/cpp/converters.h
Normal file
@@ -0,0 +1,73 @@
|
||||
#include <jni.h>
|
||||
|
||||
#include "opencv2/opencv_modules.hpp"
|
||||
#include "opencv2/core/core.hpp"
|
||||
#include "features2d_manual.hpp"
|
||||
|
||||
void Mat_to_vector_int(cv::Mat& mat, std::vector<int>& v_int);
|
||||
void vector_int_to_Mat(std::vector<int>& v_int, cv::Mat& mat);
|
||||
|
||||
void Mat_to_vector_double(cv::Mat& mat, std::vector<double>& v_double);
|
||||
void vector_double_to_Mat(std::vector<double>& v_double, cv::Mat& mat);
|
||||
|
||||
void Mat_to_vector_float(cv::Mat& mat, std::vector<float>& v_float);
|
||||
void vector_float_to_Mat(std::vector<float>& v_float, cv::Mat& mat);
|
||||
|
||||
void Mat_to_vector_uchar(cv::Mat& mat, std::vector<uchar>& v_uchar);
|
||||
void vector_uchar_to_Mat(std::vector<uchar>& v_uchar, cv::Mat& mat);
|
||||
|
||||
void Mat_to_vector_char(cv::Mat& mat, std::vector<char>& v_char);
|
||||
void vector_char_to_Mat(std::vector<char>& v_char, cv::Mat& mat);
|
||||
|
||||
void Mat_to_vector_Rect(cv::Mat& mat, std::vector<cv::Rect>& v_rect);
|
||||
void vector_Rect_to_Mat(std::vector<cv::Rect>& v_rect, cv::Mat& mat);
|
||||
|
||||
|
||||
void Mat_to_vector_Point(cv::Mat& mat, std::vector<cv::Point>& v_point);
|
||||
void Mat_to_vector_Point2f(cv::Mat& mat, std::vector<cv::Point2f>& v_point);
|
||||
void Mat_to_vector_Point2d(cv::Mat& mat, std::vector<cv::Point2d>& v_point);
|
||||
void Mat_to_vector_Point3i(cv::Mat& mat, std::vector<cv::Point3i>& v_point);
|
||||
void Mat_to_vector_Point3f(cv::Mat& mat, std::vector<cv::Point3f>& v_point);
|
||||
void Mat_to_vector_Point3d(cv::Mat& mat, std::vector<cv::Point3d>& v_point);
|
||||
|
||||
void vector_Point_to_Mat(std::vector<cv::Point>& v_point, cv::Mat& mat);
|
||||
void vector_Point2f_to_Mat(std::vector<cv::Point2f>& v_point, cv::Mat& mat);
|
||||
void vector_Point2d_to_Mat(std::vector<cv::Point2d>& v_point, cv::Mat& mat);
|
||||
void vector_Point3i_to_Mat(std::vector<cv::Point3i>& v_point, cv::Mat& mat);
|
||||
void vector_Point3f_to_Mat(std::vector<cv::Point3f>& v_point, cv::Mat& mat);
|
||||
void vector_Point3d_to_Mat(std::vector<cv::Point3d>& v_point, cv::Mat& mat);
|
||||
|
||||
void vector_Vec4i_to_Mat(std::vector<cv::Vec4i>& v_vec, cv::Mat& mat);
|
||||
void vector_Vec4f_to_Mat(std::vector<cv::Vec4f>& v_vec, cv::Mat& mat);
|
||||
void vector_Vec6f_to_Mat(std::vector<cv::Vec6f>& v_vec, cv::Mat& mat);
|
||||
|
||||
#ifdef HAVE_OPENCV_FEATURES2D
|
||||
void Mat_to_vector_KeyPoint(cv::Mat& mat, std::vector<cv::KeyPoint>& v_kp);
|
||||
void vector_KeyPoint_to_Mat(std::vector<cv::KeyPoint>& v_kp, cv::Mat& mat);
|
||||
#endif
|
||||
|
||||
void Mat_to_vector_Mat(cv::Mat& mat, std::vector<cv::Mat>& v_mat);
|
||||
void vector_Mat_to_Mat(std::vector<cv::Mat>& v_mat, cv::Mat& mat);
|
||||
|
||||
#ifdef HAVE_OPENCV_FEATURES2D
|
||||
void Mat_to_vector_DMatch(cv::Mat& mat, std::vector<cv::DMatch>& v_dm);
|
||||
void vector_DMatch_to_Mat(std::vector<cv::DMatch>& v_dm, cv::Mat& mat);
|
||||
|
||||
void Mat_to_vector_vector_KeyPoint(cv::Mat& mat, std::vector< std::vector< cv::KeyPoint > >& vv_kp);
|
||||
void vector_vector_KeyPoint_to_Mat(std::vector< std::vector< cv::KeyPoint > >& vv_kp, cv::Mat& mat);
|
||||
|
||||
void Mat_to_vector_vector_DMatch(cv::Mat& mat, std::vector< std::vector< cv::DMatch > >& vv_dm);
|
||||
void vector_vector_DMatch_to_Mat(std::vector< std::vector< cv::DMatch > >& vv_dm, cv::Mat& mat);
|
||||
#endif
|
||||
|
||||
void Mat_to_vector_vector_char(cv::Mat& mat, std::vector< std::vector< char > >& vv_ch);
|
||||
void vector_vector_char_to_Mat(std::vector< std::vector< char > >& vv_ch, cv::Mat& mat);
|
||||
|
||||
void Mat_to_vector_vector_Point(cv::Mat& mat, std::vector< std::vector< cv::Point > >& vv_pt);
|
||||
void vector_vector_Point_to_Mat(std::vector< std::vector< cv::Point > >& vv_pt, cv::Mat& mat);
|
||||
|
||||
void Mat_to_vector_vector_Point2f(cv::Mat& mat, std::vector< std::vector< cv::Point2f > >& vv_pt);
|
||||
void vector_vector_Point2f_to_Mat(std::vector< std::vector< cv::Point2f > >& vv_pt, cv::Mat& mat);
|
||||
|
||||
void Mat_to_vector_vector_Point3f(cv::Mat& mat, std::vector< std::vector< cv::Point3f > >& vv_pt);
|
||||
void vector_vector_Point3f_to_Mat(std::vector< std::vector< cv::Point3f > >& vv_pt, cv::Mat& mat);
|
26
modules/java/generator/src/cpp/core_manual.hpp
Normal file
26
modules/java/generator/src/cpp/core_manual.hpp
Normal file
@@ -0,0 +1,26 @@
|
||||
#pragma once
|
||||
|
||||
#include "opencv2/core/core.hpp"
|
||||
|
||||
#if 0
|
||||
|
||||
namespace cv
|
||||
{
|
||||
CV_EXPORTS_W void add(InputArray src1, Scalar src2, OutputArray dst, InputArray mask=noArray(), int dtype=-1);
|
||||
|
||||
CV_EXPORTS_W void subtract(InputArray src1, Scalar src2, OutputArray dst, InputArray mask=noArray(), int dtype=-1);
|
||||
|
||||
CV_EXPORTS_W void multiply(InputArray src1, Scalar src2, OutputArray dst, double scale=1, int dtype=-1);
|
||||
|
||||
CV_EXPORTS_W void divide(InputArray src1, Scalar src2, OutputArray dst, double scale=1, int dtype=-1);
|
||||
|
||||
CV_EXPORTS_W void absdiff(InputArray src1, Scalar src2, OutputArray dst);
|
||||
|
||||
CV_EXPORTS_W void compare(InputArray src1, Scalar src2, OutputArray dst, int cmpop);
|
||||
|
||||
CV_EXPORTS_W void min(InputArray src1, Scalar src2, OutputArray dst);
|
||||
|
||||
CV_EXPORTS_W void max(InputArray src1, Scalar src2, OutputArray dst);
|
||||
|
||||
}
|
||||
#endif //0
|
454
modules/java/generator/src/cpp/features2d_manual.hpp
Normal file
454
modules/java/generator/src/cpp/features2d_manual.hpp
Normal file
@@ -0,0 +1,454 @@
|
||||
#ifndef __OPENCV_FEATURES_2D_MANUAL_HPP__
|
||||
#define __OPENCV_FEATURES_2D_MANUAL_HPP__
|
||||
|
||||
#include "opencv2/opencv_modules.hpp"
|
||||
|
||||
#ifdef HAVE_OPENCV_FEATURES2D
|
||||
#include "opencv2/features2d/features2d.hpp"
|
||||
|
||||
namespace cv
|
||||
{
|
||||
|
||||
class CV_EXPORTS_AS(FeatureDetector) javaFeatureDetector : public FeatureDetector
|
||||
{
|
||||
public:
|
||||
#if 0
|
||||
//DO NOT REMOVE! The block is required for sources parser
|
||||
CV_WRAP void detect( const Mat& image, CV_OUT vector<KeyPoint>& keypoints, const Mat& mask=Mat() ) const;
|
||||
CV_WRAP void detect( const vector<Mat>& images, CV_OUT vector<vector<KeyPoint> >& keypoints, const vector<Mat>& masks=vector<Mat>() ) const;
|
||||
CV_WRAP virtual bool empty() const;
|
||||
#endif
|
||||
|
||||
enum
|
||||
{
|
||||
FAST = 1,
|
||||
STAR = 2,
|
||||
SIFT = 3,
|
||||
SURF = 4,
|
||||
ORB = 5,
|
||||
MSER = 6,
|
||||
GFTT = 7,
|
||||
HARRIS = 8,
|
||||
SIMPLEBLOB = 9,
|
||||
DENSE = 10,
|
||||
|
||||
|
||||
GRIDRETECTOR = 1000,
|
||||
|
||||
GRID_FAST = GRIDRETECTOR + FAST,
|
||||
GRID_STAR = GRIDRETECTOR + STAR,
|
||||
GRID_SIFT = GRIDRETECTOR + SIFT,
|
||||
GRID_SURF = GRIDRETECTOR + SURF,
|
||||
GRID_ORB = GRIDRETECTOR + ORB,
|
||||
GRID_MSER = GRIDRETECTOR + MSER,
|
||||
GRID_GFTT = GRIDRETECTOR + GFTT,
|
||||
GRID_HARRIS = GRIDRETECTOR + HARRIS,
|
||||
GRID_SIMPLEBLOB = GRIDRETECTOR + SIMPLEBLOB,
|
||||
GRID_DENSE = GRIDRETECTOR + DENSE,
|
||||
|
||||
|
||||
PYRAMIDDETECTOR = 2000,
|
||||
|
||||
PYRAMID_FAST = PYRAMIDDETECTOR + FAST,
|
||||
PYRAMID_STAR = PYRAMIDDETECTOR + STAR,
|
||||
PYRAMID_SIFT = PYRAMIDDETECTOR + SIFT,
|
||||
PYRAMID_SURF = PYRAMIDDETECTOR + SURF,
|
||||
PYRAMID_ORB = PYRAMIDDETECTOR + ORB,
|
||||
PYRAMID_MSER = PYRAMIDDETECTOR + MSER,
|
||||
PYRAMID_GFTT = PYRAMIDDETECTOR + GFTT,
|
||||
PYRAMID_HARRIS = PYRAMIDDETECTOR + HARRIS,
|
||||
PYRAMID_SIMPLEBLOB = PYRAMIDDETECTOR + SIMPLEBLOB,
|
||||
PYRAMID_DENSE = PYRAMIDDETECTOR + DENSE,
|
||||
|
||||
DYNAMICDETECTOR = 3000,
|
||||
|
||||
DYNAMIC_FAST = DYNAMICDETECTOR + FAST,
|
||||
DYNAMIC_STAR = DYNAMICDETECTOR + STAR,
|
||||
DYNAMIC_SIFT = DYNAMICDETECTOR + SIFT,
|
||||
DYNAMIC_SURF = DYNAMICDETECTOR + SURF,
|
||||
DYNAMIC_ORB = DYNAMICDETECTOR + ORB,
|
||||
DYNAMIC_MSER = DYNAMICDETECTOR + MSER,
|
||||
DYNAMIC_GFTT = DYNAMICDETECTOR + GFTT,
|
||||
DYNAMIC_HARRIS = DYNAMICDETECTOR + HARRIS,
|
||||
DYNAMIC_SIMPLEBLOB = DYNAMICDETECTOR + SIMPLEBLOB,
|
||||
DYNAMIC_DENSE = DYNAMICDETECTOR + DENSE
|
||||
};
|
||||
|
||||
//supported: FAST STAR SIFT SURF ORB MSER GFTT HARRIS Grid(XXXX) Pyramid(XXXX) Dynamic(XXXX)
|
||||
//not supported: SimpleBlob, Dense
|
||||
CV_WRAP static javaFeatureDetector* create( int detectorType )
|
||||
{
|
||||
string name;
|
||||
if (detectorType > DYNAMICDETECTOR)
|
||||
{
|
||||
name = "Dynamic";
|
||||
detectorType -= DYNAMICDETECTOR;
|
||||
}
|
||||
if (detectorType > PYRAMIDDETECTOR)
|
||||
{
|
||||
name = "Pyramid";
|
||||
detectorType -= PYRAMIDDETECTOR;
|
||||
}
|
||||
if (detectorType > GRIDRETECTOR)
|
||||
{
|
||||
name = "Grid";
|
||||
detectorType -= GRIDRETECTOR;
|
||||
}
|
||||
|
||||
switch(detectorType)
|
||||
{
|
||||
case FAST:
|
||||
name += "FAST";
|
||||
break;
|
||||
case STAR:
|
||||
name += "STAR";
|
||||
break;
|
||||
case SIFT:
|
||||
name += "SIFT";
|
||||
break;
|
||||
case SURF:
|
||||
name += "SURF";
|
||||
break;
|
||||
case ORB:
|
||||
name += "ORB";
|
||||
break;
|
||||
case MSER:
|
||||
name += "MSER";
|
||||
break;
|
||||
case GFTT:
|
||||
name += "GFTT";
|
||||
break;
|
||||
case HARRIS:
|
||||
name += "HARRIS";
|
||||
break;
|
||||
case SIMPLEBLOB:
|
||||
name += "SimpleBlob";
|
||||
break;
|
||||
case DENSE:
|
||||
name += "Dense";
|
||||
break;
|
||||
default:
|
||||
CV_Error( CV_StsBadArg, "Specified feature detector type is not supported." );
|
||||
break;
|
||||
}
|
||||
|
||||
Ptr<FeatureDetector> detector = FeatureDetector::create(name);
|
||||
detector.addref();
|
||||
return (javaFeatureDetector*)((FeatureDetector*) detector);
|
||||
}
|
||||
|
||||
CV_WRAP void write( const string& fileName ) const
|
||||
{
|
||||
FileStorage fs(fileName, FileStorage::WRITE);
|
||||
((FeatureDetector*)this)->write(fs);
|
||||
fs.release();
|
||||
}
|
||||
|
||||
CV_WRAP void read( const string& fileName )
|
||||
{
|
||||
FileStorage fs(fileName, FileStorage::READ);
|
||||
((FeatureDetector*)this)->read(fs.root());
|
||||
fs.release();
|
||||
}
|
||||
};
|
||||
|
||||
class CV_EXPORTS_AS(DescriptorMatcher) javaDescriptorMatcher : public DescriptorMatcher
|
||||
{
|
||||
public:
|
||||
#if 0
|
||||
//DO NOT REMOVE! The block is required for sources parser
|
||||
CV_WRAP virtual bool isMaskSupported() const;
|
||||
CV_WRAP virtual void add( const vector<Mat>& descriptors );
|
||||
CV_WRAP const vector<Mat>& getTrainDescriptors() const;
|
||||
CV_WRAP virtual void clear();
|
||||
CV_WRAP virtual bool empty() const;
|
||||
CV_WRAP virtual void train();
|
||||
CV_WRAP void match( const Mat& queryDescriptors, const Mat& trainDescriptors,
|
||||
CV_OUT vector<DMatch>& matches, const Mat& mask=Mat() ) const;
|
||||
CV_WRAP void knnMatch( const Mat& queryDescriptors, const Mat& trainDescriptors,
|
||||
CV_OUT vector<vector<DMatch> >& matches, int k,
|
||||
const Mat& mask=Mat(), bool compactResult=false ) const;
|
||||
CV_WRAP void radiusMatch( const Mat& queryDescriptors, const Mat& trainDescriptors,
|
||||
CV_OUT vector<vector<DMatch> >& matches, float maxDistance,
|
||||
const Mat& mask=Mat(), bool compactResult=false ) const;
|
||||
CV_WRAP void match( const Mat& queryDescriptors, CV_OUT vector<DMatch>& matches,
|
||||
const vector<Mat>& masks=vector<Mat>() );
|
||||
CV_WRAP void knnMatch( const Mat& queryDescriptors, CV_OUT vector<vector<DMatch> >& matches, int k,
|
||||
const vector<Mat>& masks=vector<Mat>(), bool compactResult=false );
|
||||
CV_WRAP void radiusMatch( const Mat& queryDescriptors, CV_OUT vector<vector<DMatch> >& matches, float maxDistance,
|
||||
const vector<Mat>& masks=vector<Mat>(), bool compactResult=false );
|
||||
#endif
|
||||
|
||||
enum
|
||||
{
|
||||
FLANNBASED = 1,
|
||||
BRUTEFORCE = 2,
|
||||
BRUTEFORCE_L1 = 3,
|
||||
BRUTEFORCE_HAMMING = 4,
|
||||
BRUTEFORCE_HAMMINGLUT = 5,
|
||||
BRUTEFORCE_SL2 = 6
|
||||
};
|
||||
|
||||
CV_WRAP_AS(clone) javaDescriptorMatcher* jclone( bool emptyTrainData=false ) const
|
||||
{
|
||||
Ptr<DescriptorMatcher> matcher = this->clone(emptyTrainData);
|
||||
matcher.addref();
|
||||
return (javaDescriptorMatcher*)((DescriptorMatcher*) matcher);
|
||||
}
|
||||
|
||||
//supported: FlannBased, BruteForce, BruteForce-L1, BruteForce-Hamming, BruteForce-HammingLUT
|
||||
CV_WRAP static javaDescriptorMatcher* create( int matcherType )
|
||||
{
|
||||
string name;
|
||||
|
||||
switch(matcherType)
|
||||
{
|
||||
case FLANNBASED:
|
||||
name = "FlannBased";
|
||||
break;
|
||||
case BRUTEFORCE:
|
||||
name = "BruteForce";
|
||||
break;
|
||||
case BRUTEFORCE_L1:
|
||||
name = "BruteForce-L1";
|
||||
break;
|
||||
case BRUTEFORCE_HAMMING:
|
||||
name = "BruteForce-Hamming";
|
||||
break;
|
||||
case BRUTEFORCE_HAMMINGLUT:
|
||||
name = "BruteForce-HammingLUT";
|
||||
break;
|
||||
case BRUTEFORCE_SL2:
|
||||
name = "BruteForce-SL2";
|
||||
break;
|
||||
default:
|
||||
CV_Error( CV_StsBadArg, "Specified descriptor matcher type is not supported." );
|
||||
break;
|
||||
}
|
||||
|
||||
Ptr<DescriptorMatcher> matcher = DescriptorMatcher::create(name);
|
||||
matcher.addref();
|
||||
return (javaDescriptorMatcher*)((DescriptorMatcher*) matcher);
|
||||
}
|
||||
|
||||
CV_WRAP void write( const string& fileName ) const
|
||||
{
|
||||
FileStorage fs(fileName, FileStorage::WRITE);
|
||||
((DescriptorMatcher*)this)->write(fs);
|
||||
fs.release();
|
||||
}
|
||||
|
||||
CV_WRAP void read( const string& fileName )
|
||||
{
|
||||
FileStorage fs(fileName, FileStorage::READ);
|
||||
((DescriptorMatcher*)this)->read(fs.root());
|
||||
fs.release();
|
||||
}
|
||||
};
|
||||
|
||||
class CV_EXPORTS_AS(DescriptorExtractor) javaDescriptorExtractor : public DescriptorExtractor
|
||||
{
|
||||
public:
|
||||
#if 0
|
||||
//DO NOT REMOVE! The block is required for sources parser
|
||||
CV_WRAP void compute( const Mat& image, vector<KeyPoint>& keypoints, Mat& descriptors ) const;
|
||||
CV_WRAP void compute( const vector<Mat>& images, vector<vector<KeyPoint> >& keypoints, CV_OUT vector<Mat>& descriptors ) const;
|
||||
CV_WRAP virtual int descriptorSize() const;
|
||||
CV_WRAP virtual int descriptorType() const;
|
||||
|
||||
CV_WRAP virtual bool empty() const;
|
||||
#endif
|
||||
|
||||
enum
|
||||
{
|
||||
SIFT = 1,
|
||||
SURF = 2,
|
||||
ORB = 3,
|
||||
BRIEF = 4,
|
||||
|
||||
|
||||
OPPONENTEXTRACTOR = 1000,
|
||||
|
||||
|
||||
|
||||
OPPONENT_SIFT = OPPONENTEXTRACTOR + SIFT,
|
||||
OPPONENT_SURF = OPPONENTEXTRACTOR + SURF,
|
||||
OPPONENT_ORB = OPPONENTEXTRACTOR + ORB,
|
||||
OPPONENT_BRIEF = OPPONENTEXTRACTOR + BRIEF
|
||||
};
|
||||
|
||||
//supported SIFT, SURF, ORB, BRIEF, Opponent(XXXX)
|
||||
//not supported: Calonder
|
||||
CV_WRAP static javaDescriptorExtractor* create( int extractorType )
|
||||
{
|
||||
string name;
|
||||
|
||||
if (extractorType > OPPONENTEXTRACTOR)
|
||||
{
|
||||
name = "Opponent";
|
||||
extractorType -= OPPONENTEXTRACTOR;
|
||||
}
|
||||
|
||||
switch(extractorType)
|
||||
{
|
||||
case SIFT:
|
||||
name += "SIFT";
|
||||
break;
|
||||
case SURF:
|
||||
name += "SURF";
|
||||
break;
|
||||
case ORB:
|
||||
name += "ORB";
|
||||
break;
|
||||
case BRIEF:
|
||||
name += "BRIEF";
|
||||
break;
|
||||
default:
|
||||
CV_Error( CV_StsBadArg, "Specified descriptor extractor type is not supported." );
|
||||
break;
|
||||
}
|
||||
|
||||
Ptr<DescriptorExtractor> extractor = DescriptorExtractor::create(name);
|
||||
extractor.addref();
|
||||
return (javaDescriptorExtractor*)((DescriptorExtractor*) extractor);
|
||||
}
|
||||
|
||||
CV_WRAP void write( const string& fileName ) const
|
||||
{
|
||||
FileStorage fs(fileName, FileStorage::WRITE);
|
||||
((DescriptorExtractor*)this)->write(fs);
|
||||
fs.release();
|
||||
}
|
||||
|
||||
CV_WRAP void read( const string& fileName )
|
||||
{
|
||||
FileStorage fs(fileName, FileStorage::READ);
|
||||
((DescriptorExtractor*)this)->read(fs.root());
|
||||
fs.release();
|
||||
}
|
||||
};
|
||||
|
||||
class CV_EXPORTS_AS(GenericDescriptorMatcher) javaGenericDescriptorMatcher : public GenericDescriptorMatcher
|
||||
{
|
||||
public:
|
||||
#if 0
|
||||
//DO NOT REMOVE! The block is required for sources parser
|
||||
CV_WRAP virtual void add( const vector<Mat>& images,
|
||||
vector<vector<KeyPoint> >& keypoints );
|
||||
CV_WRAP const vector<Mat>& getTrainImages() const;
|
||||
CV_WRAP const vector<vector<KeyPoint> >& getTrainKeypoints() const;
|
||||
CV_WRAP virtual void clear();
|
||||
CV_WRAP virtual bool isMaskSupported();
|
||||
CV_WRAP virtual void train();
|
||||
CV_WRAP void classify( const Mat& queryImage, CV_IN_OUT vector<KeyPoint>& queryKeypoints,
|
||||
const Mat& trainImage, vector<KeyPoint>& trainKeypoints ) const;
|
||||
CV_WRAP void classify( const Mat& queryImage, CV_IN_OUT vector<KeyPoint>& queryKeypoints );
|
||||
CV_WRAP void match( const Mat& queryImage, vector<KeyPoint>& queryKeypoints,
|
||||
const Mat& trainImage, vector<KeyPoint>& trainKeypoints,
|
||||
CV_OUT vector<DMatch>& matches, const Mat& mask=Mat() ) const;
|
||||
CV_WRAP void knnMatch( const Mat& queryImage, vector<KeyPoint>& queryKeypoints,
|
||||
const Mat& trainImage, vector<KeyPoint>& trainKeypoints,
|
||||
CV_OUT vector<vector<DMatch> >& matches, int k,
|
||||
const Mat& mask=Mat(), bool compactResult=false ) const;
|
||||
CV_WRAP void radiusMatch( const Mat& queryImage, vector<KeyPoint>& queryKeypoints,
|
||||
const Mat& trainImage, vector<KeyPoint>& trainKeypoints,
|
||||
CV_OUT vector<vector<DMatch> >& matches, float maxDistance,
|
||||
const Mat& mask=Mat(), bool compactResult=false ) const;
|
||||
CV_WRAP void match( const Mat& queryImage, vector<KeyPoint>& queryKeypoints,
|
||||
CV_OUT vector<DMatch>& matches, const vector<Mat>& masks=vector<Mat>() );
|
||||
CV_WRAP void knnMatch( const Mat& queryImage, vector<KeyPoint>& queryKeypoints,
|
||||
CV_OUT vector<vector<DMatch> >& matches, int k,
|
||||
const vector<Mat>& masks=vector<Mat>(), bool compactResult=false );
|
||||
CV_WRAP void radiusMatch( const Mat& queryImage, vector<KeyPoint>& queryKeypoints,
|
||||
CV_OUT vector<vector<DMatch> >& matches, float maxDistance,
|
||||
const vector<Mat>& masks=vector<Mat>(), bool compactResult=false );
|
||||
CV_WRAP virtual bool empty() const;
|
||||
#endif
|
||||
|
||||
enum
|
||||
{
|
||||
ONEWAY = 1,
|
||||
FERN = 2
|
||||
};
|
||||
|
||||
CV_WRAP_AS(clone) javaGenericDescriptorMatcher* jclone( bool emptyTrainData=false ) const
|
||||
{
|
||||
Ptr<GenericDescriptorMatcher> matcher = this->clone(emptyTrainData);
|
||||
matcher.addref();
|
||||
return (javaGenericDescriptorMatcher*)((GenericDescriptorMatcher*) matcher);
|
||||
}
|
||||
|
||||
//supported: OneWay, Fern
|
||||
//unsupported: Vector
|
||||
CV_WRAP static javaGenericDescriptorMatcher* create( int matcherType )
|
||||
{
|
||||
string name;
|
||||
|
||||
switch(matcherType)
|
||||
{
|
||||
case ONEWAY:
|
||||
name = "ONEWAY";
|
||||
break;
|
||||
case FERN:
|
||||
name = "FERN";
|
||||
break;
|
||||
default:
|
||||
CV_Error( CV_StsBadArg, "Specified generic descriptor matcher type is not supported." );
|
||||
break;
|
||||
}
|
||||
|
||||
Ptr<GenericDescriptorMatcher> matcher = GenericDescriptorMatcher::create(name);
|
||||
matcher.addref();
|
||||
return (javaGenericDescriptorMatcher*)((GenericDescriptorMatcher*) matcher);
|
||||
}
|
||||
|
||||
CV_WRAP void write( const string& fileName ) const
|
||||
{
|
||||
FileStorage fs(fileName, FileStorage::WRITE);
|
||||
((GenericDescriptorMatcher*)this)->write(fs);
|
||||
fs.release();
|
||||
}
|
||||
|
||||
CV_WRAP void read( const string& fileName )
|
||||
{
|
||||
FileStorage fs(fileName, FileStorage::READ);
|
||||
((GenericDescriptorMatcher*)this)->read(fs.root());
|
||||
fs.release();
|
||||
}
|
||||
};
|
||||
|
||||
#if 0
|
||||
//DO NOT REMOVE! The block is required for sources parser
|
||||
enum
|
||||
{
|
||||
DRAW_OVER_OUTIMG = 1, // Output image matrix will not be created (Mat::create).
|
||||
// Matches will be drawn on existing content of output image.
|
||||
NOT_DRAW_SINGLE_POINTS = 2, // Single keypoints will not be drawn.
|
||||
DRAW_RICH_KEYPOINTS = 4 // For each keypoint the circle around keypoint with keypoint size and
|
||||
// orientation will be drawn.
|
||||
};
|
||||
|
||||
// Draw keypoints.
|
||||
CV_EXPORTS_W void drawKeypoints( const Mat& image, const vector<KeyPoint>& keypoints, Mat& outImage,
|
||||
const Scalar& color=Scalar::all(-1), int flags=0 );
|
||||
|
||||
// Draws matches of keypints from two images on output image.
|
||||
CV_EXPORTS_W void drawMatches( const Mat& img1, const vector<KeyPoint>& keypoints1,
|
||||
const Mat& img2, const vector<KeyPoint>& keypoints2,
|
||||
const vector<DMatch>& matches1to2, Mat& outImg,
|
||||
const Scalar& matchColor=Scalar::all(-1), const Scalar& singlePointColor=Scalar::all(-1),
|
||||
const vector<char>& matchesMask=vector<char>(), int flags=0 );
|
||||
|
||||
CV_EXPORTS_AS(drawMatches2) void drawMatches( const Mat& img1, const vector<KeyPoint>& keypoints1,
|
||||
const Mat& img2, const vector<KeyPoint>& keypoints2,
|
||||
const vector<vector<DMatch> >& matches1to2, Mat& outImg,
|
||||
const Scalar& matchColor=Scalar::all(-1), const Scalar& singlePointColor=Scalar::all(-1),
|
||||
const vector<vector<char> >& matchesMask=vector<vector<char> >(), int flags=0);
|
||||
|
||||
#endif
|
||||
|
||||
} //cv
|
||||
|
||||
#endif // HAVE_OPENCV_FEATURES2D
|
||||
|
||||
#endif // __OPENCV_FEATURES_2D_MANUAL_HPP__
|
59
modules/java/generator/src/cpp/jni_part.cpp
Normal file
59
modules/java/generator/src/cpp/jni_part.cpp
Normal file
@@ -0,0 +1,59 @@
|
||||
#include <jni.h>
|
||||
|
||||
#include "opencv2/opencv_modules.hpp"
|
||||
|
||||
#ifdef HAVE_OPENCV_NONFREE
|
||||
# include "opencv2/nonfree/nonfree.hpp"
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_OPENCV_FEATURES2D
|
||||
# include "opencv2/features2d/features2d.hpp"
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_OPENCV_VIDEO
|
||||
# include "opencv2/video/video.hpp"
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_OPENCV_ML
|
||||
# include "opencv2/ml/ml.hpp"
|
||||
#endif
|
||||
|
||||
extern "C" {
|
||||
|
||||
JNIEXPORT jint JNICALL
|
||||
JNI_OnLoad(JavaVM* vm, void* )
|
||||
{
|
||||
JNIEnv* env;
|
||||
if (vm->GetEnv((void**) &env, JNI_VERSION_1_6) != JNI_OK)
|
||||
return -1;
|
||||
|
||||
bool init = true;
|
||||
#ifdef HAVE_OPENCV_NONFREE
|
||||
init &= cv::initModule_nonfree();
|
||||
#endif
|
||||
#ifdef HAVE_OPENCV_FEATURES2D
|
||||
init &= cv::initModule_features2d();
|
||||
#endif
|
||||
#ifdef HAVE_OPENCV_VIDEO
|
||||
init &= cv::initModule_video();
|
||||
#endif
|
||||
#ifdef HAVE_OPENCV_ML
|
||||
init &= cv::initModule_ml();
|
||||
#endif
|
||||
|
||||
if(!init)
|
||||
return -1;
|
||||
|
||||
/* get class with (*env)->FindClass */
|
||||
/* register methods with (*env)->RegisterNatives */
|
||||
|
||||
return JNI_VERSION_1_6;
|
||||
}
|
||||
|
||||
JNIEXPORT void JNICALL
|
||||
JNI_OnUnload(JavaVM*, void*)
|
||||
{
|
||||
//do nothing
|
||||
}
|
||||
|
||||
} // extern "C"
|
144
modules/java/generator/src/cpp/utils.cpp
Normal file
144
modules/java/generator/src/cpp/utils.cpp
Normal file
@@ -0,0 +1,144 @@
|
||||
#include <jni.h>
|
||||
|
||||
#include "opencv2/core/core.hpp"
|
||||
#include "opencv2/imgproc/imgproc.hpp"
|
||||
|
||||
#include <android/bitmap.h>
|
||||
|
||||
#include <android/log.h>
|
||||
#define LOG_TAG "org.opencv.android.Utils"
|
||||
#define LOGE(...) ((void)__android_log_print(ANDROID_LOG_ERROR, LOG_TAG, __VA_ARGS__))
|
||||
#ifdef DEBUG
|
||||
#define LOGD(...) ((void)__android_log_print(ANDROID_LOG_DEBUG, LOG_TAG, __VA_ARGS__))
|
||||
#else //!DEBUG
|
||||
#define LOGD(...)
|
||||
#endif //DEBUG
|
||||
|
||||
using namespace cv;
|
||||
|
||||
|
||||
extern "C" {
|
||||
|
||||
/*
|
||||
* Class: org_opencv_android_Utils
|
||||
* Method: void nBitmapToMat(Bitmap b, long m_addr)
|
||||
*/
|
||||
|
||||
JNIEXPORT void JNICALL Java_org_opencv_android_Utils_nBitmapToMat
|
||||
(JNIEnv * env, jclass, jobject bitmap, jlong m_addr);
|
||||
|
||||
JNIEXPORT void JNICALL Java_org_opencv_android_Utils_nBitmapToMat
|
||||
(JNIEnv * env, jclass, jobject bitmap, jlong m_addr)
|
||||
{
|
||||
AndroidBitmapInfo info;
|
||||
void* pixels = 0;
|
||||
Mat& dst = *((Mat*)m_addr);
|
||||
|
||||
try {
|
||||
LOGD("nBitmapToMat");
|
||||
CV_Assert( AndroidBitmap_getInfo(env, bitmap, &info) >= 0 );
|
||||
CV_Assert( info.format == ANDROID_BITMAP_FORMAT_RGBA_8888 ||
|
||||
info.format == ANDROID_BITMAP_FORMAT_RGB_565 );
|
||||
CV_Assert( AndroidBitmap_lockPixels(env, bitmap, &pixels) >= 0 );
|
||||
CV_Assert( pixels );
|
||||
dst.create(info.height, info.width, CV_8UC4);
|
||||
if( info.format == ANDROID_BITMAP_FORMAT_RGBA_8888 )
|
||||
{
|
||||
LOGD("nBitmapToMat: RGBA_8888 -> CV_8UC4");
|
||||
Mat tmp(info.height, info.width, CV_8UC4, pixels);
|
||||
tmp.copyTo(dst);
|
||||
} else {
|
||||
// info.format == ANDROID_BITMAP_FORMAT_RGB_565
|
||||
LOGD("nBitmapToMat: RGB_565 -> CV_8UC4");
|
||||
Mat tmp(info.height, info.width, CV_8UC2, pixels);
|
||||
cvtColor(tmp, dst, CV_BGR5652RGBA);
|
||||
}
|
||||
AndroidBitmap_unlockPixels(env, bitmap);
|
||||
return;
|
||||
} catch(cv::Exception e) {
|
||||
AndroidBitmap_unlockPixels(env, bitmap);
|
||||
LOGE("nBitmapToMat catched cv::Exception: %s", e.what());
|
||||
jclass je = env->FindClass("org/opencv/core/CvException");
|
||||
if(!je) je = env->FindClass("java/lang/Exception");
|
||||
env->ThrowNew(je, e.what());
|
||||
return;
|
||||
} catch (...) {
|
||||
AndroidBitmap_unlockPixels(env, bitmap);
|
||||
LOGE("nBitmapToMat catched unknown exception (...)");
|
||||
jclass je = env->FindClass("java/lang/Exception");
|
||||
env->ThrowNew(je, "Unknown exception in JNI code {nBitmapToMat}");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Class: org_opencv_android_Utils
|
||||
* Method: void nMatToBitmap(long m_addr, Bitmap b)
|
||||
*/
|
||||
JNIEXPORT void JNICALL Java_org_opencv_android_Utils_nMatToBitmap
|
||||
(JNIEnv * env, jclass, jlong m_addr, jobject bitmap);
|
||||
|
||||
JNIEXPORT void JNICALL Java_org_opencv_android_Utils_nMatToBitmap
|
||||
(JNIEnv * env, jclass, jlong m_addr, jobject bitmap)
|
||||
{
|
||||
AndroidBitmapInfo info;
|
||||
void* pixels = 0;
|
||||
Mat& dst = *((Mat*)m_addr);
|
||||
|
||||
try {
|
||||
LOGD("nMatToBitmap");
|
||||
CV_Assert( AndroidBitmap_getInfo(env, bitmap, &info) >= 0 );
|
||||
CV_Assert( info.format == ANDROID_BITMAP_FORMAT_RGBA_8888 ||
|
||||
info.format == ANDROID_BITMAP_FORMAT_RGB_565 );
|
||||
CV_Assert( dst.dims == 2 && info.height == (uint32_t)dst.rows && info.width == (uint32_t)dst.cols );
|
||||
CV_Assert( dst.type() == CV_8UC1 || dst.type() == CV_8UC3 || dst.type() == CV_8UC4 );
|
||||
CV_Assert( AndroidBitmap_lockPixels(env, bitmap, &pixels) >= 0 );
|
||||
CV_Assert( pixels );
|
||||
if( info.format == ANDROID_BITMAP_FORMAT_RGBA_8888 )
|
||||
{
|
||||
Mat tmp(info.height, info.width, CV_8UC4, pixels);
|
||||
if(dst.type() == CV_8UC1)
|
||||
{
|
||||
LOGD("nMatToBitmap: CV_8UC1 -> RGBA_8888");
|
||||
cvtColor(dst, tmp, CV_GRAY2RGBA);
|
||||
} else if(dst.type() == CV_8UC3){
|
||||
LOGD("nMatToBitmap: CV_8UC3 -> RGBA_8888");
|
||||
cvtColor(dst, tmp, CV_RGB2RGBA);
|
||||
} else if(dst.type() == CV_8UC4){
|
||||
LOGD("nMatToBitmap: CV_8UC4 -> RGBA_8888");
|
||||
dst.copyTo(tmp);
|
||||
}
|
||||
} else {
|
||||
// info.format == ANDROID_BITMAP_FORMAT_RGB_565
|
||||
Mat tmp(info.height, info.width, CV_8UC2, pixels);
|
||||
if(dst.type() == CV_8UC1)
|
||||
{
|
||||
LOGD("nMatToBitmap: CV_8UC1 -> RGB_565");
|
||||
cvtColor(dst, tmp, CV_GRAY2BGR565);
|
||||
} else if(dst.type() == CV_8UC3){
|
||||
LOGD("nMatToBitmap: CV_8UC3 -> RGB_565");
|
||||
cvtColor(dst, tmp, CV_RGB2BGR565);
|
||||
} else if(dst.type() == CV_8UC4){
|
||||
LOGD("nMatToBitmap: CV_8UC4 -> RGB_565");
|
||||
cvtColor(dst, tmp, CV_RGBA2BGR565);
|
||||
}
|
||||
}
|
||||
AndroidBitmap_unlockPixels(env, bitmap);
|
||||
return;
|
||||
} catch(cv::Exception e) {
|
||||
AndroidBitmap_unlockPixels(env, bitmap);
|
||||
LOGE("nMatToBitmap catched cv::Exception: %s", e.what());
|
||||
jclass je = env->FindClass("org/opencv/core/CvException");
|
||||
if(!je) je = env->FindClass("java/lang/Exception");
|
||||
env->ThrowNew(je, e.what());
|
||||
return;
|
||||
} catch (...) {
|
||||
AndroidBitmap_unlockPixels(env, bitmap);
|
||||
LOGE("nMatToBitmap catched unknown exception (...)");
|
||||
jclass je = env->FindClass("java/lang/Exception");
|
||||
env->ThrowNew(je, "Unknown exception in JNI code {nMatToBitmap}");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
} // extern "C"
|
124
modules/java/generator/src/java/android+Utils.java
Normal file
124
modules/java/generator/src/java/android+Utils.java
Normal file
@@ -0,0 +1,124 @@
|
||||
package org.opencv.android;
|
||||
|
||||
import android.content.Context;
|
||||
import android.graphics.Bitmap;
|
||||
|
||||
import org.opencv.core.CvException;
|
||||
import org.opencv.core.CvType;
|
||||
import org.opencv.core.Mat;
|
||||
import org.opencv.highgui.Highgui;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
|
||||
public class Utils {
|
||||
|
||||
public static String exportResource(Context context, int resourceId) {
|
||||
return exportResource(context, resourceId, "OpenCV_data");
|
||||
}
|
||||
|
||||
public static String exportResource(Context context, int resourceId, String dirname) {
|
||||
String fullname = context.getResources().getString(resourceId);
|
||||
String resName = fullname.substring(fullname.lastIndexOf("/") + 1);
|
||||
try {
|
||||
InputStream is = context.getResources().openRawResource(resourceId);
|
||||
File resDir = context.getDir(dirname, Context.MODE_PRIVATE);
|
||||
File resFile = new File(resDir, resName);
|
||||
|
||||
FileOutputStream os = new FileOutputStream(resFile);
|
||||
|
||||
byte[] buffer = new byte[4096];
|
||||
int bytesRead;
|
||||
while ((bytesRead = is.read(buffer)) != -1) {
|
||||
os.write(buffer, 0, bytesRead);
|
||||
}
|
||||
is.close();
|
||||
os.close();
|
||||
|
||||
return resFile.getAbsolutePath();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
throw new CvException("Failed to export resource " + resName
|
||||
+ ". Exception thrown: " + e);
|
||||
}
|
||||
}
|
||||
|
||||
public static Mat loadResource(Context context, int resourceId) throws IOException
|
||||
{
|
||||
return loadResource(context, resourceId, -1);
|
||||
}
|
||||
|
||||
public static Mat loadResource(Context context, int resourceId, int flags) throws IOException
|
||||
{
|
||||
InputStream is = context.getResources().openRawResource(resourceId);
|
||||
ByteArrayOutputStream os = new ByteArrayOutputStream(is.available());
|
||||
|
||||
byte[] buffer = new byte[4096];
|
||||
int bytesRead;
|
||||
while ((bytesRead = is.read(buffer)) != -1) {
|
||||
os.write(buffer, 0, bytesRead);
|
||||
}
|
||||
is.close();
|
||||
|
||||
Mat encoded = new Mat(1, os.size(), CvType.CV_8U);
|
||||
encoded.put(0, 0, os.toByteArray());
|
||||
os.close();
|
||||
|
||||
Mat decoded = Highgui.imdecode(encoded, flags);
|
||||
encoded.release();
|
||||
|
||||
return decoded;
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts Android Bitmap to OpenCV Mat.
|
||||
* <p>
|
||||
* The function converts an image in the Android Bitmap representation to the OpenCV Mat.
|
||||
* <br>The 'ARGB_8888' and 'RGB_565' input Bitmap formats are supported.
|
||||
* <br>The output Mat is always created of the same size as the input Bitmap and of the 'CV_8UC4' type,
|
||||
* it keeps the image in RGBA format.
|
||||
* <br>The function throws an exception if the conversion fails.
|
||||
*
|
||||
* @param b is a valid input Bitmap object of the type 'ARGB_8888' or 'RGB_565'.
|
||||
* @param m is a valid output Mat object, it will be reallocated if needed, so it's possible to pass an empty Mat.
|
||||
*/
|
||||
public static void bitmapToMat(Bitmap b, Mat m) {
|
||||
if (b == null)
|
||||
throw new java.lang.IllegalArgumentException("Bitmap b == null");
|
||||
if (m == null)
|
||||
throw new java.lang.IllegalArgumentException("Mat m == null");
|
||||
nBitmapToMat(b, m.nativeObj);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Converts OpenCV Mat to Android Bitmap.
|
||||
* <p>
|
||||
* <br>The function converts an image in the OpenCV Mat representation to the Android Bitmap.
|
||||
* <br>The input Mat object has to be of the types 'CV_8UC1' (gray-scale), 'CV_8UC3' (RGB) or 'CV_8UC4' (RGBA).
|
||||
* <br>The output Bitmap object has to be of the same size as the input Mat and of the types 'ARGB_8888' or 'RGB_565'.
|
||||
* <br>The function throws an exception if the conversion fails.
|
||||
*
|
||||
* @param m is a valid input Mat object of the types 'CV_8UC1', 'CV_8UC3' or 'CV_8UC4'.
|
||||
* @param b is a valid Bitmap object of the same size as the Mat m and of type 'ARGB_8888' or 'RGB_565'.
|
||||
*/
|
||||
public static void matToBitmap(Mat m, Bitmap b) {
|
||||
if (m == null)
|
||||
throw new java.lang.IllegalArgumentException("Mat m == null");
|
||||
if (b == null)
|
||||
throw new java.lang.IllegalArgumentException("Bitmap b == null");
|
||||
nMatToBitmap(m.nativeObj, b);
|
||||
}
|
||||
|
||||
// native stuff
|
||||
static {
|
||||
System.loadLibrary("opencv_java");
|
||||
}
|
||||
|
||||
private static native void nBitmapToMat(Bitmap b, long m_addr);
|
||||
|
||||
private static native void nMatToBitmap(long m_addr, Bitmap b);
|
||||
}
|
15
modules/java/generator/src/java/core+CvException.java
Normal file
15
modules/java/generator/src/java/core+CvException.java
Normal file
@@ -0,0 +1,15 @@
|
||||
package org.opencv.core;
|
||||
|
||||
public class CvException extends RuntimeException {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
public CvException(String msg) {
|
||||
super(msg);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "CvException [" + super.toString() + "]";
|
||||
}
|
||||
}
|
136
modules/java/generator/src/java/core+CvType.java
Normal file
136
modules/java/generator/src/java/core+CvType.java
Normal file
@@ -0,0 +1,136 @@
|
||||
package org.opencv.core;
|
||||
|
||||
public final class CvType {
|
||||
|
||||
// type depth constants
|
||||
public static final int
|
||||
CV_8U = 0, CV_8S = 1,
|
||||
CV_16U = 2, CV_16S = 3,
|
||||
CV_32S = 4,
|
||||
CV_32F = 5,
|
||||
CV_64F = 6,
|
||||
CV_USRTYPE1 = 7;
|
||||
|
||||
// predefined type constants
|
||||
public static final int
|
||||
CV_8UC1 = CV_8UC(1), CV_8UC2 = CV_8UC(2), CV_8UC3 = CV_8UC(3), CV_8UC4 = CV_8UC(4),
|
||||
CV_8SC1 = CV_8SC(1), CV_8SC2 = CV_8SC(2), CV_8SC3 = CV_8SC(3), CV_8SC4 = CV_8SC(4),
|
||||
CV_16UC1 = CV_16UC(1), CV_16UC2 = CV_16UC(2), CV_16UC3 = CV_16UC(3), CV_16UC4 = CV_16UC(4),
|
||||
CV_16SC1 = CV_16SC(1), CV_16SC2 = CV_16SC(2), CV_16SC3 = CV_16SC(3), CV_16SC4 = CV_16SC(4),
|
||||
CV_32SC1 = CV_32SC(1), CV_32SC2 = CV_32SC(2), CV_32SC3 = CV_32SC(3), CV_32SC4 = CV_32SC(4),
|
||||
CV_32FC1 = CV_32FC(1), CV_32FC2 = CV_32FC(2), CV_32FC3 = CV_32FC(3), CV_32FC4 = CV_32FC(4),
|
||||
CV_64FC1 = CV_64FC(1), CV_64FC2 = CV_64FC(2), CV_64FC3 = CV_64FC(3), CV_64FC4 = CV_64FC(4);
|
||||
|
||||
private static final int CV_CN_MAX = 512, CV_CN_SHIFT = 3, CV_DEPTH_MAX = (1 << CV_CN_SHIFT);
|
||||
|
||||
public static final int makeType(int depth, int channels) {
|
||||
if (channels <= 0 || channels >= CV_CN_MAX) {
|
||||
throw new java.lang.UnsupportedOperationException(
|
||||
"Channels count should be 1.." + (CV_CN_MAX - 1));
|
||||
}
|
||||
if (depth < 0 || depth >= CV_DEPTH_MAX) {
|
||||
throw new java.lang.UnsupportedOperationException(
|
||||
"Data type depth should be 0.." + (CV_DEPTH_MAX - 1));
|
||||
}
|
||||
return (depth & (CV_DEPTH_MAX - 1)) + ((channels - 1) << CV_CN_SHIFT);
|
||||
}
|
||||
|
||||
public static final int CV_8UC(int ch) {
|
||||
return makeType(CV_8U, ch);
|
||||
}
|
||||
|
||||
public static final int CV_8SC(int ch) {
|
||||
return makeType(CV_8S, ch);
|
||||
}
|
||||
|
||||
public static final int CV_16UC(int ch) {
|
||||
return makeType(CV_16U, ch);
|
||||
}
|
||||
|
||||
public static final int CV_16SC(int ch) {
|
||||
return makeType(CV_16S, ch);
|
||||
}
|
||||
|
||||
public static final int CV_32SC(int ch) {
|
||||
return makeType(CV_32S, ch);
|
||||
}
|
||||
|
||||
public static final int CV_32FC(int ch) {
|
||||
return makeType(CV_32F, ch);
|
||||
}
|
||||
|
||||
public static final int CV_64FC(int ch) {
|
||||
return makeType(CV_64F, ch);
|
||||
}
|
||||
|
||||
public static final int channels(int type) {
|
||||
return (type >> CV_CN_SHIFT) + 1;
|
||||
}
|
||||
|
||||
public static final int depth(int type) {
|
||||
return type & (CV_DEPTH_MAX - 1);
|
||||
}
|
||||
|
||||
public static final boolean isInteger(int type) {
|
||||
return depth(type) < CV_32F;
|
||||
}
|
||||
|
||||
public static final int ELEM_SIZE(int type) {
|
||||
switch (depth(type)) {
|
||||
case CV_8U:
|
||||
case CV_8S:
|
||||
return channels(type);
|
||||
case CV_16U:
|
||||
case CV_16S:
|
||||
return 2 * channels(type);
|
||||
case CV_32S:
|
||||
case CV_32F:
|
||||
return 4 * channels(type);
|
||||
case CV_64F:
|
||||
return 8 * channels(type);
|
||||
default:
|
||||
throw new java.lang.UnsupportedOperationException(
|
||||
"Unsupported CvType value: " + type);
|
||||
}
|
||||
}
|
||||
|
||||
public static final String typeToString(int type) {
|
||||
String s;
|
||||
switch (depth(type)) {
|
||||
case CV_8U:
|
||||
s = "CV_8U";
|
||||
break;
|
||||
case CV_8S:
|
||||
s = "CV_8S";
|
||||
break;
|
||||
case CV_16U:
|
||||
s = "CV_16U";
|
||||
break;
|
||||
case CV_16S:
|
||||
s = "CV_16S";
|
||||
break;
|
||||
case CV_32S:
|
||||
s = "CV_32S";
|
||||
break;
|
||||
case CV_32F:
|
||||
s = "CV_32F";
|
||||
break;
|
||||
case CV_64F:
|
||||
s = "CV_64F";
|
||||
break;
|
||||
case CV_USRTYPE1:
|
||||
s = "CV_USRTYPE1";
|
||||
break;
|
||||
default:
|
||||
throw new java.lang.UnsupportedOperationException(
|
||||
"Unsupported CvType value: " + type);
|
||||
}
|
||||
|
||||
int ch = channels(type);
|
||||
if (ch <= 4)
|
||||
return s + "C" + ch;
|
||||
else
|
||||
return s + "C(" + ch + ")";
|
||||
}
|
||||
|
||||
}
|
1307
modules/java/generator/src/java/core+Mat.java
Normal file
1307
modules/java/generator/src/java/core+Mat.java
Normal file
File diff suppressed because it is too large
Load Diff
79
modules/java/generator/src/java/core+MatOfByte.java
Normal file
79
modules/java/generator/src/java/core+MatOfByte.java
Normal file
@@ -0,0 +1,79 @@
|
||||
package org.opencv.core;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
public class MatOfByte extends Mat {
|
||||
// 8UC(x)
|
||||
private static final int _depth = CvType.CV_8U;
|
||||
private static final int _channels = 1;
|
||||
|
||||
public MatOfByte() {
|
||||
super();
|
||||
}
|
||||
|
||||
protected MatOfByte(long addr) {
|
||||
super(addr);
|
||||
if(checkVector(_channels, _depth) < 0 )
|
||||
throw new IllegalArgumentException("Incomatible Mat");
|
||||
//FIXME: do we need release() here?
|
||||
}
|
||||
|
||||
public static MatOfByte fromNativeAddr(long addr) {
|
||||
return new MatOfByte(addr);
|
||||
}
|
||||
|
||||
public MatOfByte(Mat m) {
|
||||
super(m, Range.all());
|
||||
if(checkVector(_channels, _depth) < 0 )
|
||||
throw new IllegalArgumentException("Incomatible Mat");
|
||||
//FIXME: do we need release() here?
|
||||
}
|
||||
|
||||
public MatOfByte(byte...a) {
|
||||
super();
|
||||
fromArray(a);
|
||||
}
|
||||
|
||||
public void alloc(int elemNumber) {
|
||||
if(elemNumber>0)
|
||||
super.create(elemNumber, 1, CvType.makeType(_depth, _channels));
|
||||
}
|
||||
|
||||
public void fromArray(byte...a) {
|
||||
if(a==null || a.length==0)
|
||||
return;
|
||||
int num = a.length / _channels;
|
||||
alloc(num);
|
||||
put(0, 0, a); //TODO: check ret val!
|
||||
}
|
||||
|
||||
public byte[] toArray() {
|
||||
int num = checkVector(_channels, _depth);
|
||||
if(num < 0)
|
||||
throw new RuntimeException("Native Mat has unexpected type or size: " + toString());
|
||||
byte[] a = new byte[num * _channels];
|
||||
if(num == 0)
|
||||
return a;
|
||||
get(0, 0, a); //TODO: check ret val!
|
||||
return a;
|
||||
}
|
||||
|
||||
public void fromList(List<Byte> lb) {
|
||||
if(lb==null || lb.size()==0)
|
||||
return;
|
||||
Byte ab[] = lb.toArray(new Byte[0]);
|
||||
byte a[] = new byte[ab.length];
|
||||
for(int i=0; i<ab.length; i++)
|
||||
a[i] = ab[i];
|
||||
fromArray(a);
|
||||
}
|
||||
|
||||
public List<Byte> toList() {
|
||||
byte[] a = toArray();
|
||||
Byte ab[] = new Byte[a.length];
|
||||
for(int i=0; i<a.length; i++)
|
||||
ab[i] = a[i];
|
||||
return Arrays.asList(ab);
|
||||
}
|
||||
}
|
83
modules/java/generator/src/java/core+MatOfDMatch.java
Normal file
83
modules/java/generator/src/java/core+MatOfDMatch.java
Normal file
@@ -0,0 +1,83 @@
|
||||
package org.opencv.core;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import org.opencv.features2d.DMatch;
|
||||
|
||||
public class MatOfDMatch extends Mat {
|
||||
// 32FC4
|
||||
private static final int _depth = CvType.CV_32F;
|
||||
private static final int _channels = 4;
|
||||
|
||||
public MatOfDMatch() {
|
||||
super();
|
||||
}
|
||||
|
||||
protected MatOfDMatch(long addr) {
|
||||
super(addr);
|
||||
if(checkVector(_channels, _depth) < 0 )
|
||||
throw new IllegalArgumentException("Incomatible Mat");
|
||||
//FIXME: do we need release() here?
|
||||
}
|
||||
|
||||
public static MatOfDMatch fromNativeAddr(long addr) {
|
||||
return new MatOfDMatch(addr);
|
||||
}
|
||||
|
||||
public MatOfDMatch(Mat m) {
|
||||
super(m, Range.all());
|
||||
if(checkVector(_channels, _depth) < 0 )
|
||||
throw new IllegalArgumentException("Incomatible Mat");
|
||||
//FIXME: do we need release() here?
|
||||
}
|
||||
|
||||
public MatOfDMatch(DMatch...ap) {
|
||||
super();
|
||||
fromArray(ap);
|
||||
}
|
||||
|
||||
public void alloc(int elemNumber) {
|
||||
if(elemNumber>0)
|
||||
super.create(elemNumber, 1, CvType.makeType(_depth, _channels));
|
||||
}
|
||||
|
||||
|
||||
public void fromArray(DMatch...a) {
|
||||
if(a==null || a.length==0)
|
||||
return;
|
||||
int num = a.length;
|
||||
alloc(num);
|
||||
float buff[] = new float[num * _channels];
|
||||
for(int i=0; i<num; i++) {
|
||||
DMatch m = a[i];
|
||||
buff[_channels*i+0] = m.queryIdx;
|
||||
buff[_channels*i+1] = m.trainIdx;
|
||||
buff[_channels*i+2] = m.imgIdx;
|
||||
buff[_channels*i+3] = m.distance;
|
||||
}
|
||||
put(0, 0, buff); //TODO: check ret val!
|
||||
}
|
||||
|
||||
public DMatch[] toArray() {
|
||||
int num = (int) total();
|
||||
DMatch[] a = new DMatch[num];
|
||||
if(num == 0)
|
||||
return a;
|
||||
float buff[] = new float[num * _channels];
|
||||
get(0, 0, buff); //TODO: check ret val!
|
||||
for(int i=0; i<num; i++)
|
||||
a[i] = new DMatch((int) buff[_channels*i+0], (int) buff[_channels*i+1], (int) buff[_channels*i+2], buff[_channels*i+3]);
|
||||
return a;
|
||||
}
|
||||
|
||||
public void fromList(List<DMatch> ldm) {
|
||||
DMatch adm[] = ldm.toArray(new DMatch[0]);
|
||||
fromArray(adm);
|
||||
}
|
||||
|
||||
public List<DMatch> toList() {
|
||||
DMatch[] adm = toArray();
|
||||
return Arrays.asList(adm);
|
||||
}
|
||||
}
|
79
modules/java/generator/src/java/core+MatOfDouble.java
Normal file
79
modules/java/generator/src/java/core+MatOfDouble.java
Normal file
@@ -0,0 +1,79 @@
|
||||
package org.opencv.core;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
public class MatOfDouble extends Mat {
|
||||
// 64FC(x)
|
||||
private static final int _depth = CvType.CV_64F;
|
||||
private static final int _channels = 1;
|
||||
|
||||
public MatOfDouble() {
|
||||
super();
|
||||
}
|
||||
|
||||
protected MatOfDouble(long addr) {
|
||||
super(addr);
|
||||
if(checkVector(_channels, _depth) < 0 )
|
||||
throw new IllegalArgumentException("Incomatible Mat");
|
||||
//FIXME: do we need release() here?
|
||||
}
|
||||
|
||||
public static MatOfDouble fromNativeAddr(long addr) {
|
||||
return new MatOfDouble(addr);
|
||||
}
|
||||
|
||||
public MatOfDouble(Mat m) {
|
||||
super(m, Range.all());
|
||||
if(checkVector(_channels, _depth) < 0 )
|
||||
throw new IllegalArgumentException("Incomatible Mat");
|
||||
//FIXME: do we need release() here?
|
||||
}
|
||||
|
||||
public MatOfDouble(double...a) {
|
||||
super();
|
||||
fromArray(a);
|
||||
}
|
||||
|
||||
public void alloc(int elemNumber) {
|
||||
if(elemNumber>0)
|
||||
super.create(elemNumber, 1, CvType.makeType(_depth, _channels));
|
||||
}
|
||||
|
||||
public void fromArray(double...a) {
|
||||
if(a==null || a.length==0)
|
||||
return;
|
||||
int num = a.length / _channels;
|
||||
alloc(num);
|
||||
put(0, 0, a); //TODO: check ret val!
|
||||
}
|
||||
|
||||
public double[] toArray() {
|
||||
int num = checkVector(_channels, _depth);
|
||||
if(num < 0)
|
||||
throw new RuntimeException("Native Mat has unexpected type or size: " + toString());
|
||||
double[] a = new double[num * _channels];
|
||||
if(num == 0)
|
||||
return a;
|
||||
get(0, 0, a); //TODO: check ret val!
|
||||
return a;
|
||||
}
|
||||
|
||||
public void fromList(List<Double> lb) {
|
||||
if(lb==null || lb.size()==0)
|
||||
return;
|
||||
Double ab[] = lb.toArray(new Double[0]);
|
||||
double a[] = new double[ab.length];
|
||||
for(int i=0; i<ab.length; i++)
|
||||
a[i] = ab[i];
|
||||
fromArray(a);
|
||||
}
|
||||
|
||||
public List<Double> toList() {
|
||||
double[] a = toArray();
|
||||
Double ab[] = new Double[a.length];
|
||||
for(int i=0; i<a.length; i++)
|
||||
ab[i] = a[i];
|
||||
return Arrays.asList(ab);
|
||||
}
|
||||
}
|
79
modules/java/generator/src/java/core+MatOfFloat.java
Normal file
79
modules/java/generator/src/java/core+MatOfFloat.java
Normal file
@@ -0,0 +1,79 @@
|
||||
package org.opencv.core;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
public class MatOfFloat extends Mat {
|
||||
// 32FC1
|
||||
private static final int _depth = CvType.CV_32F;
|
||||
private static final int _channels = 1;
|
||||
|
||||
public MatOfFloat() {
|
||||
super();
|
||||
}
|
||||
|
||||
protected MatOfFloat(long addr) {
|
||||
super(addr);
|
||||
if(checkVector(_channels, _depth) < 0 )
|
||||
throw new IllegalArgumentException("Incomatible Mat");
|
||||
//FIXME: do we need release() here?
|
||||
}
|
||||
|
||||
public static MatOfFloat fromNativeAddr(long addr) {
|
||||
return new MatOfFloat(addr);
|
||||
}
|
||||
|
||||
public MatOfFloat(Mat m) {
|
||||
super(m, Range.all());
|
||||
if(checkVector(_channels, _depth) < 0 )
|
||||
throw new IllegalArgumentException("Incomatible Mat");
|
||||
//FIXME: do we need release() here?
|
||||
}
|
||||
|
||||
public MatOfFloat(float...a) {
|
||||
super();
|
||||
fromArray(a);
|
||||
}
|
||||
|
||||
public void alloc(int elemNumber) {
|
||||
if(elemNumber>0)
|
||||
super.create(elemNumber, 1, CvType.makeType(_depth, _channels));
|
||||
}
|
||||
|
||||
public void fromArray(float...a) {
|
||||
if(a==null || a.length==0)
|
||||
return;
|
||||
int num = a.length / _channels;
|
||||
alloc(num);
|
||||
put(0, 0, a); //TODO: check ret val!
|
||||
}
|
||||
|
||||
public float[] toArray() {
|
||||
int num = checkVector(_channels, _depth);
|
||||
if(num < 0)
|
||||
throw new RuntimeException("Native Mat has unexpected type or size: " + toString());
|
||||
float[] a = new float[num * _channels];
|
||||
if(num == 0)
|
||||
return a;
|
||||
get(0, 0, a); //TODO: check ret val!
|
||||
return a;
|
||||
}
|
||||
|
||||
public void fromList(List<Float> lb) {
|
||||
if(lb==null || lb.size()==0)
|
||||
return;
|
||||
Float ab[] = lb.toArray(new Float[0]);
|
||||
float a[] = new float[ab.length];
|
||||
for(int i=0; i<ab.length; i++)
|
||||
a[i] = ab[i];
|
||||
fromArray(a);
|
||||
}
|
||||
|
||||
public List<Float> toList() {
|
||||
float[] a = toArray();
|
||||
Float ab[] = new Float[a.length];
|
||||
for(int i=0; i<a.length; i++)
|
||||
ab[i] = a[i];
|
||||
return Arrays.asList(ab);
|
||||
}
|
||||
}
|
79
modules/java/generator/src/java/core+MatOfFloat4.java
Normal file
79
modules/java/generator/src/java/core+MatOfFloat4.java
Normal file
@@ -0,0 +1,79 @@
|
||||
package org.opencv.core;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
public class MatOfFloat4 extends Mat {
|
||||
// 32FC4
|
||||
private static final int _depth = CvType.CV_32F;
|
||||
private static final int _channels = 4;
|
||||
|
||||
public MatOfFloat4() {
|
||||
super();
|
||||
}
|
||||
|
||||
protected MatOfFloat4(long addr) {
|
||||
super(addr);
|
||||
if(checkVector(_channels, _depth) < 0 )
|
||||
throw new IllegalArgumentException("Incomatible Mat");
|
||||
//FIXME: do we need release() here?
|
||||
}
|
||||
|
||||
public static MatOfFloat4 fromNativeAddr(long addr) {
|
||||
return new MatOfFloat4(addr);
|
||||
}
|
||||
|
||||
public MatOfFloat4(Mat m) {
|
||||
super(m, Range.all());
|
||||
if(checkVector(_channels, _depth) < 0 )
|
||||
throw new IllegalArgumentException("Incomatible Mat");
|
||||
//FIXME: do we need release() here?
|
||||
}
|
||||
|
||||
public MatOfFloat4(float...a) {
|
||||
super();
|
||||
fromArray(a);
|
||||
}
|
||||
|
||||
public void alloc(int elemNumber) {
|
||||
if(elemNumber>0)
|
||||
super.create(elemNumber, 1, CvType.makeType(_depth, _channels));
|
||||
}
|
||||
|
||||
public void fromArray(float...a) {
|
||||
if(a==null || a.length==0)
|
||||
return;
|
||||
int num = a.length / _channels;
|
||||
alloc(num);
|
||||
put(0, 0, a); //TODO: check ret val!
|
||||
}
|
||||
|
||||
public float[] toArray() {
|
||||
int num = checkVector(_channels, _depth);
|
||||
if(num < 0)
|
||||
throw new RuntimeException("Native Mat has unexpected type or size: " + toString());
|
||||
float[] a = new float[num * _channels];
|
||||
if(num == 0)
|
||||
return a;
|
||||
get(0, 0, a); //TODO: check ret val!
|
||||
return a;
|
||||
}
|
||||
|
||||
public void fromList(List<Float> lb) {
|
||||
if(lb==null || lb.size()==0)
|
||||
return;
|
||||
Float ab[] = lb.toArray(new Float[0]);
|
||||
float a[] = new float[ab.length];
|
||||
for(int i=0; i<ab.length; i++)
|
||||
a[i] = ab[i];
|
||||
fromArray(a);
|
||||
}
|
||||
|
||||
public List<Float> toList() {
|
||||
float[] a = toArray();
|
||||
Float ab[] = new Float[a.length];
|
||||
for(int i=0; i<a.length; i++)
|
||||
ab[i] = a[i];
|
||||
return Arrays.asList(ab);
|
||||
}
|
||||
}
|
79
modules/java/generator/src/java/core+MatOfFloat6.java
Normal file
79
modules/java/generator/src/java/core+MatOfFloat6.java
Normal file
@@ -0,0 +1,79 @@
|
||||
package org.opencv.core;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
public class MatOfFloat6 extends Mat {
|
||||
// 32FC6
|
||||
private static final int _depth = CvType.CV_32F;
|
||||
private static final int _channels = 6;
|
||||
|
||||
public MatOfFloat6() {
|
||||
super();
|
||||
}
|
||||
|
||||
protected MatOfFloat6(long addr) {
|
||||
super(addr);
|
||||
if(checkVector(_channels, _depth) < 0 )
|
||||
throw new IllegalArgumentException("Incomatible Mat");
|
||||
//FIXME: do we need release() here?
|
||||
}
|
||||
|
||||
public static MatOfFloat6 fromNativeAddr(long addr) {
|
||||
return new MatOfFloat6(addr);
|
||||
}
|
||||
|
||||
public MatOfFloat6(Mat m) {
|
||||
super(m, Range.all());
|
||||
if(checkVector(_channels, _depth) < 0 )
|
||||
throw new IllegalArgumentException("Incomatible Mat");
|
||||
//FIXME: do we need release() here?
|
||||
}
|
||||
|
||||
public MatOfFloat6(float...a) {
|
||||
super();
|
||||
fromArray(a);
|
||||
}
|
||||
|
||||
public void alloc(int elemNumber) {
|
||||
if(elemNumber>0)
|
||||
super.create(elemNumber, 1, CvType.makeType(_depth, _channels));
|
||||
}
|
||||
|
||||
public void fromArray(float...a) {
|
||||
if(a==null || a.length==0)
|
||||
return;
|
||||
int num = a.length / _channels;
|
||||
alloc(num);
|
||||
put(0, 0, a); //TODO: check ret val!
|
||||
}
|
||||
|
||||
public float[] toArray() {
|
||||
int num = checkVector(_channels, _depth);
|
||||
if(num < 0)
|
||||
throw new RuntimeException("Native Mat has unexpected type or size: " + toString());
|
||||
float[] a = new float[num * _channels];
|
||||
if(num == 0)
|
||||
return a;
|
||||
get(0, 0, a); //TODO: check ret val!
|
||||
return a;
|
||||
}
|
||||
|
||||
public void fromList(List<Float> lb) {
|
||||
if(lb==null || lb.size()==0)
|
||||
return;
|
||||
Float ab[] = lb.toArray(new Float[0]);
|
||||
float a[] = new float[ab.length];
|
||||
for(int i=0; i<ab.length; i++)
|
||||
a[i] = ab[i];
|
||||
fromArray(a);
|
||||
}
|
||||
|
||||
public List<Float> toList() {
|
||||
float[] a = toArray();
|
||||
Float ab[] = new Float[a.length];
|
||||
for(int i=0; i<a.length; i++)
|
||||
ab[i] = a[i];
|
||||
return Arrays.asList(ab);
|
||||
}
|
||||
}
|
80
modules/java/generator/src/java/core+MatOfInt.java
Normal file
80
modules/java/generator/src/java/core+MatOfInt.java
Normal file
@@ -0,0 +1,80 @@
|
||||
package org.opencv.core;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
|
||||
public class MatOfInt extends Mat {
|
||||
// 32SC1
|
||||
private static final int _depth = CvType.CV_32S;
|
||||
private static final int _channels = 1;
|
||||
|
||||
public MatOfInt() {
|
||||
super();
|
||||
}
|
||||
|
||||
protected MatOfInt(long addr) {
|
||||
super(addr);
|
||||
if(checkVector(_channels, _depth) < 0 )
|
||||
throw new IllegalArgumentException("Incomatible Mat");
|
||||
//FIXME: do we need release() here?
|
||||
}
|
||||
|
||||
public static MatOfInt fromNativeAddr(long addr) {
|
||||
return new MatOfInt(addr);
|
||||
}
|
||||
|
||||
public MatOfInt(Mat m) {
|
||||
super(m, Range.all());
|
||||
if(checkVector(_channels, _depth) < 0 )
|
||||
throw new IllegalArgumentException("Incomatible Mat");
|
||||
//FIXME: do we need release() here?
|
||||
}
|
||||
|
||||
public MatOfInt(int...a) {
|
||||
super();
|
||||
fromArray(a);
|
||||
}
|
||||
|
||||
public void alloc(int elemNumber) {
|
||||
if(elemNumber>0)
|
||||
super.create(elemNumber, 1, CvType.makeType(_depth, _channels));
|
||||
}
|
||||
|
||||
public void fromArray(int...a) {
|
||||
if(a==null || a.length==0)
|
||||
return;
|
||||
int num = a.length / _channels;
|
||||
alloc(num);
|
||||
put(0, 0, a); //TODO: check ret val!
|
||||
}
|
||||
|
||||
public int[] toArray() {
|
||||
int num = checkVector(_channels, _depth);
|
||||
if(num < 0)
|
||||
throw new RuntimeException("Native Mat has unexpected type or size: " + toString());
|
||||
int[] a = new int[num * _channels];
|
||||
if(num == 0)
|
||||
return a;
|
||||
get(0, 0, a); //TODO: check ret val!
|
||||
return a;
|
||||
}
|
||||
|
||||
public void fromList(List<Integer> lb) {
|
||||
if(lb==null || lb.size()==0)
|
||||
return;
|
||||
Integer ab[] = lb.toArray(new Integer[0]);
|
||||
int a[] = new int[ab.length];
|
||||
for(int i=0; i<ab.length; i++)
|
||||
a[i] = ab[i];
|
||||
fromArray(a);
|
||||
}
|
||||
|
||||
public List<Integer> toList() {
|
||||
int[] a = toArray();
|
||||
Integer ab[] = new Integer[a.length];
|
||||
for(int i=0; i<a.length; i++)
|
||||
ab[i] = a[i];
|
||||
return Arrays.asList(ab);
|
||||
}
|
||||
}
|
80
modules/java/generator/src/java/core+MatOfInt4.java
Normal file
80
modules/java/generator/src/java/core+MatOfInt4.java
Normal file
@@ -0,0 +1,80 @@
|
||||
package org.opencv.core;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
|
||||
public class MatOfInt4 extends Mat {
|
||||
// 32SC4
|
||||
private static final int _depth = CvType.CV_32S;
|
||||
private static final int _channels = 4;
|
||||
|
||||
public MatOfInt4() {
|
||||
super();
|
||||
}
|
||||
|
||||
protected MatOfInt4(long addr) {
|
||||
super(addr);
|
||||
if(checkVector(_channels, _depth) < 0 )
|
||||
throw new IllegalArgumentException("Incomatible Mat");
|
||||
//FIXME: do we need release() here?
|
||||
}
|
||||
|
||||
public static MatOfInt4 fromNativeAddr(long addr) {
|
||||
return new MatOfInt4(addr);
|
||||
}
|
||||
|
||||
public MatOfInt4(Mat m) {
|
||||
super(m, Range.all());
|
||||
if(checkVector(_channels, _depth) < 0 )
|
||||
throw new IllegalArgumentException("Incomatible Mat");
|
||||
//FIXME: do we need release() here?
|
||||
}
|
||||
|
||||
public MatOfInt4(int...a) {
|
||||
super();
|
||||
fromArray(a);
|
||||
}
|
||||
|
||||
public void alloc(int elemNumber) {
|
||||
if(elemNumber>0)
|
||||
super.create(elemNumber, 1, CvType.makeType(_depth, _channels));
|
||||
}
|
||||
|
||||
public void fromArray(int...a) {
|
||||
if(a==null || a.length==0)
|
||||
return;
|
||||
int num = a.length / _channels;
|
||||
alloc(num);
|
||||
put(0, 0, a); //TODO: check ret val!
|
||||
}
|
||||
|
||||
public int[] toArray() {
|
||||
int num = checkVector(_channels, _depth);
|
||||
if(num < 0)
|
||||
throw new RuntimeException("Native Mat has unexpected type or size: " + toString());
|
||||
int[] a = new int[num * _channels];
|
||||
if(num == 0)
|
||||
return a;
|
||||
get(0, 0, a); //TODO: check ret val!
|
||||
return a;
|
||||
}
|
||||
|
||||
public void fromList(List<Integer> lb) {
|
||||
if(lb==null || lb.size()==0)
|
||||
return;
|
||||
Integer ab[] = lb.toArray(new Integer[0]);
|
||||
int a[] = new int[ab.length];
|
||||
for(int i=0; i<ab.length; i++)
|
||||
a[i] = ab[i];
|
||||
fromArray(a);
|
||||
}
|
||||
|
||||
public List<Integer> toList() {
|
||||
int[] a = toArray();
|
||||
Integer ab[] = new Integer[a.length];
|
||||
for(int i=0; i<a.length; i++)
|
||||
ab[i] = a[i];
|
||||
return Arrays.asList(ab);
|
||||
}
|
||||
}
|
86
modules/java/generator/src/java/core+MatOfKeyPoint.java
Normal file
86
modules/java/generator/src/java/core+MatOfKeyPoint.java
Normal file
@@ -0,0 +1,86 @@
|
||||
package org.opencv.core;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import org.opencv.features2d.KeyPoint;
|
||||
|
||||
public class MatOfKeyPoint extends Mat {
|
||||
// 32FC7
|
||||
private static final int _depth = CvType.CV_32F;
|
||||
private static final int _channels = 7;
|
||||
|
||||
public MatOfKeyPoint() {
|
||||
super();
|
||||
}
|
||||
|
||||
protected MatOfKeyPoint(long addr) {
|
||||
super(addr);
|
||||
if(checkVector(_channels, _depth) < 0 )
|
||||
throw new IllegalArgumentException("Incomatible Mat");
|
||||
//FIXME: do we need release() here?
|
||||
}
|
||||
|
||||
public static MatOfKeyPoint fromNativeAddr(long addr) {
|
||||
return new MatOfKeyPoint(addr);
|
||||
}
|
||||
|
||||
public MatOfKeyPoint(Mat m) {
|
||||
super(m, Range.all());
|
||||
if(checkVector(_channels, _depth) < 0 )
|
||||
throw new IllegalArgumentException("Incomatible Mat");
|
||||
//FIXME: do we need release() here?
|
||||
}
|
||||
|
||||
public MatOfKeyPoint(KeyPoint...a) {
|
||||
super();
|
||||
fromArray(a);
|
||||
}
|
||||
|
||||
public void alloc(int elemNumber) {
|
||||
if(elemNumber>0)
|
||||
super.create(elemNumber, 1, CvType.makeType(_depth, _channels));
|
||||
}
|
||||
|
||||
public void fromArray(KeyPoint...a) {
|
||||
if(a==null || a.length==0)
|
||||
return;
|
||||
int num = a.length;
|
||||
alloc(num);
|
||||
float buff[] = new float[num * _channels];
|
||||
for(int i=0; i<num; i++) {
|
||||
KeyPoint kp = a[i];
|
||||
buff[_channels*i+0] = (float) kp.pt.x;
|
||||
buff[_channels*i+1] = (float) kp.pt.y;
|
||||
buff[_channels*i+2] = kp.size;
|
||||
buff[_channels*i+3] = kp.angle;
|
||||
buff[_channels*i+4] = kp.response;
|
||||
buff[_channels*i+5] = kp.octave;
|
||||
buff[_channels*i+6] = kp.class_id;
|
||||
}
|
||||
put(0, 0, buff); //TODO: check ret val!
|
||||
}
|
||||
|
||||
public KeyPoint[] toArray() {
|
||||
int num = (int) total();
|
||||
KeyPoint[] a = new KeyPoint[num];
|
||||
if(num == 0)
|
||||
return a;
|
||||
float buff[] = new float[num * _channels];
|
||||
get(0, 0, buff); //TODO: check ret val!
|
||||
for(int i=0; i<num; i++)
|
||||
a[i] = new KeyPoint( buff[_channels*i+0], buff[_channels*i+1], buff[_channels*i+2], buff[_channels*i+3],
|
||||
buff[_channels*i+4], (int) buff[_channels*i+5], (int) buff[_channels*i+6] );
|
||||
return a;
|
||||
}
|
||||
|
||||
public void fromList(List<KeyPoint> lkp) {
|
||||
KeyPoint akp[] = lkp.toArray(new KeyPoint[0]);
|
||||
fromArray(akp);
|
||||
}
|
||||
|
||||
public List<KeyPoint> toList() {
|
||||
KeyPoint[] akp = toArray();
|
||||
return Arrays.asList(akp);
|
||||
}
|
||||
}
|
78
modules/java/generator/src/java/core+MatOfPoint.java
Normal file
78
modules/java/generator/src/java/core+MatOfPoint.java
Normal file
@@ -0,0 +1,78 @@
|
||||
package org.opencv.core;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
public class MatOfPoint extends Mat {
|
||||
// 32SC2
|
||||
private static final int _depth = CvType.CV_32S;
|
||||
private static final int _channels = 2;
|
||||
|
||||
public MatOfPoint() {
|
||||
super();
|
||||
}
|
||||
|
||||
protected MatOfPoint(long addr) {
|
||||
super(addr);
|
||||
if(checkVector(_channels, _depth) < 0 )
|
||||
throw new IllegalArgumentException("Incomatible Mat");
|
||||
//FIXME: do we need release() here?
|
||||
}
|
||||
|
||||
public static MatOfPoint fromNativeAddr(long addr) {
|
||||
return new MatOfPoint(addr);
|
||||
}
|
||||
|
||||
public MatOfPoint(Mat m) {
|
||||
super(m, Range.all());
|
||||
if(checkVector(_channels, _depth) < 0 )
|
||||
throw new IllegalArgumentException("Incomatible Mat");
|
||||
//FIXME: do we need release() here?
|
||||
}
|
||||
|
||||
public MatOfPoint(Point...a) {
|
||||
super();
|
||||
fromArray(a);
|
||||
}
|
||||
|
||||
public void alloc(int elemNumber) {
|
||||
if(elemNumber>0)
|
||||
super.create(elemNumber, 1, CvType.makeType(_depth, _channels));
|
||||
}
|
||||
|
||||
public void fromArray(Point...a) {
|
||||
if(a==null || a.length==0)
|
||||
return;
|
||||
int num = a.length;
|
||||
alloc(num);
|
||||
int buff[] = new int[num * _channels];
|
||||
for(int i=0; i<num; i++) {
|
||||
Point p = a[i];
|
||||
buff[_channels*i+0] = (int) p.x;
|
||||
buff[_channels*i+1] = (int) p.y;
|
||||
}
|
||||
put(0, 0, buff); //TODO: check ret val!
|
||||
}
|
||||
|
||||
public Point[] toArray() {
|
||||
int num = (int) total();
|
||||
Point[] ap = new Point[num];
|
||||
if(num == 0)
|
||||
return ap;
|
||||
int buff[] = new int[num * _channels];
|
||||
get(0, 0, buff); //TODO: check ret val!
|
||||
for(int i=0; i<num; i++)
|
||||
ap[i] = new Point(buff[i*_channels], buff[i*_channels+1]);
|
||||
return ap;
|
||||
}
|
||||
|
||||
public void fromList(List<Point> lp) {
|
||||
Point ap[] = lp.toArray(new Point[0]);
|
||||
fromArray(ap);
|
||||
}
|
||||
|
||||
public List<Point> toList() {
|
||||
Point[] ap = toArray();
|
||||
return Arrays.asList(ap);
|
||||
}
|
||||
}
|
78
modules/java/generator/src/java/core+MatOfPoint2f.java
Normal file
78
modules/java/generator/src/java/core+MatOfPoint2f.java
Normal file
@@ -0,0 +1,78 @@
|
||||
package org.opencv.core;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
public class MatOfPoint2f extends Mat {
|
||||
// 32FC2
|
||||
private static final int _depth = CvType.CV_32F;
|
||||
private static final int _channels = 2;
|
||||
|
||||
public MatOfPoint2f() {
|
||||
super();
|
||||
}
|
||||
|
||||
protected MatOfPoint2f(long addr) {
|
||||
super(addr);
|
||||
if(checkVector(_channels, _depth) < 0 )
|
||||
throw new IllegalArgumentException("Incomatible Mat");
|
||||
//FIXME: do we need release() here?
|
||||
}
|
||||
|
||||
public static MatOfPoint2f fromNativeAddr(long addr) {
|
||||
return new MatOfPoint2f(addr);
|
||||
}
|
||||
|
||||
public MatOfPoint2f(Mat m) {
|
||||
super(m, Range.all());
|
||||
if(checkVector(_channels, _depth) < 0 )
|
||||
throw new IllegalArgumentException("Incomatible Mat");
|
||||
//FIXME: do we need release() here?
|
||||
}
|
||||
|
||||
public MatOfPoint2f(Point...a) {
|
||||
super();
|
||||
fromArray(a);
|
||||
}
|
||||
|
||||
public void alloc(int elemNumber) {
|
||||
if(elemNumber>0)
|
||||
super.create(elemNumber, 1, CvType.makeType(_depth, _channels));
|
||||
}
|
||||
|
||||
public void fromArray(Point...a) {
|
||||
if(a==null || a.length==0)
|
||||
return;
|
||||
int num = a.length;
|
||||
alloc(num);
|
||||
float buff[] = new float[num * _channels];
|
||||
for(int i=0; i<num; i++) {
|
||||
Point p = a[i];
|
||||
buff[_channels*i+0] = (float) p.x;
|
||||
buff[_channels*i+1] = (float) p.y;
|
||||
}
|
||||
put(0, 0, buff); //TODO: check ret val!
|
||||
}
|
||||
|
||||
public Point[] toArray() {
|
||||
int num = (int) total();
|
||||
Point[] ap = new Point[num];
|
||||
if(num == 0)
|
||||
return ap;
|
||||
float buff[] = new float[num * _channels];
|
||||
get(0, 0, buff); //TODO: check ret val!
|
||||
for(int i=0; i<num; i++)
|
||||
ap[i] = new Point(buff[i*_channels], buff[i*_channels+1]);
|
||||
return ap;
|
||||
}
|
||||
|
||||
public void fromList(List<Point> lp) {
|
||||
Point ap[] = lp.toArray(new Point[0]);
|
||||
fromArray(ap);
|
||||
}
|
||||
|
||||
public List<Point> toList() {
|
||||
Point[] ap = toArray();
|
||||
return Arrays.asList(ap);
|
||||
}
|
||||
}
|
79
modules/java/generator/src/java/core+MatOfPoint3.java
Normal file
79
modules/java/generator/src/java/core+MatOfPoint3.java
Normal file
@@ -0,0 +1,79 @@
|
||||
package org.opencv.core;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
public class MatOfPoint3 extends Mat {
|
||||
// 32SC3
|
||||
private static final int _depth = CvType.CV_32S;
|
||||
private static final int _channels = 3;
|
||||
|
||||
public MatOfPoint3() {
|
||||
super();
|
||||
}
|
||||
|
||||
protected MatOfPoint3(long addr) {
|
||||
super(addr);
|
||||
if(checkVector(_channels, _depth) < 0 )
|
||||
throw new IllegalArgumentException("Incomatible Mat");
|
||||
//FIXME: do we need release() here?
|
||||
}
|
||||
|
||||
public static MatOfPoint3 fromNativeAddr(long addr) {
|
||||
return new MatOfPoint3(addr);
|
||||
}
|
||||
|
||||
public MatOfPoint3(Mat m) {
|
||||
super(m, Range.all());
|
||||
if(checkVector(_channels, _depth) < 0 )
|
||||
throw new IllegalArgumentException("Incomatible Mat");
|
||||
//FIXME: do we need release() here?
|
||||
}
|
||||
|
||||
public MatOfPoint3(Point3...a) {
|
||||
super();
|
||||
fromArray(a);
|
||||
}
|
||||
|
||||
public void alloc(int elemNumber) {
|
||||
if(elemNumber>0)
|
||||
super.create(elemNumber, 1, CvType.makeType(_depth, _channels));
|
||||
}
|
||||
|
||||
public void fromArray(Point3...a) {
|
||||
if(a==null || a.length==0)
|
||||
return;
|
||||
int num = a.length;
|
||||
alloc(num);
|
||||
int buff[] = new int[num * _channels];
|
||||
for(int i=0; i<num; i++) {
|
||||
Point3 p = a[i];
|
||||
buff[_channels*i+0] = (int) p.x;
|
||||
buff[_channels*i+1] = (int) p.y;
|
||||
buff[_channels*i+2] = (int) p.z;
|
||||
}
|
||||
put(0, 0, buff); //TODO: check ret val!
|
||||
}
|
||||
|
||||
public Point3[] toArray() {
|
||||
int num = (int) total();
|
||||
Point3[] ap = new Point3[num];
|
||||
if(num == 0)
|
||||
return ap;
|
||||
int buff[] = new int[num * _channels];
|
||||
get(0, 0, buff); //TODO: check ret val!
|
||||
for(int i=0; i<num; i++)
|
||||
ap[i] = new Point3(buff[i*_channels], buff[i*_channels+1], buff[i*_channels+2]);
|
||||
return ap;
|
||||
}
|
||||
|
||||
public void fromList(List<Point3> lp) {
|
||||
Point3 ap[] = lp.toArray(new Point3[0]);
|
||||
fromArray(ap);
|
||||
}
|
||||
|
||||
public List<Point3> toList() {
|
||||
Point3[] ap = toArray();
|
||||
return Arrays.asList(ap);
|
||||
}
|
||||
}
|
79
modules/java/generator/src/java/core+MatOfPoint3f.java
Normal file
79
modules/java/generator/src/java/core+MatOfPoint3f.java
Normal file
@@ -0,0 +1,79 @@
|
||||
package org.opencv.core;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
public class MatOfPoint3f extends Mat {
|
||||
// 32FC3
|
||||
private static final int _depth = CvType.CV_32F;
|
||||
private static final int _channels = 3;
|
||||
|
||||
public MatOfPoint3f() {
|
||||
super();
|
||||
}
|
||||
|
||||
protected MatOfPoint3f(long addr) {
|
||||
super(addr);
|
||||
if(checkVector(_channels, _depth) < 0 )
|
||||
throw new IllegalArgumentException("Incomatible Mat");
|
||||
//FIXME: do we need release() here?
|
||||
}
|
||||
|
||||
public static MatOfPoint3f fromNativeAddr(long addr) {
|
||||
return new MatOfPoint3f(addr);
|
||||
}
|
||||
|
||||
public MatOfPoint3f(Mat m) {
|
||||
super(m, Range.all());
|
||||
if(checkVector(_channels, _depth) < 0 )
|
||||
throw new IllegalArgumentException("Incomatible Mat");
|
||||
//FIXME: do we need release() here?
|
||||
}
|
||||
|
||||
public MatOfPoint3f(Point3...a) {
|
||||
super();
|
||||
fromArray(a);
|
||||
}
|
||||
|
||||
public void alloc(int elemNumber) {
|
||||
if(elemNumber>0)
|
||||
super.create(elemNumber, 1, CvType.makeType(_depth, _channels));
|
||||
}
|
||||
|
||||
public void fromArray(Point3...a) {
|
||||
if(a==null || a.length==0)
|
||||
return;
|
||||
int num = a.length;
|
||||
alloc(num);
|
||||
float buff[] = new float[num * _channels];
|
||||
for(int i=0; i<num; i++) {
|
||||
Point3 p = a[i];
|
||||
buff[_channels*i+0] = (float) p.x;
|
||||
buff[_channels*i+1] = (float) p.y;
|
||||
buff[_channels*i+2] = (float) p.z;
|
||||
}
|
||||
put(0, 0, buff); //TODO: check ret val!
|
||||
}
|
||||
|
||||
public Point3[] toArray() {
|
||||
int num = (int) total();
|
||||
Point3[] ap = new Point3[num];
|
||||
if(num == 0)
|
||||
return ap;
|
||||
float buff[] = new float[num * _channels];
|
||||
get(0, 0, buff); //TODO: check ret val!
|
||||
for(int i=0; i<num; i++)
|
||||
ap[i] = new Point3(buff[i*_channels], buff[i*_channels+1], buff[i*_channels+2]);
|
||||
return ap;
|
||||
}
|
||||
|
||||
public void fromList(List<Point3> lp) {
|
||||
Point3 ap[] = lp.toArray(new Point3[0]);
|
||||
fromArray(ap);
|
||||
}
|
||||
|
||||
public List<Point3> toList() {
|
||||
Point3[] ap = toArray();
|
||||
return Arrays.asList(ap);
|
||||
}
|
||||
}
|
81
modules/java/generator/src/java/core+MatOfRect.java
Normal file
81
modules/java/generator/src/java/core+MatOfRect.java
Normal file
@@ -0,0 +1,81 @@
|
||||
package org.opencv.core;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
|
||||
public class MatOfRect extends Mat {
|
||||
// 32SC4
|
||||
private static final int _depth = CvType.CV_32S;
|
||||
private static final int _channels = 4;
|
||||
|
||||
public MatOfRect() {
|
||||
super();
|
||||
}
|
||||
|
||||
protected MatOfRect(long addr) {
|
||||
super(addr);
|
||||
if(checkVector(_channels, _depth) < 0 )
|
||||
throw new IllegalArgumentException("Incomatible Mat");
|
||||
//FIXME: do we need release() here?
|
||||
}
|
||||
|
||||
public static MatOfRect fromNativeAddr(long addr) {
|
||||
return new MatOfRect(addr);
|
||||
}
|
||||
|
||||
public MatOfRect(Mat m) {
|
||||
super(m, Range.all());
|
||||
if(checkVector(_channels, _depth) < 0 )
|
||||
throw new IllegalArgumentException("Incomatible Mat");
|
||||
//FIXME: do we need release() here?
|
||||
}
|
||||
|
||||
public MatOfRect(Rect...a) {
|
||||
super();
|
||||
fromArray(a);
|
||||
}
|
||||
|
||||
public void alloc(int elemNumber) {
|
||||
if(elemNumber>0)
|
||||
super.create(elemNumber, 1, CvType.makeType(_depth, _channels));
|
||||
}
|
||||
|
||||
public void fromArray(Rect...a) {
|
||||
if(a==null || a.length==0)
|
||||
return;
|
||||
int num = a.length;
|
||||
alloc(num);
|
||||
int buff[] = new int[num * _channels];
|
||||
for(int i=0; i<num; i++) {
|
||||
Rect r = a[i];
|
||||
buff[_channels*i+0] = (int) r.x;
|
||||
buff[_channels*i+1] = (int) r.y;
|
||||
buff[_channels*i+2] = (int) r.width;
|
||||
buff[_channels*i+3] = (int) r.height;
|
||||
}
|
||||
put(0, 0, buff); //TODO: check ret val!
|
||||
}
|
||||
|
||||
|
||||
public Rect[] toArray() {
|
||||
int num = (int) total();
|
||||
Rect[] a = new Rect[num];
|
||||
if(num == 0)
|
||||
return a;
|
||||
int buff[] = new int[num * _channels];
|
||||
get(0, 0, buff); //TODO: check ret val!
|
||||
for(int i=0; i<num; i++)
|
||||
a[i] = new Rect(buff[i*_channels], buff[i*_channels+1], buff[i*_channels+2], buff[i*_channels+3]);
|
||||
return a;
|
||||
}
|
||||
public void fromList(List<Rect> lr) {
|
||||
Rect ap[] = lr.toArray(new Rect[0]);
|
||||
fromArray(ap);
|
||||
}
|
||||
|
||||
public List<Rect> toList() {
|
||||
Rect[] ar = toArray();
|
||||
return Arrays.asList(ar);
|
||||
}
|
||||
}
|
68
modules/java/generator/src/java/core+Point.java
Normal file
68
modules/java/generator/src/java/core+Point.java
Normal file
@@ -0,0 +1,68 @@
|
||||
package org.opencv.core;
|
||||
|
||||
//javadoc:Point_
|
||||
public class Point {
|
||||
|
||||
public double x, y;
|
||||
|
||||
public Point(double x, double y) {
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
}
|
||||
|
||||
public Point() {
|
||||
this(0, 0);
|
||||
}
|
||||
|
||||
public Point(double[] vals) {
|
||||
this();
|
||||
set(vals);
|
||||
}
|
||||
|
||||
public void set(double[] vals) {
|
||||
if (vals != null) {
|
||||
x = vals.length > 0 ? vals[0] : 0;
|
||||
y = vals.length > 1 ? vals[1] : 0;
|
||||
} else {
|
||||
x = 0;
|
||||
y = 0;
|
||||
}
|
||||
}
|
||||
|
||||
public Point clone() {
|
||||
return new Point(x, y);
|
||||
}
|
||||
|
||||
public double dot(Point p) {
|
||||
return x * p.x + y * p.y;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
final int prime = 31;
|
||||
int result = 1;
|
||||
long temp;
|
||||
temp = Double.doubleToLongBits(x);
|
||||
result = prime * result + (int) (temp ^ (temp >>> 32));
|
||||
temp = Double.doubleToLongBits(y);
|
||||
result = prime * result + (int) (temp ^ (temp >>> 32));
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (this == obj) return true;
|
||||
if (!(obj instanceof Point)) return false;
|
||||
Point it = (Point) obj;
|
||||
return x == it.x && y == it.y;
|
||||
}
|
||||
|
||||
public boolean inside(Rect r) {
|
||||
return r.contains(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "{" + x + ", " + y + "}";
|
||||
}
|
||||
}
|
79
modules/java/generator/src/java/core+Point3.java
Normal file
79
modules/java/generator/src/java/core+Point3.java
Normal file
@@ -0,0 +1,79 @@
|
||||
package org.opencv.core;
|
||||
|
||||
//javadoc:Point3_
|
||||
public class Point3 {
|
||||
|
||||
public double x, y, z;
|
||||
|
||||
public Point3(double x, double y, double z) {
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.z = z;
|
||||
}
|
||||
|
||||
public Point3() {
|
||||
this(0, 0, 0);
|
||||
}
|
||||
|
||||
public Point3(Point p) {
|
||||
x = p.x;
|
||||
y = p.y;
|
||||
z = 0;
|
||||
}
|
||||
|
||||
public Point3(double[] vals) {
|
||||
this();
|
||||
set(vals);
|
||||
}
|
||||
|
||||
public void set(double[] vals) {
|
||||
if (vals != null) {
|
||||
x = vals.length > 0 ? vals[0] : 0;
|
||||
y = vals.length > 1 ? vals[1] : 0;
|
||||
z = vals.length > 2 ? vals[2] : 0;
|
||||
} else {
|
||||
x = 0;
|
||||
y = 0;
|
||||
z = 0;
|
||||
}
|
||||
}
|
||||
|
||||
public Point3 clone() {
|
||||
return new Point3(x, y, z);
|
||||
}
|
||||
|
||||
public double dot(Point3 p) {
|
||||
return x * p.x + y * p.y + z * p.z;
|
||||
}
|
||||
|
||||
public Point3 cross(Point3 p) {
|
||||
return new Point3(y * p.z - z * p.y, z * p.x - x * p.z, x * p.y - y * p.x);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
final int prime = 31;
|
||||
int result = 1;
|
||||
long temp;
|
||||
temp = Double.doubleToLongBits(x);
|
||||
result = prime * result + (int) (temp ^ (temp >>> 32));
|
||||
temp = Double.doubleToLongBits(y);
|
||||
result = prime * result + (int) (temp ^ (temp >>> 32));
|
||||
temp = Double.doubleToLongBits(z);
|
||||
result = prime * result + (int) (temp ^ (temp >>> 32));
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (this == obj) return true;
|
||||
if (!(obj instanceof Point3)) return false;
|
||||
Point3 it = (Point3) obj;
|
||||
return x == it.x && y == it.y && z == it.z;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "{" + x + ", " + y + ", " + z + "}";
|
||||
}
|
||||
}
|
82
modules/java/generator/src/java/core+Range.java
Normal file
82
modules/java/generator/src/java/core+Range.java
Normal file
@@ -0,0 +1,82 @@
|
||||
package org.opencv.core;
|
||||
|
||||
//javadoc:Range
|
||||
public class Range {
|
||||
|
||||
public int start, end;
|
||||
|
||||
public Range(int s, int e) {
|
||||
this.start = s;
|
||||
this.end = e;
|
||||
}
|
||||
|
||||
public Range() {
|
||||
this(0, 0);
|
||||
}
|
||||
|
||||
public Range(double[] vals) {
|
||||
set(vals);
|
||||
}
|
||||
|
||||
public void set(double[] vals) {
|
||||
if (vals != null) {
|
||||
start = vals.length > 0 ? (int) vals[0] : 0;
|
||||
end = vals.length > 1 ? (int) vals[1] : 0;
|
||||
} else {
|
||||
start = 0;
|
||||
end = 0;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public int size() {
|
||||
return empty() ? 0 : end - start;
|
||||
}
|
||||
|
||||
public boolean empty() {
|
||||
return end <= start;
|
||||
}
|
||||
|
||||
public static Range all() {
|
||||
return new Range(Integer.MIN_VALUE, Integer.MAX_VALUE);
|
||||
}
|
||||
|
||||
public Range intersection(Range r1) {
|
||||
Range r = new Range(Math.max(r1.start, this.start), Math.min(r1.end, this.end));
|
||||
r.end = Math.max(r.end, r.start);
|
||||
return r;
|
||||
}
|
||||
|
||||
public Range shift(int delta) {
|
||||
return new Range(start + delta, end + delta);
|
||||
}
|
||||
|
||||
public Range clone() {
|
||||
return new Range(start, end);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
final int prime = 31;
|
||||
int result = 1;
|
||||
long temp;
|
||||
temp = Double.doubleToLongBits(start);
|
||||
result = prime * result + (int) (temp ^ (temp >>> 32));
|
||||
temp = Double.doubleToLongBits(end);
|
||||
result = prime * result + (int) (temp ^ (temp >>> 32));
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (this == obj) return true;
|
||||
if (!(obj instanceof Range)) return false;
|
||||
Range it = (Range) obj;
|
||||
return start == it.start && end == it.end;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "[" + start + ", " + end + ")";
|
||||
}
|
||||
}
|
100
modules/java/generator/src/java/core+Rect.java
Normal file
100
modules/java/generator/src/java/core+Rect.java
Normal file
@@ -0,0 +1,100 @@
|
||||
package org.opencv.core;
|
||||
|
||||
//javadoc:Rect_
|
||||
public class Rect {
|
||||
|
||||
public int x, y, width, height;
|
||||
|
||||
public Rect(int x, int y, int width, int height) {
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.width = width;
|
||||
this.height = height;
|
||||
}
|
||||
|
||||
public Rect() {
|
||||
this(0, 0, 0, 0);
|
||||
}
|
||||
|
||||
public Rect(Point p1, Point p2) {
|
||||
x = (int) (p1.x < p2.x ? p1.x : p2.x);
|
||||
y = (int) (p1.y < p2.y ? p1.y : p2.y);
|
||||
width = (int) (p1.x > p2.x ? p1.x : p2.x) - x;
|
||||
height = (int) (p1.y > p2.y ? p1.y : p2.y) - y;
|
||||
}
|
||||
|
||||
public Rect(Point p, Size s) {
|
||||
this((int) p.x, (int) p.y, (int) s.width, (int) s.height);
|
||||
}
|
||||
|
||||
public Rect(double[] vals) {
|
||||
set(vals);
|
||||
}
|
||||
|
||||
public void set(double[] vals) {
|
||||
if (vals != null) {
|
||||
x = vals.length > 0 ? (int) vals[0] : 0;
|
||||
y = vals.length > 1 ? (int) vals[1] : 0;
|
||||
width = vals.length > 2 ? (int) vals[2] : 0;
|
||||
height = vals.length > 3 ? (int) vals[3] : 0;
|
||||
} else {
|
||||
x = 0;
|
||||
y = 0;
|
||||
width = 0;
|
||||
height = 0;
|
||||
}
|
||||
}
|
||||
|
||||
public Rect clone() {
|
||||
return new Rect(x, y, width, height);
|
||||
}
|
||||
|
||||
public Point tl() {
|
||||
return new Point(x, y);
|
||||
}
|
||||
|
||||
public Point br() {
|
||||
return new Point(x + width, y + height);
|
||||
}
|
||||
|
||||
public Size size() {
|
||||
return new Size(width, height);
|
||||
}
|
||||
|
||||
public double area() {
|
||||
return width * height;
|
||||
}
|
||||
|
||||
public boolean contains(Point p) {
|
||||
return x <= p.x && p.x < x + width && y <= p.y && p.y < y + height;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
final int prime = 31;
|
||||
int result = 1;
|
||||
long temp;
|
||||
temp = Double.doubleToLongBits(height);
|
||||
result = prime * result + (int) (temp ^ (temp >>> 32));
|
||||
temp = Double.doubleToLongBits(width);
|
||||
result = prime * result + (int) (temp ^ (temp >>> 32));
|
||||
temp = Double.doubleToLongBits(x);
|
||||
result = prime * result + (int) (temp ^ (temp >>> 32));
|
||||
temp = Double.doubleToLongBits(y);
|
||||
result = prime * result + (int) (temp ^ (temp >>> 32));
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (this == obj) return true;
|
||||
if (!(obj instanceof Rect)) return false;
|
||||
Rect it = (Rect) obj;
|
||||
return x == it.x && y == it.y && width == it.width && height == it.height;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "{" + x + ", " + y + ", " + width + "x" + height + "}";
|
||||
}
|
||||
}
|
113
modules/java/generator/src/java/core+RotatedRect.java
Normal file
113
modules/java/generator/src/java/core+RotatedRect.java
Normal file
@@ -0,0 +1,113 @@
|
||||
package org.opencv.core;
|
||||
|
||||
//javadoc:RotatedRect_
|
||||
public class RotatedRect {
|
||||
|
||||
public Point center;
|
||||
public Size size;
|
||||
public double angle;
|
||||
|
||||
public RotatedRect() {
|
||||
this.center = new Point();
|
||||
this.size = new Size();
|
||||
this.angle = 0;
|
||||
}
|
||||
|
||||
public RotatedRect(Point c, Size s, double a) {
|
||||
this.center = c.clone();
|
||||
this.size = s.clone();
|
||||
this.angle = a;
|
||||
}
|
||||
|
||||
public RotatedRect(double[] vals) {
|
||||
this();
|
||||
set(vals);
|
||||
}
|
||||
|
||||
public void set(double[] vals) {
|
||||
if (vals != null) {
|
||||
center.x = vals.length > 0 ? (double) vals[0] : 0;
|
||||
center.y = vals.length > 1 ? (double) vals[1] : 0;
|
||||
size.width = vals.length > 2 ? (double) vals[2] : 0;
|
||||
size.height = vals.length > 3 ? (double) vals[3] : 0;
|
||||
angle = vals.length > 4 ? (double) vals[4] : 0;
|
||||
} else {
|
||||
center.x = 0;
|
||||
center.x = 0;
|
||||
size.width = 0;
|
||||
size.height = 0;
|
||||
angle = 0;
|
||||
}
|
||||
}
|
||||
|
||||
public void points(Point pt[])
|
||||
{
|
||||
double _angle = angle * Math.PI / 180.0;
|
||||
double b = (double) Math.cos(_angle) * 0.5f;
|
||||
double a = (double) Math.sin(_angle) * 0.5f;
|
||||
|
||||
pt[0] = new Point(
|
||||
center.x - a * size.height - b * size.width,
|
||||
center.y + b * size.height - a * size.width);
|
||||
|
||||
pt[1] = new Point(
|
||||
center.x + a * size.height - b * size.width,
|
||||
center.y - b * size.height - a * size.width);
|
||||
|
||||
pt[2] = new Point(
|
||||
2 * center.x - pt[0].x,
|
||||
2 * center.y - pt[0].y);
|
||||
|
||||
pt[3] = new Point(
|
||||
2 * center.x - pt[1].x,
|
||||
2 * center.y - pt[1].y);
|
||||
}
|
||||
|
||||
public Rect boundingRect()
|
||||
{
|
||||
Point pt[] = new Point[4];
|
||||
points(pt);
|
||||
Rect r = new Rect((int) Math.floor(Math.min(Math.min(Math.min(pt[0].x, pt[1].x), pt[2].x), pt[3].x)),
|
||||
(int) Math.floor(Math.min(Math.min(Math.min(pt[0].y, pt[1].y), pt[2].y), pt[3].y)),
|
||||
(int) Math.ceil(Math.max(Math.max(Math.max(pt[0].x, pt[1].x), pt[2].x), pt[3].x)),
|
||||
(int) Math.ceil(Math.max(Math.max(Math.max(pt[0].y, pt[1].y), pt[2].y), pt[3].y)));
|
||||
r.width -= r.x - 1;
|
||||
r.height -= r.y - 1;
|
||||
return r;
|
||||
}
|
||||
|
||||
public RotatedRect clone() {
|
||||
return new RotatedRect(center, size, angle);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
final int prime = 31;
|
||||
int result = 1;
|
||||
long temp;
|
||||
temp = Double.doubleToLongBits(center.x);
|
||||
result = prime * result + (int) (temp ^ (temp >>> 32));
|
||||
temp = Double.doubleToLongBits(center.y);
|
||||
result = prime * result + (int) (temp ^ (temp >>> 32));
|
||||
temp = Double.doubleToLongBits(size.width);
|
||||
result = prime * result + (int) (temp ^ (temp >>> 32));
|
||||
temp = Double.doubleToLongBits(size.height);
|
||||
result = prime * result + (int) (temp ^ (temp >>> 32));
|
||||
temp = Double.doubleToLongBits(angle);
|
||||
result = prime * result + (int) (temp ^ (temp >>> 32));
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (this == obj) return true;
|
||||
if (!(obj instanceof RotatedRect)) return false;
|
||||
RotatedRect it = (RotatedRect) obj;
|
||||
return center.equals(it.center) && size.equals(it.size) && angle == it.angle;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "{ " + center + " " + size + " * " + angle + " }";
|
||||
}
|
||||
}
|
90
modules/java/generator/src/java/core+Scalar.java
Normal file
90
modules/java/generator/src/java/core+Scalar.java
Normal file
@@ -0,0 +1,90 @@
|
||||
package org.opencv.core;
|
||||
|
||||
//javadoc:Scalar_
|
||||
public class Scalar {
|
||||
|
||||
public double val[];
|
||||
|
||||
public Scalar(double v0, double v1, double v2, double v3) {
|
||||
val = new double[] { v0, v1, v2, v3 };
|
||||
}
|
||||
|
||||
public Scalar(double v0, double v1, double v2) {
|
||||
val = new double[] { v0, v1, v2, 0 };
|
||||
}
|
||||
|
||||
public Scalar(double v0, double v1) {
|
||||
val = new double[] { v0, v1, 0, 0 };
|
||||
}
|
||||
|
||||
public Scalar(double v0) {
|
||||
val = new double[] { v0, 0, 0, 0 };
|
||||
}
|
||||
|
||||
public Scalar(double[] vals) {
|
||||
if (vals != null && vals.length == 4)
|
||||
val = vals.clone();
|
||||
else {
|
||||
val = new double[4];
|
||||
set(vals);
|
||||
}
|
||||
}
|
||||
|
||||
public void set(double[] vals) {
|
||||
if (vals != null) {
|
||||
val[0] = vals.length > 0 ? vals[0] : 0;
|
||||
val[1] = vals.length > 1 ? vals[1] : 0;
|
||||
val[2] = vals.length > 2 ? vals[2] : 0;
|
||||
val[3] = vals.length > 3 ? vals[3] : 0;
|
||||
} else
|
||||
val[0] = val[1] = val[2] = val[3] = 0;
|
||||
}
|
||||
|
||||
public static Scalar all(double v) {
|
||||
return new Scalar(v, v, v, v);
|
||||
}
|
||||
|
||||
public Scalar clone() {
|
||||
return new Scalar(val);
|
||||
}
|
||||
|
||||
public Scalar mul(Scalar it, double scale) {
|
||||
return new Scalar(val[0] * it.val[0] * scale, val[1] * it.val[1] * scale,
|
||||
val[2] * it.val[2] * scale, val[3] * it.val[3] * scale);
|
||||
}
|
||||
|
||||
public Scalar mul(Scalar it) {
|
||||
return mul(it, 1);
|
||||
}
|
||||
|
||||
public Scalar conj() {
|
||||
return new Scalar(val[0], -val[1], -val[2], -val[3]);
|
||||
}
|
||||
|
||||
public boolean isReal() {
|
||||
return val[1] == 0 && val[2] == 0 && val[3] == 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
final int prime = 31;
|
||||
int result = 1;
|
||||
result = prime * result + java.util.Arrays.hashCode(val);
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (this == obj) return true;
|
||||
if (!(obj instanceof Scalar)) return false;
|
||||
Scalar it = (Scalar) obj;
|
||||
if (!java.util.Arrays.equals(val, it.val)) return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "[" + val[0] + ", " + val[1] + ", " + val[2] + ", " + val[3] + "]";
|
||||
}
|
||||
|
||||
}
|
69
modules/java/generator/src/java/core+Size.java
Normal file
69
modules/java/generator/src/java/core+Size.java
Normal file
@@ -0,0 +1,69 @@
|
||||
package org.opencv.core;
|
||||
|
||||
//javadoc:Size_
|
||||
public class Size {
|
||||
|
||||
public double width, height;
|
||||
|
||||
public Size(double width, double height) {
|
||||
this.width = width;
|
||||
this.height = height;
|
||||
}
|
||||
|
||||
public Size() {
|
||||
this(0, 0);
|
||||
}
|
||||
|
||||
public Size(Point p) {
|
||||
width = p.x;
|
||||
height = p.y;
|
||||
}
|
||||
|
||||
public Size(double[] vals) {
|
||||
set(vals);
|
||||
}
|
||||
|
||||
public void set(double[] vals) {
|
||||
if (vals != null) {
|
||||
width = vals.length > 0 ? vals[0] : 0;
|
||||
height = vals.length > 1 ? vals[1] : 0;
|
||||
} else {
|
||||
width = 0;
|
||||
height = 0;
|
||||
}
|
||||
}
|
||||
|
||||
public double area() {
|
||||
return width * height;
|
||||
}
|
||||
|
||||
public Size clone() {
|
||||
return new Size(width, height);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
final int prime = 31;
|
||||
int result = 1;
|
||||
long temp;
|
||||
temp = Double.doubleToLongBits(height);
|
||||
result = prime * result + (int) (temp ^ (temp >>> 32));
|
||||
temp = Double.doubleToLongBits(width);
|
||||
result = prime * result + (int) (temp ^ (temp >>> 32));
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (this == obj) return true;
|
||||
if (!(obj instanceof Size)) return false;
|
||||
Size it = (Size) obj;
|
||||
return width == it.width && height == it.height;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return (int)width + "x" + (int)height;
|
||||
}
|
||||
|
||||
}
|
93
modules/java/generator/src/java/core+TermCriteria.java
Normal file
93
modules/java/generator/src/java/core+TermCriteria.java
Normal file
@@ -0,0 +1,93 @@
|
||||
package org.opencv.core;
|
||||
|
||||
//javadoc:TermCriteria
|
||||
public class TermCriteria {
|
||||
|
||||
/**
|
||||
* the maximum number of iterations or elements to compute
|
||||
*/
|
||||
public static final int COUNT = 1;
|
||||
/**
|
||||
* the maximum number of iterations or elements to compute
|
||||
*/
|
||||
public static final int MAX_ITER = COUNT;
|
||||
/**
|
||||
* the desired accuracy or change in parameters at which the iterative algorithm stops
|
||||
*/
|
||||
public static final int EPS = 2;
|
||||
|
||||
public int type;
|
||||
public int maxCount;
|
||||
public double epsilon;
|
||||
|
||||
/**
|
||||
* Termination criteria in iterative algorithms
|
||||
*
|
||||
* @param type
|
||||
* the type of termination criteria: COUNT, EPS or COUNT + EPS
|
||||
* @param maxCount
|
||||
* the maximum number of iterations/elements
|
||||
* @param epsilon
|
||||
* the desired accuracy
|
||||
*/
|
||||
public TermCriteria(int type, int maxCount, double epsilon) {
|
||||
this.type = type;
|
||||
this.maxCount = maxCount;
|
||||
this.epsilon = epsilon;
|
||||
}
|
||||
|
||||
/**
|
||||
* Termination criteria in iterative algorithms
|
||||
*/
|
||||
public TermCriteria() {
|
||||
this(0, 0, 0.0);
|
||||
}
|
||||
|
||||
public TermCriteria(double[] vals) {
|
||||
set(vals);
|
||||
}
|
||||
|
||||
public void set(double[] vals) {
|
||||
if (vals != null) {
|
||||
type = vals.length > 0 ? (int) vals[0] : 0;
|
||||
maxCount = vals.length > 1 ? (int) vals[1] : 0;
|
||||
epsilon = vals.length > 2 ? (double) vals[2] : 0;
|
||||
} else {
|
||||
type = 0;
|
||||
maxCount = 0;
|
||||
epsilon = 0;
|
||||
}
|
||||
}
|
||||
|
||||
public TermCriteria clone() {
|
||||
return new TermCriteria(type, maxCount, epsilon);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
final int prime = 31;
|
||||
int result = 1;
|
||||
long temp;
|
||||
temp = Double.doubleToLongBits(type);
|
||||
result = prime * result + (int) (temp ^ (temp >>> 32));
|
||||
temp = Double.doubleToLongBits(maxCount);
|
||||
result = prime * result + (int) (temp ^ (temp >>> 32));
|
||||
temp = Double.doubleToLongBits(epsilon);
|
||||
result = prime * result + (int) (temp ^ (temp >>> 32));
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (this == obj) return true;
|
||||
if (!(obj instanceof TermCriteria)) return false;
|
||||
TermCriteria it = (TermCriteria) obj;
|
||||
return type == it.type && maxCount == it.maxCount && epsilon == it.epsilon;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
if (this == null) return "null";
|
||||
return "{ type: " + type + ", maxCount: " + maxCount + ", epsilon: " + epsilon + "}";
|
||||
}
|
||||
}
|
61
modules/java/generator/src/java/features2d+DMatch.java
Normal file
61
modules/java/generator/src/java/features2d+DMatch.java
Normal file
@@ -0,0 +1,61 @@
|
||||
package org.opencv.features2d;
|
||||
|
||||
//C++: class DMatch
|
||||
|
||||
/**
|
||||
* Struct for matching: query descriptor index, train descriptor index, train
|
||||
* image index and distance between descriptors.
|
||||
*/
|
||||
public class DMatch {
|
||||
|
||||
/**
|
||||
* query descriptor index
|
||||
*/
|
||||
public int queryIdx;
|
||||
/**
|
||||
* train descriptor index
|
||||
*/
|
||||
public int trainIdx;
|
||||
/**
|
||||
* train image index
|
||||
*/
|
||||
public int imgIdx;
|
||||
|
||||
// javadoc: DMatch::distance
|
||||
public float distance;
|
||||
|
||||
// javadoc: DMatch::DMatch()
|
||||
public DMatch() {
|
||||
this(-1, -1, Float.MAX_VALUE);
|
||||
}
|
||||
|
||||
// javadoc: DMatch::DMatch(_queryIdx, _trainIdx, _distance)
|
||||
public DMatch(int _queryIdx, int _trainIdx, float _distance) {
|
||||
queryIdx = _queryIdx;
|
||||
trainIdx = _trainIdx;
|
||||
imgIdx = -1;
|
||||
distance = _distance;
|
||||
}
|
||||
|
||||
// javadoc: DMatch::DMatch(_queryIdx, _trainIdx, _imgIdx, _distance)
|
||||
public DMatch(int _queryIdx, int _trainIdx, int _imgIdx, float _distance) {
|
||||
queryIdx = _queryIdx;
|
||||
trainIdx = _trainIdx;
|
||||
imgIdx = _imgIdx;
|
||||
distance = _distance;
|
||||
}
|
||||
|
||||
/**
|
||||
* less is better
|
||||
*/
|
||||
public boolean lessThan(DMatch it) {
|
||||
return distance < it.distance;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "DMatch [queryIdx=" + queryIdx + ", trainIdx=" + trainIdx
|
||||
+ ", imgIdx=" + imgIdx + ", distance=" + distance + "]";
|
||||
}
|
||||
|
||||
}
|
83
modules/java/generator/src/java/features2d+KeyPoint.java
Normal file
83
modules/java/generator/src/java/features2d+KeyPoint.java
Normal file
@@ -0,0 +1,83 @@
|
||||
package org.opencv.features2d;
|
||||
|
||||
import org.opencv.core.Point;
|
||||
|
||||
//javadoc: KeyPoint
|
||||
public class KeyPoint {
|
||||
|
||||
/**
|
||||
* coordinates of the keypoint
|
||||
*/
|
||||
public Point pt;
|
||||
/**
|
||||
* diameter of the meaningful keypoint neighborhood
|
||||
*/
|
||||
public float size;
|
||||
/**
|
||||
* computed orientation of the keypoint (-1 if not applicable)
|
||||
*/
|
||||
public float angle;
|
||||
/**
|
||||
* the response by which the most strong keypoints have been selected. Can
|
||||
* be used for further sorting or subsampling
|
||||
*/
|
||||
public float response;
|
||||
/**
|
||||
* octave (pyramid layer) from which the keypoint has been extracted
|
||||
*/
|
||||
public int octave;
|
||||
/**
|
||||
* object id that can be used to clustered keypoints by an object they
|
||||
* belong to
|
||||
*/
|
||||
public int class_id;
|
||||
|
||||
// javadoc:KeyPoint::KeyPoint(x,y,_size,_angle,_response,_octave,_class_id)
|
||||
public KeyPoint(float x, float y, float _size, float _angle, float _response, int _octave, int _class_id)
|
||||
{
|
||||
pt = new Point(x, y);
|
||||
size = _size;
|
||||
angle = _angle;
|
||||
response = _response;
|
||||
octave = _octave;
|
||||
class_id = _class_id;
|
||||
}
|
||||
|
||||
// javadoc: KeyPoint::KeyPoint()
|
||||
public KeyPoint()
|
||||
{
|
||||
this(0, 0, 0, -1, 0, 0, -1);
|
||||
}
|
||||
|
||||
// javadoc: KeyPoint::KeyPoint(x, y, _size, _angle, _response, _octave)
|
||||
public KeyPoint(float x, float y, float _size, float _angle, float _response, int _octave)
|
||||
{
|
||||
this(x, y, _size, _angle, _response, _octave, -1);
|
||||
}
|
||||
|
||||
// javadoc: KeyPoint::KeyPoint(x, y, _size, _angle, _response)
|
||||
public KeyPoint(float x, float y, float _size, float _angle, float _response)
|
||||
{
|
||||
this(x, y, _size, _angle, _response, 0, -1);
|
||||
}
|
||||
|
||||
// javadoc: KeyPoint::KeyPoint(x, y, _size, _angle)
|
||||
public KeyPoint(float x, float y, float _size, float _angle)
|
||||
{
|
||||
this(x, y, _size, _angle, 0, 0, -1);
|
||||
}
|
||||
|
||||
// javadoc: KeyPoint::KeyPoint(x, y, _size)
|
||||
public KeyPoint(float x, float y, float _size)
|
||||
{
|
||||
this(x, y, _size, -1, 0, 0, -1);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "KeyPoint [pt=" + pt + ", size=" + size + ", angle=" + angle
|
||||
+ ", response=" + response + ", octave=" + octave
|
||||
+ ", class_id=" + class_id + "]";
|
||||
}
|
||||
|
||||
}
|
246
modules/java/generator/src/java/highgui+VideoCapture.java
Normal file
246
modules/java/generator/src/java/highgui+VideoCapture.java
Normal file
@@ -0,0 +1,246 @@
|
||||
package org.opencv.highgui;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.LinkedList;
|
||||
|
||||
import org.opencv.core.Mat;
|
||||
import org.opencv.core.Size;
|
||||
|
||||
// C++: class VideoCapture
|
||||
//javadoc: VideoCapture
|
||||
public class VideoCapture {
|
||||
|
||||
protected final long nativeObj;
|
||||
|
||||
protected VideoCapture(long addr) {
|
||||
nativeObj = addr;
|
||||
}
|
||||
|
||||
//
|
||||
// C++: VideoCapture::VideoCapture()
|
||||
//
|
||||
|
||||
// javadoc: VideoCapture::VideoCapture()
|
||||
public VideoCapture()
|
||||
{
|
||||
|
||||
nativeObj = n_VideoCapture();
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
//
|
||||
// C++: VideoCapture::VideoCapture(int device)
|
||||
//
|
||||
|
||||
// javadoc: VideoCapture::VideoCapture(device)
|
||||
public VideoCapture(int device)
|
||||
{
|
||||
|
||||
nativeObj = n_VideoCapture(device);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
//
|
||||
// C++: double VideoCapture::get(int propId)
|
||||
//
|
||||
|
||||
/**
|
||||
* Returns the specified "VideoCapture" property
|
||||
*
|
||||
* Note: When querying a property that is not supported by the backend used by
|
||||
* the "VideoCapture" class, value 0 is returned.
|
||||
*
|
||||
* @param propId Property identifier. It can be one of the following:
|
||||
* * CV_CAP_PROP_FRAME_WIDTH Width of the frames in the video stream.
|
||||
* * CV_CAP_PROP_FRAME_HEIGHT Height of the frames in the video stream.
|
||||
*
|
||||
* @see <a href="http://opencv.itseez.com/modules/highgui/doc/reading_and_writing_images_and_video.html#videocapture-get">org.opencv.highgui.VideoCapture.get</a>
|
||||
*/
|
||||
public double get(int propId)
|
||||
{
|
||||
|
||||
double retVal = n_get(nativeObj, propId);
|
||||
|
||||
return retVal;
|
||||
}
|
||||
|
||||
public List<Size> getSupportedPreviewSizes()
|
||||
{
|
||||
String[] sizes_str = n_getSupportedPreviewSizes(nativeObj).split(",");
|
||||
List<Size> sizes = new LinkedList<Size>();
|
||||
|
||||
for (String str : sizes_str) {
|
||||
String[] wh = str.split("x");
|
||||
sizes.add(new Size(Double.parseDouble(wh[0]), Double.parseDouble(wh[1])));
|
||||
}
|
||||
|
||||
return sizes;
|
||||
}
|
||||
|
||||
//
|
||||
// C++: bool VideoCapture::grab()
|
||||
//
|
||||
|
||||
// javadoc: VideoCapture::grab()
|
||||
public boolean grab()
|
||||
{
|
||||
|
||||
boolean retVal = n_grab(nativeObj);
|
||||
|
||||
return retVal;
|
||||
}
|
||||
|
||||
//
|
||||
// C++: bool VideoCapture::isOpened()
|
||||
//
|
||||
|
||||
// javadoc: VideoCapture::isOpened()
|
||||
public boolean isOpened()
|
||||
{
|
||||
|
||||
boolean retVal = n_isOpened(nativeObj);
|
||||
|
||||
return retVal;
|
||||
}
|
||||
|
||||
//
|
||||
// C++: bool VideoCapture::open(int device)
|
||||
//
|
||||
|
||||
// javadoc: VideoCapture::open(device)
|
||||
public boolean open(int device)
|
||||
{
|
||||
|
||||
boolean retVal = n_open(nativeObj, device);
|
||||
|
||||
return retVal;
|
||||
}
|
||||
|
||||
//
|
||||
// C++: bool VideoCapture::read(Mat image)
|
||||
//
|
||||
|
||||
// javadoc: VideoCapture::read(image)
|
||||
public boolean read(Mat image)
|
||||
{
|
||||
|
||||
boolean retVal = n_read(nativeObj, image.nativeObj);
|
||||
|
||||
return retVal;
|
||||
}
|
||||
|
||||
//
|
||||
// C++: void VideoCapture::release()
|
||||
//
|
||||
|
||||
// javadoc: VideoCapture::release()
|
||||
public void release()
|
||||
{
|
||||
|
||||
n_release(nativeObj);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
//
|
||||
// C++: bool VideoCapture::retrieve(Mat image, int channel = 0)
|
||||
//
|
||||
|
||||
// javadoc: VideoCapture::retrieve(image, channel)
|
||||
public boolean retrieve(Mat image, int channel)
|
||||
{
|
||||
|
||||
boolean retVal = n_retrieve(nativeObj, image.nativeObj, channel);
|
||||
|
||||
return retVal;
|
||||
}
|
||||
|
||||
// javadoc: VideoCapture::retrieve(image)
|
||||
public boolean retrieve(Mat image)
|
||||
{
|
||||
|
||||
boolean retVal = n_retrieve(nativeObj, image.nativeObj);
|
||||
|
||||
return retVal;
|
||||
}
|
||||
|
||||
//
|
||||
// C++: bool VideoCapture::set(int propId, double value)
|
||||
//
|
||||
|
||||
/**
|
||||
* Sets a property in the "VideoCapture".
|
||||
*
|
||||
* @param propId Property identifier. It can be one of the following:
|
||||
* * CV_CAP_PROP_FRAME_WIDTH Width of the frames in the video stream.
|
||||
* * CV_CAP_PROP_FRAME_HEIGHT Height of the frames in the video stream.
|
||||
* @param value Value of the property.
|
||||
*
|
||||
* @see <a href="http://opencv.itseez.com/modules/highgui/doc/reading_and_writing_images_and_video.html#videocapture-set">org.opencv.highgui.VideoCapture.set</a>
|
||||
*/
|
||||
public boolean set(int propId, double value)
|
||||
{
|
||||
|
||||
boolean retVal = n_set(nativeObj, propId, value);
|
||||
|
||||
return retVal;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void finalize() throws Throwable {
|
||||
n_delete(nativeObj);
|
||||
super.finalize();
|
||||
}
|
||||
|
||||
// native stuff
|
||||
|
||||
static {
|
||||
System.loadLibrary("opencv_java");
|
||||
}
|
||||
|
||||
// C++: VideoCapture::VideoCapture()
|
||||
private static native long n_VideoCapture();
|
||||
|
||||
// C++: VideoCapture::VideoCapture(string filename)
|
||||
private static native long n_VideoCapture(java.lang.String filename);
|
||||
|
||||
// C++: VideoCapture::VideoCapture(int device)
|
||||
private static native long n_VideoCapture(int device);
|
||||
|
||||
// C++: double VideoCapture::get(int propId)
|
||||
private static native double n_get(long nativeObj, int propId);
|
||||
|
||||
// C++: bool VideoCapture::grab()
|
||||
private static native boolean n_grab(long nativeObj);
|
||||
|
||||
// C++: bool VideoCapture::isOpened()
|
||||
private static native boolean n_isOpened(long nativeObj);
|
||||
|
||||
// C++: bool VideoCapture::open(string filename)
|
||||
private static native boolean n_open(long nativeObj, java.lang.String filename);
|
||||
|
||||
// C++: bool VideoCapture::open(int device)
|
||||
private static native boolean n_open(long nativeObj, int device);
|
||||
|
||||
// C++: bool VideoCapture::read(Mat image)
|
||||
private static native boolean n_read(long nativeObj, long image_nativeObj);
|
||||
|
||||
// C++: void VideoCapture::release()
|
||||
private static native void n_release(long nativeObj);
|
||||
|
||||
// C++: bool VideoCapture::retrieve(Mat image, int channel = 0)
|
||||
private static native boolean n_retrieve(long nativeObj, long image_nativeObj, int channel);
|
||||
|
||||
private static native boolean n_retrieve(long nativeObj, long image_nativeObj);
|
||||
|
||||
// C++: bool VideoCapture::set(int propId, double value)
|
||||
private static native boolean n_set(long nativeObj, int propId, double value);
|
||||
|
||||
private static native String n_getSupportedPreviewSizes(long nativeObj);
|
||||
|
||||
// native support for java finalize()
|
||||
private static native void n_delete(long nativeObj);
|
||||
|
||||
}
|
730
modules/java/generator/src/java/utils+Converters.java
Normal file
730
modules/java/generator/src/java/utils+Converters.java
Normal file
@@ -0,0 +1,730 @@
|
||||
package org.opencv.utils;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.opencv.core.CvType;
|
||||
import org.opencv.core.Mat;
|
||||
import org.opencv.core.MatOfByte;
|
||||
import org.opencv.core.MatOfDMatch;
|
||||
import org.opencv.core.MatOfKeyPoint;
|
||||
import org.opencv.core.MatOfPoint;
|
||||
import org.opencv.core.MatOfPoint2f;
|
||||
import org.opencv.core.MatOfPoint3f;
|
||||
import org.opencv.core.Point;
|
||||
import org.opencv.core.Point3;
|
||||
import org.opencv.core.Rect;
|
||||
import org.opencv.features2d.DMatch;
|
||||
import org.opencv.features2d.KeyPoint;
|
||||
|
||||
public class Converters {
|
||||
|
||||
public static Mat vector_Point_to_Mat(List<Point> pts) {
|
||||
return vector_Point_to_Mat(pts, CvType.CV_32S);
|
||||
}
|
||||
|
||||
public static Mat vector_Point2f_to_Mat(List<Point> pts) {
|
||||
return vector_Point_to_Mat(pts, CvType.CV_32F);
|
||||
}
|
||||
|
||||
public static Mat vector_Point2d_to_Mat(List<Point> pts) {
|
||||
return vector_Point_to_Mat(pts, CvType.CV_64F);
|
||||
}
|
||||
|
||||
public static Mat vector_Point_to_Mat(List<Point> pts, int typeDepth) {
|
||||
Mat res;
|
||||
int count = (pts != null) ? pts.size() : 0;
|
||||
if (count > 0) {
|
||||
switch (typeDepth) {
|
||||
case CvType.CV_32S: {
|
||||
res = new Mat(count, 1, CvType.CV_32SC2);
|
||||
int[] buff = new int[count * 2];
|
||||
for (int i = 0; i < count; i++) {
|
||||
Point p = pts.get(i);
|
||||
buff[i * 2] = (int) p.x;
|
||||
buff[i * 2 + 1] = (int) p.y;
|
||||
}
|
||||
res.put(0, 0, buff);
|
||||
}
|
||||
break;
|
||||
|
||||
case CvType.CV_32F: {
|
||||
res = new Mat(count, 1, CvType.CV_32FC2);
|
||||
float[] buff = new float[count * 2];
|
||||
for (int i = 0; i < count; i++) {
|
||||
Point p = pts.get(i);
|
||||
buff[i * 2] = (float) p.x;
|
||||
buff[i * 2 + 1] = (float) p.y;
|
||||
}
|
||||
res.put(0, 0, buff);
|
||||
}
|
||||
break;
|
||||
|
||||
case CvType.CV_64F: {
|
||||
res = new Mat(count, 1, CvType.CV_64FC2);
|
||||
double[] buff = new double[count * 2];
|
||||
for (int i = 0; i < count; i++) {
|
||||
Point p = pts.get(i);
|
||||
buff[i * 2] = p.x;
|
||||
buff[i * 2 + 1] = p.y;
|
||||
}
|
||||
res.put(0, 0, buff);
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
throw new IllegalArgumentException("'typeDepth' can be CV_32S, CV_32F or CV_64F");
|
||||
}
|
||||
} else {
|
||||
res = new Mat();
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
public static Mat vector_Point3i_to_Mat(List<Point3> pts) {
|
||||
return vector_Point3_to_Mat(pts, CvType.CV_32S);
|
||||
}
|
||||
|
||||
public static Mat vector_Point3f_to_Mat(List<Point3> pts) {
|
||||
return vector_Point3_to_Mat(pts, CvType.CV_32F);
|
||||
}
|
||||
|
||||
public static Mat vector_Point3d_to_Mat(List<Point3> pts) {
|
||||
return vector_Point3_to_Mat(pts, CvType.CV_64F);
|
||||
}
|
||||
|
||||
public static Mat vector_Point3_to_Mat(List<Point3> pts, int typeDepth) {
|
||||
Mat res;
|
||||
int count = (pts != null) ? pts.size() : 0;
|
||||
if (count > 0) {
|
||||
switch (typeDepth) {
|
||||
case CvType.CV_32S: {
|
||||
res = new Mat(count, 1, CvType.CV_32SC3);
|
||||
int[] buff = new int[count * 3];
|
||||
for (int i = 0; i < count; i++) {
|
||||
Point3 p = pts.get(i);
|
||||
buff[i * 3] = (int) p.x;
|
||||
buff[i * 3 + 1] = (int) p.y;
|
||||
buff[i * 3 + 2] = (int) p.z;
|
||||
}
|
||||
res.put(0, 0, buff);
|
||||
}
|
||||
break;
|
||||
|
||||
case CvType.CV_32F: {
|
||||
res = new Mat(count, 1, CvType.CV_32FC3);
|
||||
float[] buff = new float[count * 3];
|
||||
for (int i = 0; i < count; i++) {
|
||||
Point3 p = pts.get(i);
|
||||
buff[i * 3] = (float) p.x;
|
||||
buff[i * 3 + 1] = (float) p.y;
|
||||
buff[i * 3 + 2] = (float) p.z;
|
||||
}
|
||||
res.put(0, 0, buff);
|
||||
}
|
||||
break;
|
||||
|
||||
case CvType.CV_64F: {
|
||||
res = new Mat(count, 1, CvType.CV_64FC3);
|
||||
double[] buff = new double[count * 3];
|
||||
for (int i = 0; i < count; i++) {
|
||||
Point3 p = pts.get(i);
|
||||
buff[i * 3] = p.x;
|
||||
buff[i * 3 + 1] = p.y;
|
||||
buff[i * 3 + 2] = p.z;
|
||||
}
|
||||
res.put(0, 0, buff);
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
throw new IllegalArgumentException("'typeDepth' can be CV_32S, CV_32F or CV_64F");
|
||||
}
|
||||
} else {
|
||||
res = new Mat();
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
public static void Mat_to_vector_Point2f(Mat m, List<Point> pts) {
|
||||
Mat_to_vector_Point(m, pts);
|
||||
}
|
||||
|
||||
public static void Mat_to_vector_Point2d(Mat m, List<Point> pts) {
|
||||
Mat_to_vector_Point(m, pts);
|
||||
}
|
||||
|
||||
public static void Mat_to_vector_Point(Mat m, List<Point> pts) {
|
||||
if (pts == null)
|
||||
throw new java.lang.IllegalArgumentException("Output List can't be null");
|
||||
int count = m.rows();
|
||||
int type = m.type();
|
||||
if (m.cols() != 1)
|
||||
throw new java.lang.IllegalArgumentException("Input Mat should have one column\n" + m);
|
||||
|
||||
pts.clear();
|
||||
if (type == CvType.CV_32SC2) {
|
||||
int[] buff = new int[2 * count];
|
||||
m.get(0, 0, buff);
|
||||
for (int i = 0; i < count; i++) {
|
||||
pts.add(new Point(buff[i * 2], buff[i * 2 + 1]));
|
||||
}
|
||||
} else if (type == CvType.CV_32FC2) {
|
||||
float[] buff = new float[2 * count];
|
||||
m.get(0, 0, buff);
|
||||
for (int i = 0; i < count; i++) {
|
||||
pts.add(new Point(buff[i * 2], buff[i * 2 + 1]));
|
||||
}
|
||||
} else if (type == CvType.CV_64FC2) {
|
||||
double[] buff = new double[2 * count];
|
||||
m.get(0, 0, buff);
|
||||
for (int i = 0; i < count; i++) {
|
||||
pts.add(new Point(buff[i * 2], buff[i * 2 + 1]));
|
||||
}
|
||||
} else {
|
||||
throw new java.lang.IllegalArgumentException(
|
||||
"Input Mat should be of CV_32SC2, CV_32FC2 or CV_64FC2 type\n" + m);
|
||||
}
|
||||
}
|
||||
|
||||
public static void Mat_to_vector_Point3i(Mat m, List<Point3> pts) {
|
||||
Mat_to_vector_Point3(m, pts);
|
||||
}
|
||||
|
||||
public static void Mat_to_vector_Point3f(Mat m, List<Point3> pts) {
|
||||
Mat_to_vector_Point3(m, pts);
|
||||
}
|
||||
|
||||
public static void Mat_to_vector_Point3d(Mat m, List<Point3> pts) {
|
||||
Mat_to_vector_Point3(m, pts);
|
||||
}
|
||||
|
||||
public static void Mat_to_vector_Point3(Mat m, List<Point3> pts) {
|
||||
if (pts == null)
|
||||
throw new java.lang.IllegalArgumentException("Output List can't be null");
|
||||
int count = m.rows();
|
||||
int type = m.type();
|
||||
if (m.cols() != 1)
|
||||
throw new java.lang.IllegalArgumentException("Input Mat should have one column\n" + m);
|
||||
|
||||
pts.clear();
|
||||
if (type == CvType.CV_32SC3) {
|
||||
int[] buff = new int[3 * count];
|
||||
m.get(0, 0, buff);
|
||||
for (int i = 0; i < count; i++) {
|
||||
pts.add(new Point3(buff[i * 3], buff[i * 3 + 1], buff[i * 3 + 2]));
|
||||
}
|
||||
} else if (type == CvType.CV_32FC3) {
|
||||
float[] buff = new float[3 * count];
|
||||
m.get(0, 0, buff);
|
||||
for (int i = 0; i < count; i++) {
|
||||
pts.add(new Point3(buff[i * 3], buff[i * 3 + 1], buff[i * 3 + 2]));
|
||||
}
|
||||
} else if (type == CvType.CV_64FC3) {
|
||||
double[] buff = new double[3 * count];
|
||||
m.get(0, 0, buff);
|
||||
for (int i = 0; i < count; i++) {
|
||||
pts.add(new Point3(buff[i * 3], buff[i * 3 + 1], buff[i * 3 + 2]));
|
||||
}
|
||||
} else {
|
||||
throw new java.lang.IllegalArgumentException(
|
||||
"Input Mat should be of CV_32SC3, CV_32FC3 or CV_64FC3 type\n" + m);
|
||||
}
|
||||
}
|
||||
|
||||
public static Mat vector_Mat_to_Mat(List<Mat> mats) {
|
||||
Mat res;
|
||||
int count = (mats != null) ? mats.size() : 0;
|
||||
if (count > 0) {
|
||||
res = new Mat(count, 1, CvType.CV_32SC2);
|
||||
int[] buff = new int[count * 2];
|
||||
for (int i = 0; i < count; i++) {
|
||||
long addr = mats.get(i).nativeObj;
|
||||
buff[i * 2] = (int) (addr >> 32);
|
||||
buff[i * 2 + 1] = (int) (addr & 0xffffffff);
|
||||
}
|
||||
res.put(0, 0, buff);
|
||||
} else {
|
||||
res = new Mat();
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
public static void Mat_to_vector_Mat(Mat m, List<Mat> mats) {
|
||||
if (mats == null)
|
||||
throw new java.lang.IllegalArgumentException("mats == null");
|
||||
int count = m.rows();
|
||||
if (CvType.CV_32SC2 != m.type() || m.cols() != 1)
|
||||
throw new java.lang.IllegalArgumentException(
|
||||
"CvType.CV_32SC2 != m.type() || m.cols()!=1\n" + m);
|
||||
|
||||
mats.clear();
|
||||
int[] buff = new int[count * 2];
|
||||
m.get(0, 0, buff);
|
||||
for (int i = 0; i < count; i++) {
|
||||
long addr = (((long) buff[i * 2]) << 32) | ((long) buff[i * 2 + 1]);
|
||||
mats.add(new Mat(addr));
|
||||
}
|
||||
}
|
||||
|
||||
public static Mat vector_float_to_Mat(List<Float> fs) {
|
||||
Mat res;
|
||||
int count = (fs != null) ? fs.size() : 0;
|
||||
if (count > 0) {
|
||||
res = new Mat(count, 1, CvType.CV_32FC1);
|
||||
float[] buff = new float[count];
|
||||
for (int i = 0; i < count; i++) {
|
||||
float f = fs.get(i);
|
||||
buff[i] = f;
|
||||
}
|
||||
res.put(0, 0, buff);
|
||||
} else {
|
||||
res = new Mat();
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
public static void Mat_to_vector_float(Mat m, List<Float> fs) {
|
||||
if (fs == null)
|
||||
throw new java.lang.IllegalArgumentException("fs == null");
|
||||
int count = m.rows();
|
||||
if (CvType.CV_32FC1 != m.type() || m.cols() != 1)
|
||||
throw new java.lang.IllegalArgumentException(
|
||||
"CvType.CV_32FC1 != m.type() || m.cols()!=1\n" + m);
|
||||
|
||||
fs.clear();
|
||||
float[] buff = new float[count];
|
||||
m.get(0, 0, buff);
|
||||
for (int i = 0; i < count; i++) {
|
||||
fs.add(buff[i]);
|
||||
}
|
||||
}
|
||||
|
||||
public static Mat vector_uchar_to_Mat(List<Byte> bs) {
|
||||
Mat res;
|
||||
int count = (bs != null) ? bs.size() : 0;
|
||||
if (count > 0) {
|
||||
res = new Mat(count, 1, CvType.CV_8UC1);
|
||||
byte[] buff = new byte[count];
|
||||
for (int i = 0; i < count; i++) {
|
||||
byte b = bs.get(i);
|
||||
buff[i] = b;
|
||||
}
|
||||
res.put(0, 0, buff);
|
||||
} else {
|
||||
res = new Mat();
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
public static void Mat_to_vector_uchar(Mat m, List<Byte> us) {
|
||||
if (us == null)
|
||||
throw new java.lang.IllegalArgumentException("Output List can't be null");
|
||||
int count = m.rows();
|
||||
if (CvType.CV_8UC1 != m.type() || m.cols() != 1)
|
||||
throw new java.lang.IllegalArgumentException(
|
||||
"CvType.CV_8UC1 != m.type() || m.cols()!=1\n" + m);
|
||||
|
||||
us.clear();
|
||||
byte[] buff = new byte[count];
|
||||
m.get(0, 0, buff);
|
||||
for (int i = 0; i < count; i++) {
|
||||
us.add(buff[i]);
|
||||
}
|
||||
}
|
||||
|
||||
public static Mat vector_char_to_Mat(List<Byte> bs) {
|
||||
Mat res;
|
||||
int count = (bs != null) ? bs.size() : 0;
|
||||
if (count > 0) {
|
||||
res = new Mat(count, 1, CvType.CV_8SC1);
|
||||
byte[] buff = new byte[count];
|
||||
for (int i = 0; i < count; i++) {
|
||||
byte b = bs.get(i);
|
||||
buff[i] = b;
|
||||
}
|
||||
res.put(0, 0, buff);
|
||||
} else {
|
||||
res = new Mat();
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
public static Mat vector_int_to_Mat(List<Integer> is) {
|
||||
Mat res;
|
||||
int count = (is != null) ? is.size() : 0;
|
||||
if (count > 0) {
|
||||
res = new Mat(count, 1, CvType.CV_32SC1);
|
||||
int[] buff = new int[count];
|
||||
for (int i = 0; i < count; i++) {
|
||||
int v = is.get(i);
|
||||
buff[i] = v;
|
||||
}
|
||||
res.put(0, 0, buff);
|
||||
} else {
|
||||
res = new Mat();
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
public static void Mat_to_vector_int(Mat m, List<Integer> is) {
|
||||
if (is == null)
|
||||
throw new java.lang.IllegalArgumentException("is == null");
|
||||
int count = m.rows();
|
||||
if (CvType.CV_32SC1 != m.type() || m.cols() != 1)
|
||||
throw new java.lang.IllegalArgumentException(
|
||||
"CvType.CV_32SC1 != m.type() || m.cols()!=1\n" + m);
|
||||
|
||||
is.clear();
|
||||
int[] buff = new int[count];
|
||||
m.get(0, 0, buff);
|
||||
for (int i = 0; i < count; i++) {
|
||||
is.add(buff[i]);
|
||||
}
|
||||
}
|
||||
|
||||
public static void Mat_to_vector_char(Mat m, List<Byte> bs) {
|
||||
if (bs == null)
|
||||
throw new java.lang.IllegalArgumentException("Output List can't be null");
|
||||
int count = m.rows();
|
||||
if (CvType.CV_8SC1 != m.type() || m.cols() != 1)
|
||||
throw new java.lang.IllegalArgumentException(
|
||||
"CvType.CV_8SC1 != m.type() || m.cols()!=1\n" + m);
|
||||
|
||||
bs.clear();
|
||||
byte[] buff = new byte[count];
|
||||
m.get(0, 0, buff);
|
||||
for (int i = 0; i < count; i++) {
|
||||
bs.add(buff[i]);
|
||||
}
|
||||
}
|
||||
|
||||
public static Mat vector_Rect_to_Mat(List<Rect> rs) {
|
||||
Mat res;
|
||||
int count = (rs != null) ? rs.size() : 0;
|
||||
if (count > 0) {
|
||||
res = new Mat(count, 1, CvType.CV_32SC4);
|
||||
int[] buff = new int[4 * count];
|
||||
for (int i = 0; i < count; i++) {
|
||||
Rect r = rs.get(i);
|
||||
buff[4 * i] = r.x;
|
||||
buff[4 * i + 1] = r.y;
|
||||
buff[4 * i + 2] = r.width;
|
||||
buff[4 * i + 3] = r.height;
|
||||
}
|
||||
res.put(0, 0, buff);
|
||||
} else {
|
||||
res = new Mat();
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
public static void Mat_to_vector_Rect(Mat m, List<Rect> rs) {
|
||||
if (rs == null)
|
||||
throw new java.lang.IllegalArgumentException("rs == null");
|
||||
int count = m.rows();
|
||||
if (CvType.CV_32SC4 != m.type() || m.cols() != 1)
|
||||
throw new java.lang.IllegalArgumentException(
|
||||
"CvType.CV_32SC4 != m.type() || m.rows()!=1\n" + m);
|
||||
|
||||
rs.clear();
|
||||
int[] buff = new int[4 * count];
|
||||
m.get(0, 0, buff);
|
||||
for (int i = 0; i < count; i++) {
|
||||
rs.add(new Rect(buff[4 * i], buff[4 * i + 1], buff[4 * i + 2], buff[4 * i + 3]));
|
||||
}
|
||||
}
|
||||
|
||||
public static Mat vector_KeyPoint_to_Mat(List<KeyPoint> kps) {
|
||||
Mat res;
|
||||
int count = (kps != null) ? kps.size() : 0;
|
||||
if (count > 0) {
|
||||
res = new Mat(count, 1, CvType.CV_64FC(7));
|
||||
double[] buff = new double[count * 7];
|
||||
for (int i = 0; i < count; i++) {
|
||||
KeyPoint kp = kps.get(i);
|
||||
buff[7 * i] = kp.pt.x;
|
||||
buff[7 * i + 1] = kp.pt.y;
|
||||
buff[7 * i + 2] = kp.size;
|
||||
buff[7 * i + 3] = kp.angle;
|
||||
buff[7 * i + 4] = kp.response;
|
||||
buff[7 * i + 5] = kp.octave;
|
||||
buff[7 * i + 6] = kp.class_id;
|
||||
}
|
||||
res.put(0, 0, buff);
|
||||
} else {
|
||||
res = new Mat();
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
public static void Mat_to_vector_KeyPoint(Mat m, List<KeyPoint> kps) {
|
||||
if (kps == null)
|
||||
throw new java.lang.IllegalArgumentException("Output List can't be null");
|
||||
int count = m.rows();
|
||||
if (CvType.CV_64FC(7) != m.type() || m.cols() != 1)
|
||||
throw new java.lang.IllegalArgumentException(
|
||||
"CvType.CV_64FC(7) != m.type() || m.cols()!=1\n" + m);
|
||||
|
||||
kps.clear();
|
||||
double[] buff = new double[7 * count];
|
||||
m.get(0, 0, buff);
|
||||
for (int i = 0; i < count; i++) {
|
||||
kps.add(new KeyPoint((float) buff[7 * i], (float) buff[7 * i + 1], (float) buff[7 * i + 2], (float) buff[7 * i + 3],
|
||||
(float) buff[7 * i + 4], (int) buff[7 * i + 5], (int) buff[7 * i + 6]));
|
||||
}
|
||||
}
|
||||
|
||||
// vector_vector_Point
|
||||
public static Mat vector_vector_Point_to_Mat(List<MatOfPoint> pts, List<Mat> mats) {
|
||||
Mat res;
|
||||
int lCount = (pts != null) ? pts.size() : 0;
|
||||
if (lCount > 0) {
|
||||
for (MatOfPoint vpt : pts)
|
||||
mats.add(vpt);
|
||||
res = vector_Mat_to_Mat(mats);
|
||||
} else {
|
||||
res = new Mat();
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
public static void Mat_to_vector_vector_Point(Mat m, List<MatOfPoint> pts) {
|
||||
if (pts == null)
|
||||
throw new java.lang.IllegalArgumentException("Output List can't be null");
|
||||
|
||||
if (m == null)
|
||||
throw new java.lang.IllegalArgumentException("Input Mat can't be null");
|
||||
|
||||
List<Mat> mats = new ArrayList<Mat>(m.rows());
|
||||
Mat_to_vector_Mat(m, mats);
|
||||
for (Mat mi : mats) {
|
||||
MatOfPoint pt = new MatOfPoint(mi);
|
||||
pts.add(pt);
|
||||
}
|
||||
}
|
||||
|
||||
// vector_vector_Point2f
|
||||
public static void Mat_to_vector_vector_Point2f(Mat m, List<MatOfPoint2f> pts) {
|
||||
if (pts == null)
|
||||
throw new java.lang.IllegalArgumentException("Output List can't be null");
|
||||
|
||||
if (m == null)
|
||||
throw new java.lang.IllegalArgumentException("Input Mat can't be null");
|
||||
|
||||
List<Mat> mats = new ArrayList<Mat>(m.rows());
|
||||
Mat_to_vector_Mat(m, mats);
|
||||
for (Mat mi : mats) {
|
||||
MatOfPoint2f pt = new MatOfPoint2f(mi);
|
||||
pts.add(pt);
|
||||
}
|
||||
}
|
||||
|
||||
// vector_vector_Point2f
|
||||
public static Mat vector_vector_Point2f_to_Mat(List<MatOfPoint2f> pts, List<Mat> mats) {
|
||||
Mat res;
|
||||
int lCount = (pts != null) ? pts.size() : 0;
|
||||
if (lCount > 0) {
|
||||
for (MatOfPoint2f vpt : pts)
|
||||
mats.add(vpt);
|
||||
res = vector_Mat_to_Mat(mats);
|
||||
} else {
|
||||
res = new Mat();
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
// vector_vector_Point3f
|
||||
public static void Mat_to_vector_vector_Point3f(Mat m, List<MatOfPoint3f> pts) {
|
||||
if (pts == null)
|
||||
throw new java.lang.IllegalArgumentException("Output List can't be null");
|
||||
|
||||
if (m == null)
|
||||
throw new java.lang.IllegalArgumentException("Input Mat can't be null");
|
||||
|
||||
List<Mat> mats = new ArrayList<Mat>(m.rows());
|
||||
Mat_to_vector_Mat(m, mats);
|
||||
for (Mat mi : mats) {
|
||||
MatOfPoint3f pt = new MatOfPoint3f(mi);
|
||||
pts.add(pt);
|
||||
}
|
||||
}
|
||||
|
||||
// vector_vector_Point3f
|
||||
public static Mat vector_vector_Point3f_to_Mat(List<MatOfPoint3f> pts, List<Mat> mats) {
|
||||
Mat res;
|
||||
int lCount = (pts != null) ? pts.size() : 0;
|
||||
if (lCount > 0) {
|
||||
for (MatOfPoint3f vpt : pts)
|
||||
mats.add(vpt);
|
||||
res = vector_Mat_to_Mat(mats);
|
||||
} else {
|
||||
res = new Mat();
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
// vector_vector_KeyPoint
|
||||
public static Mat vector_vector_KeyPoint_to_Mat(List<MatOfKeyPoint> kps, List<Mat> mats) {
|
||||
Mat res;
|
||||
int lCount = (kps != null) ? kps.size() : 0;
|
||||
if (lCount > 0) {
|
||||
for (MatOfKeyPoint vkp : kps)
|
||||
mats.add(vkp);
|
||||
res = vector_Mat_to_Mat(mats);
|
||||
} else {
|
||||
res = new Mat();
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
public static void Mat_to_vector_vector_KeyPoint(Mat m, List<MatOfKeyPoint> kps) {
|
||||
if (kps == null)
|
||||
throw new java.lang.IllegalArgumentException("Output List can't be null");
|
||||
|
||||
if (m == null)
|
||||
throw new java.lang.IllegalArgumentException("Input Mat can't be null");
|
||||
|
||||
List<Mat> mats = new ArrayList<Mat>(m.rows());
|
||||
Mat_to_vector_Mat(m, mats);
|
||||
for (Mat mi : mats) {
|
||||
MatOfKeyPoint vkp = new MatOfKeyPoint(mi);
|
||||
kps.add(vkp);
|
||||
}
|
||||
}
|
||||
|
||||
public static Mat vector_double_to_Mat(List<Double> ds) {
|
||||
Mat res;
|
||||
int count = (ds != null) ? ds.size() : 0;
|
||||
if (count > 0) {
|
||||
res = new Mat(count, 1, CvType.CV_64FC1);
|
||||
double[] buff = new double[count];
|
||||
for (int i = 0; i < count; i++) {
|
||||
double v = ds.get(i);
|
||||
buff[i] = v;
|
||||
}
|
||||
res.put(0, 0, buff);
|
||||
} else {
|
||||
res = new Mat();
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
public static void Mat_to_vector_double(Mat m, List<Double> ds) {
|
||||
if (ds == null)
|
||||
throw new java.lang.IllegalArgumentException("ds == null");
|
||||
int count = m.rows();
|
||||
if (CvType.CV_64FC1 != m.type() || m.cols() != 1)
|
||||
throw new java.lang.IllegalArgumentException(
|
||||
"CvType.CV_64FC1 != m.type() || m.cols()!=1\n" + m);
|
||||
|
||||
ds.clear();
|
||||
double[] buff = new double[count];
|
||||
m.get(0, 0, buff);
|
||||
for (int i = 0; i < count; i++) {
|
||||
ds.add(buff[i]);
|
||||
}
|
||||
}
|
||||
|
||||
public static Mat vector_DMatch_to_Mat(List<DMatch> matches) {
|
||||
Mat res;
|
||||
int count = (matches != null) ? matches.size() : 0;
|
||||
if (count > 0) {
|
||||
res = new Mat(count, 1, CvType.CV_64FC4);
|
||||
double[] buff = new double[count * 4];
|
||||
for (int i = 0; i < count; i++) {
|
||||
DMatch m = matches.get(i);
|
||||
buff[4 * i] = m.queryIdx;
|
||||
buff[4 * i + 1] = m.trainIdx;
|
||||
buff[4 * i + 2] = m.imgIdx;
|
||||
buff[4 * i + 3] = m.distance;
|
||||
}
|
||||
res.put(0, 0, buff);
|
||||
} else {
|
||||
res = new Mat();
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
public static void Mat_to_vector_DMatch(Mat m, List<DMatch> matches) {
|
||||
if (matches == null)
|
||||
throw new java.lang.IllegalArgumentException("Output List can't be null");
|
||||
int count = m.rows();
|
||||
if (CvType.CV_64FC4 != m.type() || m.cols() != 1)
|
||||
throw new java.lang.IllegalArgumentException(
|
||||
"CvType.CV_64FC4 != m.type() || m.cols()!=1\n" + m);
|
||||
|
||||
matches.clear();
|
||||
double[] buff = new double[4 * count];
|
||||
m.get(0, 0, buff);
|
||||
for (int i = 0; i < count; i++) {
|
||||
matches.add(new DMatch((int) buff[4 * i], (int) buff[4 * i + 1], (int) buff[4 * i + 2], (float) buff[4 * i + 3]));
|
||||
}
|
||||
}
|
||||
|
||||
// vector_vector_DMatch
|
||||
public static Mat vector_vector_DMatch_to_Mat(List<MatOfDMatch> lvdm, List<Mat> mats) {
|
||||
Mat res;
|
||||
int lCount = (lvdm != null) ? lvdm.size() : 0;
|
||||
if (lCount > 0) {
|
||||
for (MatOfDMatch vdm : lvdm)
|
||||
mats.add(vdm);
|
||||
res = vector_Mat_to_Mat(mats);
|
||||
} else {
|
||||
res = new Mat();
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
public static void Mat_to_vector_vector_DMatch(Mat m, List<MatOfDMatch> lvdm) {
|
||||
if (lvdm == null)
|
||||
throw new java.lang.IllegalArgumentException("Output List can't be null");
|
||||
|
||||
if (m == null)
|
||||
throw new java.lang.IllegalArgumentException("Input Mat can't be null");
|
||||
|
||||
List<Mat> mats = new ArrayList<Mat>(m.rows());
|
||||
Mat_to_vector_Mat(m, mats);
|
||||
lvdm.clear();
|
||||
for (Mat mi : mats) {
|
||||
MatOfDMatch vdm = new MatOfDMatch(mi);
|
||||
lvdm.add(vdm);
|
||||
}
|
||||
}
|
||||
|
||||
// vector_vector_char
|
||||
public static Mat vector_vector_char_to_Mat(List<MatOfByte> lvb, List<Mat> mats) {
|
||||
Mat res;
|
||||
int lCount = (lvb != null) ? lvb.size() : 0;
|
||||
if (lCount > 0) {
|
||||
for (MatOfByte vb : lvb)
|
||||
mats.add(vb);
|
||||
res = vector_Mat_to_Mat(mats);
|
||||
} else {
|
||||
res = new Mat();
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
public static void Mat_to_vector_vector_char(Mat m, List<List<Byte>> llb) {
|
||||
if (llb == null)
|
||||
throw new java.lang.IllegalArgumentException("Output List can't be null");
|
||||
|
||||
if (m == null)
|
||||
throw new java.lang.IllegalArgumentException("Input Mat can't be null");
|
||||
|
||||
List<Mat> mats = new ArrayList<Mat>(m.rows());
|
||||
Mat_to_vector_Mat(m, mats);
|
||||
for (Mat mi : mats) {
|
||||
List<Byte> lb = new ArrayList<Byte>();
|
||||
Mat_to_vector_char(mi, lb);
|
||||
llb.add(lb);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static {
|
||||
System.loadLibrary("opencv_java");
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user