gpt4 book ai didi

OpenCV::projectPoints 的 Java 实现在这个基本示例中似乎被破坏了

转载 作者:行者123 更新时间:2023-12-02 11:37:08 25 4
gpt4 key购买 nike

当我使用下面的java代码和最简单的输入运行projectPoints函数时,我得到了我认为不正确的答案。我错过了什么吗?

我得到了这个答案

(x,y,z)= [{0.0, 1.0, 1.0}, {0.0, 1.0, 5.0}, {0.0, 1.0, 10.0}]
(u,v)= [{0.0, 78.5398178100586}, {0.0, 19.73955535888672}, {0.0, 9.966865539550781}]

应该是(u,v)=[{0.0, 100.0}, {0.0, 20.0}, {0.0, 10.0}]

下面是调用projectPoint的代码,或者是我编写的可以正常工作的函数(没有相机失真)。

public static void main(String[] args) {
setDllLibraryPath("C:/aaa_eric/code/lib/x64");
System.loadLibrary(Core.NATIVE_LIBRARY_NAME);

MatOfPoint3f objectPts3f = new MatOfPoint3f(
new Point3(0.0,1.0, 1.0),
new Point3(0.0,1.0, 5.0),
new Point3(0.0,1.0,10.0));
MatOfPoint2f imagePts2f = new MatOfPoint2f();
Mat rVec = Mat.zeros(3,1, CvType.CV_64F);
Mat tVec = Mat.zeros(3,1, CvType.CV_64F);

//camera matrix, no distortion
Mat kMat = Mat.zeros(3, 3, CvType.CV_64F);
kMat.put(0, 0,
100.0, 0.0, 0.0,
0.0, 100.0, 0.0,
0.0, 0.0, 1.0);
Mat dMat = Mat.zeros(4, 1, CvType.CV_64F);

//this one is broken
Calib3d.projectPoints(objectPts3f, imagePts2f, rVec, tVec, kMat, dMat);
//this one works
ppWorks(objectPts3f, imagePts2f, rVec, tVec, kMat, dMat);

System.out.println(objectPts3f.toList());
System.out.println(imagePts2f.toList());
}

static void ppWorks(MatOfPoint3f objPt3f,MatOfPoint2f imgPt2f,Mat rVec,Mat tVec,Mat kMat, Mat dMat) {
double[] T = new double[3]; tVec.get(0,0,T);
double[] K = new double[9]; kMat.get(0,0,K);
double[] D = new double[4]; dMat.get(0,0,D);

Mat rMat = Mat.zeros(3,3,CvType.CV_64F);
Calib3d.Rodrigues(rVec, rMat);
double[] R = new double[9]; rMat.get(0,0,R);

Point3[] xf=objPt3f.toArray();
List<Point> y=new ArrayList<>();
for (int i = 0; i < objPt3f.total(); i++) {
Point3 Xi = xf[i];
Point3 Y = new Point3(
R[0]*Xi.x + R[1]*Xi.y + R[2]*Xi.z + T[0]*1.0,
R[3]*Xi.x + R[4]*Xi.y + R[5]*Xi.z + T[1]*1.0,
R[6]*Xi.x + R[7]*Xi.y + R[8]*Xi.z + T[2]*1.0
);

y.add(new Point(K[0]*Y.x/Y.z + K[2], K[4]*Y.y/Y.z + K[5]));
}
imgPt2f.fromList(y);
}

最佳答案

也面临同样的问题(Java、OpenCV 3.4.1)。看起来问题在于 Calib3d 类为“标准”和鱼眼相机模型混合了 projectPoints 方法,并且方法名称相同。

你的自定义函数对我有用,然后我简单地尝试了类似的 OpenCV 方法,但具有不同的签名,它起作用了:

// distortion coefficients have to be MatOfDouble in this signature
MatOfDouble dMat = new MatOfDouble(0,0,0,0,0);
// this one works fine
Calib3d.projectPoints(objectPts3f, rVec, tVec, kMat, dMat, imagePts2f, new Mat(), 0);

请注意,OpenCV 4.0.0 似乎已通过在鱼眼方法名称前添加前缀 ( javadocs ) 解决了该问题。

关于OpenCV::projectPoints 的 Java 实现在这个基本示例中似乎被破坏了,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48846453/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com