mirror of
https://github.com/opencv/opencv.git
synced 2026-07-29 15:23:05 +04:00
java: add converters, tests for MatOfRotatedRect
This commit is contained in:
@@ -17,6 +17,7 @@ import org.opencv.core.Mat;
|
||||
import org.opencv.core.Point;
|
||||
import org.opencv.core.Point3;
|
||||
import org.opencv.core.Rect;
|
||||
import org.opencv.core.RotatedRect;
|
||||
import org.opencv.core.Scalar;
|
||||
import org.opencv.core.Size;
|
||||
import org.opencv.core.DMatch;
|
||||
@@ -336,6 +337,15 @@ public class OpenCVTestCase extends TestCase {
|
||||
assertRectEquals(list1.get(i), list2.get(i));
|
||||
}
|
||||
|
||||
public static void assertListRotatedRectEquals(List<RotatedRect> list1, List<RotatedRect> list2) {
|
||||
if (list1.size() != list2.size()) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
for (int i = 0; i < list1.size(); i++)
|
||||
assertRotatedRectEquals(list1.get(i), list2.get(i));
|
||||
}
|
||||
|
||||
public static void assertRectEquals(Rect expected, Rect actual) {
|
||||
String msg = "expected:<" + expected + "> but was:<" + actual + ">";
|
||||
assertEquals(msg, expected.x, actual.x);
|
||||
@@ -344,6 +354,15 @@ public class OpenCVTestCase extends TestCase {
|
||||
assertEquals(msg, expected.height, actual.height);
|
||||
}
|
||||
|
||||
public static void assertRotatedRectEquals(RotatedRect expected, RotatedRect actual) {
|
||||
String msg = "expected:<" + expected + "> but was:<" + actual + ">";
|
||||
assertEquals(msg, expected.center.x, actual.center.x);
|
||||
assertEquals(msg, expected.center.y, actual.center.y);
|
||||
assertEquals(msg, expected.size.width, actual.size.width);
|
||||
assertEquals(msg, expected.size.height, actual.size.height);
|
||||
assertEquals(msg, expected.angle, actual.angle);
|
||||
}
|
||||
|
||||
public static void assertMatEqual(Mat m1, Mat m2) {
|
||||
compareMats(m1, m2, true);
|
||||
}
|
||||
|
||||
@@ -4,7 +4,9 @@ import org.opencv.core.CvType;
|
||||
import org.opencv.core.Mat;
|
||||
import org.opencv.core.Point;
|
||||
import org.opencv.core.Point3;
|
||||
import org.opencv.core.Size;
|
||||
import org.opencv.core.Rect;
|
||||
import org.opencv.core.RotatedRect;
|
||||
import org.opencv.core.DMatch;
|
||||
import org.opencv.core.KeyPoint;
|
||||
import org.opencv.test.OpenCVTestCase;
|
||||
@@ -222,6 +224,19 @@ public class ConvertersTest extends OpenCVTestCase {
|
||||
assertListRectEquals(truth, rectangles);
|
||||
}
|
||||
|
||||
public void testMat_to_vector_RotatedRect() {
|
||||
Mat src = new Mat(2, 1, CvType.CV_32FC(5));
|
||||
src.put(0, 0, 2, 2, 5, 2, 7,
|
||||
0, 6, 4, 1, 3);
|
||||
List<RotatedRect> rectangles = new ArrayList<RotatedRect>();
|
||||
|
||||
Converters.Mat_to_vector_RotatedRect(src, rectangles);
|
||||
List<RotatedRect> truth = new ArrayList<RotatedRect>();
|
||||
truth.add(new RotatedRect(new Point(2, 2), new Size(5, 2), 7));
|
||||
truth.add(new RotatedRect(new Point(0, 6), new Size(4, 1), 3));
|
||||
assertListRotatedRectEquals(truth, rectangles);
|
||||
}
|
||||
|
||||
public void testMat_to_vector_uchar() {
|
||||
Mat src = new Mat(3, 1, CvType.CV_8UC1);
|
||||
src.put(0, 0, 2, 4, 3);
|
||||
@@ -465,6 +480,19 @@ public class ConvertersTest extends OpenCVTestCase {
|
||||
assertMatEqual(truth, dst);
|
||||
}
|
||||
|
||||
public void testVector_RotatedRect_to_Mat() {
|
||||
List<RotatedRect> rectangles = new ArrayList<RotatedRect>();
|
||||
rectangles.add(new RotatedRect(new Point(2, 2), new Size(5, 2), 7));
|
||||
rectangles.add(new RotatedRect(new Point(0, 0), new Size(6, 4), 3));
|
||||
|
||||
Mat dst = Converters.vector_RotatedRect_to_Mat(rectangles);
|
||||
|
||||
Mat truth = new Mat(2, 1, CvType.CV_32FC(5));
|
||||
truth.put(0, 0, 2, 2, 5, 2, 7,
|
||||
0, 0, 6, 4, 3);
|
||||
assertMatEqual(truth, dst, EPS);
|
||||
}
|
||||
|
||||
public void testVector_uchar_to_Mat() {
|
||||
List<Byte> bytes = new ArrayList<Byte>();
|
||||
byte value1 = 1;
|
||||
@@ -498,5 +526,4 @@ public class ConvertersTest extends OpenCVTestCase {
|
||||
fail("Not yet implemented");
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -20,6 +20,7 @@ import org.opencv.core.Mat;
|
||||
import org.opencv.core.Point;
|
||||
import org.opencv.core.Point3;
|
||||
import org.opencv.core.Rect;
|
||||
import org.opencv.core.RotatedRect;
|
||||
import org.opencv.core.Scalar;
|
||||
import org.opencv.core.Size;
|
||||
import org.opencv.core.DMatch;
|
||||
@@ -362,6 +363,15 @@ public class OpenCVTestCase extends TestCase {
|
||||
assertRectEquals(list1.get(i), list2.get(i));
|
||||
}
|
||||
|
||||
public static void assertListRotatedRectEquals(List<RotatedRect> list1, List<RotatedRect> list2) {
|
||||
if (list1.size() != list2.size()) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
for (int i = 0; i < list1.size(); i++)
|
||||
assertRotatedRectEquals(list1.get(i), list2.get(i));
|
||||
}
|
||||
|
||||
public static void assertRectEquals(Rect expected, Rect actual) {
|
||||
String msg = "expected:<" + expected + "> but was:<" + actual + ">";
|
||||
assertEquals(msg, expected.x, actual.x);
|
||||
@@ -370,6 +380,15 @@ public class OpenCVTestCase extends TestCase {
|
||||
assertEquals(msg, expected.height, actual.height);
|
||||
}
|
||||
|
||||
public static void assertRotatedRectEquals(RotatedRect expected, RotatedRect actual) {
|
||||
String msg = "expected:<" + expected + "> but was:<" + actual + ">";
|
||||
assertEquals(msg, expected.center.x, actual.center.x);
|
||||
assertEquals(msg, expected.center.y, actual.center.y);
|
||||
assertEquals(msg, expected.size.width, actual.size.width);
|
||||
assertEquals(msg, expected.size.height, actual.size.height);
|
||||
assertEquals(msg, expected.angle, actual.angle);
|
||||
}
|
||||
|
||||
public static void assertMatEqual(Mat m1, Mat m2) {
|
||||
compareMats(m1, m2, true);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user