function offset($image, $a, $compare = 1, $page) { $b = array(); $c = array(); $d = array(); //temp only ? if (!isset($a['tlx']) && $compare == 1) { $c[0] = 0; $c[1] = 0; return $c; } //line edge detection $d[] = vertlinex($page['TL_VERT_TLX'], $page['TL_VERT_TLY'], $page['TL_VERT_BRX'], $page['TL_VERT_BRY'], $image, $page['VERT_WIDTH_BOX'], int_divide($page['VERT_WIDTH_BOX'], 10), 50, false); $d[] = horiliney($page['TL_HORI_TLX'], $page['TL_HORI_TLY'], $page['TL_HORI_BRX'], $page['TL_HORI_BRY'], $image, $page['HORI_WIDTH_BOX'], int_divide($page['HORI_WIDTH_BOX'], 10), 50, false); $d[] = vertlinex($page['TR_VERT_TLX'], $page['TR_VERT_TLY'], $page['TR_VERT_BRX'], $page['TR_VERT_BRY'], $image, $page['VERT_WIDTH_BOX'], int_divide($page['VERT_WIDTH_BOX'], 10), 50, false); $d[] = horiliney($page['TR_HORI_TLX'], $page['TR_HORI_TLY'], $page['TR_HORI_BRX'], $page['TR_HORI_BRY'], $image, $page['HORI_WIDTH_BOX'], int_divide($page['HORI_WIDTH_BOX'], 10), 50, false); $d[] = vertlinex($page['BL_VERT_TLX'], $page['BL_VERT_TLY'], $page['BL_VERT_BRX'], $page['BL_VERT_BRY'], $image, $page['VERT_WIDTH_BOX'], int_divide($page['VERT_WIDTH_BOX'], 10), 50, false); $d[] = horiliney($page['BL_HORI_TLX'], $page['BL_HORI_TLY'], $page['BL_HORI_BRX'], $page['BL_HORI_BRY'], $image, $page['HORI_WIDTH_BOX'], int_divide($page['HORI_WIDTH_BOX'], 10), 50, false); $d[] = vertlinex($page['BR_VERT_TLX'], $page['BR_VERT_TLY'], $page['BR_VERT_BRX'], $page['BR_VERT_BRY'], $image, $page['VERT_WIDTH_BOX'], int_divide($page['VERT_WIDTH_BOX'], 10), 50, false); $d[] = horiliney($page['BR_HORI_TLX'], $page['BR_HORI_TLY'], $page['BR_HORI_BRX'], $page['BR_HORI_BRY'], $image, $page['HORI_WIDTH_BOX'], int_divide($page['HORI_WIDTH_BOX'], 10), 50, false); //check to see how many are 0 - if none are - proceed, otherwise try for box //edge detection // $boxerrors = 0; foreach ($d as $bb) { if ($bb == 0) { $boxerrors++; } } if ($boxerrors > 0) { //try box edge detection $b[] = vertlinex($page['TL_VERT_TLX'], $page['TL_VERT_TLY'], $page['TL_VERT_BRX'], $page['TL_VERT_BRY'], $image, $page['VERT_WIDTH'], int_divide($page['VERT_WIDTH'], 3)); $b[] = horiliney($page['TL_HORI_TLX'], $page['TL_HORI_TLY'], $page['TL_HORI_BRX'], $page['TL_HORI_BRY'], $image, $page['HORI_WIDTH'], int_divide($page['HORI_WIDTH'], 3)); $b[] = vertlinex($page['TR_VERT_TLX'], $page['TR_VERT_TLY'], $page['TR_VERT_BRX'], $page['TR_VERT_BRY'], $image, $page['VERT_WIDTH'], int_divide($page['VERT_WIDTH'], 3)); $b[] = horiliney($page['TR_HORI_TLX'], $page['TR_HORI_TLY'], $page['TR_HORI_BRX'], $page['TR_HORI_BRY'], $image, $page['HORI_WIDTH'], int_divide($page['HORI_WIDTH'], 3)); $b[] = vertlinex($page['BL_VERT_TLX'], $page['BL_VERT_TLY'], $page['BL_VERT_BRX'], $page['BL_VERT_BRY'], $image, $page['VERT_WIDTH'], int_divide($page['VERT_WIDTH'], 3)); $b[] = horiliney($page['BL_HORI_TLX'], $page['BL_HORI_TLY'], $page['BL_HORI_BRX'], $page['BL_HORI_BRY'], $image, $page['HORI_WIDTH'], int_divide($page['HORI_WIDTH'], 3)); $b[] = vertlinex($page['BR_VERT_TLX'], $page['BR_VERT_TLY'], $page['BR_VERT_BRX'], $page['BR_VERT_BRY'], $image, $page['VERT_WIDTH'], int_divide($page['VERT_WIDTH'], 3)); $b[] = horiliney($page['BR_HORI_TLX'], $page['BR_HORI_TLY'], $page['BR_HORI_BRX'], $page['BR_HORI_BRY'], $image, $page['HORI_WIDTH'], int_divide($page['HORI_WIDTH'], 3)); $lineerrors = 0; foreach ($b as $bb) { if ($bb == 0) { $lineerrors++; } } //check which one has the least number of errors if ($lineerrors < $boxerrors) { $d = $b; } } if ($compare == 0) { return $d; } $xa = 0; $xb = 0; $xc = 0; $ya = 0; $yb = 0; $yc = 0; if ($b[0] != 0) { $xa += $a['tlx']; $xb += $b[0]; $xc++; } else { return false; } if ($b[2] != 0) { $xa += $a['trx']; $xb += $b[2]; $xc++; } else { return false; } if ($b[4] != 0) { $xa += $a['blx']; $xb += $b[4]; $xc++; } else { return false; } if ($b[6] != 0) { $xa += $a['brx']; $xb += $b[6]; $xc++; } else { return false; } if ($b[1] != 0) { $ya += $a['tly']; $yb += $b[1]; $yc++; } else { return false; } if ($b[3] != 0) { $ya += $a['try']; $yb += $b[3]; $yc++; } else { return false; } if ($b[5] != 0) { $ya += $a['bly']; $yb += $b[5]; $yc++; } else { return false; } if ($b[7] != 0) { $ya += $a['bry']; $yb += $b[7]; $yc++; } else { return false; } $c[0] = round($xb / $xc) - round($xa / $xc); $c[1] = round($yb / $yc) - round($ya / $yc); return $c; }
function offset($image, $a, $compare = 1, $page) { $b = array(); $c = array(); //temp only ? if (!isset($a['tlx']) && $compare == 1) { $c[0] = 0; $c[1] = 0; return $c; } $b[] = vertlinex($page['TL_VERT_TLX'], $page['TL_VERT_TLY'], $page['TL_VERT_BRX'], $page['TL_VERT_BRY'], $image, $page['VERT_WIDTH']); $b[] = horiliney($page['TL_HORI_TLX'], $page['TL_HORI_TLY'], $page['TL_HORI_BRX'], $page['TL_HORI_BRY'], $image, $page['HORI_WIDTH']); $b[] = vertlinex($page['TR_VERT_TLX'], $page['TR_VERT_TLY'], $page['TR_VERT_BRX'], $page['TR_VERT_BRY'], $image, $page['VERT_WIDTH']); $b[] = horiliney($page['TR_HORI_TLX'], $page['TR_HORI_TLY'], $page['TR_HORI_BRX'], $page['TR_HORI_BRY'], $image, $page['HORI_WIDTH']); $b[] = vertlinex($page['BL_VERT_TLX'], $page['BL_VERT_TLY'], $page['BL_VERT_BRX'], $page['BL_VERT_BRY'], $image, $page['VERT_WIDTH']); $b[] = horiliney($page['BL_HORI_TLX'], $page['BL_HORI_TLY'], $page['BL_HORI_BRX'], $page['BL_HORI_BRY'], $image, $page['HORI_WIDTH']); $b[] = vertlinex($page['BR_VERT_TLX'], $page['BR_VERT_TLY'], $page['BR_VERT_BRX'], $page['BR_VERT_BRY'], $image, $page['VERT_WIDTH']); $b[] = horiliney($page['BR_HORI_TLX'], $page['BR_HORI_TLY'], $page['BR_HORI_BRX'], $page['BR_HORI_BRY'], $image, $page['HORI_WIDTH']); if ($compare == 0) { return $b; } $xa = 0; $xb = 0; $xc = 0; $ya = 0; $yb = 0; $yc = 0; if ($b[0] != 0) { $xa += $a['tlx']; $xb += $b[0]; $xc++; } else { return false; } if ($b[2] != 0) { $xa += $a['trx']; $xb += $b[2]; $xc++; } else { return false; } if ($b[4] != 0) { $xa += $a['blx']; $xb += $b[4]; $xc++; } else { return false; } if ($b[6] != 0) { $xa += $a['brx']; $xb += $b[6]; $xc++; } else { return false; } if ($b[1] != 0) { $ya += $a['tly']; $yb += $b[1]; $yc++; } else { return false; } if ($b[3] != 0) { $ya += $a['try']; $yb += $b[3]; $yc++; } else { return false; } if ($b[5] != 0) { $ya += $a['bly']; $yb += $b[5]; $yc++; } else { return false; } if ($b[7] != 0) { $ya += $a['bry']; $yb += $b[7]; $yc++; } else { return false; } $c[0] = round($xb / $xc) - round($xa / $xc); $c[1] = round($yb / $yc) - round($ya / $yc); return $c; }