69 const CByteImage *pImage,
int nColumns,
int nRows,
float fSquareSize,
79 CvMemStorage *pStorage = cvCreateMemStorage();
81 CvPoint2D32f *pIplPoints =
new CvPoint2D32f[nColumns * nRows];
85 if (cvFindChessBoardCornerGuesses(pIplImage, pIplTempImage, pStorage,
86 cvSize(nColumns - 1, nRows - 1), pIplPoints, &nPoints) == 0 ||
87 nPoints != (nRows - 1) * (nColumns - 1))
90 cvReleaseImageHeader(&pIplImage);
91 cvReleaseImageHeader(&pIplTempImage);
92 cvReleaseMemStorage(&pStorage);
97 cvFindCornerSubPix(pIplImage, pIplPoints, nPoints,
98 cvSize(5, 5), cvSize(-1, -1),
99 cvTermCriteria(CV_TERMCRIT_ITER |CV_TERMCRIT_EPS, 10, 0.1));
105 CvPoint2D32f principalPoint;
106 float rotationVector[3];
107 float translationVector[3];
112 CvPoint3D32f *pIplObjectPoints = (CvPoint3D32f *) malloc(nPoints *
sizeof(CvPoint3D32f));
115 for (
int y = 0; y < nRows - 1; y++)
116 for (
int x = 0; x < nColumns - 1; x++, i++)
118 pIplObjectPoints[i].x = fSquareSize * x;
119 pIplObjectPoints[i].y = fSquareSize * y;
120 pIplObjectPoints[i].z = 0;
123 cvFindExtrinsicCameraParams(nPoints,
133 float rotationMatrix[9];
135 CvMat rmat = cvMat(3, 3, CV_32FC1, rotationMatrix);
136 CvMat rvec = cvMat(3, 1, CV_32FC1, rotationVector);
137 cvRodrigues(&rmat, &rvec, 0, CV_RODRIGUES_V2M);
142 Math3d::SetVec(translation, translationVector[0], translationVector[1], translationVector[2]);
145 rotation.
r1 = rotationMatrix[0];
146 rotation.
r2 = rotationMatrix[1];
147 rotation.
r3 = rotationMatrix[2];
148 rotation.
r4 = rotationMatrix[3];
149 rotation.
r5 = rotationMatrix[4];
150 rotation.
r6 = rotationMatrix[5];
151 rotation.
r7 = rotationMatrix[6];
152 rotation.
r8 = rotationMatrix[7];
153 rotation.
r9 = rotationMatrix[8];
156 for (i = 0; i < nPoints; i++)
160 cvReleaseImageHeader(&pIplImage);
161 cvReleaseImageHeader(&pIplTempImage);
162 cvReleaseMemStorage(&pStorage);
163 free(pIplObjectPoints);
164 delete [] pIplPoints;
172 Vec3d worldPoint0 = { 0, 0, 0 };
173 Vec3d worldPointX = { 2 * fSquareSize, 0, 0 };
174 Vec3d worldPointY = { 0, 2 * fSquareSize, 0 };
175 Vec2d imagePoint0, imagePointX, imagePointY;
186 if (pPoints && nPoints > 0)
191 for (
int i = 0; i < nPoints; i++)
194 hsv2rgb(
int(
float(i) / (nPoints - 1) * 240), 255, 255, r, g, b);
Data structure for the representation of a 2D vector.
void hsv2rgb(int h, int s, int v, int &r, int &g, int &b)
void WorldToImageCoordinates(const Vec3d &worldPoint, Vec2d &imagePoint, bool bUseDistortionParameters=true) const
Transforms 3D world coordinates to 2D image coordinates.
bool ConvertImage(const CByteImage *pInputImage, CByteImage *pOutputImage, bool bFast=false, const MyRegion *pROI=0)
Converts a grayscale CByteImage to an RGB CByteImage image and vice versa.
IplImage * Adapt(const CByteImage *pImage, bool bAllocateMemory=false)
Converts a CByteImage to an IplImage.
const CCameraParameters & GetCameraParameters() const
Gives access to the camera parameters.
bool GetPointsAndTranslationAndRotation(const CCalibration *pCalibration, const CByteImage *pImage, int nColumns, int nRows, float fSquareSize, Vec2d *pPoints, Mat3d &rotation, Vec3d &translation)
void PutText(CByteImage *pImage, const char *pText, double x, double y, double scale_x, double scale_y, int r=255, int g=255, int b=255, int thickness=1)
Draws text into a CByteImage.
int width
The width of the image in pixels.
int height
The height of the image in pixels.
Data structure for the representation of a 3D vector.
Camera model parameters and functions for a single camera.
void DrawLine(CByteImage *pImage, const PointPair2d &line, int r=255, int g=255, int b=255, int thickness=1)
Draws a line segment into a CByteImage, given its two end points.
void DrawExtrinsic(CByteImage *pResultImage, const CCalibration *pCalibration, const Vec2d *pPoints, int nPoints, float fSquareSize)
Data structure for the representation of a 3x3 matrix.
Data structure for the representation of 8-bit grayscale images and 24-bit RGB (or HSV) color images ...
void SetVec(Vec2d &vec, float x, float y)
void SetVec(Vec3d &vec, float x, float y, float z)
void DrawCircle(CByteImage *pImage, float mx, float my, float radius, int r=255, int g=255, int b=255, int thickness=1, bool bAntiAlias=false)
Draws a circle into a CByteImage.
Struct containing all parameters of the camera model.