24 #ifndef __FIREVISION_MODELS_MIRROR_MIRROR_CALIB_H_
25 #define __FIREVISION_MODELS_MIRROR_MIRROR_CALIB_H_
27 #if !defined(HAVE_IPP) and !defined(HAVE_OPENCV)
28 # error "Neither IPP nor OpenCV are installed."
31 #include <geometry/hom_point.h>
32 #include <utils/math/angle.h>
33 #include <fvutils/base/types.h>
35 #include <fvmodels/mirror/bulb.h>
47 static void draw_line(
unsigned char* yuv_buffer,
double angle_deg,
50 static void draw_crosshair(
unsigned char* yuv_buffer,
int center_x,
51 int center_y,
int width,
int height);
56 void load_mask(
const char* mask_file_name);
57 void push_back(
const unsigned char* yuv_buffer,
77 inline int center_x()
const {
return img_center_x_; }
80 inline int center_y()
const {
return img_center_y_; }
82 void eval(
unsigned int x,
87 void load(
const char* filename);
88 void save(
const char* filename);
93 typedef std::vector<StepResult> StepResultList;
100 typedef std::vector<Hole> HoleList;
101 typedef double PolarAngle;
102 typedef int PolarRadius;
103 typedef int RealDistance;
104 typedef std::vector<PolarRadius> MarkList;
105 typedef std::map<PolarAngle, MarkList> MarkMap;
106 typedef std::pair<PolarAngle, PolarAngle> PolarAnglePair;
107 typedef std::vector<Image> ImageList;
109 class ConvexPolygon :
public std::vector<PixelPoint> {
111 bool contains(
const CartesianImage& img,
const CartesianPoint& r)
const;
112 bool contains(
const PixelPoint& r)
const;
115 enum StepName { SHARPENING, EDGE_DETECTION, COMBINATION, CENTERING,
116 PRE_MARKING, FINAL_MARKING, DONE };
118 struct CalibrationState {
120 ImageList::size_type image_index;
123 : step(SHARPENING), image_index(0), centering_done(false) {};
127 void goto_next_state();
128 void set_last_yuv_buffer(
const unsigned char* last_buf);
129 void draw_center(StepResult& result);
132 static PolarAngle relativeOrientationToImageRotation(PolarAngle ori);
133 static PolarAngle imageRotationToRelativeOrientation(PolarAngle ori);
135 static void apply_sobel(
unsigned char* src,
unsigned char* dst,
136 int widt,
int height,
138 static void apply_sharpen(
unsigned char* src,
unsigned char* dst,
139 int widt,
int height);
140 static void apply_median(
unsigned char* src,
unsigned char* dst,
141 int widt,
int height,
int i);
142 static void apply_min(
unsigned char* src,
unsigned char* dst,
143 int widt,
int height);
144 static void apply_or(
unsigned char* src1,
unsigned char* src2,
145 unsigned char* dst,
int widt,
int height);
146 static void make_contrast(
unsigned char* buf,
size_t buflen);
147 static void make_grayscale(
unsigned char* buf,
size_t buflen);
148 static MirrorCalibTool::MarkList premark(
const StepResult& prev,
const unsigned char* yuv_mask,
149 StepResult& result, PolarAngle phi,
150 const PixelPoint& center);
151 static MirrorCalibTool::MarkList premark(
const ConvexPolygon& polygon,
const StepResult& prev,
152 const unsigned char* yuv_mask, StepResult& result,
153 PolarAngle phi,
const PixelPoint& center);
154 static HoleList search_holes(
const MarkList& premarks);
155 static HoleList filter_biggest_holes(
const HoleList& holes,
unsigned int n);
156 static MarkList determine_marks(
const HoleList& holes);
157 static MarkList mark(
const MarkList& premarks,
const unsigned char* yuv_mask,
158 StepResult& result, PolarAngle phi,
159 const PixelPoint& center);
161 static PixelPoint calculate_center(
const ImageList& images);
162 static RealDistance calculate_real_distance(
int n);
163 static PolarAnglePair find_nearest_neighbors(PolarAngle angle,
164 const MarkMap& mark_map);
165 static RealDistance interpolate(PolarRadius radius,
const MarkList& marks);
166 static Bulb generate(
int width,
int height,
167 const PixelPoint& center,
168 const MarkMap& mark_map);
170 unsigned char* img_yuv_buffer_;
173 unsigned char* img_yuv_mask_;
175 ImageList source_images_;
176 CalibrationState state_;
180 const unsigned char* last_yuv_buffer_;