summaryrefslogtreecommitdiff
path: root/ARMFCaptureD3D/ARAnalyse.h
blob: 0d8a61b6174688a2a8f7646f477eb86dab9c10a9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143

#pragma once
#include <cstdio>
#include <map>
#include <vector>
#include <set>
#include <ARToolKitPlus/TrackerMultiMarker.h>
#include <Ivy.h>
#include "Calibration.h"
#include "MinMaxAvg.h"

using ARToolKitPlus::TrackerMultiMarker;
#pragma comment (lib, "ARToolKitPlus.lib")

class MyMakerInfo
{
public:
	int id;
	ARFloat confidence;
	ARFloat x;
	ARFloat y;
	int area;
	int dir;
	ARFloat prev_matrix[3][4];
	int absent; // count of marker absence if > 10 ==> remove
	double time;
};

class ARAnalyse 
{
public:
	ARAnalyse();
	~ARAnalyse();
	bool	InitialiseTracker( int width, int height, int sample_size);
	void	Transform( unsigned char * cameraBuffer, int size, bool moyen );
	void	Analyse( double SampleTime, const unsigned char * cameraBuffer, int size );
	bool	Calibrate();
	void SaveCalibration();
	void RestoreCalibration();

	bool	IsCalibrationEnabled()
	{
		return m_calibration_enabled;
	}
	bool	IsCalibrated()
	{
		return m_calibrated;
	}
	void IvyInit(const char *domain);
	typedef std::map<int, MyMakerInfo> MarkersMap;
	MarkersMap markers;
	ARToolKitPlus::ARMarkerInfo getDetectedMarker(int i)
	{
		return m_tracker->getDetectedMarker(i);
	}
	const ARFloat* getModelViewMatrix() const
	{
		return m_tracker->getModelViewMatrix();
	}
	const ARFloat* getProjectionMatrix() const
	{
		return m_tracker->getProjectionMatrix();
	}
	bool ToggleAutoThreshold();
	void setThreshold( int thr )
	{
		if ( ! m_tracker->isAutoThresholdActivated() )
				m_tracker->setThreshold( thr );
	}
	int getThreshold()
	{
		return m_tracker->getThreshold();
	}
	bool IsCalibrationID( int id );
	MinMaxAvg confidence;
	MinMaxAvg frame_per_seconds;
	MinMaxAvg frame_delay;

	int DownSample;
	int BlurPass;
	typedef enum { GrayScale, Blur, Diff, Threshold, Moyen } DisplayType;
	typedef enum {	FMoyen, FLaplacien4, FLaplacien8, FLaplaciend, FSobel, FPrewitt, FGaussian } FilterType;
	
	DisplayType Display;
	FilterType filter;

protected:
	// Ivy;
	Ivy*		bus;
	char *		camera;
	// For calibration Process
	std::set<int> m_calibration_ids;
    std::map<int,Calibration::Corners> m_IdToCorner;
	Calibration *m_calibration;
	bool m_calibrated;

	bool m_calibration_enabled;
	bool first_calibration_done;

	TrackerMultiMarker		*m_tracker;      // Manages ARToolkit tracker

	int m_width, m_height; // image size
	int nb_pixel;
	
	typedef float pixel_type;
	typedef float value_type;
	pixel_type *m_gray;
	pixel_type *m_blur0;
	pixel_type *m_blur1;
	pixel_type *m_filter_v;
	pixel_type *m_filter_h;

	// filtre moyen sur plusieurs images
	void CalcMoyen();

	void DisplayGrayScale(unsigned char * cameraBuffer, pixel_type * dest);
	void DisplayBlur(unsigned char * cameraBuffer, pixel_type * dest);
	void DisplayDiff(unsigned char * cameraBuffer, pixel_type * dest);
	void DisplayThreshold(unsigned char * cameraBuffer, pixel_type * dest);
	void DisplayMoyen(unsigned char * cameraBuffer, pixel_type * dest);
	void Filter ( const float *k, int k_size, pixel_type *src, pixel_type *dst );
	
	void CombineFilter ( pixel_type *src_h, pixel_type *src_v, pixel_type *dst );
	
	float *m_sum;
	pixel_type **m_images;
	int m_first_image;
	int m_last_image;
	int nb_images;

	long FrameCount;
	double MarkerWidth;
	ARToolKitPlus::MARKER_MODE MarkerType;
	std::string CameraParameterFile;
	std::string MarkerSetConfigFile;
	std::string CalibrationFile;
	double MarkerMoveThreshold;
	int MarkerSeekingThreshold;
	float MarkerBorderPercentage;
	int MarkerAbsenceCount;


};