(#1636) Java API: adding undistortPoints() support and smoke test; minor improvements in Java stuff

This commit is contained in:
Andrey Pavlenko 2012-03-14 07:37:48 +00:00
parent b232ffcde7
commit 36890cc959
6 changed files with 54 additions and 13 deletions

View File

@ -656,9 +656,9 @@ CV_EXPORTS_W Mat getDefaultNewCameraMatrix( InputArray cameraMatrix, Size imgsiz
bool centerPrincipalPoint=false );
//! returns points' coordinates after lens distortion correction
CV_EXPORTS void undistortPoints( InputArray src, OutputArray dst,
InputArray cameraMatrix, InputArray distCoeffs,
InputArray R=noArray(), InputArray P=noArray());
CV_EXPORTS_W void undistortPoints( InputArray src, OutputArray dst,
InputArray cameraMatrix, InputArray distCoeffs,
InputArray R=noArray(), InputArray P=noArray());
template<> CV_EXPORTS void Ptr<CvHistogram>::delete_obj();

View File

@ -55,7 +55,7 @@ public class UtilsTest extends OpenCVTestCase {
public void testMatToBitmap() {
Mat imgBGR = Highgui.imread( OpenCVTestRunner.LENA_PATH );
assertTrue(imgBGR.channels() == 3);
assertTrue(imgBGR != null && !imgBGR.empty() && imgBGR.channels() == 3);
Mat m16 = new Mat(imgBGR.rows(), imgBGR.cols(), CvType.CV_8UC4);
Mat m32 = new Mat(imgBGR.rows(), imgBGR.cols(), CvType.CV_8UC4);
@ -71,7 +71,7 @@ public class UtilsTest extends OpenCVTestCase {
// RGBA
Mat imgRGBA = new Mat();
Imgproc.cvtColor(imgBGR, imgRGBA, Imgproc.COLOR_BGR2RGBA);
assertTrue(imgRGBA.channels() == 4);
assertTrue(!imgRGBA.empty() && imgRGBA.channels() == 4);
bmp16.eraseColor(Color.BLACK); m16.setTo(s0);
Utils.matToBitmap(imgRGBA, bmp16); Utils.bitmapToMat(bmp16, m16);
@ -89,7 +89,7 @@ public class UtilsTest extends OpenCVTestCase {
// RGB
Mat imgRGB = new Mat();
Imgproc.cvtColor(imgBGR, imgRGB, Imgproc.COLOR_BGR2RGB);
assertTrue(imgRGB.channels() == 3);
assertTrue(!imgRGB.empty() && imgRGB.channels() == 3);
bmp16.eraseColor(Color.BLACK); m16.setTo(s0);
Utils.matToBitmap(imgRGB, bmp16); Utils.bitmapToMat(bmp16, m16);
@ -107,7 +107,7 @@ public class UtilsTest extends OpenCVTestCase {
// Gray
Mat imgGray = new Mat();
Imgproc.cvtColor(imgBGR, imgGray, Imgproc.COLOR_BGR2GRAY);
assertTrue(imgGray.channels() == 1);
assertTrue(!imgGray.empty() && imgGray.channels() == 1);
Mat tmp = new Mat();
bmp16.eraseColor(Color.BLACK); m16.setTo(s0);

View File

@ -1,5 +1,9 @@
package org.opencv.test.features2d;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import org.opencv.core.Core;
import org.opencv.core.CvType;
import org.opencv.core.Mat;
@ -13,10 +17,6 @@ import org.opencv.features2d.KeyPoint;
import org.opencv.test.OpenCVTestCase;
import org.opencv.test.OpenCVTestRunner;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
public class BruteForceDescriptorMatcherTest extends OpenCVTestCase {
DescriptorMatcher matcher;
@ -163,7 +163,25 @@ public class BruteForceDescriptorMatcherTest extends OpenCVTestCase {
}
public void testKnnMatchMatMatListOfListOfDMatchInt() {
fail("Not yet implemented");
final int k = 3;
Mat train = getTrainDescriptors();
Mat query = getQueryDescriptors();
List<List<DMatch>> matches = new ArrayList<List<DMatch>>();
matcher.knnMatch(query, train, matches, k);
/*
matcher.add(Arrays.asList(train));
matcher.knnMatch(query, matches, k);
*/
assertEquals(query.rows(), matches.size());
for(int i = 0; i<matches.size(); i++)
{
List<DMatch> ldm = matches.get(i);
assertEquals(Math.min(k, train.rows()), ldm.size());
for(DMatch dm : ldm)
{
assertEquals(dm.queryIdx, i);
}
}
}
public void testKnnMatchMatMatListOfListOfDMatchIntMat() {

View File

@ -2102,6 +2102,24 @@ public class ImgprocTest extends OpenCVTestCase {
assertMatEqual(truth, dst, EPS);
}
//undistortPoints(List<Point> src, List<Point> dst, Mat cameraMatrix, Mat distCoeffs)
public void testUndistortPointsListOfPointListOfPointMatMat() {
List<Point> src = new ArrayList<Point>(3);
src.add( new Point(1, 2) );
src.add( new Point(3, 4) );
src.add( new Point(-1, -1) );
List<Point> dst = new ArrayList<Point>();
Mat cameraMatrix = Mat.eye(3, 3, CvType.CV_64FC1);
Mat distCoeffs = new Mat(8, 1, CvType.CV_64FC1, new Scalar(0));
Imgproc.undistortPoints(src, dst, cameraMatrix, distCoeffs);
assertEquals(src.size(), dst.size());
for(int i=0; i<src.size(); i++) {
//Log.d("UndistortPoints", "s="+src.get(i)+", d="+dst.get(i));
assertTrue(src.get(i).equals(dst.get(i)));
}
}
public void testWarpAffineMatMatMatSize() {
Mat src = new Mat(3, 3, CvType.CV_32F) {
{

View File

@ -514,7 +514,7 @@ func_arg_fix = {
'getAffineTransform' : { 'src' : 'vector_Point2f', 'dst' : 'vector_Point2f', },
'hconcat' : { 'src' : 'vector_Mat', },
'vconcat' : { 'src' : 'vector_Mat', },
'undistortPoints' : { 'src' : 'vector_Point2d', 'dst' : 'vector_Point2d' }
}, # '', i.e. no class
} # func_arg_fix

View File

@ -643,4 +643,9 @@ public class Converters {
}
}
static {
System.loadLibrary("opencv_java");
}
}