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;
import org.opencv.core.CvType;
import org.opencv.core.Mat;
import org.opencv.core.Point;
import org.opencv.core.Point3;
import org.opencv.core.Rect;
import org.opencv.core.Scalar;
import org.opencv.features2d.DMatch;
......@@ -221,6 +222,15 @@ public class OpenCVTestCase extends TestCase {
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) {
if (list1.size() != list2.size()) {
throw new UnsupportedOperationException();
......@@ -297,6 +307,13 @@ public class OpenCVTestCase extends TestCase {
assertEquals(msg, expected.x, actual.x, 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) {
if (expected.type() != actual.type() || expected.cols() != actual.cols() || expected.rows() != actual.rows()) {
......
package org.opencv.test.features2d;
import org.opencv.features2d.DMatch;
import junit.framework.TestCase;
public class DMatchTest extends TestCase {
public void testDMatch() {
fail("Not yet implemented");
new DMatch();
}
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() {
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() {
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() {
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;
import org.opencv.core.Point;
import org.opencv.features2d.KeyPoint;
import org.opencv.test.OpenCVTestCase;
......@@ -9,6 +10,10 @@ public class KeyPointTest extends OpenCVTestCase {
private float size;
private float x;
private float y;
private float angle;
private float response;
private int octave;
private int classId;
@Override
protected void setUp() throws Exception {
......@@ -18,88 +23,104 @@ public class KeyPointTest extends OpenCVTestCase {
x = 1.0f;
y = 2.0f;
size = 3.0f;
angle = 30.0f;
response = 2.0f;
octave = 1;
classId = 1;
}
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() {
fail("Not yet implemented");
keyPoint = new KeyPoint(x, y, size, angle, response, octave, classId);
assertEquals(1, keyPoint.class_id);
}
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() {
fail("Not yet implemented");
keyPoint = new KeyPoint(x, y, size);
assertPointEquals(new Point(1, 2), keyPoint.pt, EPS);
}
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() {
fail("Not yet implemented");
keyPoint = new KeyPoint(x, y, size);
assertEquals(3.0f, keyPoint.size);
}
public void testKeyPoint() {
keyPoint = new KeyPoint();
assertTrue(null != keyPoint);
}
public void testKeyPointFloatFloatFloat() {
keyPoint = new KeyPoint(x, y, size);
assertTrue(null != keyPoint);
}
public void testKeyPointFloatFloatFloatFloat() {
keyPoint = new KeyPoint(x, y, size, 10.0f);
assertTrue(null != keyPoint);
}
public void testKeyPointFloatFloatFloatFloatFloat() {
keyPoint = new KeyPoint(x, y, size, 1.0f, 1.0f);
assertTrue(null != keyPoint);
}
public void testKeyPointFloatFloatFloatFloatFloatInt() {
keyPoint = new KeyPoint(x, y, size, 1.0f, 1.0f, 1);
assertTrue(null != keyPoint);
}
public void testKeyPointFloatFloatFloatFloatFloatIntInt() {
keyPoint = new KeyPoint(x, y, size, 1.0f, 1.0f, 1, 1);
assertTrue(null != keyPoint);
}
public void testSet_angle() {
fail("Not yet implemented");
keyPoint = new KeyPoint(x, y, size, angle);
keyPoint.angle = 10f;
}
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() {
fail("Not yet implemented");
keyPoint = new KeyPoint(x, y, size, angle, response, octave);
keyPoint.octave = 0;
}
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() {
fail("Not yet implemented");
keyPoint = new KeyPoint(x, y, size, angle, response);
keyPoint.response = 1.5f;
}
public void testSet_size() {
fail("Not yet implemented");
keyPoint = new KeyPoint(x, y, size);
keyPoint.size = 5.0f;
}
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;
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.video.BackgroundSubtractorMOG;
public class BackgroundSubtractorMOGTest extends OpenCVTestCase {
public void testApplyMatMat() {
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() {
......
......@@ -65,7 +65,7 @@ class JavaParser:
if os.path.isfile(path):
if path.endswith("FeatureDetector.java"):
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)
elif path.endswith("DescriptorExtractor.java"):
for prefix1 in ("", "Opponent"):
......
......@@ -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_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_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_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_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"),),
"jni_var" : "Mat& %(n)s = *((Mat*)%(n)s_nativeObj)",
......@@ -1139,7 +1142,8 @@ extern "C" {
else:
j_prologue.append( "Mat %s_mat = new Mat();" % a.name )
if "O" in a.out:
j_epilogue.append("Converters.Mat_to_%(t)s(%(n)s_mat, %(n)s);" % {"t" : a.ctype, "n" : a.name})
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})
c_epilogue.append( "%(t)s_to_Mat( %(n)s, %(n)s_mat );" % {"n" : a.name, "t" : a.ctype} )
else:
fields = type_dict[a.ctype].get("jn_args", ((a.ctype, ""),))
......
......@@ -354,3 +354,26 @@ void vector_vector_char_to_Mat(vector< vector< char > >& vv_ch, Mat& 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);
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_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 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 > >&
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 vector_vector_Point2f_to_Mat(std::vector< std::vector< cv::Point2f > >& vv_pt, cv::Mat& mat);
......@@ -25,41 +25,49 @@ public:
MSER = 6,
GFTT = 7,
HARRIS = 8,
SIMPLEBLOB = 9,
DENSE = 10,
GRIDRETECTOR = 1000,
GRID_FAST = GRIDRETECTOR + FAST,
GRID_STAR = GRIDRETECTOR + STAR,
GRID_SIFT = GRIDRETECTOR + SIFT,
GRID_SURF = GRIDRETECTOR + SURF,
GRID_ORB = GRIDRETECTOR + ORB,
GRID_MSER = GRIDRETECTOR + MSER,
GRID_GFTT = GRIDRETECTOR + GFTT,
GRID_HARRIS = GRIDRETECTOR + HARRIS,
GRID_FAST = GRIDRETECTOR + FAST,
GRID_STAR = GRIDRETECTOR + STAR,
GRID_SIFT = GRIDRETECTOR + SIFT,
GRID_SURF = GRIDRETECTOR + SURF,
GRID_ORB = GRIDRETECTOR + ORB,
GRID_MSER = GRIDRETECTOR + MSER,
GRID_GFTT = GRIDRETECTOR + GFTT,
GRID_HARRIS = GRIDRETECTOR + HARRIS,
GRID_SIMPLEBLOB = GRIDRETECTOR + SIMPLEBLOB,
GRID_DENSE = GRIDRETECTOR + DENSE,
PYRAMIDDETECTOR = 2000,
PYRAMID_FAST = PYRAMIDDETECTOR + FAST,
PYRAMID_STAR = PYRAMIDDETECTOR + STAR,
PYRAMID_SIFT = PYRAMIDDETECTOR + SIFT,
PYRAMID_SURF = PYRAMIDDETECTOR + SURF,
PYRAMID_ORB = PYRAMIDDETECTOR + ORB,
PYRAMID_MSER = PYRAMIDDETECTOR + MSER,
PYRAMID_GFTT = PYRAMIDDETECTOR + GFTT,
PYRAMID_HARRIS = PYRAMIDDETECTOR + HARRIS,
PYRAMID_FAST = PYRAMIDDETECTOR + FAST,
PYRAMID_STAR = PYRAMIDDETECTOR + STAR,
PYRAMID_SIFT = PYRAMIDDETECTOR + SIFT,
PYRAMID_SURF = PYRAMIDDETECTOR + SURF,
PYRAMID_ORB = PYRAMIDDETECTOR + ORB,
PYRAMID_MSER = PYRAMIDDETECTOR + MSER,
PYRAMID_GFTT = PYRAMIDDETECTOR + GFTT,
PYRAMID_HARRIS = PYRAMIDDETECTOR + HARRIS,
PYRAMID_SIMPLEBLOB = PYRAMIDDETECTOR + SIMPLEBLOB,
PYRAMID_DENSE = PYRAMIDDETECTOR + DENSE,
DYNAMICDETECTOR = 3000,
DYNAMIC_FAST = DYNAMICDETECTOR + FAST,
DYNAMIC_STAR = DYNAMICDETECTOR + STAR,
DYNAMIC_SIFT = DYNAMICDETECTOR + SIFT,
DYNAMIC_SURF = DYNAMICDETECTOR + SURF,
DYNAMIC_ORB = DYNAMICDETECTOR + ORB,
DYNAMIC_MSER = DYNAMICDETECTOR + MSER,
DYNAMIC_GFTT = DYNAMICDETECTOR + GFTT,
DYNAMIC_HARRIS = DYNAMICDETECTOR + HARRIS
DYNAMIC_FAST = DYNAMICDETECTOR + FAST,
DYNAMIC_STAR = DYNAMICDETECTOR + STAR,
DYNAMIC_SIFT = DYNAMICDETECTOR + SIFT,
DYNAMIC_SURF = DYNAMICDETECTOR + SURF,
DYNAMIC_ORB = DYNAMICDETECTOR + ORB,
DYNAMIC_MSER = DYNAMICDETECTOR + MSER,
DYNAMIC_GFTT = DYNAMICDETECTOR + GFTT,
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)
......@@ -109,6 +117,12 @@ public:
case HARRIS:
name += "HARRIS";
break;
case SIMPLEBLOB:
name += "SimpleBlob";
break;
case DENSE:
name += "Dense";
break;
default:
CV_Error( CV_StsBadArg, "Specified feature detector type is not supported." );
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