Improved rst_parser; added javadoc comments generator; added javadoc markers to handwritten .java files
This commit is contained in:
parent
4151a4590e
commit
7c43e7e7e0
163
modules/java/gen_javadoc.py
Normal file
163
modules/java/gen_javadoc.py
Normal file
@ -0,0 +1,163 @@
|
|||||||
|
import os, sys, re, string, glob
|
||||||
|
|
||||||
|
javadoc_marker = "//javadoc:"
|
||||||
|
|
||||||
|
def parceJavadocMarker(line):
|
||||||
|
assert line.lstrip().startswith(javadoc_marker)
|
||||||
|
offset = line[:line.find(javadoc_marker)]
|
||||||
|
line = line.strip()[len(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
|
||||||
|
return (line[:args_start].strip(), offset, filter(None, list(arg.strip() for arg in line[args_start+1:args_end].split(","))))
|
||||||
|
return (line, offset, [])
|
||||||
|
|
||||||
|
def document(infile, outfile, decls):
|
||||||
|
inf = open(infile, "rt")
|
||||||
|
outf = open(outfile, "wt")
|
||||||
|
try:
|
||||||
|
for l in inf.readlines():
|
||||||
|
if l.lstrip().startswith(javadoc_marker):
|
||||||
|
marker = parceJavadocMarker(l)
|
||||||
|
decl = decls.get(marker[0],None)
|
||||||
|
if decl:
|
||||||
|
for line in makeJavadoc(decl, marker[2]).split("\n"):
|
||||||
|
outf.write(marker[1] + line + "\n")
|
||||||
|
else:
|
||||||
|
print "Error: could not find documentation for %s" % l.lstrip()[len(javadoc_marker):-1]
|
||||||
|
else:
|
||||||
|
outf.write(l.replace("\t", " ").rstrip()+"\n")
|
||||||
|
except:
|
||||||
|
inf.close()
|
||||||
|
outf.close()
|
||||||
|
os.remove(outfile)
|
||||||
|
raise
|
||||||
|
else:
|
||||||
|
inf.close()
|
||||||
|
outf.close()
|
||||||
|
|
||||||
|
def ReformatForJavadoc(s):
|
||||||
|
out = ""
|
||||||
|
for term in s.split("\n"):
|
||||||
|
if term.startswith("*") or term.startswith("#."):
|
||||||
|
term = " " + term
|
||||||
|
if not term:
|
||||||
|
out += " *\n"
|
||||||
|
else:
|
||||||
|
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:
|
||||||
|
if not term[pos_end].isspace():
|
||||||
|
pos_end -= 1
|
||||||
|
else:
|
||||||
|
break
|
||||||
|
if pos_end < pos_start:
|
||||||
|
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
|
||||||
|
out += " * " + term[pos_start:pos_end+1].rstrip() + "\n"
|
||||||
|
pos_start = pos_end + 1
|
||||||
|
pos_end = min(pos_start + 77, len(term)-1)
|
||||||
|
return out
|
||||||
|
|
||||||
|
def getJavaName(decl):
|
||||||
|
name = "org.opencv."
|
||||||
|
name += decl["module"]
|
||||||
|
if "class" in decl:
|
||||||
|
name += "." + decl["class"]
|
||||||
|
if "method" in decl:
|
||||||
|
name += "." + decl["method"]
|
||||||
|
return name
|
||||||
|
|
||||||
|
def getDocURL(decl):
|
||||||
|
url = "http://opencv.itseez.com/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(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 + ReformatForJavadoc(decl["brief"])
|
||||||
|
prefix = " *\n"
|
||||||
|
elif "long" not in decl:
|
||||||
|
print "Warning: no description for " + decl_type + " \"%s\" File: %s (line %s)" % (func["name"], func["file"], func["line"])
|
||||||
|
doc += prefix + ReformatForJavadoc("This " + decl_type + " is undocumented")
|
||||||
|
prefix = " *\n"
|
||||||
|
|
||||||
|
# long goes after brief
|
||||||
|
if "long" in decl:
|
||||||
|
doc += prefix + 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
|
||||||
|
print "Warning: parameter \"%s\" of \"%s\" is undocumented. File: %s (line %s)" % (arg, decl["name"], decl["file"], decl["line"])
|
||||||
|
doc += prefix + ReformatForJavadoc("@param " + arg + " " + arg_doc)
|
||||||
|
prefix = ""
|
||||||
|
prefix = " *\n"
|
||||||
|
|
||||||
|
# @see tags
|
||||||
|
# always link to documentation
|
||||||
|
doc += prefix + " * @see <a href=\"" + getDocURL(decl) + "\">" + getJavaName(decl) + "</a>\n"
|
||||||
|
prefix = ""
|
||||||
|
# other links
|
||||||
|
if "seealso" in decl:
|
||||||
|
for see in decl["seealso"]:
|
||||||
|
doc += prefix + " * @see " + see.replace("::",".") + "\n"
|
||||||
|
prefix = " *\n"
|
||||||
|
|
||||||
|
#doc += prefix + " * File: " + decl["file"] + " (line " + str(decl["line"]) + ")\n"
|
||||||
|
|
||||||
|
return (doc + " */").replace("::",".")
|
||||||
|
|
||||||
|
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
|
||||||
|
|
||||||
|
parser = rst_parser.RstParser(hdr_parser.CppHeaderParser())
|
||||||
|
|
||||||
|
print "Parsing documentation..."
|
||||||
|
for m in ["core", "flann", "imgproc", "ml", "highgui", "video", "features2d", "calib3d", "objdetect", "legacy", "contrib", "gpu", "androidcamera", "haartraining", "java", "python", "stitching", "traincascade", "ts"]:
|
||||||
|
parser.parse(m, os.path.join(selfpath, "../" + m))
|
||||||
|
|
||||||
|
for i in range(1, len(sys.argv)):
|
||||||
|
folder = os.path.abspath(sys.argv[i])
|
||||||
|
for jfile in glob.glob(os.path.join(folder,"*.java")):
|
||||||
|
outfile = os.path.abspath(os.path.basename(jfile).replace(".java", "-jdoc.java"))
|
||||||
|
document(jfile, outfile, parser.definitions)
|
@ -1,5 +1,4 @@
|
|||||||
import os, sys, re, string, glob
|
import os, sys, re, string, glob
|
||||||
from string import Template
|
|
||||||
|
|
||||||
class DeclarationParser(object):
|
class DeclarationParser(object):
|
||||||
def __init__(self, line=None):
|
def __init__(self, line=None):
|
||||||
@ -445,8 +444,6 @@ class RstParser(object):
|
|||||||
return s
|
return s
|
||||||
# normalize line endings
|
# normalize line endings
|
||||||
s = re.sub(r"\r\n", "\n", s)
|
s = re.sub(r"\r\n", "\n", s)
|
||||||
# remove tailing ::
|
|
||||||
s = re.sub(r"::$", "\n", s)
|
|
||||||
# remove extra line breaks before/after _ or ,
|
# remove extra line breaks before/after _ or ,
|
||||||
s = re.sub(r"\n[ ]*([_,])\n", r"\1 ", s)
|
s = re.sub(r"\n[ ]*([_,])\n", r"\1 ", s)
|
||||||
# remove extra line breaks after `
|
# remove extra line breaks after `
|
||||||
@ -465,7 +462,7 @@ class RstParser(object):
|
|||||||
# remove extra line breaks after #.
|
# remove extra line breaks after #.
|
||||||
s = re.sub(r"\n#\.\n+", "\n#. ", s)
|
s = re.sub(r"\n#\.\n+", "\n#. ", s)
|
||||||
# remove extra line breaks before `
|
# remove extra line breaks before `
|
||||||
s = re.sub(r"\n[ ]*`", " `", s)
|
#s = re.sub(r"\n[ ]*`", " `", s)
|
||||||
# remove trailing whitespaces
|
# remove trailing whitespaces
|
||||||
s = re.sub(r"[ ]+$", "", s)
|
s = re.sub(r"[ ]+$", "", s)
|
||||||
# remove .. for references
|
# remove .. for references
|
||||||
@ -485,6 +482,7 @@ class RstParser(object):
|
|||||||
|
|
||||||
s = s.replace("]_", "]")
|
s = s.replace("]_", "]")
|
||||||
s = s.replace(".. note::", "Note:")
|
s = s.replace(".. note::", "Note:")
|
||||||
|
s = s.replace(".. table::", "")
|
||||||
s = s.replace(".. ocv:function::", "")
|
s = s.replace(".. ocv:function::", "")
|
||||||
s = s.replace(".. ocv:cfunction::", "")
|
s = s.replace(".. ocv:cfunction::", "")
|
||||||
|
|
||||||
@ -492,6 +490,8 @@ class RstParser(object):
|
|||||||
s = re.sub(r"(^|\n)\.\. [a-zA-Z_0-9]+(::[a-zA-Z_0-9]+)?:(\n|$)", "\n ", s)
|
s = re.sub(r"(^|\n)\.\. [a-zA-Z_0-9]+(::[a-zA-Z_0-9]+)?:(\n|$)", "\n ", s)
|
||||||
# unwrap urls
|
# unwrap urls
|
||||||
s = re.sub(r"`([^`<]+ )<(https?://[^>]+)>`_", "\\1(\\2)", s)
|
s = re.sub(r"`([^`<]+ )<(https?://[^>]+)>`_", "\\1(\\2)", s)
|
||||||
|
# remove tailing ::
|
||||||
|
s = re.sub(r"::$", "\n", s)
|
||||||
|
|
||||||
# remove whitespace before .
|
# remove whitespace before .
|
||||||
s = re.sub(r"[ ]+\.", ".", s)
|
s = re.sub(r"[ ]+\.", ".", s)
|
||||||
@ -502,7 +502,7 @@ class RstParser(object):
|
|||||||
# compress line breaks
|
# compress line breaks
|
||||||
s = re.sub(r"\n\n+", "\n\n", s)
|
s = re.sub(r"\n\n+", "\n\n", s)
|
||||||
# remove other newlines
|
# remove other newlines
|
||||||
s = re.sub(r"([^.\n])\n([^*#\n])", "\\1 \\2", s)
|
s = re.sub(r"([^.\n\\=])\n([^*#\n])", "\\1 \\2", s)
|
||||||
# compress whitespace
|
# compress whitespace
|
||||||
s = re.sub(r" +", " ", s)
|
s = re.sub(r" +", " ", s)
|
||||||
|
|
||||||
@ -518,7 +518,7 @@ class RstParser(object):
|
|||||||
return s
|
return s
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
if len(sys.argv) < 1:
|
if len(sys.argv) < 2:
|
||||||
print "Usage:\n", os.path.basename(sys.argv[0]), " <module path>"
|
print "Usage:\n", os.path.basename(sys.argv[0]), " <module path>"
|
||||||
exit(0)
|
exit(0)
|
||||||
|
|
||||||
@ -569,4 +569,8 @@ if __name__ == "__main__":
|
|||||||
for lang in sorted(stat.items()):
|
for lang in sorted(stat.items()):
|
||||||
print " %7s functions documented: %s" % lang
|
print " %7s functions documented: %s" % lang
|
||||||
|
|
||||||
|
# sys.exit(0)
|
||||||
|
# for name, d in parser.definitions.items():
|
||||||
|
# print
|
||||||
|
# print ToJavadoc(d, d.get("params",{}).keys())
|
||||||
|
|
||||||
|
@ -1,299 +1,357 @@
|
|||||||
package org.opencv;
|
package org.opencv;
|
||||||
|
|
||||||
|
//javadoc:Mat
|
||||||
public class Mat {
|
public class Mat {
|
||||||
|
|
||||||
|
|
||||||
protected Mat(long nativeMat) {
|
protected Mat(long nativeMat) {
|
||||||
/*if(nativeMat == 0)
|
/*if(nativeMat == 0)
|
||||||
throw new java.lang.UnsupportedOperationException("Native object address is NULL");*/
|
throw new java.lang.UnsupportedOperationException("Native object address is NULL");*/
|
||||||
this.nativeObj = nativeMat;
|
this.nativeObj = nativeMat;
|
||||||
}
|
|
||||||
|
|
||||||
public Mat() {
|
|
||||||
this( nCreateMat() );
|
|
||||||
}
|
|
||||||
|
|
||||||
public Mat(int rows, int cols, CvType type) {
|
|
||||||
this( nCreateMat(rows, cols, type.toInt()) );
|
|
||||||
}
|
|
||||||
|
|
||||||
public Mat(int rows, int cols, int depth) {
|
|
||||||
this( rows, cols, new CvType(depth, 1) );
|
|
||||||
}
|
|
||||||
|
|
||||||
public Mat(int rows, int cols, CvType type, Scalar val) {
|
|
||||||
this( nCreateMat(rows, cols, type.toInt(), val.v0, val.v1, val.v2, val.v3) );
|
|
||||||
}
|
|
||||||
|
|
||||||
public Mat(int rows, int cols, int depth, Scalar val) {
|
|
||||||
this( rows, cols, new CvType(depth, 1), val );
|
|
||||||
}
|
|
||||||
|
|
||||||
public void dispose() {
|
|
||||||
nRelease(nativeObj);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void finalize() throws Throwable {
|
|
||||||
nDelete(nativeObj);
|
|
||||||
nativeObj = 0;
|
|
||||||
super.finalize();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String toString() {
|
|
||||||
if(nativeObj == 0) return "Mat [ nativeObj=NULL ]";
|
|
||||||
return "Mat [ " +
|
|
||||||
rows() + "*" + cols() + "*" + type() +
|
|
||||||
", isCont=" + isContinuous() + ", isSubmat=" + isSubmatrix() +
|
|
||||||
", nativeObj=0x" + Long.toHexString(nativeObj) +
|
|
||||||
", dataAddr=0x" + Long.toHexString(dataAddr()) +
|
|
||||||
" ]";
|
|
||||||
}
|
|
||||||
|
|
||||||
public String dump() {
|
|
||||||
return nDump(nativeObj);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean empty() {
|
//javadoc:Mat::Mat()
|
||||||
if(nativeObj == 0) return true;
|
public Mat() {
|
||||||
return nIsEmpty(nativeObj);
|
this( nCreateMat() );
|
||||||
}
|
}
|
||||||
|
|
||||||
private void checkNull() {
|
//javadoc:Mat::Mat(rows,cols,type)
|
||||||
if(nativeObj == 0)
|
public Mat(int rows, int cols, CvType type) {
|
||||||
throw new java.lang.UnsupportedOperationException("Native object address is NULL");
|
this( nCreateMat(rows, cols, type.toInt()) );
|
||||||
}
|
}
|
||||||
|
|
||||||
public CvType type() {
|
//javadoc:Mat::Mat(rows,cols,depth)
|
||||||
checkNull();
|
public Mat(int rows, int cols, int depth) {
|
||||||
return new CvType( nType(nativeObj) );
|
this( rows, cols, new CvType(depth, 1) );
|
||||||
}
|
}
|
||||||
public int depth() { return type().depth(); }
|
|
||||||
public int channels() { return type().channels(); }
|
|
||||||
public int elemSize() { return type().CV_ELEM_SIZE(); }
|
|
||||||
|
|
||||||
public int rows() {
|
//javadoc:Mat::Mat(rows,cols,type,s)
|
||||||
if(nativeObj == 0)
|
public Mat(int rows, int cols, CvType type, Scalar s) {
|
||||||
return 0;
|
this( nCreateMat(rows, cols, type.toInt(), s.v0, s.v1, s.v2, s.v3) );
|
||||||
return nRows(nativeObj);
|
}
|
||||||
}
|
|
||||||
public int height() { return rows(); }
|
|
||||||
public int cols() {
|
|
||||||
if(nativeObj == 0)
|
|
||||||
return 0;
|
|
||||||
return nCols(nativeObj);
|
|
||||||
}
|
|
||||||
public int width() { return cols(); }
|
|
||||||
public int total() { return rows() * cols(); }
|
|
||||||
|
|
||||||
public long dataAddr() {
|
//javadoc:Mat::Mat(rows,cols,depth,s)
|
||||||
if(nativeObj == 0)
|
public Mat(int rows, int cols, int depth, Scalar s) {
|
||||||
return 0;
|
this( rows, cols, new CvType(depth, 1), s );
|
||||||
return nData(nativeObj);
|
}
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isContinuous() {
|
//javadoc:Mat::dispose()
|
||||||
if(nativeObj == 0)
|
public void dispose() {
|
||||||
return false; // maybe throw an exception instead?
|
nRelease(nativeObj);
|
||||||
return nIsCont(nativeObj);
|
}
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isSubmatrix() {
|
//javadoc:Mat::finalize()
|
||||||
if(nativeObj == 0)
|
@Override
|
||||||
return false; // maybe throw an exception instead?
|
protected void finalize() throws Throwable {
|
||||||
return nIsSubmat(nativeObj);
|
nDelete(nativeObj);
|
||||||
}
|
nativeObj = 0;
|
||||||
|
super.finalize();
|
||||||
|
}
|
||||||
|
|
||||||
public Mat submat(int rowStart, int rowEnd, int colStart, int colEnd) {
|
//javadoc:Mat::toString()
|
||||||
checkNull();
|
@Override
|
||||||
return new Mat( nSubmat(nativeObj, rowStart, rowEnd, colStart, colEnd) );
|
public String toString() {
|
||||||
}
|
if(nativeObj == 0) return "Mat [ nativeObj=NULL ]";
|
||||||
public Mat rowRange(int start, int end) { return submat(start, end, 0, -1); }
|
return "Mat [ " +
|
||||||
public Mat row(int num) { return submat(num, num+1, 0, -1); }
|
rows() + "*" + cols() + "*" + type() +
|
||||||
public Mat colRange(int start, int end) { return submat(0, -1, start, end); }
|
", isCont=" + isContinuous() + ", isSubmat=" + isSubmatrix() +
|
||||||
public Mat col(int num) { return submat(0, -1, num, num+1); }
|
", nativeObj=0x" + Long.toHexString(nativeObj) +
|
||||||
|
", dataAddr=0x" + Long.toHexString(dataAddr()) +
|
||||||
|
" ]";
|
||||||
|
}
|
||||||
|
|
||||||
public Mat clone() {
|
//javadoc:Mat::dump()
|
||||||
checkNull();
|
public String dump() {
|
||||||
return new Mat( nClone(nativeObj) );
|
return nDump(nativeObj);
|
||||||
}
|
}
|
||||||
|
|
||||||
public int put(int row, int col, double...data) {
|
//javadoc:Mat::empty()
|
||||||
checkNull();
|
public boolean empty() {
|
||||||
if(data != null)
|
if(nativeObj == 0) return true;
|
||||||
return nPutD(nativeObj, row, col, data.length, data);
|
return nIsEmpty(nativeObj);
|
||||||
else
|
}
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int put(int row, int col, float[] data) {
|
private void checkNull() {
|
||||||
checkNull();
|
if(nativeObj == 0)
|
||||||
if(data != null) {
|
throw new java.lang.UnsupportedOperationException("Native object address is NULL");
|
||||||
CvType t = type();
|
}
|
||||||
if(t.depth() == CvType.CV_32F) {
|
|
||||||
return nPutF(nativeObj, row, col, data.length, data);
|
|
||||||
}
|
|
||||||
throw new java.lang.UnsupportedOperationException("Mat data type is not compatible: " + t);
|
|
||||||
} else return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int put(int row, int col, int[] data) {
|
//javadoc:Mat::type()
|
||||||
checkNull();
|
public CvType type() {
|
||||||
if(data != null) {
|
checkNull();
|
||||||
CvType t = type();
|
return new CvType( nType(nativeObj) );
|
||||||
if(t.depth() == CvType.CV_32S) {
|
}
|
||||||
return nPutI(nativeObj, row, col, data.length, data);
|
|
||||||
}
|
|
||||||
throw new java.lang.UnsupportedOperationException("Mat data type is not compatible: " + t);
|
|
||||||
} else return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int put(int row, int col, short[] data) {
|
//javadoc:Mat::depth()
|
||||||
checkNull();
|
public int depth() { return type().depth(); }
|
||||||
if(data != null) {
|
|
||||||
CvType t = type();
|
|
||||||
if(t.depth() == CvType.CV_16U || t.depth() == CvType.CV_16S) {
|
|
||||||
return nPutS(nativeObj, row, col, data.length, data);
|
|
||||||
}
|
|
||||||
throw new java.lang.UnsupportedOperationException("Mat data type is not compatible: " + t);
|
|
||||||
} else return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int put(int row, int col, byte[] data) {
|
//javadoc:Mat::channels()
|
||||||
checkNull();
|
public int channels() { return type().channels(); }
|
||||||
if(data != null) {
|
|
||||||
CvType t = type();
|
|
||||||
if(t.depth() == CvType.CV_8U || t.depth() == CvType.CV_8S) {
|
|
||||||
return nPutB(nativeObj, row, col, data.length, data);
|
|
||||||
}
|
|
||||||
throw new java.lang.UnsupportedOperationException("Mat data type is not compatible: " + t);
|
|
||||||
} else return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int get(int row, int col, byte[] data) {
|
//javadoc:Mat::elemSize()
|
||||||
checkNull();
|
public int elemSize() { return type().CV_ELEM_SIZE(); }
|
||||||
CvType t = type();
|
|
||||||
if(t.depth() == CvType.CV_8U || t.depth() == CvType.CV_8S) {
|
|
||||||
return nGetB(nativeObj, row, col, data.length, data);
|
|
||||||
}
|
|
||||||
throw new java.lang.UnsupportedOperationException("Mat data type is not compatible: " + t);
|
|
||||||
}
|
|
||||||
|
|
||||||
public int get(int row, int col, short[] data) {
|
//javadoc:Mat::rows()
|
||||||
checkNull();
|
public int rows() {
|
||||||
CvType t = type();
|
if(nativeObj == 0)
|
||||||
if(t.depth() == CvType.CV_16U || t.depth() == CvType.CV_16S) {
|
return 0;
|
||||||
return nGetS(nativeObj, row, col, data.length, data);
|
return nRows(nativeObj);
|
||||||
}
|
}
|
||||||
throw new java.lang.UnsupportedOperationException("Mat data type is not compatible: " + t);
|
|
||||||
}
|
|
||||||
|
|
||||||
public int get(int row, int col, int[] data) {
|
//javadoc:Mat::height()
|
||||||
checkNull();
|
public int height() { return rows(); }
|
||||||
CvType t = type();
|
|
||||||
if(t.depth() == CvType.CV_32S) {
|
|
||||||
return nGetI(nativeObj, row, col, data.length, data);
|
|
||||||
}
|
|
||||||
throw new java.lang.UnsupportedOperationException("Mat data type is not compatible: " + t);
|
|
||||||
}
|
|
||||||
|
|
||||||
public int get(int row, int col, float[] data) {
|
//javadoc:Mat::cols()
|
||||||
checkNull();
|
public int cols() {
|
||||||
CvType t = type();
|
if(nativeObj == 0)
|
||||||
if(t.depth() == CvType.CV_32F) {
|
return 0;
|
||||||
return nGetF(nativeObj, row, col, data.length, data);
|
return nCols(nativeObj);
|
||||||
}
|
}
|
||||||
throw new java.lang.UnsupportedOperationException("Mat data type is not compatible: " + t);
|
|
||||||
}
|
|
||||||
|
|
||||||
public int get(int row, int col, double[] data) {
|
//javadoc:Mat::width()
|
||||||
checkNull();
|
public int width() { return cols(); }
|
||||||
CvType t = type();
|
|
||||||
if(t.depth() == CvType.CV_64F) {
|
|
||||||
return nGetD(nativeObj, row, col, data.length, data);
|
|
||||||
}
|
|
||||||
throw new java.lang.UnsupportedOperationException("Mat data type is not compatible: " + t);
|
|
||||||
}
|
|
||||||
|
|
||||||
public double[] get(int row, int col) {
|
//javadoc:Mat::total()
|
||||||
checkNull();
|
public int total() { return rows() * cols(); }
|
||||||
//CvType t = type();
|
|
||||||
//if(t.depth() == CvType.CV_64F) {
|
//javadoc:Mat::dataAddr()
|
||||||
return nGet(nativeObj, row, col);
|
public long dataAddr() {
|
||||||
//}
|
if(nativeObj == 0)
|
||||||
//throw new java.lang.UnsupportedOperationException("Mat data type is not compatible: " + t);
|
return 0;
|
||||||
}
|
return nData(nativeObj);
|
||||||
|
}
|
||||||
|
|
||||||
|
//javadoc:Mat::isContinuous()
|
||||||
|
public boolean isContinuous() {
|
||||||
|
if(nativeObj == 0)
|
||||||
|
return false; // maybe throw an exception instead?
|
||||||
|
return nIsCont(nativeObj);
|
||||||
|
}
|
||||||
|
|
||||||
|
//javadoc:Mat::isSubmatrix()
|
||||||
|
public boolean isSubmatrix() {
|
||||||
|
if(nativeObj == 0)
|
||||||
|
return false; // maybe throw an exception instead?
|
||||||
|
return nIsSubmat(nativeObj);
|
||||||
|
}
|
||||||
|
|
||||||
|
//javadoc:Mat::submat(rowStart,rowEnd,colStart,colEnd)
|
||||||
|
public Mat submat(int rowStart, int rowEnd, int colStart, int colEnd) {
|
||||||
|
checkNull();
|
||||||
|
return new Mat( nSubmat(nativeObj, rowStart, rowEnd, colStart, colEnd) );
|
||||||
|
}
|
||||||
|
|
||||||
|
//javadoc:Mat::rowRange(startrow,endrow)
|
||||||
|
public Mat rowRange(int startrow, int endrow) { return submat(startrow, endrow, 0, -1); }
|
||||||
|
|
||||||
|
//javadoc:Mat::row(i)
|
||||||
|
public Mat row(int i) { return submat(i, i+1, 0, -1); }
|
||||||
|
|
||||||
|
//javadoc:Mat::colRange(startcol,endcol)
|
||||||
|
public Mat colRange(int startcol, int endcol) { return submat(0, -1, startcol, endcol); }
|
||||||
|
|
||||||
|
//javadoc:Mat::col(j)
|
||||||
|
public Mat col(int j) { return submat(0, -1, j, j+1); }
|
||||||
|
|
||||||
|
//javadoc:Mat::clone()
|
||||||
|
public Mat clone() {
|
||||||
|
checkNull();
|
||||||
|
return new Mat( nClone(nativeObj) );
|
||||||
|
}
|
||||||
|
|
||||||
|
//javadoc:Mat::put(row,col,data)
|
||||||
|
public int put(int row, int col, double...data) {
|
||||||
|
checkNull();
|
||||||
|
if(data != null)
|
||||||
|
return nPutD(nativeObj, row, col, data.length, data);
|
||||||
|
else
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
//javadoc:Mat::put(row,col,data)
|
||||||
|
public int put(int row, int col, float[] data) {
|
||||||
|
checkNull();
|
||||||
|
if(data != null) {
|
||||||
|
CvType t = type();
|
||||||
|
if(t.depth() == CvType.CV_32F) {
|
||||||
|
return nPutF(nativeObj, row, col, data.length, data);
|
||||||
|
}
|
||||||
|
throw new java.lang.UnsupportedOperationException("Mat data type is not compatible: " + t);
|
||||||
|
} else return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
//javadoc:Mat::put(row,col,data)
|
||||||
|
public int put(int row, int col, int[] data) {
|
||||||
|
checkNull();
|
||||||
|
if(data != null) {
|
||||||
|
CvType t = type();
|
||||||
|
if(t.depth() == CvType.CV_32S) {
|
||||||
|
return nPutI(nativeObj, row, col, data.length, data);
|
||||||
|
}
|
||||||
|
throw new java.lang.UnsupportedOperationException("Mat data type is not compatible: " + t);
|
||||||
|
} else return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
//javadoc:Mat::put(row,col,data)
|
||||||
|
public int put(int row, int col, short[] data) {
|
||||||
|
checkNull();
|
||||||
|
if(data != null) {
|
||||||
|
CvType t = type();
|
||||||
|
if(t.depth() == CvType.CV_16U || t.depth() == CvType.CV_16S) {
|
||||||
|
return nPutS(nativeObj, row, col, data.length, data);
|
||||||
|
}
|
||||||
|
throw new java.lang.UnsupportedOperationException("Mat data type is not compatible: " + t);
|
||||||
|
} else return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
//javadoc:Mat::put(row,col,data)
|
||||||
|
public int put(int row, int col, byte[] data) {
|
||||||
|
checkNull();
|
||||||
|
if(data != null) {
|
||||||
|
CvType t = type();
|
||||||
|
if(t.depth() == CvType.CV_8U || t.depth() == CvType.CV_8S) {
|
||||||
|
return nPutB(nativeObj, row, col, data.length, data);
|
||||||
|
}
|
||||||
|
throw new java.lang.UnsupportedOperationException("Mat data type is not compatible: " + t);
|
||||||
|
} else return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
//javadoc:Mat::get(row,col,data)
|
||||||
|
public int get(int row, int col, byte[] data) {
|
||||||
|
checkNull();
|
||||||
|
CvType t = type();
|
||||||
|
if(t.depth() == CvType.CV_8U || t.depth() == CvType.CV_8S) {
|
||||||
|
return nGetB(nativeObj, row, col, data.length, data);
|
||||||
|
}
|
||||||
|
throw new java.lang.UnsupportedOperationException("Mat data type is not compatible: " + t);
|
||||||
|
}
|
||||||
|
|
||||||
|
//javadoc:Mat::get(row,col,data)
|
||||||
|
public int get(int row, int col, short[] data) {
|
||||||
|
checkNull();
|
||||||
|
CvType t = type();
|
||||||
|
if(t.depth() == CvType.CV_16U || t.depth() == CvType.CV_16S) {
|
||||||
|
return nGetS(nativeObj, row, col, data.length, data);
|
||||||
|
}
|
||||||
|
throw new java.lang.UnsupportedOperationException("Mat data type is not compatible: " + t);
|
||||||
|
}
|
||||||
|
|
||||||
|
//javadoc:Mat::get(row,col,data)
|
||||||
|
public int get(int row, int col, int[] data) {
|
||||||
|
checkNull();
|
||||||
|
CvType t = type();
|
||||||
|
if(t.depth() == CvType.CV_32S) {
|
||||||
|
return nGetI(nativeObj, row, col, data.length, data);
|
||||||
|
}
|
||||||
|
throw new java.lang.UnsupportedOperationException("Mat data type is not compatible: " + t);
|
||||||
|
}
|
||||||
|
|
||||||
|
//javadoc:Mat::get(row,col,data)
|
||||||
|
public int get(int row, int col, float[] data) {
|
||||||
|
checkNull();
|
||||||
|
CvType t = type();
|
||||||
|
if(t.depth() == CvType.CV_32F) {
|
||||||
|
return nGetF(nativeObj, row, col, data.length, data);
|
||||||
|
}
|
||||||
|
throw new java.lang.UnsupportedOperationException("Mat data type is not compatible: " + t);
|
||||||
|
}
|
||||||
|
|
||||||
|
//javadoc:Mat::get(row,col,data)
|
||||||
|
public int get(int row, int col, double[] data) {
|
||||||
|
checkNull();
|
||||||
|
CvType t = type();
|
||||||
|
if(t.depth() == CvType.CV_64F) {
|
||||||
|
return nGetD(nativeObj, row, col, data.length, data);
|
||||||
|
}
|
||||||
|
throw new java.lang.UnsupportedOperationException("Mat data type is not compatible: " + t);
|
||||||
|
}
|
||||||
|
|
||||||
|
//javadoc:Mat::get(row,col)
|
||||||
|
public double[] get(int row, int col) {
|
||||||
|
checkNull();
|
||||||
|
//CvType t = type();
|
||||||
|
//if(t.depth() == CvType.CV_64F) {
|
||||||
|
return nGet(nativeObj, row, col);
|
||||||
|
//}
|
||||||
|
//throw new java.lang.UnsupportedOperationException("Mat data type is not compatible: " + t);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
public void setTo(Scalar val) {
|
//javadoc:Mat::setTo(s)
|
||||||
checkNull();
|
public void setTo(Scalar s) {
|
||||||
nSetTo(nativeObj, val.v0, val.v1, val.v2, val.v3);
|
checkNull();
|
||||||
}
|
nSetTo(nativeObj, s.v0, s.v1, s.v2, s.v3);
|
||||||
|
}
|
||||||
|
|
||||||
public void copyTo(Mat m) {
|
//javadoc:Mat::copyTo(m)
|
||||||
checkNull();
|
public void copyTo(Mat m) {
|
||||||
if(m.nativeObj == 0)
|
checkNull();
|
||||||
throw new java.lang.UnsupportedOperationException("Destination native object address is NULL");
|
if(m.nativeObj == 0)
|
||||||
nCopyTo(nativeObj, m.nativeObj);
|
throw new java.lang.UnsupportedOperationException("Destination native object address is NULL");
|
||||||
}
|
nCopyTo(nativeObj, m.nativeObj);
|
||||||
|
}
|
||||||
|
|
||||||
public double dot(Mat m) {
|
//javadoc:Mat::dot(m)
|
||||||
checkNull();
|
public double dot(Mat m) {
|
||||||
return nDot(nativeObj, m.nativeObj);
|
checkNull();
|
||||||
}
|
return nDot(nativeObj, m.nativeObj);
|
||||||
|
}
|
||||||
|
|
||||||
public Mat cross(Mat m) {
|
//javadoc:Mat::cross(m)
|
||||||
checkNull();
|
public Mat cross(Mat m) {
|
||||||
return new Mat( nCross(nativeObj, m.nativeObj) );
|
checkNull();
|
||||||
}
|
return new Mat( nCross(nativeObj, m.nativeObj) );
|
||||||
|
}
|
||||||
|
|
||||||
public Mat inv() {
|
//javadoc:Mat::inv()
|
||||||
checkNull();
|
public Mat inv() {
|
||||||
return new Mat( nInv(nativeObj) );
|
checkNull();
|
||||||
}
|
return new Mat( nInv(nativeObj) );
|
||||||
|
}
|
||||||
|
|
||||||
public long getNativeObjAddr() {
|
//javadoc:Mat::getNativeObjAddr()
|
||||||
return nativeObj;
|
public long getNativeObjAddr() {
|
||||||
}
|
return nativeObj;
|
||||||
|
}
|
||||||
|
|
||||||
|
//javadoc:Mat::eye(rows,cols,type)
|
||||||
static public Mat eye(int rows, int cols, CvType type) {
|
static public Mat eye(int rows, int cols, CvType type) {
|
||||||
return new Mat( nEye(rows, cols, type.toInt()) );
|
return new Mat( nEye(rows, cols, type.toInt()) );
|
||||||
}
|
}
|
||||||
|
|
||||||
// native stuff
|
// native stuff
|
||||||
static { System.loadLibrary("opencv_java"); }
|
static { System.loadLibrary("opencv_java"); }
|
||||||
protected long nativeObj;
|
protected long nativeObj;
|
||||||
private static native long nCreateMat();
|
private static native long nCreateMat();
|
||||||
private static native long nCreateMat(int rows, int cols, int type);
|
private static native long nCreateMat(int rows, int cols, int type);
|
||||||
private static native long nCreateMat(int rows, int cols, int type, double v0, double v1, double v2, double v3);
|
private static native long nCreateMat(int rows, int cols, int type, double v0, double v1, double v2, double v3);
|
||||||
private static native void nRelease(long self);
|
private static native void nRelease(long self);
|
||||||
private static native void nDelete(long self);
|
private static native void nDelete(long self);
|
||||||
private static native int nType(long self);
|
private static native int nType(long self);
|
||||||
private static native int nRows(long self);
|
private static native int nRows(long self);
|
||||||
private static native int nCols(long self);
|
private static native int nCols(long self);
|
||||||
private static native long nData(long self);
|
private static native long nData(long self);
|
||||||
private static native boolean nIsEmpty(long self);
|
private static native boolean nIsEmpty(long self);
|
||||||
private static native boolean nIsCont(long self);
|
private static native boolean nIsCont(long self);
|
||||||
private static native boolean nIsSubmat(long self);
|
private static native boolean nIsSubmat(long self);
|
||||||
private static native long nSubmat(long self, int rowStart, int rowEnd, int colStart, int colEnd);
|
private static native long nSubmat(long self, int rowStart, int rowEnd, int colStart, int colEnd);
|
||||||
private static native long nClone(long self);
|
private static native long nClone(long self);
|
||||||
private static native int nPutD(long self, int row, int col, int count, double[] data);
|
private static native int nPutD(long self, int row, int col, int count, double[] data);
|
||||||
private static native int nPutF(long self, int row, int col, int count, float[] data);
|
private static native int nPutF(long self, int row, int col, int count, float[] data);
|
||||||
private static native int nPutI(long self, int row, int col, int count, int[] data);
|
private static native int nPutI(long self, int row, int col, int count, int[] data);
|
||||||
private static native int nPutS(long self, int row, int col, int count, short[] data);
|
private static native int nPutS(long self, int row, int col, int count, short[] data);
|
||||||
private static native int nPutB(long self, int row, int col, int count, byte[] data);
|
private static native int nPutB(long self, int row, int col, int count, byte[] data);
|
||||||
private static native int nGetB(long self, int row, int col, int count, byte[] vals);
|
private static native int nGetB(long self, int row, int col, int count, byte[] vals);
|
||||||
private static native int nGetS(long self, int row, int col, int count, short[] vals);
|
private static native int nGetS(long self, int row, int col, int count, short[] vals);
|
||||||
private static native int nGetI(long self, int row, int col, int count, int[] vals);
|
private static native int nGetI(long self, int row, int col, int count, int[] vals);
|
||||||
private static native int nGetF(long self, int row, int col, int count, float[] vals);
|
private static native int nGetF(long self, int row, int col, int count, float[] vals);
|
||||||
private static native int nGetD(long self, int row, int col, int count, double[] vals);
|
private static native int nGetD(long self, int row, int col, int count, double[] vals);
|
||||||
private static native double[] nGet(long self, int row, int col);
|
private static native double[] nGet(long self, int row, int col);
|
||||||
private static native void nSetTo(long self, double v0, double v1, double v2, double v3);
|
private static native void nSetTo(long self, double v0, double v1, double v2, double v3);
|
||||||
private static native void nCopyTo(long self, long mat);
|
private static native void nCopyTo(long self, long mat);
|
||||||
private static native double nDot(long self, long mat);
|
private static native double nDot(long self, long mat);
|
||||||
private static native long nCross(long self, long mat);
|
private static native long nCross(long self, long mat);
|
||||||
private static native long nInv(long self);
|
private static native long nInv(long self);
|
||||||
private static native long nEye(int rows, int cols, int type);
|
private static native long nEye(int rows, int cols, int type);
|
||||||
private static native String nDump(long self);
|
private static native String nDump(long self);
|
||||||
|
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
package org.opencv;
|
package org.opencv;
|
||||||
|
|
||||||
|
//javadoc:Point_
|
||||||
public class Point {
|
public class Point {
|
||||||
|
|
||||||
public double x, y;
|
public double x, y;
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
package org.opencv;
|
package org.opencv;
|
||||||
|
|
||||||
|
//javadoc:Point3_
|
||||||
public class Point3 {
|
public class Point3 {
|
||||||
|
|
||||||
public double x, y, z;
|
public double x, y, z;
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
package org.opencv;
|
package org.opencv;
|
||||||
|
|
||||||
|
//javadoc:Rect_
|
||||||
public class Rect {
|
public class Rect {
|
||||||
|
|
||||||
int x, y, width, height;
|
int x, y, width, height;
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
package org.opencv;
|
package org.opencv;
|
||||||
|
|
||||||
|
//javadoc:Scalar_
|
||||||
public class Scalar {
|
public class Scalar {
|
||||||
|
|
||||||
public double v0, v1, v2, v3;
|
public double v0, v1, v2, v3;
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
package org.opencv;
|
package org.opencv;
|
||||||
|
|
||||||
|
//javadoc:Size_
|
||||||
public class Size {
|
public class Size {
|
||||||
|
|
||||||
public int width, height;
|
public int width, height;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user