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 { ...@@ -60,8 +60,12 @@ public class MatTest extends OpenCVTestCase {
assertEquals(CvType.CV_32F, gray0_32f.depth()); assertEquals(CvType.CV_32F, gray0_32f.depth());
} }
public void testDispose() { public void testRelease() {
fail("Not yet implemented"); assertTrue( gray0.empty() == false );
assertTrue( gray0.rows() > 0 );
gray0.release();
assertTrue( gray0.empty() == true );
assertTrue( gray0.rows() == 0 );
} }
public void testDot() { public void testDot() {
......
...@@ -161,16 +161,31 @@ public class coreTest extends OpenCVTestCase { ...@@ -161,16 +161,31 @@ public class coreTest extends OpenCVTestCase {
Scalar color = new Scalar(128); Scalar color = new Scalar(128);
assertTrue(0 == Core.countNonZero(gray0)); 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)); assertTrue(0 != Core.countNonZero(gray0));
} }
public void testCircleMatPointIntScalarIntInt() { 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() { 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() { public void testClipLine() {
......
...@@ -5,8 +5,8 @@ public class Mat { ...@@ -5,8 +5,8 @@ public class Mat {
public Mat(long nativeMat) { public 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;
} }
...@@ -25,6 +25,11 @@ public class Mat { ...@@ -25,6 +25,11 @@ public class Mat {
this( nCreateMat(rows, cols, type, s.val[0], s.val[1], s.val[2], s.val[3]) ); 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() //javadoc:Mat::release()
public void release() { public void release() {
nRelease(nativeObj); nRelease(nativeObj);
...@@ -40,7 +45,6 @@ public class Mat { ...@@ -40,7 +45,6 @@ public class Mat {
//javadoc:Mat::toString() //javadoc:Mat::toString()
@Override @Override
public String toString() { public String toString() {
if(nativeObj == 0) return "Mat [ nativeObj=NULL ]";
return "Mat [ " + return "Mat [ " +
rows() + "*" + cols() + "*" + CvType.typeToString(type()) + rows() + "*" + cols() + "*" + CvType.typeToString(type()) +
", isCont=" + isContinuous() + ", isSubmat=" + isSubmatrix() + ", isCont=" + isContinuous() + ", isSubmat=" + isSubmatrix() +
...@@ -62,158 +66,142 @@ public class Mat { ...@@ -62,158 +66,142 @@ public class Mat {
//javadoc:Mat::size() //javadoc:Mat::size()
public Size size() { public Size size() {
if(nativeObj == 0) return new Size();
return new Size(nSize(nativeObj)); return new Size(nSize(nativeObj));
} }
private void checkNull() {
if(nativeObj == 0)
throw new java.lang.UnsupportedOperationException("Native object address is NULL");
}
//javadoc:Mat::type() //javadoc:Mat::type()
public int type() { public int type() {
checkNull();
return nType(nativeObj); return nType(nativeObj);
} }
//javadoc:Mat::depth() //javadoc:Mat::depth()
public int depth() { return CvType.depth(type()); } public int depth() {
return CvType.depth(type());
}
//javadoc:Mat::channels() //javadoc:Mat::channels()
public int channels() { return CvType.channels(type()); } public int channels() {
return CvType.channels(type());
}
//javadoc:Mat::elemSize() //javadoc:Mat::elemSize()
public int elemSize() { return CvType.ELEM_SIZE(type()); } public int elemSize() {
return CvType.ELEM_SIZE(type());
}
//javadoc:Mat::rows() //javadoc:Mat::rows()
public int rows() { public int rows() {
if(nativeObj == 0)
return 0;
return nRows(nativeObj); return nRows(nativeObj);
} }
//javadoc:Mat::height() //javadoc:Mat::height()
public int height() { return rows(); } public int height() {
return rows();
}
//javadoc:Mat::cols() //javadoc:Mat::cols()
public int cols() { public int cols() {
if(nativeObj == 0)
return 0;
return nCols(nativeObj); return nCols(nativeObj);
} }
//javadoc:Mat::width() //javadoc:Mat::width()
public int width() { return cols(); } public int width() {
return cols();
}
//javadoc:Mat::total() //javadoc:Mat::total()
public int total() { return rows() * cols(); } public int total() {
return rows() * cols();
}
//javadoc:Mat::dataAddr() //javadoc:Mat::dataAddr()
public long dataAddr() { public long dataAddr() {
if(nativeObj == 0)
return 0;
return nData(nativeObj); return nData(nativeObj);
} }
//javadoc:Mat::isContinuous() //javadoc:Mat::isContinuous()
public boolean isContinuous() { public boolean isContinuous() {
if(nativeObj == 0)
return false; // maybe throw an exception instead?
return nIsCont(nativeObj); return nIsCont(nativeObj);
} }
//javadoc:Mat::isSubmatrix() //javadoc:Mat::isSubmatrix()
public boolean isSubmatrix() { public boolean isSubmatrix() {
if(nativeObj == 0)
return false; // maybe throw an exception instead?
return nIsSubmat(nativeObj); return nIsSubmat(nativeObj);
} }
//javadoc:Mat::submat(rowStart,rowEnd,colStart,colEnd) //javadoc:Mat::submat(rowStart,rowEnd,colStart,colEnd)
public Mat submat(int rowStart, int rowEnd, int colStart, int colEnd) { public Mat submat(int rowStart, int rowEnd, int colStart, int colEnd) {
checkNull();
return new Mat( nSubmat(nativeObj, rowStart, rowEnd, colStart, colEnd) ); return new Mat( nSubmat(nativeObj, rowStart, rowEnd, colStart, colEnd) );
} }
//javadoc:Mat::rowRange(startrow,endrow) //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) //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) //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) //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() //javadoc:Mat::clone()
public Mat clone() { public Mat clone() {
checkNull();
return new Mat( nClone(nativeObj) ); return new Mat( nClone(nativeObj) );
} }
//javadoc:Mat::put(row,col,data) //javadoc:Mat::put(row,col,data)
public int put(int row, int col, double...data) { public int put(int row, int col, double...data) {
checkNull(); return nPutD(nativeObj, row, col, data.length, data);
if(data != null)
return nPutD(nativeObj, row, col, data.length, data);
else
return 0;
} }
//javadoc:Mat::put(row,col,data) //javadoc:Mat::put(row,col,data)
public int put(int row, int col, float[] data) { public int put(int row, int col, float[] data) {
checkNull(); int t = type();
if(data != null) { if(CvType.depth(t) == CvType.CV_32F) {
int t = type(); return nPutF(nativeObj, row, col, data.length, data);
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);
}
throw new java.lang.UnsupportedOperationException("Mat data type is not compatible: " + t);
} else return 0;
} }
//javadoc:Mat::put(row,col,data) //javadoc:Mat::put(row,col,data)
public int put(int row, int col, int[] data) { public int put(int row, int col, int[] data) {
checkNull(); int t = type();
if(data != null) { if(CvType.depth(t) == CvType.CV_32S) {
int t = type(); return nPutI(nativeObj, row, col, data.length, data);
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);
}
throw new java.lang.UnsupportedOperationException("Mat data type is not compatible: " + t);
} else return 0;
} }
//javadoc:Mat::put(row,col,data) //javadoc:Mat::put(row,col,data)
public int put(int row, int col, short[] data) { public int put(int row, int col, short[] data) {
checkNull(); int t = type();
if(data != null) { if(CvType.depth(t) == CvType.CV_16U || CvType.depth(t) == CvType.CV_16S) {
int t = type(); return nPutS(nativeObj, row, col, data.length, data);
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);
}
throw new java.lang.UnsupportedOperationException("Mat data type is not compatible: " + t);
} else return 0;
} }
//javadoc:Mat::put(row,col,data) //javadoc:Mat::put(row,col,data)
public int put(int row, int col, byte[] data) { public int put(int row, int col, byte[] data) {
checkNull(); int t = type();
if(data != null) { if(CvType.depth(t) == CvType.CV_8U || CvType.depth(t) == CvType.CV_8S) {
int t = type(); return nPutB(nativeObj, row, col, data.length, data);
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);
}
throw new java.lang.UnsupportedOperationException("Mat data type is not compatible: " + t);
} else return 0;
} }
//javadoc:Mat::get(row,col,data) //javadoc:Mat::get(row,col,data)
public int get(int row, int col, byte[] data) { public int get(int row, int col, byte[] data) {
checkNull();
int t = type(); int t = type();
if(CvType.depth(t) == CvType.CV_8U || CvType.depth(t) == CvType.CV_8S) { if(CvType.depth(t) == CvType.CV_8U || CvType.depth(t) == CvType.CV_8S) {
return nGetB(nativeObj, row, col, data.length, data); return nGetB(nativeObj, row, col, data.length, data);
...@@ -223,7 +211,6 @@ public class Mat { ...@@ -223,7 +211,6 @@ public class Mat {
//javadoc:Mat::get(row,col,data) //javadoc:Mat::get(row,col,data)
public int get(int row, int col, short[] data) { public int get(int row, int col, short[] data) {
checkNull();
int t = type(); int t = type();
if(CvType.depth(t) == CvType.CV_16U || CvType.depth(t) == CvType.CV_16S) { if(CvType.depth(t) == CvType.CV_16U || CvType.depth(t) == CvType.CV_16S) {
return nGetS(nativeObj, row, col, data.length, data); return nGetS(nativeObj, row, col, data.length, data);
...@@ -233,7 +220,6 @@ public class Mat { ...@@ -233,7 +220,6 @@ public class Mat {
//javadoc:Mat::get(row,col,data) //javadoc:Mat::get(row,col,data)
public int get(int row, int col, int[] data) { public int get(int row, int col, int[] data) {
checkNull();
int t = type(); int t = type();
if(CvType.depth(t) == CvType.CV_32S) { if(CvType.depth(t) == CvType.CV_32S) {
return nGetI(nativeObj, row, col, data.length, data); return nGetI(nativeObj, row, col, data.length, data);
...@@ -243,7 +229,6 @@ public class Mat { ...@@ -243,7 +229,6 @@ public class Mat {
//javadoc:Mat::get(row,col,data) //javadoc:Mat::get(row,col,data)
public int get(int row, int col, float[] data) { public int get(int row, int col, float[] data) {
checkNull();
int t = type(); int t = type();
if(CvType.depth(t) == CvType.CV_32F) { if(CvType.depth(t) == CvType.CV_32F) {
return nGetF(nativeObj, row, col, data.length, data); return nGetF(nativeObj, row, col, data.length, data);
...@@ -253,7 +238,6 @@ public class Mat { ...@@ -253,7 +238,6 @@ public class Mat {
//javadoc:Mat::get(row,col,data) //javadoc:Mat::get(row,col,data)
public int get(int row, int col, double[] data) { public int get(int row, int col, double[] data) {
checkNull();
int t = type(); int t = type();
if(CvType.depth(t) == CvType.CV_64F) { if(CvType.depth(t) == CvType.CV_64F) {
return nGetD(nativeObj, row, col, data.length, data); return nGetD(nativeObj, row, col, data.length, data);
...@@ -263,44 +247,32 @@ public class Mat { ...@@ -263,44 +247,32 @@ public class Mat {
//javadoc:Mat::get(row,col) //javadoc:Mat::get(row,col)
public double[] get(int row, int col) { public double[] get(int row, int col) {
checkNull(); return nGet(nativeObj, row, col);
//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::setTo(s) //javadoc:Mat::setTo(s)
public void setTo(Scalar s) { public void setTo(Scalar s) {
checkNull();
nSetTo(nativeObj, s.val[0], s.val[1], s.val[2], s.val[3]); nSetTo(nativeObj, s.val[0], s.val[1], s.val[2], s.val[3]);
} }
//javadoc:Mat::copyTo(m) //javadoc:Mat::copyTo(m)
public void copyTo(Mat 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); nCopyTo(nativeObj, m.nativeObj);
} }
//javadoc:Mat::dot(m) //javadoc:Mat::dot(m)
public double dot(Mat m) { public double dot(Mat m) {
checkNull();
return nDot(nativeObj, m.nativeObj); return nDot(nativeObj, m.nativeObj);
} }
//javadoc:Mat::cross(m) //javadoc:Mat::cross(m)
public Mat cross(Mat m) { public Mat cross(Mat m) {
checkNull();
return new Mat( nCross(nativeObj, m.nativeObj) ); return new Mat( nCross(nativeObj, m.nativeObj) );
} }
//javadoc:Mat::inv() //javadoc:Mat::inv()
public Mat inv() { public Mat inv() {
checkNull();
return new Mat( nInv(nativeObj) ); return new Mat( nInv(nativeObj) );
} }
...@@ -309,11 +281,6 @@ public class Mat { ...@@ -309,11 +281,6 @@ public class Mat {
return nativeObj; 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 // native stuff
static { System.loadLibrary("opencv_java"); } static { System.loadLibrary("opencv_java"); }
public final long nativeObj; 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