diff --git a/modules/java/android_test/src/org/opencv/test/OpenCVTestCase.java b/modules/java/android_test/src/org/opencv/test/OpenCVTestCase.java index d4a4d1db69..55a8e93cff 100644 --- a/modules/java/android_test/src/org/opencv/test/OpenCVTestCase.java +++ b/modules/java/android_test/src/org/opencv/test/OpenCVTestCase.java @@ -122,7 +122,7 @@ public class OpenCVTestCase extends TestCase { //OpenCVTestRunner.Log(m1.toString()); //OpenCVTestRunner.Log(m2.toString()); - if (!m1.type().equals(m2.type()) || + if (m1.type() != m2.type() || m1.cols() != m2.cols() || m1.rows() != m2.rows()) { throw new UnsupportedOperationException(); } diff --git a/modules/java/src/java/Converters.java b/modules/java/src/java/Converters.java index 7014af8db8..53c677a406 100644 --- a/modules/java/src/java/Converters.java +++ b/modules/java/src/java/Converters.java @@ -32,7 +32,7 @@ public class Converters { if(pts == null) throw new java.lang.IllegalArgumentException(); int cols = m.cols(); - if(!CvType.CV_32SC2.equals(m.type()) || m.rows()!=1 ) + if(CvType.CV_32SC2 != m.type() || m.rows()!=1 ) throw new java.lang.IllegalArgumentException(); pts.clear(); @@ -65,7 +65,7 @@ public class Converters { if(mats == null) throw new java.lang.IllegalArgumentException(); int cols = m.cols(); - if(!CvType.CV_32SC2.equals(m.type()) || m.rows()!=1 ) + if(CvType.CV_32SC2 != m.type() || m.rows()!=1 ) throw new java.lang.IllegalArgumentException(); mats.clear(); @@ -102,7 +102,7 @@ public class Converters { if(fs == null) throw new java.lang.IllegalArgumentException(); int cols = m.cols(); - if(!CvType.CV_32FC1.equals(m.type()) || m.rows()!=1 ) + if(CvType.CV_32FC1 != m.type() || m.rows()!=1 ) throw new java.lang.IllegalArgumentException(); fs.clear(); @@ -151,7 +151,7 @@ public class Converters { if(is == null) throw new java.lang.IllegalArgumentException(); int cols = m.cols(); - if(!CvType.CV_32SC1.equals(m.type()) || m.rows()!=1 ) + if(CvType.CV_32SC1 != m.type() || m.rows()!=1 ) throw new java.lang.IllegalArgumentException(); is.clear(); @@ -186,7 +186,7 @@ public class Converters { if(rs == null) throw new java.lang.IllegalArgumentException(); int cols = m.cols(); - if(!CvType.CV_32SC4.equals(m.type()) || m.rows()!=1 ) + if(CvType.CV_32SC4 != m.type() || m.rows()!=1 ) throw new java.lang.IllegalArgumentException(); rs.clear(); diff --git a/modules/java/src/java/core+CvType.java b/modules/java/src/java/core+CvType.java index cef9de4d2c..c055030208 100644 --- a/modules/java/src/java/core+CvType.java +++ b/modules/java/src/java/core+CvType.java @@ -2,129 +2,110 @@ package org.opencv.core; public final class CvType { - - // predefined type constants - public static final CvType - CV_8UC1 = CV_8UC(1), CV_8UC2 = CV_8UC(2), CV_8UC3 = CV_8UC(3), CV_8UC4 = CV_8UC(4), - CV_8SC1 = CV_8SC(1), CV_8SC2 = CV_8SC(2), CV_8SC3 = CV_8SC(3), CV_8SC4 = CV_8SC(4), - CV_16UC1 = CV_16UC(1), CV_16UC2 = CV_16UC(2), CV_16UC3 = CV_16UC(3), CV_16UC4 = CV_16UC(4), - CV_16SC1 = CV_16SC(1), CV_16SC2 = CV_16SC(2), CV_16SC3 = CV_16SC(3), CV_16SC4 = CV_16SC(4), - CV_32SC1 = CV_32SC(1), CV_32SC2 = CV_32SC(2), CV_32SC3 = CV_32SC(3), CV_32SC4 = CV_32SC(4), - CV_32FC1 = CV_32FC(1), CV_32FC2 = CV_32FC(2), CV_32FC3 = CV_32FC(3), CV_32FC4 = CV_32FC(4), - CV_64FC1 = CV_64FC(1), CV_64FC2 = CV_64FC(2), CV_64FC3 = CV_64FC(3), CV_64FC4 = CV_64FC(4); - - // type depth constants - public static final int CV_8U = 0, - CV_8S = 1, - CV_16U = 2, - CV_16S = 3, - CV_32S = 4, - CV_32F = 5, - CV_64F = 6, - CV_USRTYPE1=7; - - private static final int CV_CN_MAX = 512, CV_CN_SHIFT = 3, CV_DEPTH_MAX = (1 << CV_CN_SHIFT); - - private final int value; - - protected CvType(int depth, int channels) { - if(channels<=0 || channels>=CV_CN_MAX) { - throw new java.lang.UnsupportedOperationException( - "Channels count should be 1.." + (CV_CN_MAX-1) ); - } - if(depth<0 || depth>=CV_DEPTH_MAX) { - throw new java.lang.UnsupportedOperationException( - "Data type depth should be 0.." + (CV_DEPTH_MAX-1) ); - } - value = (depth & (CV_DEPTH_MAX-1)) + ((channels-1) << CV_CN_SHIFT); - } - - protected CvType(int val) { value = val; } - - public static final CvType CV_8UC(int ch) { return new CvType(CV_8U, ch); } - - public static final CvType CV_8SC(int ch) { return new CvType(CV_8S, ch); } - - public static final CvType CV_16UC(int ch) { return new CvType(CV_16U, ch); } - - public static final CvType CV_16SC(int ch) { return new CvType(CV_16S, ch); } - - public static final CvType CV_32SC(int ch) { return new CvType(CV_32S, ch); } - - public static final CvType CV_32FC(int ch) { return new CvType(CV_32F, ch); } - - public static final CvType CV_64FC(int ch) { return new CvType(CV_64F, ch); } - - public final int toInt() { return value; } - - public final int channels() { return (value >> CV_CN_SHIFT) + 1; } - - public final int depth() { return value & (CV_DEPTH_MAX-1); } - - public final boolean isInteger() { return depth() < CV_32F; } - - public final int CV_ELEM_SIZE() { - switch (depth()) { - case CV_8U: - case CV_8S: - return channels(); - case CV_16U: - case CV_16S: - return 2 * channels(); - case CV_32S: - case CV_32F: - return 4 * channels(); - case CV_64F: - return 8 * channels(); - default: - throw new java.lang.UnsupportedOperationException( - "Unsupported CvType value: " + value ); - } - } - - @Override - public final String toString() { - String s; - switch (depth()) { - case CV_8U: - s = "CV_8U"; - break; - case CV_8S: - s = "CV_8S"; - break; - case CV_16U: - s = "CV_16U"; - break; - case CV_16S: - s = "CV_16S"; - break; - case CV_32S: - s = "CV_32S"; - break; - case CV_32F: - s = "CV_32F"; - break; - case CV_64F: - s = "CV_64F"; - break; - default: - s = "CV_USRTYPE1"; - } - - int ch = channels(); - if(ch<=4) return s + "C" + ch; - else return s + "C(" + ch + ")"; - } - - // hashCode() has to be overridden if equals() is - @Override - public final int hashCode() { return value; } - - @Override - public final boolean equals(Object obj) { - if (this == obj) return true; - if ( !(obj instanceof CvType) ) return false; - CvType other = (CvType) obj; - return value == other.value; - } + + // type depth constants + public static final int CV_8U = 0, CV_8S = 1, + CV_16U = 2, CV_16S = 3, + CV_32S = 4, + CV_32F = 5, + CV_64F = 6, + CV_USRTYPE1=7; + + // predefined type constants + public static final int + CV_8UC1 = CV_8UC(1), CV_8UC2 = CV_8UC(2), CV_8UC3 = CV_8UC(3), CV_8UC4 = CV_8UC(4), + CV_8SC1 = CV_8SC(1), CV_8SC2 = CV_8SC(2), CV_8SC3 = CV_8SC(3), CV_8SC4 = CV_8SC(4), + CV_16UC1 = CV_16UC(1), CV_16UC2 = CV_16UC(2), CV_16UC3 = CV_16UC(3), CV_16UC4 = CV_16UC(4), + CV_16SC1 = CV_16SC(1), CV_16SC2 = CV_16SC(2), CV_16SC3 = CV_16SC(3), CV_16SC4 = CV_16SC(4), + CV_32SC1 = CV_32SC(1), CV_32SC2 = CV_32SC(2), CV_32SC3 = CV_32SC(3), CV_32SC4 = CV_32SC(4), + CV_32FC1 = CV_32FC(1), CV_32FC2 = CV_32FC(2), CV_32FC3 = CV_32FC(3), CV_32FC4 = CV_32FC(4), + CV_64FC1 = CV_64FC(1), CV_64FC2 = CV_64FC(2), CV_64FC3 = CV_64FC(3), CV_64FC4 = CV_64FC(4); + + private static final int CV_CN_MAX = 512, CV_CN_SHIFT = 3, CV_DEPTH_MAX = (1 << CV_CN_SHIFT); + + public static final int makeType(int depth, int channels) { + if(channels<=0 || channels>=CV_CN_MAX) { + throw new java.lang.UnsupportedOperationException( + "Channels count should be 1.." + (CV_CN_MAX-1) ); + } + if(depth<0 || depth>=CV_DEPTH_MAX) { + throw new java.lang.UnsupportedOperationException( + "Data type depth should be 0.." + (CV_DEPTH_MAX-1) ); + } + return (depth & (CV_DEPTH_MAX-1)) + ((channels-1) << CV_CN_SHIFT); + } + + + public static final int CV_8UC(int ch) { return makeType(CV_8U, ch); } + + public static final int CV_8SC(int ch) { return makeType(CV_8S, ch); } + + public static final int CV_16UC(int ch) { return makeType(CV_16U, ch); } + + public static final int CV_16SC(int ch) { return makeType(CV_16S, ch); } + + public static final int CV_32SC(int ch) { return makeType(CV_32S, ch); } + + public static final int CV_32FC(int ch) { return makeType(CV_32F, ch); } + + public static final int CV_64FC(int ch) { return makeType(CV_64F, ch); } + + public static final int channels(int type) { return (type >> CV_CN_SHIFT) + 1; } + + public static final int depth(int type) { return type & (CV_DEPTH_MAX-1); } + + public static final boolean isInteger(int type) { return depth(type) < CV_32F; } + + public static final int ELEM_SIZE(int type) { + switch (depth(type)) { + case CV_8U: + case CV_8S: + return channels(type); + case CV_16U: + case CV_16S: + return 2 * channels(type); + case CV_32S: + case CV_32F: + return 4 * channels(type); + case CV_64F: + return 8 * channels(type); + default: + throw new java.lang.UnsupportedOperationException( + "Unsupported CvType value: " + type ); + } + } + + public static final String typeToString(int type) { + String s; + switch (depth(type)) { + case CV_8U: + s = "CV_8U"; + break; + case CV_8S: + s = "CV_8S"; + break; + case CV_16U: + s = "CV_16U"; + break; + case CV_16S: + s = "CV_16S"; + break; + case CV_32S: + s = "CV_32S"; + break; + case CV_32F: + s = "CV_32F"; + break; + case CV_64F: + s = "CV_64F"; + break; + default: + s = "CV_USRTYPE1"; + } + + int ch = channels(type); + if(ch<=4) return s + "C" + ch; + else return s + "C(" + ch + ")"; + } + } diff --git a/modules/java/src/java/core+Mat.java b/modules/java/src/java/core+Mat.java index d7a57d7367..d60d1f9098 100644 --- a/modules/java/src/java/core+Mat.java +++ b/modules/java/src/java/core+Mat.java @@ -16,27 +16,17 @@ public class Mat { } //javadoc:Mat::Mat(rows,cols,type) - public Mat(int rows, int cols, CvType type) { - this( nCreateMat(rows, cols, type.toInt()) ); - } - - //javadoc:Mat::Mat(rows,cols,depth) - public Mat(int rows, int cols, int depth) { - this( rows, cols, new CvType(depth, 1) ); + public Mat(int rows, int cols, int type) { + this( nCreateMat(rows, cols, type) ); } //javadoc:Mat::Mat(rows,cols,type,s) - public Mat(int rows, int cols, CvType type, Scalar s) { - this( nCreateMat(rows, cols, type.toInt(), s.val[0], s.val[1], s.val[2], s.val[3]) ); - } - - //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 Mat(int rows, int cols, int type, Scalar s) { + this( nCreateMat(rows, cols, type, s.val[0], s.val[1], s.val[2], s.val[3]) ); } - //javadoc:Mat::dispose() - public void dispose() { + //javadoc:Mat::release() + public void release() { nRelease(nativeObj); } @@ -52,7 +42,7 @@ public class Mat { public String toString() { if(nativeObj == 0) return "Mat [ nativeObj=NULL ]"; return "Mat [ " + - rows() + "*" + cols() + "*" + type() + + rows() + "*" + cols() + "*" + CvType.typeToString(type()) + ", isCont=" + isContinuous() + ", isSubmat=" + isSubmatrix() + ", nativeObj=0x" + Long.toHexString(nativeObj) + ", dataAddr=0x" + Long.toHexString(dataAddr()) + @@ -82,19 +72,19 @@ public class Mat { } //javadoc:Mat::type() - public CvType type() { + public int type() { checkNull(); - return new CvType( nType(nativeObj) ); + return nType(nativeObj); } //javadoc:Mat::depth() - public int depth() { return type().depth(); } + public int depth() { return CvType.depth(type()); } //javadoc:Mat::channels() - public int channels() { return type().channels(); } + public int channels() { return CvType.channels(type()); } //javadoc:Mat::elemSize() - public int elemSize() { return type().CV_ELEM_SIZE(); } + public int elemSize() { return CvType.ELEM_SIZE(type()); } //javadoc:Mat::rows() public int rows() { @@ -177,8 +167,8 @@ public class Mat { public int put(int row, int col, float[] data) { checkNull(); if(data != null) { - CvType t = type(); - if(t.depth() == CvType.CV_32F) { + 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); @@ -189,8 +179,8 @@ public class Mat { public int put(int row, int col, int[] data) { checkNull(); if(data != null) { - CvType t = type(); - if(t.depth() == CvType.CV_32S) { + 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); @@ -201,8 +191,8 @@ public class Mat { 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) { + 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); @@ -213,8 +203,8 @@ public class Mat { 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) { + 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); @@ -224,8 +214,8 @@ public class Mat { //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) { + int t = type(); + if(CvType.depth(t) == CvType.CV_8U || CvType.depth(t) == CvType.CV_8S) { return nGetB(nativeObj, row, col, data.length, data); } throw new java.lang.UnsupportedOperationException("Mat data type is not compatible: " + t); @@ -234,8 +224,8 @@ public class Mat { //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) { + int t = type(); + if(CvType.depth(t) == CvType.CV_16U || CvType.depth(t) == CvType.CV_16S) { return nGetS(nativeObj, row, col, data.length, data); } throw new java.lang.UnsupportedOperationException("Mat data type is not compatible: " + t); @@ -244,8 +234,8 @@ public class Mat { //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) { + int t = type(); + if(CvType.depth(t) == CvType.CV_32S) { return nGetI(nativeObj, row, col, data.length, data); } throw new java.lang.UnsupportedOperationException("Mat data type is not compatible: " + t); @@ -254,8 +244,8 @@ public class Mat { //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) { + int t = type(); + if(CvType.depth(t) == CvType.CV_32F) { return nGetF(nativeObj, row, col, data.length, data); } throw new java.lang.UnsupportedOperationException("Mat data type is not compatible: " + t); @@ -264,8 +254,8 @@ public class Mat { //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) { + int t = type(); + if(CvType.depth(t) == CvType.CV_64F) { return nGetD(nativeObj, row, col, data.length, data); } throw new java.lang.UnsupportedOperationException("Mat data type is not compatible: " + t); @@ -320,8 +310,8 @@ public class Mat { } //javadoc:Mat::eye(rows,cols,type) - static public Mat eye(int rows, int cols, CvType type) { - return new Mat( nEye(rows, cols, type.toInt()) ); + static public Mat eye(int rows, int cols, int type) { + return new Mat( nEye(rows, cols, type) ); } // native stuff diff --git a/samples/android/15-puzzle/src/org/opencv/samples/puzzle15/puzzle15View.java b/samples/android/15-puzzle/src/org/opencv/samples/puzzle15/puzzle15View.java index 9bb2bc99ed..9721d27cc2 100644 --- a/samples/android/15-puzzle/src/org/opencv/samples/puzzle15/puzzle15View.java +++ b/samples/android/15-puzzle/src/org/opencv/samples/puzzle15/puzzle15View.java @@ -159,16 +159,16 @@ public class puzzle15View extends SampleCvViewBase implements OnTouchListener { // Explicitly deallocate Mats if (mCells != null) { for (Mat m : mCells) - m.dispose(); + m.release(); } if (mCells15 != null) { for (Mat m : mCells15) - m.dispose(); + m.release(); } if (mRgba != null) - mRgba.dispose(); + mRgba.release(); if (mRgba15 != null) - mRgba15.dispose(); + mRgba15.release(); mRgba = null; mRgba15 = null; diff --git a/samples/android/face-detection/src/org/opencv/samples/fd/FdView.java b/samples/android/face-detection/src/org/opencv/samples/fd/FdView.java index 54e52686af..07e1589f67 100644 --- a/samples/android/face-detection/src/org/opencv/samples/fd/FdView.java +++ b/samples/android/face-detection/src/org/opencv/samples/fd/FdView.java @@ -105,9 +105,9 @@ class FdView extends SampleCvViewBase { synchronized (this) { // Explicitly deallocate Mats if (mRgba != null) - mRgba.dispose(); + mRgba.release(); if (mGray != null) - mGray.dispose(); + mGray.release(); mRgba = null; mGray = null; diff --git a/samples/android/image-manipulations/src/org/opencv/samples/imagemanipulations/ImageManipulationsView.java b/samples/android/image-manipulations/src/org/opencv/samples/imagemanipulations/ImageManipulationsView.java index 8b7e2a8551..a7ded090ca 100644 --- a/samples/android/image-manipulations/src/org/opencv/samples/imagemanipulations/ImageManipulationsView.java +++ b/samples/android/image-manipulations/src/org/opencv/samples/imagemanipulations/ImageManipulationsView.java @@ -149,21 +149,21 @@ class ImageManipulationsView extends SampleCvViewBase { synchronized (this) { // Explicitly deallocate Mats if (mZoomWindow != null) - mZoomWindow.dispose(); + mZoomWindow.release(); if (mZoomCorner != null) - mZoomCorner.dispose(); + mZoomCorner.release(); if (mBlurWindow != null) - mBlurWindow.dispose(); + mBlurWindow.release(); if (mGrayInnerWindow != null) - mGrayInnerWindow.dispose(); + mGrayInnerWindow.release(); if (mRgbaInnerWindow != null) - mRgbaInnerWindow.dispose(); + mRgbaInnerWindow.release(); if (mRgba != null) - mRgba.dispose(); + mRgba.release(); if (mGray != null) - mGray.dispose(); + mGray.release(); if (mIntermediateMat != null) - mIntermediateMat.dispose(); + mIntermediateMat.release(); mRgba = null; mGray = null; diff --git a/samples/android/tutorial-1-addopencv/src/org/opencv/samples/tutorial1/Sample1View.java b/samples/android/tutorial-1-addopencv/src/org/opencv/samples/tutorial1/Sample1View.java index 206b5b5c91..81d2e754c2 100644 --- a/samples/android/tutorial-1-addopencv/src/org/opencv/samples/tutorial1/Sample1View.java +++ b/samples/android/tutorial-1-addopencv/src/org/opencv/samples/tutorial1/Sample1View.java @@ -70,13 +70,13 @@ class Sample1View extends SampleViewBase { synchronized (this) { // Explicitly deallocate Mats if (mYuv != null) - mYuv.dispose(); + mYuv.release(); if (mRgba != null) - mRgba.dispose(); + mRgba.release(); if (mGraySubmat != null) - mGraySubmat.dispose(); + mGraySubmat.release(); if (mIntermediateMat != null) - mIntermediateMat.dispose(); + mIntermediateMat.release(); mYuv = null; mRgba = null; diff --git a/samples/android/tutorial-2-opencvcamera/src/org/opencv/samples/tutorial2/Sample2View.java b/samples/android/tutorial-2-opencvcamera/src/org/opencv/samples/tutorial2/Sample2View.java index 83a69050df..099ef4838e 100644 --- a/samples/android/tutorial-2-opencvcamera/src/org/opencv/samples/tutorial2/Sample2View.java +++ b/samples/android/tutorial-2-opencvcamera/src/org/opencv/samples/tutorial2/Sample2View.java @@ -68,11 +68,11 @@ class Sample2View extends SampleCvViewBase { synchronized (this) { // Explicitly deallocate Mats if (mRgba != null) - mRgba.dispose(); + mRgba.release(); if (mGray != null) - mGray.dispose(); + mGray.release(); if (mIntermediateMat != null) - mIntermediateMat.dispose(); + mIntermediateMat.release(); mRgba = null; mGray = null; diff --git a/samples/android/tutorial-4-mixed/src/org/opencv/samples/tutorial4/Sample4View.java b/samples/android/tutorial-4-mixed/src/org/opencv/samples/tutorial4/Sample4View.java index 2a0f72b370..c589f6df68 100644 --- a/samples/android/tutorial-4-mixed/src/org/opencv/samples/tutorial4/Sample4View.java +++ b/samples/android/tutorial-4-mixed/src/org/opencv/samples/tutorial4/Sample4View.java @@ -70,13 +70,13 @@ class Sample4View extends SampleViewBase { synchronized (this) { // Explicitly deallocate Mats if (mYuv != null) - mYuv.dispose(); + mYuv.release(); if (mRgba != null) - mRgba.dispose(); + mRgba.release(); if (mGraySubmat != null) - mGraySubmat.dispose(); + mGraySubmat.release(); if (mIntermediateMat != null) - mIntermediateMat.dispose(); + mIntermediateMat.release(); mYuv = null; mRgba = null;