【发布时间】:2016-01-06 14:02:45
【问题描述】:
我想不扭曲 EmguCV 中的某些点,但在执行过程中我得到了 CVException,因为以下断言失败:
OpenCV: src.isContinuous() && (src.depth() == CV_32F || src.depth() == CV_64F) && ((src.rows == 1 && src.channels() == 2) || src.cols*src.channels() == 2)
我是这样调用函数的:
//fx fy, cx, cy, k1, k2, p1, p2
IntrinsicParameters intrinsic = new IntrinsicParameters( 1, 1, 100, 100, 0, 0, 0, 0);
VectorOfPoint points = new VectorOfPoint(new Point[] { new Point(0, 0), new Point(255, 255) });
VectorOfPoint pointsUndistorted = new VectorOfPoint(points.Size);
CvInvoke.UndistortPoints(points, pointsUndistorted, intrinsic.CameraMatrix, intrinsic.DistorionCoefficients);
解释:
-
IntrinsicParameters是一个自定义类,它包装了所有内部参数,我使用了默认值)。我在上面添加了一条注释来表示哪个参数是哪个 - 我创建了一个名为
points的VectorOfPoint,我想对其进行扭曲。 - 我创建另一个
VectorOfPoint来保存结果 - 程序挂在所提供的 sn-p 中的最后一行。当我在 VisualStudio 中单击暂停时,调试器说上述断言失败。
除了there's no comment whatsoever in the openCV source code之外,我试图找到一些解释这一切的含义。
我在这里做错了什么?我不应该在这种类型的积分上使用undistortPoints() 吗?但是为什么我可以将它们传递给函数呢?
使用Mat 更新
我尝试改用Mat,使用起来有点麻烦。 I found this question explaining how to set the elements of a Mat 并想出了这段代码:
int n = 2;
Mat mat = new Mat(new Size(1, n), Emgu.CV.CvEnum.DepthType.Cv32F, 2);
Mat matDistorted = new Mat(new Size(1, n), Emgu.CV.CvEnum.DepthType.Cv32F, 2);
Matrix<float> yetAnotherMatrixOr_YAM_forShort = new Matrix<float>(new float[,]{{0, 0}, {255, 255}});
mat.SetTo(yetAnotherMatrixOr_YAM_forShort);
CvInvoke.UndistortPoints(mat, matDistorted, intrinsic.CameraMatrix, intrinsic.DistorionCoefficients);
我现在得到的异常来自不同的断言(欢呼?):
OpenCV: checkScalar(value, type(), _value.kind(), _InputArray::MAT )
调用mat.SetTo() 时似乎会发生这种情况。我不知道为什么这么复杂。
【问题讨论】:
-
你能用
Point2f代替Point吗? -
@Micka 我该怎么做? EmguCV 有
MCvPoint2D64f,我可以创建一个数组:MCvPoint2D64f[],但我既不能将其包装成VectorOfPoints,也不能将其传递给CvInvoke.UndistortPoints()。也没有VectorOfPoints2f。我如何将许多Point2f对象传递给CvInvoke.UndistortPoints()?不管是什么,我认为它必须实现InputArray,但我不确定。这个库的类型系统仍然让我感到困惑。 -
抱歉,对 emguCV 了解不够……是否可以创建具有 CV_32FC2 等效项的 Mat 对象?喜欢 new Mat(size, Cv32F, 2)?将您的点位置(n 点)提供给它并选择大小为 1 列和 n 行。
-
@Micka 我想我尝试过类似的方法,请看看我的编辑。我把
Mat弄乱了吗? -
@Micka 你让我走上了正轨,虽然 EmguCV 中没有
Point2f,但我设法通过使用PointF解决了这个问题。谢谢!
标签: c# opencv emgucv distortion