Пример #1
0
float Detector::sizeOfBlackWhiteBlackRunBothWays(int fromX, int fromY, int toX, int toY) {

    float result = sizeOfBlackWhiteBlackRun(fromX, fromY, toX, toY);

    // Now count other way -- don't run off image though of course
    float scale = 1.0f;
    int otherToX = fromX - (toX - fromX);
    if (otherToX < 0) {
      scale = (float) fromX / (float) (fromX - otherToX);
      otherToX = 0;
    } else if (otherToX >= (int)image_->getWidth()) {
      scale = (float) (image_->getWidth() - 1 - fromX) / (float) (otherToX - fromX);
      otherToX = image_->getWidth() - 1;
    }
    int otherToY = (int) (fromY - (toY - fromY) * scale);

    scale = 1.0f;
    if (otherToY < 0) {
      scale = (float) fromY / (float) (fromY - otherToY);
      otherToY = 0;
    } else if (otherToY >= (int)image_->getHeight()) {
      scale = (float) (image_->getHeight() - 1 - fromY) / (float) (otherToY - fromY);
      otherToY = image_->getHeight() - 1;
    }
    otherToX = (int) (fromX + (otherToX - fromX) * scale);

    result += sizeOfBlackWhiteBlackRun(fromX, fromY, otherToX, otherToY);

    // Middle pixel is double-counted this way; subtract 1
    return result - 1.0f;
}
Пример #2
0
 float Detector::sizeOfBlackWhiteBlackRunBothWays(int fromX, int fromY, 
                                                  int toX, int toY) {
   
   float result = sizeOfBlackWhiteBlackRun(fromX, fromY, toX, toY);
   
   // Now count other way -- don't run off image though of course
   size_t otherToX = fromX - (toX - fromX);
   if (otherToX >= image_->getWidth()) {
     otherToX = image_->getWidth();
   }
   size_t otherToY = fromY - (toY - fromY);
   if (otherToY >= image_->getHeight()) {
     otherToY = image_->getHeight();
   }
   result += sizeOfBlackWhiteBlackRun(fromX, fromY, otherToX, otherToY);
   return result - 1.0f; // -1 because we counted the middle pixel twice
 }