60 #include <opencv2/legacy/compat.hpp> 68 const CByteImage *pImage,
int nColumns,
int nRows,
float fSquareSize,
78 CvMemStorage *pStorage = cvCreateMemStorage();
80 CvPoint2D32f *pIplPoints =
new CvPoint2D32f[nColumns * nRows];
84 if (cvFindChessBoardCornerGuesses(pIplImage, pIplTempImage, pStorage,
85 cvSize(nColumns - 1, nRows - 1), pIplPoints, &nPoints) == 0 ||
86 nPoints != (nRows - 1) * (nColumns - 1))
89 cvReleaseImageHeader(&pIplImage);
90 cvReleaseImageHeader(&pIplTempImage);
91 cvReleaseMemStorage(&pStorage);
96 cvFindCornerSubPix(pIplImage, pIplPoints, nPoints,
97 cvSize(5, 5), cvSize(-1, -1),
98 cvTermCriteria(CV_TERMCRIT_ITER |CV_TERMCRIT_EPS, 10, 0.1));
104 CvPoint2D32f principalPoint;
105 float rotationVector[3];
106 float translationVector[3];
111 CvPoint3D32f *pIplObjectPoints = (CvPoint3D32f *) malloc(nPoints *
sizeof(CvPoint3D32f));
114 for (
int y = 0;
y < nRows - 1;
y++)
115 for (
int x = 0;
x < nColumns - 1;
x++, i++)
117 pIplObjectPoints[i].x = fSquareSize *
x;
118 pIplObjectPoints[i].y = fSquareSize *
y;
119 pIplObjectPoints[i].z = 0;
122 cvFindExtrinsicCameraParams(nPoints,
132 float rotationMatrix[9];
134 CvMat rmat = cvMat(3, 3, CV_32FC1, rotationMatrix);
135 CvMat rvec = cvMat(3, 1, CV_32FC1, rotationVector);
136 cvRodrigues(&rmat, &rvec, 0, CV_RODRIGUES_V2M);
141 Math3d::SetVec(translation, translationVector[0], translationVector[1], translationVector[2]);
144 rotation.
r1 = rotationMatrix[0];
145 rotation.
r2 = rotationMatrix[1];
146 rotation.
r3 = rotationMatrix[2];
147 rotation.
r4 = rotationMatrix[3];
148 rotation.
r5 = rotationMatrix[4];
149 rotation.
r6 = rotationMatrix[5];
150 rotation.
r7 = rotationMatrix[6];
151 rotation.
r8 = rotationMatrix[7];
152 rotation.
r9 = rotationMatrix[8];
155 for (i = 0; i < nPoints; i++)
159 cvReleaseImageHeader(&pIplImage);
160 cvReleaseImageHeader(&pIplTempImage);
161 cvReleaseMemStorage(&pStorage);
162 free(pIplObjectPoints);
163 delete [] pIplPoints;
171 Vec3d worldPoint0 = { 0, 0, 0 };
172 Vec3d worldPointX = { 2 * fSquareSize, 0, 0 };
173 Vec3d worldPointY = { 0, 2 * fSquareSize, 0 };
174 Vec2d imagePoint0, imagePointX, imagePointY;
185 if (pPoints && nPoints > 0)
190 for (
int i = 0; i < nPoints; i++)
193 hsv2rgb(
int(
float(i) / (nPoints - 1) * 240), 255, 255, r, g, b);
Struct containing all parameters of the camera model.
int width
The width of the image in pixels.
void hsv2rgb(int h, int s, int v, int &r, int &g, int &b)
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.
Data structure for the representation of a 3D vector.
Data structure for the representation of 8-bit grayscale images and 24-bit RGB (or HSV) color images ...
bool GetPointsAndTranslationAndRotation(const CCalibration *pCalibration, const CByteImage *pImage, int nColumns, int nRows, float fSquareSize, Vec2d *pPoints, Mat3d &rotation, Vec3d &translation)
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.
const CCameraParameters & GetCameraParameters() const
Gives access to the camera parameters.
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.
void DrawExtrinsic(CByteImage *pResultImage, const CCalibration *pCalibration, const Vec2d *pPoints, int nPoints, float fSquareSize)
int height
The height of the image in pixels.
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.
GLdouble GLdouble GLdouble r
Data structure for the representation of a 2D vector.
IplImage * Adapt(const CByteImage *pImage, bool bAllocateMemory=false)
Converts a CByteImage to an IplImage.
void SetVec(Vec2d &vec, float x, float y)
Data structure for the representation of a 3x3 matrix.
Camera model parameters and functions for a single camera.
void WorldToImageCoordinates(const Vec3d &worldPoint, Vec2d &imagePoint, bool bUseDistortionParameters=true) const
Transforms 3D world coordinates to 2D image coordinates.