Matrix data

118 views
Skip to first unread message

AKA

unread,
May 7, 2012, 10:43:02 AM5/7/12
to android...@googlegroups.com

I'm trying to code the camera clibration for an android application and when I use the opencv method

 
Calib3d.findChessboardCorner(mImage, boardSize, pointbuf,Calib3d.CALIB_CB_ADAPTIVE_THRESH & Calib3d.CALIB_CB_FAST_CHECK & Calib3d.CALIB_CB_NORMALIZE_IMAGE);
it returns pointbuf which is a 1*40 matrix (40 because my chessboard is 8*5) in each element of this matrix there's a data array with the 80 coordinates (x,y) for each of the 40 points. Don't ask me why, I didn't write this fonction.
 
in order to create the matrix containing the 3d coordinates of these same points I needed to create the same type of matrix, exept that the data array will have 120 elements(x,y,z) for each of the 40 points. My problem is that i create a data array, I put the coordinates in it and then when I call data.put(i,j,data) to add this array to the matrix it only copies the 8 first elements. here's the code for the method that does this :
 

static
Mat calcChessboardCorners(Size boardSize, float squareSize){

int put;

double n=boardSize.width*boardSize.height;

Mat corners=

new Mat(40,1,CvType.CV_32F);

 

int k=0;

float [] data = new float[120];

for( int i = 0; i < boardSize.width; i++ ){

for( int j = 0; j < boardSize.height; j++ ){

data[k]=(

float)i*squareSize;

data[k+1]=(

float)j*squareSize;

 

k+=3;

}

}

float [] data1=new float [120];

for (int l=0;l<n;l++){

put =corners.put(l, 0, data);

 

}

return corners;

}

  

peppschmier

unread,
May 9, 2012, 4:34:48 AM5/9/12
to android...@googlegroups.com
Here are my functions to calculate the object points:

mImagePoints: List<Mat> output from findChessboardCorners
mObjectPoints: List<Mat> (should be the same for every detected chessboard image as long as it does not change)

private Mat CalcChessboardCorners(){
List<Point3> corners = new Vector<Point3>();
for(int i = 0; i<mBoardSize.height; i++)
for(int j = 0; j<mBoardSize.width; j++){
corners.add(new Point3((float)(i*mSquareSize),(float)(j*mSquareSize),0.0f));
}
Mat ret = Converters.vector_Point3f_to_Mat(corners);
return ret;
}

private void CalcObjectPoints(){
mObjectPoints = new Vector<Mat>();
mObjectPoints.add(CalcChessboardCorners());
for(int i = 1; i<mImagePoints.size(); ++i){
mObjectPoints.add(mObjectPoints.get(0));
}
}

AKA

unread,
May 9, 2012, 4:49:00 AM5/9/12
to android...@googlegroups.com
thanks a lot :) 

AKA

unread,
May 9, 2012, 5:44:57 AM5/9/12
to android...@googlegroups.com
This seems to have worked but I know get a problem when I use
Calib3d.projectPoints(objectPoints.get(i), rMat, tMat,cameraMatrix, distCoeffs, imagePoints2);
I get this error : All the matrices should have the same data type in function cvRodrigues(const cvMat*,cvMat*,cvMat*)
At first I had initialized imagePoints2 as a Mat(1,40,CV_32F), I tried changing it as I thought maybe I was having the same problem as above so I created a list of Point all 40 equal to 0.0f and then converted it using vector_point2f_to Mat. I still get the error and when I check the data types for objectPoints(i) and imagePoints2 using elemSize1() I get 4 which is CV_32S when I want CV_32F.Any ideas of what i'm doing wrong? thanks a lot for your help,
 

peppschmier

unread,
May 9, 2012, 6:54:33 AM5/9/12
to android...@googlegroups.com
Try this:

Mat imagePoints2 = new Mat();

Calib3d.projectPoints(........,imagePoints2);

imagePoints should be an Output array - in most cases OpenCV allocates the correct
size and type by itself. If this isn't the solution it could be also a type-mismatch witch
the other matrices (rotation, translation, intrinsic, distortion...).

AKA

unread,
May 14, 2012, 10:34:44 AM5/14/12
to android...@googlegroups.com
thanks it was just a type mismatch with the rotation and translation matrices it works now :D
Reply all
Reply to author
Forward
0 new messages