Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Tetragramm
GitHub Repository: Tetragramm/opencv
Path: blob/master/modules/core/misc/java/test/MatOfByteTest.java
16354 views
1
package org.opencv.test.core;
2
3
import java.util.Arrays;
4
5
import org.opencv.core.Core;
6
import org.opencv.core.CvException;
7
import org.opencv.core.CvType;
8
import org.opencv.core.Mat;
9
import org.opencv.core.MatOfByte;
10
import org.opencv.core.MatOfDouble;
11
import org.opencv.test.OpenCVTestCase;
12
import org.opencv.imgcodecs.Imgcodecs;
13
14
public class MatOfByteTest extends OpenCVTestCase {
15
16
public void testMatOfSubByteArray() {
17
byte[] inputBytes = { 1,2,3,4,5 };
18
19
MatOfByte m0 = new MatOfByte(inputBytes);
20
MatOfByte m1 = new MatOfByte(0, inputBytes.length, inputBytes);
21
MatOfByte m2 = new MatOfByte(1, inputBytes.length - 2, inputBytes);
22
23
assertEquals(5.0, m0.size().height);
24
assertEquals(1.0, m0.size().width);
25
26
assertEquals(m0.get(0, 0)[0], m1.get(0, 0)[0]);
27
assertEquals(m0.get((int) m0.size().height - 1, 0)[0], m1.get((int) m1.size().height - 1, 0)[0]);
28
29
assertEquals(3.0, m2.size().height);
30
assertEquals(1.0, m2.size().width);
31
32
assertEquals(2.0, m2.get(0, 0)[0]);
33
assertEquals(3.0, m2.get(1, 0)[0]);
34
assertEquals(4.0, m2.get(2, 0)[0]);
35
}
36
37
38
public void testMatOfSubByteArray_BadArg() {
39
byte[] inputBytes = { 1,2,3,4,5 };
40
41
try {
42
MatOfByte m1 = new MatOfByte(-1, inputBytes.length, inputBytes);
43
fail("Missing check: offset < 0");
44
} catch (IllegalArgumentException e) {
45
// pass
46
}
47
48
try {
49
MatOfByte m1 = new MatOfByte(0, inputBytes.length, null);
50
fail("Missing check: NullPointerException");
51
} catch (NullPointerException e) {
52
// pass
53
}
54
55
try {
56
MatOfByte m1 = new MatOfByte(0, -1, inputBytes);
57
fail("Missing check: length < 0");
58
} catch (IllegalArgumentException e) {
59
// pass
60
}
61
62
try {
63
MatOfByte m1 = new MatOfByte(1, inputBytes.length, inputBytes);
64
fail("Missing check: buffer bounds");
65
} catch (IllegalArgumentException e) {
66
// pass
67
}
68
}
69
70
}
71
72