Wikisource:Google OCR

From Wikisource
Jump to: navigation, search

The Google OCR tool adds a Page-namespace toolbar button that will derive text from the current page's image, via Google's Cloud Vision API OCR service.

It is used on Wikisources in languages with scripts that are not supported by the standard Tesseract OCR system. It should not be used where that system can be used instead, as there is a limit to the number of requests we can make against Google's services.

Any issues should be reported via Phabricator and tagged as Community-Tech. Report an issue now.

Note that this tool does not currently work for the following languages: Malayalam, Telugu, Oriya, Gujrati, or Kannada. Work is being done to fix this, but it may take a few more months.

Direct usage[edit]

The tool can be used on its own to OCR any image that is hosted on Commons.

To do this, just go to the tool's web interface at https://tools.wmflabs.org/ws-google-ocr/ and paste in any image's full URL (i.e. after right clicking on an image and choosing 'copy image location'). This can be of use when processing images in the needing transcription category, for example.

Images with substantial amounts of text should be included in Wikisource instead, and proofread in the normal fashion.

Setting up as a user script or global script[edit]

Individual users can load Google OCR for themselves by adding the following to their common.js:

mw.loader.load('//wikisource.org/w/index.php?title=MediaWiki:GoogleOCR.js&action=raw&ctype=text/javascript');

Wikis that want to make the OCR tool available by default for everyone can add the line above to their MediaWiki:Common.js.

You will also need to create the system messages mentioned below if they don't already exist on your wiki.

Setting up as a gadget[edit]

To use Google OCR on any Wikisource, you should set it up as a Gadget (only administrators can do this).

  1. Create MediaWiki:Gadget-GoogleOCR.js and add the following:
    mw.loader.load('//wikisource.org/w/index.php?title=MediaWiki:GoogleOCR.js&action=raw&ctype=text/javascript');
  2. Add the following to MediaWiki:Gadgets-definition:
    * GoogleOCR[ResourceLoader]|GoogleOCR.js
  3. Create the following system messages:
    • MediaWiki:google-ocr-button-label — tooltip text for the buttons, e.g.: "Get text via Google OCR".
    • MediaWiki:google-ocr-request-in-progress — 'loading' text displayed while the OCR request is being carried out; e.g.: "Loading text from Google OCR".
    • MediaWiki:google-ocr-no-text — message displayed when the OCR tool didn't fail but also didn't return an error; e.g.: "No text retrieved from Google OCR"
    • MediaWiki:google-ocr-image-not-found — the image is expected to be in an element with class prp-page-image; if it can't be found, this message is displayed in a bubble notification; e.g.: "No image found on this page"
  4. Enable the gadget for yourself, and test its operation. Bugs should be reported via Phabricator.

For more information about gadget configuration, see mw:Extension:Gadgets.

Sites using this[edit]

If your Wikisource is loading the Google OCR script as a gadget or a site script please list it here so we can keep you up to date with developments.

Language Code Link
Assamese as as:MediaWiki:Common.js
Bengali bn bn:MediaWiki:Common.js
Kannada kn kn:MediaWiki:Gadget-GoogleOcr.js
Marathi mr mr:MediaWiki:Common.js
Malayalam ml ml:MediaWiki:Gadget-GoogleOCR.js
Odia or or:MediaWiki:Gadget-GoogleOCR.js
Sanskrit sa sa:MediaWiki:Common.js
Tamil ta ta:MediaWiki:Gadget-GoogleOCR.js

The struck-out langauges above are not yet supported.

Development[edit]