Java API: (per code review) adding check (data.length % CvType.channels(t) != 0) for Mat:: put/get, adding 2 tests for them
Testing: 1176/4/580
This commit is contained in:
parent
3f22bd6dff
commit
024482adac
@ -98,7 +98,16 @@ public class MatTest extends OpenCVTestCase {
|
||||
}
|
||||
|
||||
public void testGetIntIntByteArray() {
|
||||
fail("Not yet implemented");
|
||||
Mat m = new Mat(5, 5, CvType.CV_8UC3, new Scalar(1, 2, 3));
|
||||
byte[] goodData = new byte[9];
|
||||
byte[] badData = new byte[7];
|
||||
m.get(1, 1, goodData);
|
||||
try {
|
||||
m.get(2, 2, badData);
|
||||
fail("Expected UnsupportedOperationException (data.length % CvType.channels(t) != 0)");
|
||||
} catch (UnsupportedOperationException e) {
|
||||
// expected
|
||||
}
|
||||
}
|
||||
|
||||
public void testGetIntIntDoubleArray() {
|
||||
@ -192,7 +201,14 @@ public class MatTest extends OpenCVTestCase {
|
||||
}
|
||||
|
||||
public void testPutIntIntDoubleArray() {
|
||||
fail("Not yet implemented");
|
||||
Mat m = new Mat(5, 5, CvType.CV_8UC3);
|
||||
m.put(1, 1, 10, 20, 30, 40, 50, 60);
|
||||
try {
|
||||
m.put(2, 2, 11, 22, 33, 44, 55);
|
||||
fail("Expected UnsupportedOperationException (data.length % CvType.channels(t) != 0)");
|
||||
} catch (UnsupportedOperationException e) {
|
||||
// expected
|
||||
}
|
||||
}
|
||||
|
||||
public void testPutIntIntFloatArray() {
|
||||
|
@ -957,12 +957,25 @@ public class Mat {
|
||||
|
||||
//javadoc:Mat::put(row,col,data)
|
||||
public int put(int row, int col, double...data) {
|
||||
int t = type();
|
||||
if(data == null || data.length % CvType.channels(t) != 0)
|
||||
throw new java.lang.UnsupportedOperationException(
|
||||
"Provided data element number (" +
|
||||
(data == null ? 0 : data.length) +
|
||||
") should be multiple of the Mat channels count (" +
|
||||
CvType.channels(t) + ")");
|
||||
return nPutD(nativeObj, row, col, data.length, data);
|
||||
}
|
||||
|
||||
//javadoc:Mat::put(row,col,data)
|
||||
public int put(int row, int col, float[] data) {
|
||||
int t = type();
|
||||
if(data == null || data.length % CvType.channels(t) != 0)
|
||||
throw new java.lang.UnsupportedOperationException(
|
||||
"Provided data element number (" +
|
||||
(data == null ? 0 : data.length) +
|
||||
") should be multiple of the Mat channels count (" +
|
||||
CvType.channels(t) + ")");
|
||||
if(CvType.depth(t) == CvType.CV_32F) {
|
||||
return nPutF(nativeObj, row, col, data.length, data);
|
||||
}
|
||||
@ -972,6 +985,12 @@ public class Mat {
|
||||
//javadoc:Mat::put(row,col,data)
|
||||
public int put(int row, int col, int[] data) {
|
||||
int t = type();
|
||||
if(data == null || data.length % CvType.channels(t) != 0)
|
||||
throw new java.lang.UnsupportedOperationException(
|
||||
"Provided data element number (" +
|
||||
(data == null ? 0 : data.length) +
|
||||
") should be multiple of the Mat channels count (" +
|
||||
CvType.channels(t) + ")");
|
||||
if(CvType.depth(t) == CvType.CV_32S) {
|
||||
return nPutI(nativeObj, row, col, data.length, data);
|
||||
}
|
||||
@ -981,6 +1000,12 @@ public class Mat {
|
||||
//javadoc:Mat::put(row,col,data)
|
||||
public int put(int row, int col, short[] data) {
|
||||
int t = type();
|
||||
if(data == null || data.length % CvType.channels(t) != 0)
|
||||
throw new java.lang.UnsupportedOperationException(
|
||||
"Provided data element number (" +
|
||||
(data == null ? 0 : data.length) +
|
||||
") should be multiple of the Mat channels count (" +
|
||||
CvType.channels(t) + ")");
|
||||
if(CvType.depth(t) == CvType.CV_16U || CvType.depth(t) == CvType.CV_16S) {
|
||||
return nPutS(nativeObj, row, col, data.length, data);
|
||||
}
|
||||
@ -990,6 +1015,12 @@ public class Mat {
|
||||
//javadoc:Mat::put(row,col,data)
|
||||
public int put(int row, int col, byte[] data) {
|
||||
int t = type();
|
||||
if(data == null || data.length % CvType.channels(t) != 0)
|
||||
throw new java.lang.UnsupportedOperationException(
|
||||
"Provided data element number (" +
|
||||
(data == null ? 0 : data.length) +
|
||||
") should be multiple of the Mat channels count (" +
|
||||
CvType.channels(t) + ")");
|
||||
if(CvType.depth(t) == CvType.CV_8U || CvType.depth(t) == CvType.CV_8S) {
|
||||
return nPutB(nativeObj, row, col, data.length, data);
|
||||
}
|
||||
@ -999,6 +1030,12 @@ public class Mat {
|
||||
//javadoc:Mat::get(row,col,data)
|
||||
public int get(int row, int col, byte[] data) {
|
||||
int t = type();
|
||||
if(data == null || data.length % CvType.channels(t) != 0)
|
||||
throw new java.lang.UnsupportedOperationException(
|
||||
"Provided data element number (" +
|
||||
(data == null ? 0 : data.length) +
|
||||
") should be multiple of the Mat channels count (" +
|
||||
CvType.channels(t) + ")");
|
||||
if(CvType.depth(t) == CvType.CV_8U || CvType.depth(t) == CvType.CV_8S) {
|
||||
return nGetB(nativeObj, row, col, data.length, data);
|
||||
}
|
||||
@ -1008,6 +1045,12 @@ public class Mat {
|
||||
//javadoc:Mat::get(row,col,data)
|
||||
public int get(int row, int col, short[] data) {
|
||||
int t = type();
|
||||
if(data == null || data.length % CvType.channels(t) != 0)
|
||||
throw new java.lang.UnsupportedOperationException(
|
||||
"Provided data element number (" +
|
||||
(data == null ? 0 : data.length) +
|
||||
") should be multiple of the Mat channels count (" +
|
||||
CvType.channels(t) + ")");
|
||||
if(CvType.depth(t) == CvType.CV_16U || CvType.depth(t) == CvType.CV_16S) {
|
||||
return nGetS(nativeObj, row, col, data.length, data);
|
||||
}
|
||||
@ -1017,6 +1060,12 @@ public class Mat {
|
||||
//javadoc:Mat::get(row,col,data)
|
||||
public int get(int row, int col, int[] data) {
|
||||
int t = type();
|
||||
if(data == null || data.length % CvType.channels(t) != 0)
|
||||
throw new java.lang.UnsupportedOperationException(
|
||||
"Provided data element number (" +
|
||||
(data == null ? 0 : data.length) +
|
||||
") should be multiple of the Mat channels count (" +
|
||||
CvType.channels(t) + ")");
|
||||
if(CvType.depth(t) == CvType.CV_32S) {
|
||||
return nGetI(nativeObj, row, col, data.length, data);
|
||||
}
|
||||
@ -1026,6 +1075,12 @@ public class Mat {
|
||||
//javadoc:Mat::get(row,col,data)
|
||||
public int get(int row, int col, float[] data) {
|
||||
int t = type();
|
||||
if(data == null || data.length % CvType.channels(t) != 0)
|
||||
throw new java.lang.UnsupportedOperationException(
|
||||
"Provided data element number (" +
|
||||
(data == null ? 0 : data.length) +
|
||||
") should be multiple of the Mat channels count (" +
|
||||
CvType.channels(t) + ")");
|
||||
if(CvType.depth(t) == CvType.CV_32F) {
|
||||
return nGetF(nativeObj, row, col, data.length, data);
|
||||
}
|
||||
@ -1035,6 +1090,12 @@ public class Mat {
|
||||
//javadoc:Mat::get(row,col,data)
|
||||
public int get(int row, int col, double[] data) {
|
||||
int t = type();
|
||||
if(data == null || data.length % CvType.channels(t) != 0)
|
||||
throw new java.lang.UnsupportedOperationException(
|
||||
"Provided data element number (" +
|
||||
(data == null ? 0 : data.length) +
|
||||
") should be multiple of the Mat channels count (" +
|
||||
CvType.channels(t) + ")");
|
||||
if(CvType.depth(t) == CvType.CV_64F) {
|
||||
return nGetD(nativeObj, row, col, data.length, data);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user