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 <fvmodels/mirror/bulb.h> 32 #include <fvutils/base/types.h> 33 #include <utils/math/angle.h> 40 namespace firevision {
45 static void draw_line(
unsigned char *yuv_buffer,
58 void load_mask(
const char *mask_file_name);
59 void push_back(
const unsigned char *yuv_buffer,
size_t buflen,
int width,
int height,
double ori);
90 void eval(
unsigned int x,
unsigned int y,
float *x_ret,
float *y_ret);
92 void load(
const char *filename);
93 void save(
const char *filename);
98 typedef std::vector<StepResult> StepResultList;
101 class CartesianPoint;
102 class CartesianImage;
105 typedef std::vector<Hole> HoleList;
106 typedef double PolarAngle;
107 typedef int PolarRadius;
108 typedef int RealDistance;
109 typedef std::vector<PolarRadius> MarkList;
110 typedef std::map<PolarAngle, MarkList> MarkMap;
111 typedef std::pair<PolarAngle, PolarAngle> PolarAnglePair;
112 typedef std::vector<Image> ImageList;
114 class ConvexPolygon :
public std::vector<PixelPoint>
118 bool contains(
const CartesianImage &img,
const CartesianPoint &r)
const;
119 bool contains(
const PixelPoint &r)
const;
132 struct CalibrationState
135 ImageList::size_type image_index;
137 CalibrationState() : step(SHARPENING), image_index(0), centering_done(false){};
141 void goto_next_state();
142 void set_last_yuv_buffer(
const unsigned char *last_buf);
143 void draw_center(StepResult &result);
145 static PolarAngle relativeOrientationToImageRotation(PolarAngle ori);
146 static PolarAngle imageRotationToRelativeOrientation(PolarAngle ori);
149 apply_sobel(
unsigned char *src,
unsigned char *dst,
int widt,
int height, orientation_t ori);
150 static void apply_sharpen(
unsigned char *src,
unsigned char *dst,
int widt,
int height);
151 static void apply_median(
unsigned char *src,
unsigned char *dst,
int widt,
int height,
int i);
152 static void apply_min(
unsigned char *src,
unsigned char *dst,
int widt,
int height);
154 apply_or(
unsigned char *src1,
unsigned char *src2,
unsigned char *dst,
int widt,
int height);
155 static void make_contrast(
unsigned char *buf,
size_t buflen);
156 static void make_grayscale(
unsigned char *buf,
size_t buflen);
157 static MirrorCalibTool::MarkList premark(
const StepResult & prev,
158 const unsigned char *yuv_mask,
161 const PixelPoint & center);
162 static MirrorCalibTool::MarkList premark(
const ConvexPolygon &polygon,
163 const StepResult & prev,
164 const unsigned char *yuv_mask,
167 const PixelPoint & center);
168 static HoleList search_holes(
const MarkList &premarks);
169 static HoleList filter_biggest_holes(
const HoleList &holes,
unsigned int n);
170 static MarkList determine_marks(
const HoleList &holes);
171 static MarkList mark(
const MarkList & premarks,
172 const unsigned char *yuv_mask,
175 const PixelPoint & center);
177 static PixelPoint calculate_center(
const ImageList &images);
178 static RealDistance calculate_real_distance(
int n);
179 static PolarAnglePair find_nearest_neighbors(PolarAngle angle,
const MarkMap &mark_map);
180 static RealDistance interpolate(PolarRadius radius,
const MarkList &marks);
181 static Bulb generate(
int width,
int height,
const PixelPoint ¢er,
const MarkMap &mark_map);
183 unsigned char *img_yuv_buffer_;
186 unsigned char *img_yuv_mask_;
188 ImageList source_images_;
189 CalibrationState state_;
193 const unsigned char *last_yuv_buffer_;