Ask Your Question

NicolasC's profile - activity

2015-03-23 03:05:46 -0600 answered a question Exception in cvConvertScale in OpenCV calling solvePnP

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 !

2015-03-19 06:54:19 -0600 asked a question Exception in cvConvertScale in OpenCV calling solvePnP

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 ?