From 8b16dbe791a41216ba3d64ba4d8ac5ac1997a3a5 Mon Sep 17 00:00:00 2001 From: Andrey Pavlenko Date: Wed, 3 Aug 2011 13:31:51 +0000 Subject: [PATCH] Java API: calcOpticalFlowPyrLK() args types are changed to vector<> Testing: 1130/0/585 --- .../src/org/opencv/test/video/videoTest.java | 76 ++++++++++--------- modules/java/gen_java.py | 2 + modules/java/src/cpp/converters.cpp | 10 +++ modules/java/src/cpp/converters.h | 3 + modules/java/src/java/utils+Converters.java | 23 +++++- 5 files changed, 77 insertions(+), 37 deletions(-) diff --git a/modules/java/android_test/src/org/opencv/test/video/videoTest.java b/modules/java/android_test/src/org/opencv/test/video/videoTest.java index db8d45a69a..1a844b8d1a 100644 --- a/modules/java/android_test/src/org/opencv/test/video/videoTest.java +++ b/modules/java/android_test/src/org/opencv/test/video/videoTest.java @@ -1,10 +1,14 @@ package org.opencv.test.video; +import java.util.ArrayList; +import java.util.List; + import org.opencv.core.Core; -import org.opencv.core.CvType; import org.opencv.core.Mat; +import org.opencv.core.Point; import org.opencv.core.Size; import org.opencv.test.OpenCVTestCase; +import org.opencv.utils.Converters; import org.opencv.video.Video; public class videoTest extends OpenCVTestCase { @@ -17,9 +21,10 @@ public class videoTest extends OpenCVTestCase { private Mat subLena1 = null; private Mat subLena2 = null; - private Mat nextPts = null; - private Mat status = null; - private Mat err = null; + List prevPts = null; + private List nextPts = null; + private List status = null; + private List err = null; @Override protected void setUp() throws Exception { @@ -33,9 +38,14 @@ public class videoTest extends OpenCVTestCase { subLena1 = rgbLena.submat(shift1, h + shift1, shift1, w + shift1); subLena2 = rgbLena.submat(shift2, h + shift2, shift2, w + shift2); - nextPts = new Mat(); - status = new Mat(); - err = new Mat(); + prevPts = new ArrayList(); + prevPts.add(new Point(1.0, 1.0)); + prevPts.add(new Point(5.0, 5.0)); + prevPts.add(new Point(10.0, 10.0)); + + nextPts = new ArrayList(); + status = new ArrayList(); + err = new ArrayList(); } public void testCalcGlobalOrientation() { @@ -54,39 +64,37 @@ public class videoTest extends OpenCVTestCase { fail("Not yet implemented"); } - public void testCalcOpticalFlowPyrLKMatMatMatMatMatMat() { - Mat prevPts = new Mat(1, 3, CvType.CV_32FC2); - prevPts.put(0, 0, 1.0, 1.0, 5.0, 5.0, 10.0, 10.0); - - Video.calcOpticalFlowPyrLK(subLena1, subLena2, prevPts, nextPts, status, err); - assertEquals(3, Core.countNonZero(status)); - } - - public void testCalcOpticalFlowPyrLKMatMatMatMatMatMatSize() { - Mat prevPts = new Mat(1, 3, CvType.CV_32FC2); - prevPts.put(0, 0, 1.0, 1.0, 5.0, 5.0, 10.0, 10.0); + public void testCalcOpticalFlowPyrLKMatMatListOfPointListOfPointListOfByteListOfFloatSizeIntTermCriteriaDoubleIntDouble() { + fail("Not yet implemented"); + } - Size sz = new Size(3, 3); - Video.calcOpticalFlowPyrLK(subLena1, subLena2, prevPts, nextPts, status, err, sz); - assertEquals(0, Core.countNonZero(status)); - } + public void testCalcOpticalFlowPyrLKMatMatListOfPointListOfPointListOfByteListOfFloatSizeIntTermCriteriaDoubleInt() { + fail("Not yet implemented"); + } - public void testCalcOpticalFlowPyrLKMatMatMatMatMatMatSizeInt() { - fail("Not yet implemented"); - } + public void testCalcOpticalFlowPyrLKMatMatListOfPointListOfPointListOfByteListOfFloatSizeIntTermCriteriaDouble() { + fail("Not yet implemented"); + } - public void testCalcOpticalFlowPyrLKMatMatMatMatMatMatSizeIntTermCriteria() { - fail("Not yet implemented"); - } + public void testCalcOpticalFlowPyrLKMatMatListOfPointListOfPointListOfByteListOfFloatSizeIntTermCriteria() { + fail("Not yet implemented"); + } - public void testCalcOpticalFlowPyrLKMatMatMatMatMatMatSizeIntTermCriteriaDouble() { - fail("Not yet implemented"); - } + public void testCalcOpticalFlowPyrLKMatMatListOfPointListOfPointListOfByteListOfFloatSizeInt() { + fail("Not yet implemented"); + } - public void testCalcOpticalFlowPyrLKMatMatMatMatMatMatSizeIntTermCriteriaDoubleInt() { - fail("Not yet implemented"); - } + public void testCalcOpticalFlowPyrLKMatMatListOfPointListOfPointListOfByteListOfFloatSize() { + Size sz = new Size(3, 3); + Video.calcOpticalFlowPyrLK(subLena1, subLena2, prevPts, nextPts, status, err, sz); + assertEquals(0, Core.countNonZero( Converters.vector_uchar_to_Mat(status) )); + } + public void testCalcOpticalFlowPyrLKMatMatListOfPointListOfPointListOfByteListOfFloat() { + Video.calcOpticalFlowPyrLK(subLena1, subLena2, prevPts, nextPts, status, err); + assertEquals(3, Core.countNonZero( Converters.vector_uchar_to_Mat(status) )); + } + public void testCamShift() { fail("Not yet implemented"); } diff --git a/modules/java/gen_java.py b/modules/java/gen_java.py index 61da6f9fd2..f347e275e1 100644 --- a/modules/java/gen_java.py +++ b/modules/java/gen_java.py @@ -478,6 +478,8 @@ func_arg_fix = { 'findHomography' : { 'srcPoints' : 'vector_Point2f', 'dstPoints' : 'vector_Point2f', }, 'solvePnP' : { 'objectPoints' : 'vector_Point3f', 'imagePoints' : 'vector_Point2f', }, 'solvePnPRansac' : { 'objectPoints' : 'vector_Point3f', 'imagePoints' : 'vector_Point2f', }, + 'calcOpticalFlowPyrLK' : { 'prevPts' : 'vector_Point2f', 'nextPts' : 'vector_Point2f', + 'status' : 'vector_uchar', 'err' : 'vector_float', }, }, # '', i.e. no class } # func_arg_fix diff --git a/modules/java/src/cpp/converters.cpp b/modules/java/src/cpp/converters.cpp index 414b2d1d63..e2fa441139 100644 --- a/modules/java/src/cpp/converters.cpp +++ b/modules/java/src/cpp/converters.cpp @@ -67,6 +67,11 @@ void Mat_to_vector_uchar(Mat& mat, vector& v_uchar) v_uchar = (vector) mat; } +void vector_uchar_to_Mat(vector& v_uchar, Mat& mat) +{ + mat = Mat(v_uchar, true); +} + void Mat_to_vector_char(Mat& mat, vector& v_char) { v_char.clear(); @@ -74,6 +79,11 @@ void Mat_to_vector_char(Mat& mat, vector& v_char) v_char = (vector) mat; } +void vector_char_to_Mat(vector& v_char, Mat& mat) +{ + mat = Mat(v_char, true); +} + //vector_Rect diff --git a/modules/java/src/cpp/converters.h b/modules/java/src/cpp/converters.h index c39d603d71..32af1e57e1 100644 --- a/modules/java/src/cpp/converters.h +++ b/modules/java/src/cpp/converters.h @@ -15,7 +15,10 @@ void Mat_to_vector_float(cv::Mat& mat, std::vector& v_float); void vector_float_to_Mat(std::vector& v_float, cv::Mat& mat); void Mat_to_vector_uchar(cv::Mat& mat, std::vector& v_uchar); +void vector_uchar_to_Mat(std::vector& v_uchar, cv::Mat& mat); + void Mat_to_vector_char(cv::Mat& mat, std::vector& v_char); +void vector_char_to_Mat(std::vector& v_char, cv::Mat& mat); void Mat_to_vector_Rect(cv::Mat& mat, std::vector& v_rect); void vector_Rect_to_Mat(std::vector& v_rect, cv::Mat& mat); diff --git a/modules/java/src/java/utils+Converters.java b/modules/java/src/java/utils+Converters.java index 8c19095792..005a1f0dc6 100644 --- a/modules/java/src/java/utils+Converters.java +++ b/modules/java/src/java/utils+Converters.java @@ -293,7 +293,7 @@ public class Converters { float[] buff = new float[count]; m.get(0, 0, buff); for(int i=0; i us) { + if(us == null) + throw new java.lang.IllegalArgumentException("Output List can't be null"); + int count = m.rows(); + if( CvType.CV_8UC1 != m.type() || m.cols()!=1 ) + throw new java.lang.IllegalArgumentException( + "CvType.CV_8UC1 != m.type() || m.cols()!=1\n" + m); + + us.clear(); + byte[] buff = new byte[count]; + m.get(0, 0, buff); + for(int i=0; i bs) { Mat res; int count = (bs!=null) ? bs.size() : 0; @@ -360,7 +377,7 @@ public class Converters { int[] buff = new int[count]; m.get(0, 0, buff); for(int i=0; i