I can't get the cameraMatrix , rotation and translation Matrix from the method Cvinvoke.CalibrateCamera()

32 views Asked by At

Dear csharp developers,

I have calculated the image coordinaten of a set of images and I have save it in a List in my csharp program. All the images I used was calibrated with circles and there was 3 big circles that I have used as my points of reference . A picture is joined to this message.

I'm also having the objectpoints and I wish to use this image points and objectpoints to calibrate my camera .

Here below is an example of my code:

Image for calibration:

enter image description here

public static void Test1(List<MyPoints> finalPoints, Image<Gray, byte> image)
{
 
// Liste imagepoints------------------------------------------------ 
List<VectorOfPointF> imagePoints = new List<VectorOfPointF>(); 
VectorOfPointF imagePointsvector = new VectorOfPointF(); 
List<PointF> imagespointF = new List<PointF>();

for (int i = 0; i < finalPoints.Count; i++)
 {
    imagespointF.Add(new PointF() { X = (float)finalPoints[i].OriginalCenter.X, Y =                          (float)finalPoints[i].OriginalCenter.Y });
 }
 imagePointsvector.Push(imagespointF.ToArray());
 for (int i = 0; i < finalPoints.Count; i++)
 {
     imagePoints.Add(imagePointsvector);
 }

 // Liste objectPoints-----------------------------------------
 List<MCvPoint3D32f[]> objectPoints = new List<MCvPoint3D32f[]>();
 MCvPoint3D32f[] objectPointsvector = new MCvPoint3D32f[objectPoints.Count];
 List<MCvPoint3D32f> objectpointsF = new List<MCvPoint3D32f>();

 for (int i = 0; i < finalPoints.Count; i++)
 {
     objectpointsF.Add(new MCvPoint3D32f()
     {
         X = (float)finalPoints[i].OriginalCenter.X,
         Y = (float)finalPoints[i].OriginalCenter.Y,
         Z = (float)finalPoints[i].OriginalCenter.Z
     });
 }  
 Array.Copy(objectpointsF.ToArray(), objectPointsvector, objectPointsvector.Length);
 for (int i = 0; i < finalPoints.Count; i++)
 {
     objectPoints.Add(objectPointsvector);
 }



 Size imageSize = new Size(image.Width, image.Height);
 var cameraMatrix = new Emgu.CV.Matrix<double>(3, 3);
 var distortionCoeffs = new Emgu.CV.Matrix<double>(4, 1);
 var termCriteria = new MCvTermCriteria(30, 0.1);
 System.Drawing.PointF[][] imagePointss = imagePoints.Select(p => p.ToArray()).ToArray();
 MCvPoint3D32f[][] worldPointss = objectPoints.Select(p => p.ToArray()).ToArray();
 double error = CvInvoke.CalibrateCamera(worldPointss, imagePointss, imageSize, cameraMatrix,             distortionCoeffs, CalibType.RationalModel, termCriteria, out Mat[] rotationVectors, out Mat[] translationVectors);
 var rotation = new Emgu.CV.Matrix<double>(rotationVectors[0].Rows, rotationVectors[0].Cols, rotationVectors[0].DataPointer);
 var translation = new Emgu.CV.Matrix<double>(translationVectors[0].Rows, translationVectors[0].Cols, translationVectors[0].DataPointer);

}

I have tried to solve it manuelly but it was too complicated. I hope to find a solution here in order to continue with my project.

This is the error I'm receiving any time I compiled the code.

Error message

0

There are 0 answers