GrabBag/Module/ChessboardDetector/Inc/IChessboardDetector.h

163 lines
4.6 KiB
C
Raw Permalink Normal View History

2026-02-18 15:11:41 +08:00
#ifndef ICHESSBOARDDETECTOR_H
#define ICHESSBOARDDETECTOR_H
#include <vector>
/**
* @brief 2D
*/
struct Point2D
{
double x;
double y;
Point2D() : x(0.0), y(0.0) {}
Point2D(double _x, double _y) : x(_x), y(_y) {}
};
/**
* @brief 3D
*/
struct Point3D
{
double x;
double y;
double z;
Point3D() : x(0.0), y(0.0), z(0.0) {}
Point3D(double _x, double _y, double _z) : x(_x), y(_y), z(_z) {}
};
/**
* @brief
*/
struct ChessboardDetectResult
{
bool detected; // 是否检测到标定板
std::vector<Point2D> corners; // 角点坐标(图像坐标系)
int patternWidth; // 标定板内角点宽度
int patternHeight; // 标定板内角点高度
// 位姿信息(如果提供了相机内参)
bool hasPose; // 是否计算了位姿
Point3D center; // 标定板中心位置相机坐标系单位mm
Point3D normal; // 标定板法向量(单位向量)
double rvec[3]; // 旋转向量
double tvec[3]; // 平移向量
double rotationMatrix[9]; // 旋转矩阵 (3x3)
double eulerAngles[3]; // 欧拉角 (roll, pitch, yaw) 单位:度
ChessboardDetectResult()
: detected(false)
, patternWidth(0)
, patternHeight(0)
, hasPose(false)
{
for (int i = 0; i < 3; i++) {
rvec[i] = 0.0;
tvec[i] = 0.0;
eulerAngles[i] = 0.0;
}
for (int i = 0; i < 9; i++) {
rotationMatrix[i] = 0.0;
}
}
};
/**
* @brief
*/
struct CameraIntrinsics
{
double fx; // 焦距 x
double fy; // 焦距 y
double cx; // 主点 x
double cy; // 主点 y
double k1, k2, p1, p2, k3; // 畸变系数
CameraIntrinsics()
: fx(1000.0), fy(1000.0)
, cx(640.0), cy(480.0)
, k1(0.0), k2(0.0), p1(0.0), p2(0.0), k3(0.0)
{}
};
/**
* @brief
*/
class IChessboardDetector
{
public:
virtual ~IChessboardDetector() = default;
/**
* @brief
* @param imageData
* @param width
* @param height
* @param channels (1=, 3=BGR)
* @param patternWidth
* @param patternHeight
* @param result
* @return 0
*/
virtual int DetectChessboard(
const unsigned char* imageData,
int width,
int height,
int channels,
int patternWidth,
int patternHeight,
ChessboardDetectResult& result) = 0;
/**
* @brief 姿
* @param imageData
* @param width
* @param height
* @param channels
* @param patternWidth
* @param patternHeight
* @param squareSize mm
* @param intrinsics
* @param result 姿
* @return 0
*/
virtual int DetectChessboardWithPose(
const unsigned char* imageData,
int width,
int height,
int channels,
int patternWidth,
int patternHeight,
double squareSize,
const CameraIntrinsics& intrinsics,
ChessboardDetectResult& result) = 0;
/**
* @brief
* @param adaptiveThresh 使
* @param normalizeImage
* @param filterQuads
* @return 0
*/
virtual int SetDetectionFlags(
bool adaptiveThresh,
bool normalizeImage,
bool filterQuads) = 0;
};
/**
* @brief
* @return
*/
IChessboardDetector* CreateChessboardDetectorInstance();
/**
* @brief
* @param instance
*/
void DestroyChessboardDetectorInstance(IChessboardDetector* instance);
#endif // ICHESSBOARDDETECTOR_H