Ask Your Question
0

Exception in cvConvertScale in OpenCV calling solvePnP

asked 2015-03-19 06:22:11 -0500

I'm trying to use solvePnP from OpenCV (through OpenCvSharp) but I get an exception that I don't understand.

An unhandled exception of type 'OpenCvSharp.OpenCVException' occurred in OpenCvSharp.dll
Additional information: src.size == dst.size && src.channels() == dst.channels()

After some searching, I found that it comes from cvConvertScale in convert.cpp

Here is how I use it:

var objectPoints = new OpenCvSharp.CPlusPlus.Point3f[4] { o1, o2, o3, o4 };
var imagePoints = new OpenCvSharp.CPlusPlus.Point2f[4] { i1, i2, i3, i4 };
var intrinsic = new double[3, 3] { { d1, d2, d3 }, { d4, d5, d6}, { d7, d8, d9 } };

double[] rvec, tvec;

OpenCvSharp.CPlusPlus.Cv2.SolvePnP(objectPoints,
                                   imagePoints,
                                   intrinsic,
                                   null, out rvec, out tvec);

If I understand this exception right, it means there is a conversion of sort happening and the source and destination matrixes don't have the same size or the same number of channels. But both my list of points are of the same size. My camera matrix is 3x3 which should be fine. I don't get it.

Could someone shed some light on this ?

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
0

answered 2015-03-23 02:57:11 -0500

Well I think I found the issue so I'll post it here in case anyone stumble upon this...

It seems my camera matrix was not properly initialized. I don't know why but I dont get a 3x3 matrix from my double[3,3]. So I initialized it using the OpenCV Mat constructor like this:

var intrinsic = new Mat(3, 3, MatType.CV_64F, new double[] { d1, d2, d3, d4, d5, d6, d7, d8, d9 });

And now it's working... if anyone know why my double[3,3] was not producing the corresponding Mat(3,3) feel free to share !

edit flag offensive delete link more
Login/Signup to Answer

Question Tools

1 follower

Stats

Asked: 2015-03-19 06:22:11 -0500

Seen: 376 times

Last updated: Mar 19 '15