Closed lubo closed 7 years ago
Please keep in mind that Pyocr is just a wrapper for Tesseract and Cuneiform. Therefore, does Tesseract or Cuneiform provide such functionality ?
That's why I stated If it's possible. I don't know if they provide API for that, but Tesseract prints to stdout Emtpy page!!!
when it detects one. I thought you could provide more info on that one.
I can't find any option related to what you are looking for. I doubt there is one. I think being able to tell there is no text implies that you must try to find text, which in turn implies running the full OCR process to be perfectly sure.
I'm going to close this ticket. Feel free to comment here if you find such option, and I will reopen this ticket.
BTW, are you looking to know if there is no text at all (only images, photos, etc), or if the input image is actually empty ? Both things are not the same at all. If you want to know whether there is text or not, using Tesseract makes senses. However, if you want to know if an image is entirely empty, you should look at image processing libraries (OpenCV, libpillowfight, etc).
I want to know if there is a text or not. If I wanted to know, whether an image is entirely empty, I would go for Google Cloud Vision for sure. Also, Google Cloud Vision can do something close to what I want, and it's that you can limit number of detected text annotations. But it still returns way more data than I need and it's kind of expensive for just saying whether there is a text or not.
I've been playing around with Tesseract CLI and just found out it returns Script and Script confidence in OSD-only PSM. Using this feature seems to be ~36x faster than using mode 3 on a image with ~12,000 characters (2.4 instead of 88.3 seconds). I see that these values are omitted in detect_os(handle)
.
Oh good point, I forgot about this, my bad : https://github.com/openpaperwork/pyocr/#orientation-detection << "detect_orientation() MAY raise an exception if there is no text detected in the image." << this part actually concern Tesseract. Tesseract (3.03) does return an error when there is no text.
Currently, it seems like the only way to detect whether an image is empty or not is using
image_to_string(...)
. However, this method is very inefficient on images containing thousands of characters or more. If it's possible, I'd be great to implement something likeis_image_empty(image)
, which would return abool
describing, whether the image is empty or not.