Commit 25261e6e authored by Andrey Kamaev's avatar Andrey Kamaev

Added new tests written by Hussein Abdinoor; Added support for new classes in…

Added new tests written by Hussein Abdinoor; Added support for new classes in features2d and imgproc
parent d3f8b2ee
...@@ -15,6 +15,7 @@ import org.opencv.core.Core; ...@@ -15,6 +15,7 @@ import org.opencv.core.Core;
import org.opencv.core.CvType; import org.opencv.core.CvType;
import org.opencv.core.Mat; import org.opencv.core.Mat;
import org.opencv.core.Point; import org.opencv.core.Point;
import org.opencv.core.Point3;
import org.opencv.core.Rect; import org.opencv.core.Rect;
import org.opencv.core.Scalar; import org.opencv.core.Scalar;
import org.opencv.features2d.DMatch; import org.opencv.features2d.DMatch;
...@@ -221,6 +222,15 @@ public class OpenCVTestCase extends TestCase { ...@@ -221,6 +222,15 @@ public class OpenCVTestCase extends TestCase {
assertPointEquals(list1.get(i), list2.get(i), epsilon); assertPointEquals(list1.get(i), list2.get(i), epsilon);
} }
public static void assertListPoint3Equals(List<Point3> list1, List<Point3> list2, double epsilon) {
if (list1.size() != list2.size()) {
throw new UnsupportedOperationException();
}
for (int i = 0; i < list1.size(); i++)
assertPoint3Equals(list1.get(i), list2.get(i), epsilon);
}
public static void assertListRectEquals(List<Rect> list1, List<Rect> list2) { public static void assertListRectEquals(List<Rect> list1, List<Rect> list2) {
if (list1.size() != list2.size()) { if (list1.size() != list2.size()) {
throw new UnsupportedOperationException(); throw new UnsupportedOperationException();
...@@ -298,6 +308,13 @@ public class OpenCVTestCase extends TestCase { ...@@ -298,6 +308,13 @@ public class OpenCVTestCase extends TestCase {
assertEquals(msg, expected.y, actual.y, eps); assertEquals(msg, expected.y, actual.y, eps);
} }
public static void assertPoint3Equals(Point3 expected, Point3 actual, double eps) {
String msg = "expected:<" + expected + "> but was:<" + actual + ">";
assertEquals(msg, expected.x, actual.x, eps);
assertEquals(msg, expected.y, actual.y, eps);
assertEquals(msg, expected.z, actual.z, eps);
}
static private void compareMats(Mat expected, Mat actual, boolean isEqualityMeasured) { static private void compareMats(Mat expected, Mat actual, boolean isEqualityMeasured) {
if (expected.type() != actual.type() || expected.cols() != actual.cols() || expected.rows() != actual.rows()) { if (expected.type() != actual.type() || expected.cols() != actual.cols() || expected.rows() != actual.rows()) {
throw new UnsupportedOperationException("Can not compare " + expected + " and " + actual); throw new UnsupportedOperationException("Can not compare " + expected + " and " + actual);
......
package org.opencv.test.features2d; package org.opencv.test.features2d;
import org.opencv.features2d.DMatch;
import junit.framework.TestCase; import junit.framework.TestCase;
public class DMatchTest extends TestCase { public class DMatchTest extends TestCase {
public void testDMatch() { public void testDMatch() {
fail("Not yet implemented"); new DMatch();
} }
public void testDMatchIntIntFloat() { public void testDMatchIntIntFloat() {
fail("Not yet implemented"); DMatch dm1 = new DMatch(1, 4, 4.0f);
assertEquals(1, dm1.queryIdx);
assertEquals(4, dm1.trainIdx);
assertEquals(4.0f, dm1.distance);
} }
public void testDMatchIntIntIntFloat() { public void testDMatchIntIntIntFloat() {
fail("Not yet implemented"); DMatch dm2 = new DMatch(2, 6, -1, 8.0f);
assertEquals(2, dm2.queryIdx);
assertEquals(6, dm2.trainIdx);
assertEquals(-1, dm2.imgIdx);
assertEquals(8.0f, dm2.distance);
} }
public void testLessThan() { public void testLessThan() {
fail("Not yet implemented"); DMatch dm1 = new DMatch(1, 4, 4.0f);
DMatch dm2 = new DMatch(2, 6, -1, 8.0f);
assertTrue(dm1.lessThan(dm2));
} }
public void testToString() { public void testToString() {
fail("Not yet implemented"); DMatch dm2 = new DMatch(2, 6, -1, 8.0f);
String actual = dm2.toString();
String expected = "DMatch [queryIdx=2, trainIdx=6, imgIdx=-1, distance=8.0]";
assertEquals(expected, actual);
} }
} }
package org.opencv.test.features2d; package org.opencv.test.features2d;
import org.opencv.core.Point;
import org.opencv.features2d.KeyPoint; import org.opencv.features2d.KeyPoint;
import org.opencv.test.OpenCVTestCase; import org.opencv.test.OpenCVTestCase;
...@@ -9,6 +10,10 @@ public class KeyPointTest extends OpenCVTestCase { ...@@ -9,6 +10,10 @@ public class KeyPointTest extends OpenCVTestCase {
private float size; private float size;
private float x; private float x;
private float y; private float y;
private float angle;
private float response;
private int octave;
private int classId;
@Override @Override
protected void setUp() throws Exception { protected void setUp() throws Exception {
...@@ -18,88 +23,104 @@ public class KeyPointTest extends OpenCVTestCase { ...@@ -18,88 +23,104 @@ public class KeyPointTest extends OpenCVTestCase {
x = 1.0f; x = 1.0f;
y = 2.0f; y = 2.0f;
size = 3.0f; size = 3.0f;
angle = 30.0f;
response = 2.0f;
octave = 1;
classId = 1;
} }
public void testGet_angle() { public void testGet_angle() {
fail("Not yet implemented"); keyPoint = new KeyPoint(x, y, size, angle);
assertEquals(30.0f, keyPoint.angle);
} }
public void testGet_class_id() { public void testGet_class_id() {
fail("Not yet implemented"); keyPoint = new KeyPoint(x, y, size, angle, response, octave, classId);
assertEquals(1, keyPoint.class_id);
} }
public void testGet_octave() { public void testGet_octave() {
fail("Not yet implemented"); keyPoint = new KeyPoint(x, y, size, angle, response, octave);
assertEquals(1, keyPoint.octave);
} }
public void testGet_pt() { public void testGet_pt() {
fail("Not yet implemented"); keyPoint = new KeyPoint(x, y, size);
assertPointEquals(new Point(1, 2), keyPoint.pt, EPS);
} }
public void testGet_response() { public void testGet_response() {
fail("Not yet implemented"); keyPoint = new KeyPoint(x, y, size, angle, response);
assertEquals(2.0f, keyPoint.response);
} }
public void testGet_size() { public void testGet_size() {
fail("Not yet implemented"); keyPoint = new KeyPoint(x, y, size);
assertEquals(3.0f, keyPoint.size);
} }
public void testKeyPoint() { public void testKeyPoint() {
keyPoint = new KeyPoint(); keyPoint = new KeyPoint();
assertTrue(null != keyPoint);
} }
public void testKeyPointFloatFloatFloat() { public void testKeyPointFloatFloatFloat() {
keyPoint = new KeyPoint(x, y, size); keyPoint = new KeyPoint(x, y, size);
assertTrue(null != keyPoint);
} }
public void testKeyPointFloatFloatFloatFloat() { public void testKeyPointFloatFloatFloatFloat() {
keyPoint = new KeyPoint(x, y, size, 10.0f); keyPoint = new KeyPoint(x, y, size, 10.0f);
assertTrue(null != keyPoint);
} }
public void testKeyPointFloatFloatFloatFloatFloat() { public void testKeyPointFloatFloatFloatFloatFloat() {
keyPoint = new KeyPoint(x, y, size, 1.0f, 1.0f); keyPoint = new KeyPoint(x, y, size, 1.0f, 1.0f);
assertTrue(null != keyPoint);
} }
public void testKeyPointFloatFloatFloatFloatFloatInt() { public void testKeyPointFloatFloatFloatFloatFloatInt() {
keyPoint = new KeyPoint(x, y, size, 1.0f, 1.0f, 1); keyPoint = new KeyPoint(x, y, size, 1.0f, 1.0f, 1);
assertTrue(null != keyPoint);
} }
public void testKeyPointFloatFloatFloatFloatFloatIntInt() { public void testKeyPointFloatFloatFloatFloatFloatIntInt() {
keyPoint = new KeyPoint(x, y, size, 1.0f, 1.0f, 1, 1); keyPoint = new KeyPoint(x, y, size, 1.0f, 1.0f, 1, 1);
assertTrue(null != keyPoint);
} }
public void testSet_angle() { public void testSet_angle() {
fail("Not yet implemented"); keyPoint = new KeyPoint(x, y, size, angle);
keyPoint.angle = 10f;
} }
public void testSet_class_id() { public void testSet_class_id() {
fail("Not yet implemented"); keyPoint = new KeyPoint(x, y, size, angle, response, octave, classId);
keyPoint.class_id = 2;
} }
public void testSet_octave() { public void testSet_octave() {
fail("Not yet implemented"); keyPoint = new KeyPoint(x, y, size, angle, response, octave);
keyPoint.octave = 0;
} }
public void testSet_pt() { public void testSet_pt() {
fail("Not yet implemented"); keyPoint = new KeyPoint(x, y, size);
keyPoint.pt = new Point(4, 3);
assertPointEquals(new Point(4, 3), keyPoint.pt, EPS);
} }
public void testSet_response() { public void testSet_response() {
fail("Not yet implemented"); keyPoint = new KeyPoint(x, y, size, angle, response);
keyPoint.response = 1.5f;
} }
public void testSet_size() { public void testSet_size() {
fail("Not yet implemented"); keyPoint = new KeyPoint(x, y, size);
keyPoint.size = 5.0f;
} }
public void testToString() { public void testToString() {
fail("Not yet implemented"); keyPoint = new KeyPoint(x, y, size, angle, response, octave, classId);
String actual = keyPoint.toString();
String expected = "KeyPoint [pt={1.0, 2.0}, size=3.0, angle=30.0, response=2.0, octave=1, class_id=1]";
assertEquals(expected, actual);
} }
} }
package org.opencv.test.video; package org.opencv.test.video;
import org.opencv.core.Core;
import org.opencv.core.CvType;
import org.opencv.core.Mat;
import org.opencv.core.Point;
import org.opencv.core.Scalar;
import org.opencv.highgui.Highgui;
import org.opencv.test.OpenCVTestCase; import org.opencv.test.OpenCVTestCase;
import org.opencv.video.BackgroundSubtractorMOG;
public class BackgroundSubtractorMOGTest extends OpenCVTestCase { public class BackgroundSubtractorMOGTest extends OpenCVTestCase {
public void testApplyMatMat() { public void testApplyMatMat() {
fail("Not yet implemented"); fail("Not yet implemented");
BackgroundSubtractorMOG backGroundSubtract = new BackgroundSubtractorMOG();
Point bottomRight = new Point(rgbLena.cols() / 2, rgbLena.rows() / 2);
Point topLeft = new Point(0, 0);
Scalar color = new Scalar(128);
Mat mask = new Mat(rgbLena.size(), CvType.CV_16UC3, new Scalar(1));
Core.rectangle(rgbLena, bottomRight, topLeft, color, Core.FILLED);
backGroundSubtract.apply(rgbLena, mask);
Mat truth = new Mat(rgbLena.size(), rgbLena.type(), new Scalar(0));
Core.rectangle(truth, bottomRight, topLeft, color, Core.FILLED);
// OpenCVTestRunner.Log(dst.dump());
// OpenCVTestRunner.Log(rgbLena.dump());
Highgui.imwrite("/mnt/sdcard/lena1.png", rgbLena);
assertMatEqual(truth, rgbLena);
} }
public void testApplyMatMatDouble() { public void testApplyMatMatDouble() {
......
...@@ -65,7 +65,7 @@ class JavaParser: ...@@ -65,7 +65,7 @@ class JavaParser:
if os.path.isfile(path): if os.path.isfile(path):
if path.endswith("FeatureDetector.java"): if path.endswith("FeatureDetector.java"):
for prefix1 in ("", "Grid", "Pyramid", "Dynamic"): for prefix1 in ("", "Grid", "Pyramid", "Dynamic"):
for prefix2 in ("FAST", "STAR", "MSER", "ORB", "SIFT", "SURF", "GFTT", "HARRIS"): for prefix2 in ("FAST", "STAR", "MSER", "ORB", "SIFT", "SURF", "GFTT", "HARRIS", "SIMPLEBLOB", "DENSE"):
parser.parse_file(path,prefix1+prefix2) parser.parse_file(path,prefix1+prefix2)
elif path.endswith("DescriptorExtractor.java"): elif path.endswith("DescriptorExtractor.java"):
for prefix1 in ("", "Opponent"): for prefix1 in ("", "Opponent"):
......
...@@ -206,11 +206,14 @@ type_dict = { ...@@ -206,11 +206,14 @@ type_dict = {
"vector_int" : { "j_type" : "List<Integer>", "jn_type" : "long", "jni_type" : "jlong", "jni_var" : "vector<int> %(n)s", "suffix" : "J" }, "vector_int" : { "j_type" : "List<Integer>", "jn_type" : "long", "jni_type" : "jlong", "jni_var" : "vector<int> %(n)s", "suffix" : "J" },
"vector_float" : { "j_type" : "List<Float>", "jn_type" : "long", "jni_type" : "jlong", "jni_var" : "vector<float> %(n)s", "suffix" : "J" }, "vector_float" : { "j_type" : "List<Float>", "jn_type" : "long", "jni_type" : "jlong", "jni_var" : "vector<float> %(n)s", "suffix" : "J" },
"vector_double" : { "j_type" : "List<Double>", "jn_type" : "long", "jni_type" : "jlong", "jni_var" : "vector<double> %(n)s", "suffix" : "J" }, "vector_double" : { "j_type" : "List<Double>", "jn_type" : "long", "jni_type" : "jlong", "jni_var" : "vector<double> %(n)s", "suffix" : "J" },
"vector_Vec4f" : { "j_type" : "Mat", "jn_type" : "long", "jni_type" : "jlong", "jni_var" : "vector<Vec4f> %(n)s", "suffix" : "J" },
"vector_Vec6f" : { "j_type" : "Mat", "jn_type" : "long", "jni_type" : "jlong", "jni_var" : "vector<Vec6f> %(n)s", "suffix" : "J" },
"vector_vector_KeyPoint": { "j_type" : "List<List<KeyPoint>>", "jn_type" : "long", "jni_type" : "jlong", "jni_var" : "vector< vector<KeyPoint> > %(n)s" }, "vector_vector_KeyPoint": { "j_type" : "List<List<KeyPoint>>", "jn_type" : "long", "jni_type" : "jlong", "jni_var" : "vector< vector<KeyPoint> > %(n)s" },
"vector_vector_DMatch" : { "j_type" : "List<List<DMatch>>", "jn_type" : "long", "jni_type" : "jlong", "jni_var" : "vector< vector<DMatch> > %(n)s" }, "vector_vector_DMatch" : { "j_type" : "List<List<DMatch>>", "jn_type" : "long", "jni_type" : "jlong", "jni_var" : "vector< vector<DMatch> > %(n)s" },
"vector_vector_char" : { "j_type" : "List<List<Byte>>", "jn_type" : "long", "jni_type" : "jlong", "jni_var" : "vector< vector<char> > %(n)s" }, "vector_vector_char" : { "j_type" : "List<List<Byte>>", "jn_type" : "long", "jni_type" : "jlong", "jni_var" : "vector< vector<char> > %(n)s" },
"vector_vector_Point" : { "j_type" : "List<List<Point>>", "jn_type" : "long", "jni_type" : "jlong", "jni_var" : "vector< vector<Point> > %(n)s" }, "vector_vector_Point" : { "j_type" : "List<List<Point>>", "jn_type" : "long", "jni_type" : "jlong", "jni_var" : "vector< vector<Point> > %(n)s" },
"vector_vector_Point2f" : { "j_type" : "List<List<Point>>", "jn_type" : "long", "jni_type" : "jlong", "jni_var" : "vector< vector<Point2f> > %(n)s" },
"Mat" : { "j_type" : "Mat", "jn_type" : "long", "jn_args" : (("__int64", ".nativeObj"),), "Mat" : { "j_type" : "Mat", "jn_type" : "long", "jn_args" : (("__int64", ".nativeObj"),),
"jni_var" : "Mat& %(n)s = *((Mat*)%(n)s_nativeObj)", "jni_var" : "Mat& %(n)s = *((Mat*)%(n)s_nativeObj)",
...@@ -1139,6 +1142,7 @@ extern "C" { ...@@ -1139,6 +1142,7 @@ extern "C" {
else: else:
j_prologue.append( "Mat %s_mat = new Mat();" % a.name ) j_prologue.append( "Mat %s_mat = new Mat();" % a.name )
if "O" in a.out: if "O" in a.out:
if type_dict[a.ctype]["j_type"] != "Mat":
j_epilogue.append("Converters.Mat_to_%(t)s(%(n)s_mat, %(n)s);" % {"t" : a.ctype, "n" : a.name}) j_epilogue.append("Converters.Mat_to_%(t)s(%(n)s_mat, %(n)s);" % {"t" : a.ctype, "n" : a.name})
c_epilogue.append( "%(t)s_to_Mat( %(n)s, %(n)s_mat );" % {"n" : a.name, "t" : a.ctype} ) c_epilogue.append( "%(t)s_to_Mat( %(n)s, %(n)s_mat );" % {"n" : a.name, "t" : a.ctype} )
else: else:
......
...@@ -354,3 +354,26 @@ void vector_vector_char_to_Mat(vector< vector< char > >& vv_ch, Mat& mat) ...@@ -354,3 +354,26 @@ void vector_vector_char_to_Mat(vector< vector< char > >& vv_ch, Mat& mat)
} }
vector_Mat_to_Mat(vm, mat); vector_Mat_to_Mat(vm, mat);
} }
void vector_vector_Point2f_to_Mat(vector< vector< Point2f > >& vv_pt, Mat& mat)
{
vector<Mat> vm;
vm.reserve( vv_pt.size() );
for(size_t i=0; i<vv_pt.size(); i++)
{
Mat m;
vector_Point2f_to_Mat(vv_pt[i], m);
vm.push_back(m);
}
vector_Mat_to_Mat(vm, mat);
}
void vector_Vec4f_to_Mat(vector<Vec4f>& v_vec, Mat& mat)
{
mat = Mat(v_vec, true);
}
void vector_Vec6f_to_Mat(vector<Vec6f>& v_vec, Mat& mat)
{
mat = Mat(v_vec, true);
}
...@@ -38,6 +38,9 @@ void vector_Point3i_to_Mat(std::vector<cv::Point3i>& v_point, cv::Mat& mat); ...@@ -38,6 +38,9 @@ void vector_Point3i_to_Mat(std::vector<cv::Point3i>& v_point, cv::Mat& mat);
void vector_Point3f_to_Mat(std::vector<cv::Point3f>& v_point, cv::Mat& mat); void vector_Point3f_to_Mat(std::vector<cv::Point3f>& v_point, cv::Mat& mat);
void vector_Point3d_to_Mat(std::vector<cv::Point3d>& v_point, cv::Mat& mat); void vector_Point3d_to_Mat(std::vector<cv::Point3d>& v_point, cv::Mat& mat);
void vector_Vec4f_to_Mat(std::vector<cv::Vec4f>& v_vec, cv::Mat& mat);
void vector_Vec6f_to_Mat(std::vector<cv::Vec6f>& v_vec, cv::Mat& mat);
void Mat_to_vector_KeyPoint(cv::Mat& mat, std::vector<cv::KeyPoint>& v_kp); void Mat_to_vector_KeyPoint(cv::Mat& mat, std::vector<cv::KeyPoint>& v_kp);
void vector_KeyPoint_to_Mat(std::vector<cv::KeyPoint>& v_kp, cv::Mat& mat); void vector_KeyPoint_to_Mat(std::vector<cv::KeyPoint>& v_kp, cv::Mat& mat);
...@@ -57,3 +60,5 @@ void Mat_to_vector_vector_char(cv::Mat& mat, std::vector< std::vector< char > >& ...@@ -57,3 +60,5 @@ void Mat_to_vector_vector_char(cv::Mat& mat, std::vector< std::vector< char > >&
void vector_vector_char_to_Mat(std::vector< std::vector< char > >& vv_ch, cv::Mat& mat); void vector_vector_char_to_Mat(std::vector< std::vector< char > >& vv_ch, cv::Mat& mat);
void Mat_to_vector_vector_Point(cv::Mat& mat, std::vector< std::vector< cv::Point > >& vv_pt); void Mat_to_vector_vector_Point(cv::Mat& mat, std::vector< std::vector< cv::Point > >& vv_pt);
void vector_vector_Point2f_to_Mat(std::vector< std::vector< cv::Point2f > >& vv_pt, cv::Mat& mat);
...@@ -25,6 +25,8 @@ public: ...@@ -25,6 +25,8 @@ public:
MSER = 6, MSER = 6,
GFTT = 7, GFTT = 7,
HARRIS = 8, HARRIS = 8,
SIMPLEBLOB = 9,
DENSE = 10,
GRIDRETECTOR = 1000, GRIDRETECTOR = 1000,
...@@ -37,6 +39,8 @@ public: ...@@ -37,6 +39,8 @@ public:
GRID_MSER = GRIDRETECTOR + MSER, GRID_MSER = GRIDRETECTOR + MSER,
GRID_GFTT = GRIDRETECTOR + GFTT, GRID_GFTT = GRIDRETECTOR + GFTT,
GRID_HARRIS = GRIDRETECTOR + HARRIS, GRID_HARRIS = GRIDRETECTOR + HARRIS,
GRID_SIMPLEBLOB = GRIDRETECTOR + SIMPLEBLOB,
GRID_DENSE = GRIDRETECTOR + DENSE,
PYRAMIDDETECTOR = 2000, PYRAMIDDETECTOR = 2000,
...@@ -49,6 +53,8 @@ public: ...@@ -49,6 +53,8 @@ public:
PYRAMID_MSER = PYRAMIDDETECTOR + MSER, PYRAMID_MSER = PYRAMIDDETECTOR + MSER,
PYRAMID_GFTT = PYRAMIDDETECTOR + GFTT, PYRAMID_GFTT = PYRAMIDDETECTOR + GFTT,
PYRAMID_HARRIS = PYRAMIDDETECTOR + HARRIS, PYRAMID_HARRIS = PYRAMIDDETECTOR + HARRIS,
PYRAMID_SIMPLEBLOB = PYRAMIDDETECTOR + SIMPLEBLOB,
PYRAMID_DENSE = PYRAMIDDETECTOR + DENSE,
DYNAMICDETECTOR = 3000, DYNAMICDETECTOR = 3000,
...@@ -59,7 +65,9 @@ public: ...@@ -59,7 +65,9 @@ public:
DYNAMIC_ORB = DYNAMICDETECTOR + ORB, DYNAMIC_ORB = DYNAMICDETECTOR + ORB,
DYNAMIC_MSER = DYNAMICDETECTOR + MSER, DYNAMIC_MSER = DYNAMICDETECTOR + MSER,
DYNAMIC_GFTT = DYNAMICDETECTOR + GFTT, DYNAMIC_GFTT = DYNAMICDETECTOR + GFTT,
DYNAMIC_HARRIS = DYNAMICDETECTOR + HARRIS DYNAMIC_HARRIS = DYNAMICDETECTOR + HARRIS,
DYNAMIC_SIMPLEBLOB = DYNAMICDETECTOR + SIMPLEBLOB,
DYNAMIC_DENSE = DYNAMICDETECTOR + DENSE
}; };
//supported: FAST STAR SIFT SURF ORB MSER GFTT HARRIS Grid(XXXX) Pyramid(XXXX) Dynamic(XXXX) //supported: FAST STAR SIFT SURF ORB MSER GFTT HARRIS Grid(XXXX) Pyramid(XXXX) Dynamic(XXXX)
...@@ -109,6 +117,12 @@ public: ...@@ -109,6 +117,12 @@ public:
case HARRIS: case HARRIS:
name += "HARRIS"; name += "HARRIS";
break; break;
case SIMPLEBLOB:
name += "SimpleBlob";
break;
case DENSE:
name += "Dense";
break;
default: default:
CV_Error( CV_StsBadArg, "Specified feature detector type is not supported." ); CV_Error( CV_StsBadArg, "Specified feature detector type is not supported." );
break; break;
......
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