ofxCV chessboard points

hi

i am working of the ofxcv example-ar file.
I am trying to get the coordinates for the corners of each chessboard square.

The problem is that toOf(objectPoints[i]) returns this and not actual x/y points:

0, 0 | 1, 0 | 2, 0 | 3, 0 | 4, 0 | 5, 0 | 6, 0 | 7, 0 | 8, 0 | 9, 0 |
0, 1 | 1, 1 | 2, 1 | 3, 1 | 4, 1 | 5, 1 | 6, 1 | 7, 1 | 8, 1 | 9, 1 |
0, 2 | 1, 2 | 2, 2 | 3, 2 | etc.

it has something todo with the modelMatrix. but what do i have to do to not just see the change but also get the points?

thx.

  
if(found) {  
		calibrationCam.getDistortedIntrinsics().loadProjectionMatrix();  
		applyMatrix(modelMatrix);  
  
		ofSetColor(255,0,0);  
		cornerPoints.clear();  
		for(int i = 0; i < objectPoints.size(); i++) {  
			cornerPoints.push_back(ofVec2f(toOf(objectPoints[i])));  
			cout<<ofVec2f(toOf(objectPoints[i]))<<endl;  
		}  
	}  
  

“object space” is in the object’s coordinates, so those are correct.

“image space” is the 2d image coordinates, which are probably not what you want.

“world space” is what you’re looking for, which is the object space plus translation and rotation.

to convert from object space to world space, you need to multiply by the modelMatrix. this should be as simple as:

  
  
ofVec3f worldPoint = modelMatrix * toOf(objectPoints[i]);  
  

but i might be forgetting something. give it a shot.

thanks for the fast reply.

this gives me these numbers. which don’t seem to make any sense.
i tried using ofMap to width and height of video image. but the points are still clustered together.

0, 0, 0 | -0.133226, -0.00468276, -0.00463665 | -0.142746, -0.00501739, -0.00496799 | -0.146229, -0.00513982, -0.00508922 | -0.148036, -0.00520331, -0.00515208 | -0.149141, -0.00524216, -0.00519054 | -0.149887, -0.00526838, -0.00521651 | -0.150424, -0.00528727, -0.00523521 | -0.15083, -0.00530153, -0.00524933 | -0.151147, -0.00531267, -0.00526036 | 0.0120084, -0.395755, 0.0546506 | -0.107651, -0.113933, 0.0113317 | -0.126972, -0.0684296, 0.0043374 | -0.134877, -0.0498109, 0.00147552 |

  
  
  
		cornerPoints.clear();  
		for(int i = 0; i < objectPoints.size(); i++) {  
			ofVec3f worldPoint = modelMatrix * toOf(objectPoints[i]);   
			  
			//worldPoint.x = ofMap(worldPoint.x, -1, 1, 0, 640);  
                       //worldPoint.y = ofMap(worldPoint.y, -1, 1, 0, 480);  
		  
			cornerPoints.push_back(worldPoint);  
			cout<<cornerPoints[cornerPoints.size()-1]<<"  |   ";  
		}  
  
  

ok turns out imagePoints is what i needed

  
ofSetColor(0,255,0);  
		ofFill();  
		for(int i = 0; i < imagePoints.size(); i++) {  
			ofCircle(640+imagePoints[i].x,imagePoints[i].y, 10);  
		}  

ok, so there’s one more step i thought we might be able to avoid. but let’s try it out.

  
  
ofVec4f worldPoint = modelMatrix * toOf(objectPoints[i]);  
ofVec3f homWorldPoint = ofVec3f(worldPoint) / worldPoint.w;  
cornerPoints.push_back(homWorldPoint);    
cout<<cornerPoints.back() <<"  |   ";    
  

notice that worldPoint is now an ofVec4f.

edit: aha! sorry, i thought since you were starting from example-ar that you wanted 3d coordinates instead of 2d.

sorry, did not clarify that. 2d is fine. it was the only example that kind of exposed how you dealt with the chessboard corners in a visual way.

thanks again.