-
Notifications
You must be signed in to change notification settings - Fork 593
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
Extend the ability to process image only from disk to from both disk and memory #260
base: master
Are you sure you want to change the base?
Conversation
… method can only read image from disk i.e. from a filename (string). The new method extend the ability to read image from both disk and memory. Read image from memory means that it can also accept file object or PIL.Image.Image object as the parameter of this method.
I think this is a useful extension, thanks. Can you create a short python script that tests this behavior, i.e. passing a |
…ss instances for methods 'read_image_gray()' and 'read_image_binary()'
…ss instances for methods 'read_image_gray()' and 'read_image_binary()'
…ss instances for methods 'read_image_gray()' and 'read_image_binary()'
Thank you. @kba I write a simple script to only call methods "read_image_gray()" and "read_image_binary()" with a parameter 'file name' and 'PIL.Image.Image instance' respectively. And print their return value (array type) to compare. I didn't put these two methods in image processing to compare their output, in which I need to change the script 'ocropus-nlbin' and 'ocropus-gpageseg' to call these two methods with PIL.Image.Image instance respectively. Certainly, I also test them in local, if you need I can upload the script and updated scripts 'ocropus-nlbin' and 'ocropus-gpageseg' which only changed two code lines to call these two methods with PIL.Image.Image instance. Besides, I upload the script in TXT file tyle for the limitation of uploaded file type. |
Hi @kba Sorry for replying the unit test so late. The attached file is the unit test code for testing functions read_image_gray() and read_image_binary(). Because these two functions accept a raw image and a binarized image respectively, I used two images (tests/testpage.png and tests/010030.bin.png) and their related PIL.Image objects to test. You can run this test code by uncomprocessing it under folder 'ocropy', and certainly with the updated read_image_gray() and read_image_binary(). |
…ll script to run python test scripts
…ll script to run python test scripts
Goal: Extend the ability to process image only from disk to from both disk and memory.
Updates: changed methods 'read_image_gray()' and 'read_image_binary' in module 'ocrlib/common.py'.
Description: The method can only read an image from disk i.e. from a filename (string). The new method extends the ability to read an image from both disk and memory. Read image from memory means that it can also accept file object or PIL.Image.Image object as the parameter of this method.
My application context: Now I developed OCRopus related services and used the library 'ocrlib', but it can only read an image from disk (the parameter type must be 'string'). While for my service, I used the Django framework, which receives the image uploaded by users as an 'InMemoryUploadFile' type which is a file type object. Thus, the 'ocrlib' can not take it as a parameter of the read_image_ methods and thus cannot process. So I changed the methods and now it can process image from disk (string type) and memory (file object or PIL.Image.Image)