Make proper use of minimum control line count

When using control lines for perspective correction, set the number of
vertical and horizontal lines to the proper values instead of
hard-coding them to 4. The minimum line count is set to 2 when using
control lines, and defaults to 4 when using fully-automatic correction.
This commit is contained in:
Lawrence Lee 2020-06-23 21:57:10 -07:00
parent 6c59f0586f
commit 9a40c14858
2 changed files with 13 additions and 10 deletions

View File

@ -2111,7 +2111,7 @@ static double model_fitness(double *params, void *data)
} }
// setup all data structures for fitting and call NM simplex // setup all data structures for fitting and call NM simplex
static dt_iop_ashift_nmsresult_t nmsfit(dt_iop_module_t *module, dt_iop_ashift_params_t *p, dt_iop_ashift_fitaxis_t dir) static dt_iop_ashift_nmsresult_t nmsfit(dt_iop_module_t *module, dt_iop_ashift_params_t *p, dt_iop_ashift_fitaxis_t dir, int min_line_count)
{ {
dt_iop_ashift_gui_data_t *g = (dt_iop_ashift_gui_data_t *)module->gui_data; dt_iop_ashift_gui_data_t *g = (dt_iop_ashift_gui_data_t *)module->gui_data;
@ -2227,7 +2227,7 @@ static dt_iop_ashift_nmsresult_t nmsfit(dt_iop_module_t *module, dt_iop_ashift_p
// we use vertical lines for fitting // we use vertical lines for fitting
fit.linetype |= ASHIFT_LINE_DIRVERT; fit.linetype |= ASHIFT_LINE_DIRVERT;
fit.weight += g->vertical_weight; fit.weight += g->vertical_weight;
enough_lines = enough_lines && (g->vertical_count >= MINIMUM_FITLINES); enough_lines = enough_lines && (g->vertical_count >= min_line_count);
} }
if(mdir & ASHIFT_FIT_LINES_HOR) if(mdir & ASHIFT_FIT_LINES_HOR)
@ -2235,7 +2235,7 @@ static dt_iop_ashift_nmsresult_t nmsfit(dt_iop_module_t *module, dt_iop_ashift_p
// we use horizontal lines for fitting // we use horizontal lines for fitting
fit.linetype |= 0; fit.linetype |= 0;
fit.weight += g->horizontal_weight; fit.weight += g->horizontal_weight;
enough_lines = enough_lines && (g->horizontal_count >= MINIMUM_FITLINES); enough_lines = enough_lines && (g->horizontal_count >= min_line_count);
} }
// this needs to come after ASHIFT_FIT_LINES_VERT and ASHIFT_FIT_LINES_HOR // this needs to come after ASHIFT_FIT_LINES_VERT and ASHIFT_FIT_LINES_HOR
@ -2905,7 +2905,7 @@ static int do_clean_structure(dt_iop_module_t *module, dt_iop_ashift_params_t *p
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
// helper function to start parameter fit and report about errors // helper function to start parameter fit and report about errors
static int do_fit(dt_iop_module_t *module, dt_iop_ashift_params_t *p, dt_iop_ashift_fitaxis_t dir) static int do_fit(dt_iop_module_t *module, dt_iop_ashift_params_t *p, dt_iop_ashift_fitaxis_t dir, int min_line_count = MINIMUM_FITLINES)
{ {
dt_iop_ashift_gui_data_t *g = (dt_iop_ashift_gui_data_t *)module->gui_data; dt_iop_ashift_gui_data_t *g = (dt_iop_ashift_gui_data_t *)module->gui_data;
dt_iop_ashift_nmsresult_t res; dt_iop_ashift_nmsresult_t res;
@ -2918,7 +2918,7 @@ static int do_fit(dt_iop_module_t *module, dt_iop_ashift_params_t *p, dt_iop_ash
g->fitting = 1; g->fitting = 1;
res = nmsfit(module, p, dir); res = nmsfit(module, p, dir, min_line_count);
switch(res) switch(res)
{ {
@ -3815,8 +3815,10 @@ void gui_post_expose(struct dt_iop_module_t *self, cairo_t *cr, int32_t width, i
cairo_restore(cr); cairo_restore(cr);
} }
#endif // if 0
//-----------------------------------------------------------------------------
update the number of selected vertical and horizontal lines // update the number of selected vertical and horizontal lines
static void update_lines_count(const dt_iop_ashift_line_t *lines, const int lines_count, static void update_lines_count(const dt_iop_ashift_line_t *lines, const int lines_count,
int *vertical_count, int *horizontal_count) int *vertical_count, int *horizontal_count)
{ {
@ -3835,6 +3837,9 @@ static void update_lines_count(const dt_iop_ashift_line_t *lines, const int line
*horizontal_count = hlines; *horizontal_count = hlines;
} }
//-----------------------------------------------------------------------------
// RT: BEGIN COMMENT
#if 0
int mouse_moved(struct dt_iop_module_t *self, double x, double y, double pressure, int which) int mouse_moved(struct dt_iop_module_t *self, double x, double y, double pressure, int which)
{ {
dt_iop_ashift_gui_data_t *g = (dt_iop_ashift_gui_data_t *)self->gui_data; dt_iop_ashift_gui_data_t *g = (dt_iop_ashift_gui_data_t *)self->gui_data;

View File

@ -356,10 +356,8 @@ PerspectiveCorrection::Params PerspectiveCorrection::autocompute(ImageSource *sr
g->lines = toAshiftLines(control_lines, control_lines_count); g->lines = toAshiftLines(control_lines, control_lines_count);
g->lines_in_height = fh; g->lines_in_height = fh;
g->lines_in_width = fw; g->lines_in_width = fw;
// A hack. update_lines_count(g->lines, g->lines_count, &(g->vertical_count), &(g->horizontal_count));
g->horizontal_count = 4; res = do_fit(&module, &p, fitaxis, 2);
g->vertical_count = 4;
res = do_fit(&module, &p, fitaxis);
} }
Params retval = { Params retval = {
.angle = p.rotation, .angle = p.rotation,