1
0
mirror of https://github.com/opencv/opencv.git synced 2026-07-29 23:33:05 +04:00

Merge pull request #29230 from asmorkalov:as/move_undistort

Inverted imgproc-geometry dependency and moved more functions to geometry #29230

Fixes: https://github.com/opencv/opencv/issues/20267
Continues: https://github.com/opencv/opencv/pull/29175

OpenCV Contrib: https://github.com/opencv/opencv_contrib/pull/4137
OpenCV Extra: https://github.com/opencv/opencv_extra/pull/1377

Summary:
- LSD returned back to imgproc
- drawing functions moved to imgproc
- undistort image and related perf-pixel functions moved to imgproc
- moments moved to geometry
- estimateXXXtransform moved to geometry

After the patch the geometry module depends on code and Flann and may be used everywhere without potential circular dependencies

### Pull Request Readiness Checklist

See details at https://github.com/opencv/opencv/wiki/How_to_contribute#making-a-good-pull-request

- [x] I agree to contribute to the project under Apache 2 License.
- [x] To the best of my knowledge, the proposed patch is not based on a code under GPL or another license that is incompatible with OpenCV
- [ ] The PR is proposed to the proper branch
- [ ] There is a reference to the original bug report and related work
- [ ] There is accuracy test, performance test and test data in opencv_extra repository, if applicable
      Patch to opencv_extra has the same branch name.
- [ ] The feature is well documented and sample code can be built with the project CMake
This commit is contained in:
Alexander Smorkalov
2026-06-05 10:13:45 +03:00
committed by GitHub
parent ada32973b4
commit 40ddc700aa
58 changed files with 2021 additions and 1612 deletions
@@ -452,101 +452,6 @@ public class GeometryTest extends OpenCVTestCase {
// TODO_: write better test
}
public void testInitUndistortRectifyMap() {
fail("Not yet implemented");
Mat cameraMatrix = new Mat(3, 3, CvType.CV_32F);
cameraMatrix.put(0, 0, 1, 0, 1);
cameraMatrix.put(1, 0, 0, 1, 1);
cameraMatrix.put(2, 0, 0, 0, 1);
Mat R = new Mat(3, 3, CvType.CV_32F, new Scalar(2));
Mat newCameraMatrix = new Mat(3, 3, CvType.CV_32F, new Scalar(3));
Mat distCoeffs = new Mat();
Mat map1 = new Mat();
Mat map2 = new Mat();
// TODO: complete this test
Geometry.initUndistortRectifyMap(cameraMatrix, distCoeffs, R, newCameraMatrix, size, CvType.CV_32F, map1, map2);
}
public void testInitWideAngleProjMapMatMatSizeIntIntMatMat() {
fail("Not yet implemented");
Mat cameraMatrix = new Mat(3, 3, CvType.CV_32F);
Mat distCoeffs = new Mat(1, 4, CvType.CV_32F);
// Size imageSize = new Size(2, 2);
cameraMatrix.put(0, 0, 1, 0, 1);
cameraMatrix.put(1, 0, 0, 1, 2);
cameraMatrix.put(2, 0, 0, 0, 1);
distCoeffs.put(0, 0, 1, 3, 2, 4);
truth = new Mat(3, 3, CvType.CV_32F);
truth.put(0, 0, 0, 0, 0);
truth.put(1, 0, 0, 0, 0);
truth.put(2, 0, 0, 3, 0);
// TODO: No documentation for this function
// Geometry.initWideAngleProjMap(cameraMatrix, distCoeffs, imageSize,
// 5, m1type, truthput1, truthput2);
}
public void testInitWideAngleProjMapMatMatSizeIntIntMatMatInt() {
fail("Not yet implemented");
}
public void testInitWideAngleProjMapMatMatSizeIntIntMatMatIntDouble() {
fail("Not yet implemented");
}
public void testUndistortMatMatMatMat() {
Mat src = new Mat(3, 3, CvType.CV_32F, new Scalar(3));
Mat cameraMatrix = new Mat(3, 3, CvType.CV_32F) {
{
put(0, 0, 1, 0, 1);
put(1, 0, 0, 1, 2);
put(2, 0, 0, 0, 1);
}
};
Mat distCoeffs = new Mat(1, 4, CvType.CV_32F) {
{
put(0, 0, 1, 3, 2, 4);
}
};
Geometry.undistort(src, dst, cameraMatrix, distCoeffs);
truth = new Mat(3, 3, CvType.CV_32F) {
{
put(0, 0, 0, 0, 0);
put(1, 0, 0, 0, 0);
put(2, 0, 0, 3, 0);
}
};
assertMatEqual(truth, dst, EPS);
}
public void testUndistortMatMatMatMatMat() {
Mat src = new Mat(3, 3, CvType.CV_32F, new Scalar(3));
Mat cameraMatrix = new Mat(3, 3, CvType.CV_32F) {
{
put(0, 0, 1, 0, 1);
put(1, 0, 0, 1, 2);
put(2, 0, 0, 0, 1);
}
};
Mat distCoeffs = new Mat(1, 4, CvType.CV_32F) {
{
put(0, 0, 2, 1, 4, 5);
}
};
Mat newCameraMatrix = new Mat(3, 3, CvType.CV_32F, new Scalar(1));
Geometry.undistort(src, dst, cameraMatrix, distCoeffs, newCameraMatrix);
truth = new Mat(3, 3, CvType.CV_32F, new Scalar(3));
assertMatEqual(truth, dst, EPS);
}
//undistortPoints(List<Point> src, List<Point> dst, Mat cameraMatrix, Mat distCoeffs)
public void testUndistortPointsListOfPointListOfPointMatMat() {
MatOfPoint2f src = new MatOfPoint2f(new Point(1, 2), new Point(3, 4), new Point(-1, -1));
@@ -687,7 +592,7 @@ public class GeometryTest extends OpenCVTestCase {
Mat linePoints = new Mat(4, 1, CvType.CV_32FC1);
linePoints.put(0, 0, 0.53198653, 0.84675282, 2.5, 3.75);
Geometry.fitLine(points, dst, Imgproc.DIST_L12, 0, 0.01, 0.01);
Geometry.fitLine(points, dst, Geometry.DIST_L12, 0, 0.01, 0.01);
assertMatEqual(linePoints, dst, EPS);
}
@@ -780,4 +685,44 @@ public class GeometryTest extends OpenCVTestCase {
assertTrue(bbox.contains(p1));
assertFalse(bbox.contains(p2));
}
public void testGetAffineTransform() {
MatOfPoint2f src = new MatOfPoint2f(new Point(2, 3), new Point(3, 1), new Point(1, 4));
MatOfPoint2f dst = new MatOfPoint2f(new Point(3, 3), new Point(7, 4), new Point(5, 6));
Mat transform = Geometry.getAffineTransform(src, dst);
Mat truth = new Mat(2, 3, CvType.CV_64FC1) {
{
put(0, 0, -8, -6, 37);
put(1, 0, -7, -4, 29);
}
};
assertMatEqual(truth, transform, EPS);
}
public void testGetRotationMatrix2D() {
Point center = new Point(0, 0);
dst = Geometry.getRotationMatrix2D(center, 0, 1);
truth = new Mat(2, 3, CvType.CV_64F) {
{
put(0, 0, 1, 0, 0);
put(1, 0, 0, 1, 0);
}
};
assertMatEqual(truth, dst, EPS);
}
public void testInvertAffineTransform() {
Mat src = new Mat(2, 3, CvType.CV_64F, new Scalar(1));
Geometry.invertAffineTransform(src, dst);
truth = new Mat(2, 3, CvType.CV_64F, new Scalar(0));
assertMatEqual(truth, dst, EPS);
}
}
@@ -0,0 +1,51 @@
package org.opencv.test.geometry;
import org.opencv.test.OpenCVTestCase;
import org.opencv.core.Core;
import org.opencv.core.Mat;
import org.opencv.core.CvType;
import org.opencv.core.Scalar;
import org.opencv.geometry.Geometry;
import org.opencv.geometry.Moments;
public class MomentsTest extends OpenCVTestCase {
Mat data;
@Override
protected void setUp() throws Exception {
super.setUp();
data = new Mat(3,3, CvType.CV_8UC1, new Scalar(1));
data.row(1).setTo(new Scalar(5));
}
public void testAll() {
Moments res = Geometry.moments(data);
assertEquals(res.m00, 21.0, EPS);
assertEquals(res.m10, 21.0, EPS);
assertEquals(res.m01, 21.0, EPS);
assertEquals(res.m20, 35.0, EPS);
assertEquals(res.m11, 21.0, EPS);
assertEquals(res.m02, 27.0, EPS);
assertEquals(res.m30, 63.0, EPS);
assertEquals(res.m21, 35.0, EPS);
assertEquals(res.m12, 27.0, EPS);
assertEquals(res.m03, 39.0, EPS);
assertEquals(res.mu20, 14.0, EPS);
assertEquals(res.mu11, 0.0, EPS);
assertEquals(res.mu02, 6.0, EPS);
assertEquals(res.mu30, 0.0, EPS);
assertEquals(res.mu21, 0.0, EPS);
assertEquals(res.mu12, 0.0, EPS);
assertEquals(res.mu03, 0.0, EPS);
assertEquals(res.nu20, 0.031746031746031744, EPS);
assertEquals(res.nu11, 0.0, EPS);
assertEquals(res.nu02, 0.013605442176870746, EPS);
assertEquals(res.nu30, 0.0, EPS);
assertEquals(res.nu21, 0.0, EPS);
assertEquals(res.nu12, 0.0, EPS);
assertEquals(res.nu03, 0.0, EPS);
}
}