-
Notifications
You must be signed in to change notification settings - Fork 9.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
text2image segmentation fault on macOS ( regression #195?) #736
Comments
Here is the source for the regression: |
It also affects 4.00. |
@atuyosi, please try my patch: |
Hi @amitdo Thanks for your quick response. I tried your patch, but same result.
try patched binary:
|
Try to manually set the environment variable |
No error occurred. It looks work. It seems to be working.
But macOS's Preview.app can't open this tif file (although Gimp can open this file ). |
I tried to run
Note: I replaced |
It should also work without my patch. The patch was supposed to programmatically set the said environment variable. Since you reported it did not work, I asked you to do it manually. The call to the |
thank you amitdo. it fixed my problem too~~ |
Got the same problem on MAC OSX 10.13.3 using tessercat 4.0.0-beta.1, fixed it using the |
Can you please check my new patch? Don't set the environment variable |
Instead of setting |
@stweil, your suggested method looks simpler. Please make a PR. |
Is this issue still valid? If yes can we get this modification to 4.0 finale release? |
I don't have a Mac, but we didn't done anything to fix this issue. |
@zdenop It has not fixed (4.0.0-beta.4-164-g5dfce). It is still necessary to set environment variables |
Can you please check if 345e5ee solve the problem? |
@zdenop , I tested 345e5ee. No error occurred. It's OK.
Software Version:
|
I have to revert this patch because of side effects. Other solution should be found or implemented... |
@atuyosi: can you please try get the latest code and post output of |
I have ready something like this: diff --git a/src/training/text2image.cpp b/src/training/text2image.cpp
index 1142bb68..3e2b8a23 100644
--- a/src/training/text2image.cpp
+++ b/src/training/text2image.cpp
@@ -50,6 +50,9 @@
#include "tlog.h"
#include "unicharset.h"
#include "util.h"
+#ifdef __APPLE__
+# include "TargetConditionals.h"
+#endif
// A number with which to initialize the random number generator.
const int kRandomSeed = 0x18273645;
@@ -689,5 +692,19 @@ int main(int argc, char** argv) {
}
}
tesseract::ParseCommandLineFlags(argv[0], &argc, &argv, true);
+#ifdef TARGET_OS_MAC
+ // Respect enviroment variable. could be:
+ // fc (fontconfig), win32, and coretext
+ // If not set force fontconfig for Mac OS.
+ // See https://github.com/tesseract-ocr/tesseract/issues/736
+ char* backend;
+ backend = getenv("PANGOCAIRO_BACKEND");
+ if (backend == NULL) {
+ putenv("PANGOCAIRO_BACKEND=fc");
+ } else {
+ printf("Using '%s' as pango cairo backend based on enviroment "
+ "variable.\n", backend);
+ }
+#endif
return Main();
} Maybe we can implement it as option |
text2image's code needs the 'fc' backend on linux and mac. |
@amitdo : code you quoted means that program will accept what user will set (intentionally). This will give user option to choose backend (in case of new backend or fix for actual) I have possibility to test it (just sort text - not whole training) on linux and windows:
|
@tfmorris : Can you please test this ('text2image -v' and patch above?)? |
Linux always uses 'fc'. Originally Windows had the same issue: This patch fixed the crash on windows & mac: but Ray partly reverted it, so it is only compiled for win32 and not on linux or mac. Although the workaround is still there for win32, it has this remark:
|
@amitdo: thanks for analysis. Thank I will not limit this change to Mac. |
|
Why? |
Because the default bacend on mac is 'coretext', but text2image is not designed to work with it You should force 'fc' as backend, at least for mac. |
... and the patch DOES NOT care about default backend... It cares about environment variable definition. So it should work. |
@amitdo: do you have Mac or did you test it on Mac? Because you are claiming that Mac has set PANGOCAIRO_BACKEND variable by default to some value... |
@atuyosi: can you please test current code? |
...and patch, that reflect above logic, will do:
So crash should happened only in case 1. when user set PANGOCAIRO_BACKEND to wrong backend. |
@amitdo : can you please read my comments? You miss the point. Or try the code ;-) |
I will reread the code, maybe I missed something. |
It looks okay :-) Please pardon me. You changed the code a few times in the last week, and I was reading the diffs, so I didn't see the whole picture. That was the reason for my confusion. |
@stweil : I do not remember, but pango was always strange for me. ;-) After pango changed build system, I lost interest to to play with as I am mainly on windows at this time... |
Meson is great and it does work on windows. |
Thank you for your answers. The main problem was obviously unreleased memory. I now have a different solution for #3189. |
There seems to be a regression bug with text2image of 3.05 release.
The
text2image
utility caused segfault, so I couldn' use tesstrain.sh on macOS (10.12.3).ref. #195
for detail:
The text was updated successfully, but these errors were encountered: