I want to undistort some points in EmguCV, but I get a CVException
during execution, because the following assertion fails:
OpenCV: src.isContinuous() && (src.depth() == CV_32F || src.depth() == CV_64F) && ((src.rows == 1 && src.channels() == 2) || src.cols*src.channels() == 2)
Here's how I call the function:
//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);
explanation:
IntrinsicParameters
is a custom class that wraps all intrinsic parameters, which I used default values for). I added a comment above to denote what parameter is which- I create a
VectorOfPoint
calledpoints
that I want to distort. - I create another
VectorOfPoint
to hold the result - The program hangs on the last line in the snippet provided. When I click pause in VisualStudio the debugger says the mentioned assertion failed.
I tried to find some explanation of what this all means but there's no comment whatsoever in the openCV source code.
What am I doing wrong here? Am I not supposed to use undistortPoints()
with this type of points? But then why can I pass them to the function?
Update using Mat
I tried to use Mat
instead, which is a bit of a pain to use. I found this question explaining how to set the elements of a Mat
and came up with this code:
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);
The exception I get now comes from a different assertion (hurray?):
OpenCV: checkScalar(value, type(), _value.kind(), _InputArray::MAT )
It looks like this happens when calling mat.SetTo()
. I'm not sure why this is so complicated.