JD2022-TU1/main/extern/Camcam/DLLInc/Fast2D.h

160 lines
No EOL
5.3 KiB
C++

// The following ifdef block is the standard way of creating macros which make exporting
// from a DLL simpler. All files within this DLL are compiled with the FAST2D_EXPORTS
// symbol defined on the command line. this symbol should not be defined on any project
// that uses this DLL. This way any other project whose source files include this file see
// FAST2D_API functions as being imported from a DLL, whereas this DLL sees symbols
// defined with this macro as being exported.
#ifndef ___FAST2D_H___
#define ___FAST2D_H___
//#define FAST2D_DLL_MODE
#ifdef FAST2D_DLL_MODE
#ifdef FAST2D_EXPORTS
#define FAST2D_API __declspec(dllexport)
#else
#define FAST2D_API __declspec(dllimport)
#endif
#else
#define FAST2D_API
#endif
/***********************************************/
/******* Need Math Library *********************/
#include "CCMath.h"
/******* Need MAP Library *********************/
#include "CCMap.h"
#define MAX_F2DT 1000
#define F2DT8Size 11
#define F2DT8Size1 9
#define F2DT8Size2 6
#define F2DTLevels 3
typedef struct FAST2DTRACKSTACK_
{
u32 Init;
s16 InitMap[F2DT8Size*F2DT8Size + F2DT8Size1*F2DT8Size1 + F2DT8Size2*F2DT8Size2];
float X,Y;
float Norm[F2DTLevels];
float LastError;
u32 Level;
} FAST2DTRACKSTACK;
#define DEFAULT_QFB_DX 5
#define DEFAULT_QFB_DY 5
#define MAX_QFB_DX 32
#define MAX_QFB_DY 32
#define MINIMALERRORDEFAULT 0.6f
#define PertinenceLimiteDownDefault 40.f
#define PertinenceBlend 0.6f
#define MAX_QFB (MAX_QFB_DX * MAX_QFB_DY)
#define TOLERANSAC_FIXE 7.0
#define TOLERANSAC_NOTFIXE 2.0
#define DISC_PIXEL (F2DT8Size - (F2DT8Size>>2))//3*F2DT8Size2)
#define MAX_FEATBOX 80
typedef struct Fast2DFeatureBox_
{
u32 TrackerID[MAX_QFB];
Vector FirstPos[MAX_QFB];
float ParticlesPonderation[MAX_QFB];
u32 IsInit;
float Pertinence;
float PertinenceLimiteDown;
float X,Y,W,H,SearchX,SearchY;
float YScale;
float XScale;
Vector LastMovesXYS;
float Rotation;
u32 DXSize,DYSize;
/* SettingParrams */
u8 ComputeScale:1;
u8 ComputeRotation:1;
u8 FixeMode:1;
u8 LearningMode:1;
u8 BigSearchBase:4;
u8 DontMoveMode:1;
u8 PausedMode:1;
u32 ulNumberOfParticules;
MATRIX LastTransforMatrix;
float MINIMALERROR;
float TOLERANCE;
} Fast2DFeatureBox;
// This class is exported from the Fast2D.dll
class FAST2D_API CFast2D {
public:
CFast2D(void);
// TODO: add your methods here.
u32 Compute(MAP *CurrentMap,u32 Option);
u32 Compute(MAP *CurrentMap,MAP16 *ZMap,u32 Option);
u32 CreateFeatureBox(u32 Index, s32 X,s32 Y,s32 W, s32 H, float Rotation);
u32 DestroyFeatureBox(u32 Index);
// Set option for FAST2D.
// "SCAL" for scale activation
// "TURN" for rotation activation
// "WIND" for set tracking radius outside featurebox
void FeatureBoxSetParam(u32 Index,char *String , float Value);
// Return moving vector (delta X,delta Y,delta SCALE).
// Sould be called after Compute
u32 FeatureBoxGetXYS(u32 Index,Vector *Result);
// Return Scale X and Y
// Sould be called after Compute
u32 FeatureBoxGetSXSY(u32 Index,Vector *Result);
// Return rotation angle
// Sould be called after Compute
u32 FeatureBoxGetRot(u32 Index,float *Result);
// Return quality of tracking between 0 and 1
float FeatureBoxGetPertinence(u32 Index);
// Return FULL MATRIX
MATRIX *FeatureBoxGetMatrix(u32 Index);
// process feature frame
u32 FeatureBoxFrame(MAP *DebugMap,u32 Only4Clear);
private:
static u32 FirstInit;
static MAP16 MWork[F2DTLevels];
static MAP16 MWork_Help[F2DTLevels];
static MAP16 MWork_Help2[F2DTLevels];
static FAST2DTRACKSTACK TRACKSTACK[MAX_F2DT];
static s32 LeveledSize[F2DTLevels];
static s32 LeveledDelta[F2DTLevels];
static Fast2DFeatureBox FB_Table[MAX_FEATBOX];
static u32 FB_init;
static void DoFirstInit();
private:
u32 New(float X ,float Y );
void Destroy(u32 Index);
float CopyData(MAP16 *WORKMAP, s16 *pDst , s32 X , s32 Y , u32 Size , u32 ModeMule = 0);
void CopyDataRGBA(MAP *WORKMAP, s16 *pDst , s32 X , s32 Y , u32 Size , float Factor);
void UpdateData(u32 Index,float MergeF = 0.0f);
void BuildOneTrackData(MAP16 *WORKMAP , FAST2DTRACKSTACK *pDt , s32 X ,s32 Y);
void ComputeTrack(u32 i,u32 BigSearch);
void ComputeTrack(MAP16 *WORKMAP , FAST2DTRACKSTACK *pTrack,u32 BigSearch = 0);
void Set(u32 ID, Vector *pResult);
u32 Get(u32 ID, Vector *pResult);
float GetError(u32 ID);
float GetNorm(u32 ID, u32 LVL);
s32 GetSign(MAP *CurrentMap);
// Feature
u32 EvaluateNumber(u8 *Valid , u32 ulNumber);
float EvaluateError(u8 *Valid , u32 ulNumber, const Vector *Lastpos , const Vector *Newpos , MATRIX *Matrix23 , float Threshold = 100000000.0f);
u32 ComputeGCXY(u8 *Valid , u32 ulNumber , const Vector *Positions , Vector *GCenter );
float ComputeGCScale(u8 *Valid , u32 ulNumber , const Vector *Lastpos , const Vector *Newpos , Vector *LastGC, Vector *NewGC , float *Scale , float *Angle);
void ComputeGCXYScale(u8 *Valid , u32 ulNumber , const Vector *Lastpos , const Vector *Newpos , Vector *YAxis,float *XScale,float *YScale);
float FeatureBoxRansac(u8 *Valid , u32 ulNumber , const Vector *LastPosition , const Vector *NewPosition , Vector *SpeedScaleDest , float *Rotation,Fast2DFeatureBox *pFB ,float LowLimit);
void FeatureBoxUpdateOne(u32 Index);
// void ComputeFullMatrix(u8 *Valid , u32 ulNumber , const Vector *Lastpos , const Vector *Newpos , Vector *LastGC, Vector *NewGC , float *Scale , float *Angle);
};
#endif