Commit 55e71a5c authored by Andrey Pavlenko's avatar Andrey Pavlenko

a couple of new smoke tests; Mat.java code clean-up

parent 322b09fc
......@@ -60,8 +60,12 @@ public class MatTest extends OpenCVTestCase {
assertEquals(CvType.CV_32F, gray0_32f.depth());
}
public void testDispose() {
fail("Not yet implemented");
public void testRelease() {
assertTrue( gray0.empty() == false );
assertTrue( gray0.rows() > 0 );
gray0.release();
assertTrue( gray0.empty() == true );
assertTrue( gray0.rows() == 0 );
}
public void testDot() {
......
......@@ -161,16 +161,31 @@ public class coreTest extends OpenCVTestCase {
Scalar color = new Scalar(128);
assertTrue(0 == Core.countNonZero(gray0));
Core.circle(gray0, center, radius, color, -1);
Core.circle(gray0, center, radius, color, -1 /*filled circle*/);
assertTrue(0 != Core.countNonZero(gray0));
}
public void testCircleMatPointIntScalarIntInt() {
fail("Not yet implemented");
Point center = new Point(gray0.cols() / 2, gray0.rows()/2);
int radius = Math.min(gray0.cols()/4, gray0.rows()/4);
Scalar color = new Scalar(128);
assertTrue(0 == Core.countNonZero(gray0));
Core.circle(gray0, center, radius, color, 2, 4/*4-connected line*/);
assertTrue(0 != Core.countNonZero(gray0));
}
public void testCircleMatPointIntScalarIntIntInt() {
fail("Not yet implemented");
Point center = new Point(gray0.cols() / 2, gray0.rows()/2);
Point center2 = new Point(gray0.cols(), gray0.rows());
int radius = Math.min(gray0.cols()/4, gray0.rows()/4);
Scalar color128 = new Scalar(128);
Scalar color0 = new Scalar(0);
assertTrue(0 == Core.countNonZero(gray0));
Core.circle(gray0, center2, radius*2, color128, 2, 4, 1/*Number of fractional bits*/);
Core.circle(gray0, center, radius, color0, 2, 4, 0);
assertTrue(0 == Core.countNonZero(gray0));
}
public void testClipLine() {
......
......@@ -5,8 +5,8 @@ public class Mat {
public Mat(long nativeMat) {
/*if(nativeMat == 0)
throw new java.lang.UnsupportedOperationException("Native object address is NULL");*/
if(nativeMat == 0)
throw new java.lang.UnsupportedOperationException("Native object address is NULL");
this.nativeObj = nativeMat;
}
......@@ -25,6 +25,11 @@ public class Mat {
this( nCreateMat(rows, cols, type, s.val[0], s.val[1], s.val[2], s.val[3]) );
}
//javadoc:Mat::eye(rows,cols,type)
public static Mat eye(int rows, int cols, int type) {
return new Mat( nEye(rows, cols, type) );
}
//javadoc:Mat::release()
public void release() {
nRelease(nativeObj);
......@@ -40,7 +45,6 @@ public class Mat {
//javadoc:Mat::toString()
@Override
public String toString() {
if(nativeObj == 0) return "Mat [ nativeObj=NULL ]";
return "Mat [ " +
rows() + "*" + cols() + "*" + CvType.typeToString(type()) +
", isCont=" + isContinuous() + ", isSubmat=" + isSubmatrix() +
......@@ -62,158 +66,142 @@ public class Mat {
//javadoc:Mat::size()
public Size size() {
if(nativeObj == 0) return new Size();
return new Size(nSize(nativeObj));
}
private void checkNull() {
if(nativeObj == 0)
throw new java.lang.UnsupportedOperationException("Native object address is NULL");
}
//javadoc:Mat::type()
public int type() {
checkNull();
return nType(nativeObj);
}
//javadoc:Mat::depth()
public int depth() { return CvType.depth(type()); }
public int depth() {
return CvType.depth(type());
}
//javadoc:Mat::channels()
public int channels() { return CvType.channels(type()); }
public int channels() {
return CvType.channels(type());
}
//javadoc:Mat::elemSize()
public int elemSize() { return CvType.ELEM_SIZE(type()); }
public int elemSize() {
return CvType.ELEM_SIZE(type());
}
//javadoc:Mat::rows()
public int rows() {
if(nativeObj == 0)
return 0;
return nRows(nativeObj);
}
//javadoc:Mat::height()
public int height() { return rows(); }
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(); }
public int width() {
return cols();
}
//javadoc:Mat::total()
public int total() { return rows() * cols(); }
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); }
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); }
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); }
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); }
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;
return nPutD(nativeObj, row, col, data.length, data);
}
//javadoc:Mat::put(row,col,data)
public int put(int row, int col, float[] data) {
checkNull();
if(data != null) {
int t = type();
if(CvType.depth(t) == 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;
int t = type();
if(CvType.depth(t) == CvType.CV_32F) {
return nPutF(nativeObj, row, col, data.length, data);
}
throw new java.lang.UnsupportedOperationException("Mat data type is not compatible: " + t);
}
//javadoc:Mat::put(row,col,data)
public int put(int row, int col, int[] data) {
checkNull();
if(data != null) {
int t = type();
if(CvType.depth(t) == 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;
int t = type();
if(CvType.depth(t) == CvType.CV_32S) {
return nPutI(nativeObj, row, col, data.length, data);
}
throw new java.lang.UnsupportedOperationException("Mat data type is not compatible: " + t);
}
//javadoc:Mat::put(row,col,data)
public int put(int row, int col, short[] data) {
checkNull();
if(data != null) {
int t = type();
if(CvType.depth(t) == CvType.CV_16U || CvType.depth(t) == 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;
int t = type();
if(CvType.depth(t) == CvType.CV_16U || CvType.depth(t) == CvType.CV_16S) {
return nPutS(nativeObj, row, col, data.length, data);
}
throw new java.lang.UnsupportedOperationException("Mat data type is not compatible: " + t);
}
//javadoc:Mat::put(row,col,data)
public int put(int row, int col, byte[] data) {
checkNull();
if(data != null) {
int t = type();
if(CvType.depth(t) == CvType.CV_8U || CvType.depth(t) == 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;
int t = type();
if(CvType.depth(t) == CvType.CV_8U || CvType.depth(t) == CvType.CV_8S) {
return nPutB(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, byte[] data) {
checkNull();
int t = type();
if(CvType.depth(t) == CvType.CV_8U || CvType.depth(t) == CvType.CV_8S) {
return nGetB(nativeObj, row, col, data.length, data);
......@@ -223,7 +211,6 @@ public class Mat {
//javadoc:Mat::get(row,col,data)
public int get(int row, int col, short[] data) {
checkNull();
int t = type();
if(CvType.depth(t) == CvType.CV_16U || CvType.depth(t) == CvType.CV_16S) {
return nGetS(nativeObj, row, col, data.length, data);
......@@ -233,7 +220,6 @@ public class Mat {
//javadoc:Mat::get(row,col,data)
public int get(int row, int col, int[] data) {
checkNull();
int t = type();
if(CvType.depth(t) == CvType.CV_32S) {
return nGetI(nativeObj, row, col, data.length, data);
......@@ -243,7 +229,6 @@ public class Mat {
//javadoc:Mat::get(row,col,data)
public int get(int row, int col, float[] data) {
checkNull();
int t = type();
if(CvType.depth(t) == CvType.CV_32F) {
return nGetF(nativeObj, row, col, data.length, data);
......@@ -253,7 +238,6 @@ public class Mat {
//javadoc:Mat::get(row,col,data)
public int get(int row, int col, double[] data) {
checkNull();
int t = type();
if(CvType.depth(t) == CvType.CV_64F) {
return nGetD(nativeObj, row, col, data.length, data);
......@@ -263,44 +247,32 @@ public class Mat {
//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);
return nGet(nativeObj, row, col);
}
//javadoc:Mat::setTo(s)
public void setTo(Scalar s) {
checkNull();
nSetTo(nativeObj, s.val[0], s.val[1], s.val[2], s.val[3]);
}
//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) );
}
//javadoc:Mat::inv()
public Mat inv() {
checkNull();
return new Mat( nInv(nativeObj) );
}
......@@ -309,11 +281,6 @@ public class Mat {
return nativeObj;
}
//javadoc:Mat::eye(rows,cols,type)
static public Mat eye(int rows, int cols, int type) {
return new Mat( nEye(rows, cols, type) );
}
// native stuff
static { System.loadLibrary("opencv_java"); }
public final long nativeObj;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment