Commit e017c2d2 for tesseract
commit e017c2d28e3bad5aaa15555f109af175b31792ff
Author: Stefan Weil <sw@weilnetz.de>
Date: Fri Nov 27 13:46:38 2026 +0100
Fix uninitialized value in ProjectiveCoeffs
The factor FN_INCOLOR, which selects white or black for the pixels
which do not exist in the source image, was never set, but the return
value of the function was derived from it.
Set it to a random value between 0 and 1 like the other factors,
without the scaling which is used for those.
This adds one random number for each call, so the distorted images
which are made for training differ from those of earlier versions.
g++ reported it with -Wall (-Wuninitialized).
Assisted-by: Claude Fable 5.2 (Anthropic)
Signed-off-by: Stefan Weil <sw@weilnetz.de>
diff --git a/src/training/degradeimage.cpp b/src/training/degradeimage.cpp
index 94e52d8e..bf040ed6 100644
--- a/src/training/degradeimage.cpp
+++ b/src/training/degradeimage.cpp
@@ -285,14 +285,16 @@ int ProjectiveCoeffs(int width, int height, TRand *randomizer, float **im_coeffs
shear = factors[FN_X1];
}
factors[i] = shear;
- } else if (i != FN_INCOLOR) {
+ } else {
factors[i] = fabs(randomizer->SignedRand(1.0));
- if (i <= FN_Y3) {
- factors[i] *= 5.0 / 8.0;
- } else {
- factors[i] *= 0.5;
+ if (i != FN_INCOLOR) {
+ if (i <= FN_Y3) {
+ factors[i] *= 5.0 / 8.0;
+ } else {
+ factors[i] *= 0.5;
+ }
+ factors[i] *= factors[i];
}
- factors[i] *= factors[i];
}
}
// Setup "to" points.