src/textord/imagefind.cpp
double ImageFind::ColorDistanceFromLine(const uint8_t *line1, const uint8_t *line2,
                                        const uint8_t *point) {
  int line_vector[kRGBRMSColors];
  int point_vector[kRGBRMSColors];
  for (int i = 0; i < kRGBRMSColors; ++i) {
    line_vector[i] = static_cast<int>(line2[i]) - static_cast<int>(line1[i]);
    point_vector[i] = static_cast<int>(point[i]) - static_cast<int>(line1[i]);
  }
  line_vector[L_ALPHA_CHANNEL] = 0;
  // Now the cross product in 3d.
  int cross[kRGBRMSColors];
  cross[COLOR_RED] = line_vector[COLOR_GREEN] * point_vector[COLOR_BLUE] -
                     line_vector[COLOR_BLUE] * point_vector[COLOR_GREEN];
  cross[COLOR_GREEN] = line_vector[COLOR_BLUE] * point_vector[COLOR_RED] -
                       line_vector[COLOR_RED] * point_vector[COLOR_BLUE];
  cross[COLOR_BLUE] = line_vector[COLOR_RED] * point_vector[COLOR_GREEN] -
                      line_vector[COLOR_GREEN] * point_vector[COLOR_RED];
  cross[L_ALPHA_CHANNEL] = 0;
  // Now the sums of the squares.
  double cross_sq = 0.0;
  double line_sq = 0.0;
  for (int j = 0; j < kRGBRMSColors; ++j) {
    cross_sq += static_cast<double>(cross[j]) * cross[j];
    line_sq += static_cast<double>(line_vector[j]) * line_vector[j];
  }
  if (line_sq == 0.0) {
    return 0.0;
  }
  return cross_sq / line_sq; // This is the squared distance.
}
// Given a point in 3-D (RGB) space, returns the squared Euclidean distance
// of the point from the given line, defined by a pair of points in the 3-D
// (RGB) space, line1 and line2.
Given a point in 3-D (RGB) space, returns the squared Euclidean distance
of the point from the given line, defined by a pair of points in the 3-D
(RGB) space, line1 and line2.
Given a point in 3 - D ( RGB ) space returns the squared Euclidean distance of the point from the given line defined by a pair of points in the 3 - D ( RGB ) space line1 and line2 .
double ImageFind::ColorDistanceFromLine(const uint8_t *line1, const uint8_t *line2,
                                        const uint8_t *point) {
  int line_vector[kRGBRMSColors];
  int point_vector[kRGBRMSColors];
  for (int i = 0; i < kRGBRMSColors; ++i) {
    line_vector[i] = static_cast<int>(line2[i]) - static_cast<int>(line1[i]);
    point_vector[i] = static_cast<int>(point[i]) - static_cast<int>(line1[i]);
  }
  line_vector[L_ALPHA_CHANNEL] = 0;
  int cross[kRGBRMSColors];
  cross[COLOR_RED] = line_vector[COLOR_GREEN] * point_vector[COLOR_BLUE] -
                     line_vector[COLOR_BLUE] * point_vector[COLOR_GREEN];
  cross[COLOR_GREEN] = line_vector[COLOR_BLUE] * point_vector[COLOR_RED] -
                       line_vector[COLOR_RED] * point_vector[COLOR_BLUE];
  cross[COLOR_BLUE] = line_vector[COLOR_RED] * point_vector[COLOR_GREEN] -
                      line_vector[COLOR_GREEN] * point_vector[COLOR_RED];
  cross[L_ALPHA_CHANNEL] = 0;
  double cross_sq = 0.0;
  double line_sq = 0.0;
  for (int j = 0; j < kRGBRMSColors; ++j) {
    cross_sq += static_cast<double>(cross[j]) * cross[j];
    line_sq += static_cast<double>(line_vector[j]) * line_vector[j];
  }
  if (line_sq == 0.0) {
    return 0.0;
  }
  return cross_sq / line_sq; 
}
double ImageFind :: ColorDistanceFromLine ( const uint8_t * line1 , const uint8_t * line2 , const uint8_t * point ) { int line_vector [ kRGBRMSColors ] ; int point_vector [ kRGBRMSColors ] ; for ( int i = 0 ; i < kRGBRMSColors ; ++ i ) { line_vector [ i ] = static_cast < int > ( line2 [ i ] ) - static_cast < int > ( line1 [ i ] ) ; point_vector [ i ] = static_cast < int > ( point [ i ] ) - static_cast < int > ( line1 [ i ] ) ; } line_vector [ L_ALPHA_CHANNEL ] = 0 ; int cross [ kRGBRMSColors ] ; cross [ COLOR_RED ] = line_vector [ COLOR_GREEN ] * point_vector [ COLOR_BLUE ] - line_vector [ COLOR_BLUE ] * point_vector [ COLOR_GREEN ] ; cross [ COLOR_GREEN ] = line_vector [ COLOR_BLUE ] * point_vector [ COLOR_RED ] - line_vector [ COLOR_RED ] * point_vector [ COLOR_BLUE ] ; cross [ COLOR_BLUE ] = line_vector [ COLOR_RED ] * point_vector [ COLOR_GREEN ] - line_vector [ COLOR_GREEN ] * point_vector [ COLOR_RED ] ; cross [ L_ALPHA_CHANNEL ] = 0 ; double cross_sq = 0.0 ; double line_sq = 0.0 ; for ( int j = 0 ; j < kRGBRMSColors ; ++ j ) { cross_sq += static_cast < double > ( cross [ j ] ) * cross [ j ] ; line_sq += static_cast < double > ( line_vector [ j ] ) * line_vector [ j ] ; } if ( line_sq == 0.0 ) { return 0.0 ; } return cross_sq / line_sq ; }
Given a point in 3-D (RGB) space, returns the squared Euclidean distance
of the point from the given line, defined by a pair of points in the 3-D
(RGB) space, line1 and line2.
Given a point in 3 - D ( RGB ) space returns the squared Euclidean distance of the point from the given line defined by a pair of points in the 3 - D ( RGB ) space line1 and line2 .
// Now the cross product in 3d. // Now the sums of the squares. // This is the squared distance.