mirror of
https://github.com/opencv/opencv.git
synced 2025-01-18 22:44:02 +08:00
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
|
||||
from string import Template
|
||||
|
||||
class DeclarationParser(object):
|
||||
def __init__(self, line=None):
|
||||
@ -445,8 +444,6 @@ class RstParser(object):
|
||||
return s
|
||||
# normalize line endings
|
||||
s = re.sub(r"\r\n", "\n", s)
|
||||
# remove tailing ::
|
||||
s = re.sub(r"::$", "\n", s)
|
||||
# remove extra line breaks before/after _ or ,
|
||||
s = re.sub(r"\n[ ]*([_,])\n", r"\1 ", s)
|
||||
# remove extra line breaks after `
|
||||
@ -465,7 +462,7 @@ class RstParser(object):
|
||||
# remove extra line breaks after #.
|
||||
s = re.sub(r"\n#\.\n+", "\n#. ", s)
|
||||
# remove extra line breaks before `
|
||||
s = re.sub(r"\n[ ]*`", " `", s)
|
||||
#s = re.sub(r"\n[ ]*`", " `", s)
|
||||
# remove trailing whitespaces
|
||||
s = re.sub(r"[ ]+$", "", s)
|
||||
# remove .. for references
|
||||
@ -485,6 +482,7 @@ class RstParser(object):
|
||||
|
||||
s = s.replace("]_", "]")
|
||||
s = s.replace(".. note::", "Note:")
|
||||
s = s.replace(".. table::", "")
|
||||
s = s.replace(".. ocv:function::", "")
|
||||
s = s.replace(".. ocv:cfunction::", "")
|
||||
|
||||
@ -492,7 +490,9 @@ class RstParser(object):
|
||||
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", s)
|
||||
|
||||
# remove whitespace before .
|
||||
s = re.sub(r"[ ]+\.", ".", s)
|
||||
# remove tailing whitespace
|
||||
@ -502,7 +502,7 @@ class RstParser(object):
|
||||
# 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)
|
||||
s = re.sub(r"([^.\n\\=])\n([^*#\n])", "\\1 \\2", s)
|
||||
# compress whitespace
|
||||
s = re.sub(r" +", " ", s)
|
||||
|
||||
@ -518,7 +518,7 @@ class RstParser(object):
|
||||
return s
|
||||
|
||||
if __name__ == "__main__":
|
||||
if len(sys.argv) < 1:
|
||||
if len(sys.argv) < 2:
|
||||
print "Usage:\n", os.path.basename(sys.argv[0]), " <module path>"
|
||||
exit(0)
|
||||
|
||||
@ -569,4 +569,8 @@ if __name__ == "__main__":
|
||||
for lang in sorted(stat.items()):
|
||||
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;
|
||||
|
||||
//javadoc:Mat
|
||||
public class Mat {
|
||||
|
||||
|
||||
protected Mat(long nativeMat) {
|
||||
/*if(nativeMat == 0)
|
||||
throw new java.lang.UnsupportedOperationException("Native object address is NULL");*/
|
||||
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);
|
||||
protected Mat(long nativeMat) {
|
||||
/*if(nativeMat == 0)
|
||||
throw new java.lang.UnsupportedOperationException("Native object address is NULL");*/
|
||||
this.nativeObj = nativeMat;
|
||||
}
|
||||
|
||||
//javadoc:Mat::Mat()
|
||||
public Mat() {
|
||||
this( nCreateMat() );
|
||||
}
|
||||
|
||||
public boolean empty() {
|
||||
if(nativeObj == 0) return true;
|
||||
return nIsEmpty(nativeObj);
|
||||
}
|
||||
|
||||
private void checkNull() {
|
||||
if(nativeObj == 0)
|
||||
throw new java.lang.UnsupportedOperationException("Native object address is NULL");
|
||||
}
|
||||
|
||||
public CvType type() {
|
||||
checkNull();
|
||||
return new CvType( nType(nativeObj) );
|
||||
}
|
||||
public int depth() { return type().depth(); }
|
||||
public int channels() { return type().channels(); }
|
||||
public int elemSize() { return type().CV_ELEM_SIZE(); }
|
||||
//javadoc:Mat::Mat(rows,cols,type)
|
||||
public Mat(int rows, int cols, CvType type) {
|
||||
this( nCreateMat(rows, cols, type.toInt()) );
|
||||
}
|
||||
|
||||
public int rows() {
|
||||
if(nativeObj == 0)
|
||||
return 0;
|
||||
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(); }
|
||||
//javadoc:Mat::Mat(rows,cols,depth)
|
||||
public Mat(int rows, int cols, int depth) {
|
||||
this( rows, cols, new CvType(depth, 1) );
|
||||
}
|
||||
|
||||
public long dataAddr() {
|
||||
if(nativeObj == 0)
|
||||
return 0;
|
||||
return nData(nativeObj);
|
||||
}
|
||||
//javadoc:Mat::Mat(rows,cols,type,s)
|
||||
public Mat(int rows, int cols, CvType type, Scalar s) {
|
||||
this( nCreateMat(rows, cols, type.toInt(), s.v0, s.v1, s.v2, s.v3) );
|
||||
}
|
||||
|
||||
public boolean isContinuous() {
|
||||
if(nativeObj == 0)
|
||||
return false; // maybe throw an exception instead?
|
||||
return nIsCont(nativeObj);
|
||||
}
|
||||
//javadoc:Mat::Mat(rows,cols,depth,s)
|
||||
public Mat(int rows, int cols, int depth, Scalar s) {
|
||||
this( rows, cols, new CvType(depth, 1), s );
|
||||
}
|
||||
|
||||
public boolean isSubmatrix() {
|
||||
if(nativeObj == 0)
|
||||
return false; // maybe throw an exception instead?
|
||||
return nIsSubmat(nativeObj);
|
||||
}
|
||||
//javadoc:Mat::dispose()
|
||||
public void dispose() {
|
||||
nRelease(nativeObj);
|
||||
}
|
||||
|
||||
//javadoc:Mat::finalize()
|
||||
@Override
|
||||
protected void finalize() throws Throwable {
|
||||
nDelete(nativeObj);
|
||||
nativeObj = 0;
|
||||
super.finalize();
|
||||
}
|
||||
|
||||
public Mat submat(int rowStart, int rowEnd, int colStart, int colEnd) {
|
||||
checkNull();
|
||||
return new Mat( nSubmat(nativeObj, rowStart, rowEnd, colStart, colEnd) );
|
||||
}
|
||||
public Mat rowRange(int start, int end) { return submat(start, end, 0, -1); }
|
||||
public Mat row(int num) { return submat(num, num+1, 0, -1); }
|
||||
public Mat colRange(int start, int end) { return submat(0, -1, start, end); }
|
||||
public Mat col(int num) { return submat(0, -1, num, num+1); }
|
||||
|
||||
public Mat clone() {
|
||||
checkNull();
|
||||
return new Mat( nClone(nativeObj) );
|
||||
}
|
||||
|
||||
public int put(int row, int col, double...data) {
|
||||
checkNull();
|
||||
if(data != null)
|
||||
return nPutD(nativeObj, row, col, data.length, data);
|
||||
else
|
||||
return 0;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
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::toString()
|
||||
@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 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::dump()
|
||||
public String dump() {
|
||||
return nDump(nativeObj);
|
||||
}
|
||||
|
||||
//javadoc:Mat::empty()
|
||||
public boolean empty() {
|
||||
if(nativeObj == 0) return true;
|
||||
return nIsEmpty(nativeObj);
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
private void checkNull() {
|
||||
if(nativeObj == 0)
|
||||
throw new java.lang.UnsupportedOperationException("Native object address is NULL");
|
||||
}
|
||||
|
||||
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::type()
|
||||
public CvType type() {
|
||||
checkNull();
|
||||
return new CvType( nType(nativeObj) );
|
||||
}
|
||||
|
||||
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::depth()
|
||||
public int depth() { return type().depth(); }
|
||||
|
||||
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);
|
||||
}
|
||||
//javadoc:Mat::channels()
|
||||
public int channels() { return type().channels(); }
|
||||
|
||||
//javadoc:Mat::elemSize()
|
||||
public int elemSize() { return type().CV_ELEM_SIZE(); }
|
||||
|
||||
//javadoc:Mat::rows()
|
||||
public int rows() {
|
||||
if(nativeObj == 0)
|
||||
return 0;
|
||||
return nRows(nativeObj);
|
||||
}
|
||||
|
||||
//javadoc:Mat::height()
|
||||
public int height() { return rows(); }
|
||||
|
||||
//javadoc:Mat::cols()
|
||||
public int cols() {
|
||||
if(nativeObj == 0)
|
||||
return 0;
|
||||
return nCols(nativeObj);
|
||||
}
|
||||
|
||||
//javadoc:Mat::width()
|
||||
public int width() { return cols(); }
|
||||
|
||||
//javadoc:Mat::total()
|
||||
public int total() { return rows() * cols(); }
|
||||
|
||||
//javadoc:Mat::dataAddr()
|
||||
public long dataAddr() {
|
||||
if(nativeObj == 0)
|
||||
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) {
|
||||
checkNull();
|
||||
nSetTo(nativeObj, val.v0, val.v1, val.v2, val.v3);
|
||||
}
|
||||
|
||||
public void copyTo(Mat m) {
|
||||
checkNull();
|
||||
if(m.nativeObj == 0)
|
||||
throw new java.lang.UnsupportedOperationException("Destination native object address is NULL");
|
||||
nCopyTo(nativeObj, m.nativeObj);
|
||||
}
|
||||
|
||||
public double dot(Mat m) {
|
||||
checkNull();
|
||||
return nDot(nativeObj, m.nativeObj);
|
||||
}
|
||||
|
||||
public Mat cross(Mat m) {
|
||||
checkNull();
|
||||
return new Mat( nCross(nativeObj, m.nativeObj) );
|
||||
}
|
||||
//javadoc:Mat::setTo(s)
|
||||
public void setTo(Scalar s) {
|
||||
checkNull();
|
||||
nSetTo(nativeObj, s.v0, s.v1, s.v2, s.v3);
|
||||
}
|
||||
|
||||
//javadoc:Mat::copyTo(m)
|
||||
public void copyTo(Mat m) {
|
||||
checkNull();
|
||||
if(m.nativeObj == 0)
|
||||
throw new java.lang.UnsupportedOperationException("Destination native object address is NULL");
|
||||
nCopyTo(nativeObj, m.nativeObj);
|
||||
}
|
||||
|
||||
//javadoc:Mat::dot(m)
|
||||
public double dot(Mat m) {
|
||||
checkNull();
|
||||
return nDot(nativeObj, m.nativeObj);
|
||||
}
|
||||
|
||||
//javadoc:Mat::cross(m)
|
||||
public Mat cross(Mat m) {
|
||||
checkNull();
|
||||
return new Mat( nCross(nativeObj, m.nativeObj) );
|
||||
}
|
||||
|
||||
public Mat inv() {
|
||||
checkNull();
|
||||
return new Mat( nInv(nativeObj) );
|
||||
}
|
||||
|
||||
public long getNativeObjAddr() {
|
||||
return nativeObj;
|
||||
}
|
||||
|
||||
//javadoc:Mat::inv()
|
||||
public Mat inv() {
|
||||
checkNull();
|
||||
return new Mat( nInv(nativeObj) );
|
||||
}
|
||||
|
||||
//javadoc:Mat::getNativeObjAddr()
|
||||
public long getNativeObjAddr() {
|
||||
return nativeObj;
|
||||
}
|
||||
|
||||
//javadoc:Mat::eye(rows,cols,type)
|
||||
static public Mat eye(int rows, int cols, CvType type) {
|
||||
return new Mat( nEye(rows, cols, type.toInt()) );
|
||||
}
|
||||
|
||||
// native stuff
|
||||
static { System.loadLibrary("opencv_java"); }
|
||||
protected long nativeObj;
|
||||
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, double v0, double v1, double v2, double v3);
|
||||
private static native void nRelease(long self);
|
||||
private static native void nDelete(long self);
|
||||
private static native int nType(long self);
|
||||
private static native int nRows(long self);
|
||||
private static native int nCols(long self);
|
||||
private static native long nData(long self);
|
||||
private static native boolean nIsEmpty(long self);
|
||||
private static native boolean nIsCont(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 nClone(long self);
|
||||
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 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 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 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 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 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 nCopyTo(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 nInv(long self);
|
||||
|
||||
// native stuff
|
||||
static { System.loadLibrary("opencv_java"); }
|
||||
protected long nativeObj;
|
||||
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, double v0, double v1, double v2, double v3);
|
||||
private static native void nRelease(long self);
|
||||
private static native void nDelete(long self);
|
||||
private static native int nType(long self);
|
||||
private static native int nRows(long self);
|
||||
private static native int nCols(long self);
|
||||
private static native long nData(long self);
|
||||
private static native boolean nIsEmpty(long self);
|
||||
private static native boolean nIsCont(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 nClone(long self);
|
||||
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 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 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 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 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 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 nCopyTo(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 nInv(long self);
|
||||
private static native long nEye(int rows, int cols, int type);
|
||||
private static native String nDump(long self);
|
||||
|
||||
|
@ -1,5 +1,6 @@
|
||||
package org.opencv;
|
||||
|
||||
//javadoc:Point_
|
||||
public class Point {
|
||||
|
||||
public double x, y;
|
||||
|
@ -1,5 +1,6 @@
|
||||
package org.opencv;
|
||||
|
||||
//javadoc:Point3_
|
||||
public class Point3 {
|
||||
|
||||
public double x, y, z;
|
||||
|
@ -1,5 +1,6 @@
|
||||
package org.opencv;
|
||||
|
||||
//javadoc:Rect_
|
||||
public class Rect {
|
||||
|
||||
int x, y, width, height;
|
||||
|
@ -1,5 +1,6 @@
|
||||
package org.opencv;
|
||||
|
||||
//javadoc:Scalar_
|
||||
public class Scalar {
|
||||
|
||||
public double v0, v1, v2, v3;
|
||||
|
@ -1,5 +1,6 @@
|
||||
package org.opencv;
|
||||
|
||||
//javadoc:Size_
|
||||
public class Size {
|
||||
|
||||
public int width, height;
|
||||
|
Loading…
Reference in New Issue
Block a user