Commit 3d9cb082 authored by Andrey Pavlenko's avatar Andrey Pavlenko

making CV data type to be int

parent 8378ba75
......@@ -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();
}
......
......@@ -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();
......
......@@ -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 + ")";
}
}
......@@ -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
......
......@@ -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;
......
......@@ -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;
......
......@@ -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;
......
......@@ -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;
......
......@@ -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;
......
......@@ -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;
......
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