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
how to use sbb_binarization within a script? #26
Comments
It appears that the directory containing the from os import environ
if 'PATH' in environ:
environ['PATH'] += ':/path/to/dir-containing-sbb-binarize/'
else:
environ['PATH'] = '/path/to/dir-containing-sbb-binarize/'
# stuff with subprocess |
Or use an absolute path instead of |
Thanks so much for responding, @kba. I believe I tried absolute path before, but just in case, I did it again, with these results:
(The traceback looks almost identical to the first one, but the last-line error has changed, of course.) (More info: I winnowed down my code in order to post. I also originally had the following, as well: |
This looks like the executable doesn't have (in Linux terminology) the executable bit set. I don't think that exists in Windows. So I guess you'd have to do something like args = ['C:/path/to/python3.exe', 'C:/path/to/sbb_binarize', '--patches', '-m', 'C:/Users/Scott/Desktop/Python2/sbb_binarization/models', 'C:/Users/Scott/Desktop/Python2/Kpics/Pages_cropped/061r.png', 'C:/Users/Scott/Desktop/Python2/Kpics/new_test8.png'] But why go through that route at all, why not use the python code directly? from sbb_binarize import SbbBinarizer
SbbBinarizer("C:/...").run(image_path="C:/...", save="C:/...") |
Thanks again. Trying your last suggestion. I appreciate something that more experienced folks know to be more direct and/or simpler. I can't get it working yet. I also tried things like |
If you can run it from the terminal, it should be usable in a script. We work with virtual environments exclusively to control what python version which which packages is available. I'm sure VirtualStudio should support that too. But in the meantime: how did you install |
Thank you so much! After all this, it seems it is something as simple as this. I thought that if I had activated the appropriate conda environment (in this case, the one I created for sbb_binarization), that scripts would run from that environment, not just command line stuff. I made each -- command line and script -- print python version. Command line was 3.7.0 (as I specified during installation -- a step I figured out I needed to take during my installation of sbb_binarization). Script in code runner was 3.8.6, which is the python version of my default environment. I had to search to figure out how to remedy this. You have to manually select the correct "interpreter path" prior to running the script. (I thought terminal environment and interpreter path basically synced.) So, hallelujah, I can now run the script as script. :) This is using a script I wrote ('my_sbb_test2b.py') which is placed inside the sbb_binarization/sbb_binarize folder. (It takes a long time (1070.903 seconds for 1 11.8MB image), but it also took long in the command line, of course...and it works! Thank you!) Now, being one step closer, what I ultimately need is to be able to call this script (or just |
Great!
Yes, we have not made any optimizations for speed yet, only for quality of results (same with eynollah). Are you using a GPU or CPU only? Using a GPU can cut processing time roughly in half. |
Yeah, just GPU. Thanks. |
I think you meant CPU. On my (not very powerful) machine without a GPU, even a minimal example will take at least 5-10 times as long as with GPU. Also goes for eynollah and sbb_textline_detection. These tools use neural networks that benefit from the massively parallel calculations a GPU can do. |
Ha. Yes, of course I meant CPU. Sorry about that! Thanks once again. |
Hi. After searching for numerous hours without success, I am wondering if someone might offer insight on how to run this from within a python script.
(Using Windows 10 os, Visual Studio Code)
For example, I can run the following successfully from the terminal:
sbb_binarize --patches -m 'C:/Users/Scott/Desktop/Python2/sbb_binarization/models' 'C:/Users/Scott/Desktop/Python2/Kpics/Pages_cropped/061r.png' 'C:/Users/Scott/Desktop/Python2/Kpics/new_test8.png'
However, if I try the following script (using CodeRunner extension):
I get the following:
I don't suggest that this is a bug or anything. I'm rather sure the "issue" is mine. I'm very green at python/coding in general. Any help would be greatly appreciated.
The text was updated successfully, but these errors were encountered: