1

(There's a six-year-old, closed question about this, but I'd like to begin a fresh thread.)

I'm looking for really good optical-character recognition (OCR, 光學字元辨識) for Chinese.

I used to use the functionality that came built-in in the high-end version of Adobe Acrobat. It was fair, but I've grown dissatisfied with Adobe's subscription model and price. Now that I'm using PDF Expert, I find the Chinese OCR even less good than Adobe's.

My needs are:

  • I'd like to be able to recognize the widest range of characters, including traditional, simplified, and non-standard forms as possible.

  • I work with texts that are both vertically and horizontally composed. Sometimes both appear on the same page.

  • Since some of the texts I use have Mandarin Phonetic Symbols (bopo mofo, 注音符號) to their right, it would be good if the software could tell that those are not characters proper — even if it can't recognize them.

  • Primarily I am dealing with PDFs — I can convert to or from images, of course.

I can use Linux or Macintosh tools. What is the state of software quality and availability these days?

2
  • 1
    Use tesseract-ocr in Linux. No ocr is perfect, but tesseract is pretty good!
    – Pedroski
    Nov 19, 2023 at 16:02
  • 1
    (I went and modified the old question as a [forward] duplicate of this question. There's the resources page, but I think it's incomplete with regards to OCR; we should update it as answers come in.)
    – Becky 李蓓
    Nov 19, 2023 at 22:58

3 Answers 3

1

Try tesseract-ocr with Linux. But if you are mixing all kinds of stuff, I would first crop the images and just leave the Simplified Chinese or Traditional Chinese. tesseract is not all-knowing!!

This is a little Python function for Portuguese, using the Python module pytesseract. First split a pdf then ocr it. I also cropped the images to remove unwanted stuff first.

def convert2text(name):
    # get the jpgs
    jpgFiles = os.listdir(destination_jpg)
    jpgFiles.sort()
    this_text = open(save_text_path + name, 'a')
    # this works fine
    for i in range(len(jpgFiles)):
        if not os.path.isdir(destination_jpg + '/' + jpgFiles[i]):
            porText1 = pytesseract.image_to_string(Image.open(destination_jpg + jpgFiles[i]), lang='por')
            print('Page ' + str(i + 1) + ' done')
            this_text.write(porText1)
            print('Next loop coming up')
    this_text.close()
    print('removing the jpgs ... ')
    junkjpgs(destination_jpg)
    print('finished this PDF ... ')

You can download chi_sim or chi_tra trained data for tesseract. I find it works well. But not if you mix in all kinds of sh**!

On the command line check the installed languages:

pedro@pedro-HP:~$ tesseract --list-langs
List of available languages(4):
chi_sim
eng
osd
por
pedro@pedro-HP:~$

5
  • The code you've provided is not runnable - there's undefined symbols (destination_jpg, save_text_path), missing imports and/or unspecified third-party libraries (os, pytesseract, Image), and undefined references to functions (junkjpgs). You also didn't provide a link to the documentation which lists the available language codes. What does someone specify for Chinese in lieu of "por" if they want to install more languages / how do they install more languages?
    – dROOOze
    Nov 20, 2023 at 10:57
  • No, the whole code was much longer, about 80 lines, with crop image, split pdf, clear up function and other things. The paths are my paths. Your paths will very likely be different! Define your own paths! This is not a Python forum, so I just posted an indication of how it works. Set lang='chi_sim' for 简体中文, or lang='chi_tra' for 繁体中文 The code was part of a solution for someone who wanted to extract text in tables, which makes things more difficult when there is more than 1 line in a column! Just search "tesseract-ocr install language data" for available languages!
    – Pedroski
    Nov 20, 2023 at 15:19
  • “This is not a Python forum”, which means it’s even more important to provide a working example. Nobody is expected to program here, so you might as well have written Martian with a non-functional example.
    – dROOOze
    Nov 20, 2023 at 17:04
  • Well, again, we don't agree! The working example would be 80+ lines of code! Too much Martian for a Chinese forum! If you want to ocr some pdfs, just ask, I will see if I can help!
    – Pedroski
    Nov 20, 2023 at 17:17
  • The functional code isn’t for me (I can write code and can write my own OCR app if need be). In any answer on a StackExchange, you’re supposed to cater for a maximum of readers on the forum. The average user here would have absolutely no idea what you wrote, and couldn’t even begin to find out, with zero links to third party documentation. It’s always going to be a wrestle getting any kind of information out of an answer with maybe-googleable terms that may or may not show up in a search; you’re making people guess your intentions and meaning all the time with this kind of answer.
    – dROOOze
    Nov 20, 2023 at 17:51
1

The OCR I use is the paid add-on in Pleco. Here's a photo of a page in my Chinese textbook:

新实用汉语课本5 p.85

Here's me inputting it into the Pleco OCR:

The Pleco interface

And here's the output:

I 新素食主义来了
人们常常将素食主义者理解为因宗教、民族的原因 或者因某种奇怪的习惯而不吃鸡、鸭、鱼、肉等动物性食品的人。但我们所说的“新素食主义者”,既不是信仰某种宗教.也不是扮‘啭”,更不是吃腻了大鱼大肉。他们选择素食,为的是身体健康;他们选择素食,为的是在繁华、热闹的城市里保留一份自然的心情;他们选择素食,是为了保护他们生活的环境;他们选择素食,是要给人类以外的其他生命平等的权利。他们选择素食作为自己的一种生活方式,是基于他们对自己健康的重视以及对除人以外其他生命的更多的爱和尊重。l 那么,“新素食主义者’,离我们远吗?当我们看到写字楼里以素食为午餐的白领小姐,看到大学餐厅里只选素菜的大学生 看到素菜馆里来来往往的顾客……我们会感觉到,新素食主义真的来了。“新素食主义者,,就在我们身边,尽管还只是少数 但毕竟不再让人觉得没法理解。也许在不久之后,素食將会成为更多人的个人选择。 新素食主义者向我们说明了三个理由:

My experience is that it works incredibly well for textbook pages (like above). But it can get confused if there are margins or pinyin. You still need to do a bit of manual polishing. It can help to first increase the contrast in image-editing software.

The arrow implies it's reading "left to right"; you can also do "top to bottom". Taking the image from here, we get:

Pleco interface; vertical text

And this is the result:

弒其君者,必千乘之君者,必百乘之家。焉,不為不多矣。苟奪不翼。未有仁而遗

5
  • Many thanks! Can you show us how it works on text in columns? Nov 19, 2023 at 23:14
  • 1
    Okay, I added it.
    – Becky 李蓓
    Nov 19, 2023 at 23:20
  • Thank you very much! Does this work only with the camera? Or can it be used on files, as well? Nov 20, 2023 at 6:57
  • The OCR Demo version of Pleco installed on my phone does not work with files, so I think I will pay the US$10 and see if I can get it to work on a sample page or not. Nov 20, 2023 at 7:05
  • I suspect it is using the module cv2 from opencv-python to find the characters. That's how it can draw over them in green.
    – Pedroski
    Nov 20, 2023 at 7:37
1

Following up on the reply by Becky 李蓓, here are the results I got using the paid version of Pleco's OCR functionality, working with (I concede) typographically very complex texts, first scanned to PDF and then OCR-ed using Pleco's Still OCRImage / PDF File function.

In brief the results are enough to start editing with, but far from glorious. I'd still like to know if there are better tools available.

I have not yet had a chance to get started experimenting with tesseract-ocr, recommended by Pedroski.

After the Pleco results, I have added results from a very old version of Adobe Acrobat Pro and the current version of PDF Expert.


In detail:

  1. A page from an edition of the Jī Zhōngsǎn jí 嵇中散集, with Mandarin Phonetic Symbols beside two of the lines of text, several different kinds of brackets common in Chinese texts (「」《》【】), and what Unicode calls "dingbat negative circled digits".

The uncorrected text captured by OCR is:

「有顏回者好學,不幸短命死矣。]@不及童烏 顏回昧於養生而短折,遢不如童烏夭於天命。不,底本作「下」。周樹人校曰..「各本作不。」今據改。童烏,漢文學家揚雄之子,九歲即能與其父討論《太玄》,早卒。《法言.間神》..「育而不苗者,吾家之童烏乎!九龄而與我玄文。]注..「童烏,子雲之子也。仲尼悼顏淵(回)苗而不秀,子雲傷童烏育而不苗。一又,戴明揚引黄節語..「至於童烏之年,短於顏子,乃由天命,不關養生。是顏子昧於養生而短折,不如童烏之委於天命也。一o早徂 早死。徂,通「殂」。《說文》:「殂,往死也。]@自令不辜 自貪酒色,仍不悟酒色為何物,則謂酒色無罪,故加速自身死亡。【語 譯】勞心勞神疲敝慯人,肆意縱欲使人喪生。顏回好學可惜短命,還不如童烏委於天命。放縱自己毫不顧忌,無不早早喪命。酒色何物執迷不悟,自謂無罪以致乏絕。詩歌因而這樣唱:酒色使人枯竭。 :*iJ一T* *I Aro 恕‘ 厂… “ 絕智棄學,遊6[蒸黝e。逊=復悔,當衣a衙@。彰鉍一窒,如黧一郾E鬱№征恥令,秕氯卧墨白。歌*毒≈,澎诎玉裁踟。

【注 釋一e玄默 幽深恬默,無憂無為。令過而復悔二句 《莊子.大宗師》:「古之真人……過而弗悔,當而不自得也。]意思是..古代的真人(天道體現者),有了過失,也不懊悔;作得適當,也不自鳴得意。過者,謂於事有所過失也;當者,謂行之得當也。眾人之情,於事有所過失則後悔,作之得當,則自以為得意,真人不然。故曰..「過而弗悔,當而不自得也。]復,「弗」字之誤。@垂釣一壑二句 垂釣於一溝一壑,如同歡樂於一圃(天下)。如,吳鈔原本作「如」,周校本誤「好」。今徑改。《漢書.敘傳》:「班嗣報桓生書曰:

重作六+l口詩Ll首m戊秋胡1歌詩t首盯

page scanned from edition of the Jī Zhōngsǎn jí 嵇中散集


  1. A page from an edition of the Wénxīn diāolóng 文心雕龍, with several different sizes of text, including two different sizes in vertical columns, text in the upper margin, and what Unicode calls "circled ideograph digits".

The uncorrected text captured by OCR is:

四段言之要歸需空識需事證

二段述附會<即謀篇布局)之方法 文心雕龍技本 下篇 二四四 凡大體文章,類⑦多枝派,整派者依源,理枝者循幹,是以附辭會義,務總綱領[叠㈦,驅萬塗於同歸,貞百慮於一致⑩,使眾理雖繁,而無倒置之乖,羣言雖多,而無棼絲⑩之亂;扶陽而出條,順陰而藏跡曰㈦④,首尾周密,表裹一體,此附會之術也。 夫畫者謹髮而易貌,射者儀毫而失艢⑩,銳精⑩細巧,必疏體統㈦吞。故宜訕寸以信尺①,枉尺以直尋,棄偏善之巧,學具①美之績,此命篇之經昙也@。 夫女變無騵一」鹏i=;*納齜噺黢咨:===《‘l*以方@,意見浮雜回,約⑦則義 孤,博則辭叛@,率故多尤囪,需為事賊园。且*分不同,思緒各異,或製首以 通尾㈦,或尺接以寸附㈣,然通製者蓋寡,接附者甚眾回。若統緒失宗回,辭味 必亂;義脈不流⑩,則偏枯文體@岂。吮愴 夫能玄慷$=Ti*$=唿既識腠触*」狼ii】=婿理回,然後節文自會,如膠F 之粘木,石之合玉囟§:辩:*$玩ON始镟‘=砼做王矣。是以駟牡異力,而六轡如琴 多;並駕齊驅,而一轂統輻茵;馭文之法,有似於此。去留隨心,修短在手,齊 其步驟,總轡而已。故善附者異旨如肝膽因,拙會者同音如胡越令,敢章難於造

page scanned from edition of Wénxīn diāolóng 文心雕龍


For comparison, below are the uncorrected text captured long ago from the same documents by an old version (v. 11, dating back to 2012) of Adobe Acrobat Pro, and after that, the text captured by the current version (v. 3.5.2) of PDF Expert. Both are using the "Traditional Chinese" settings.

Both are able to embed the result of OCR in the PDF to make a "searchable image" — if the goal is simply to be able to find text in an already-typeset document, even if some (though not most) of the text is recognized incorrectly, this is still a significant advantage over applications that only generate a separate text file.

Both applications are confounded at times by characters appearing in different sizes, by Mandarin Phonetic Symbols, and by circled digits (Chinese or Arabic). However, the 2012 version of Acrobat is much, much better than the 2023 version of PDF Expert, which seems to have difficulty recognizing columnar text.


I. Adobe Acrobat Pro v. 11

  1. Wénxīn diāolóng 文心雕龍:

需需之四 事文要段 '-'@P~史 證識歸言 之謀述 方鱗附 二一會 法布會 。’。附 。局(二 文心雕龍指明本7嵐 一明白 几大體文章,類@多枝派,整派者依源,理校者循幹,是以附辭會義, 綱領〔評三】,驅萬塗於同歸,貞百慮於一致@,使眾理雖繁,而無 言雖多,而無勢絲@之亂;扶陽而出條,順陰而臟跡@〔評哩,首尾 一體,此附會之術也。 一一一段揭示侮 夫晝者謹髮而易貌,射者儀毫而失牆@, 銳精@細巧, 必疏體統吾吾。故 文之通病。 其中先霄謀 o 篇之病,繼 宜翻寸以信尺@,枉尺以直尋,棄偏善之巧,學兵@美之績,此命 霄命意之病 ,寫實才分 之病。 敵百制師嗎輯轍r冷齡帥一一向欄如你阻 以芳@,意見浮雜@,約@則義 夫文變無M間恥h叫仰f伊 孤,博則辭叛@,率故多尤@,需為事賊@。且才分不同,思緒各異, 過尾@,或尺接以寸附@,然通製者蓋寡, 接附者甚眾@。若統緒失宗昏,辭味 必亂.,義脈不流@,則偏枯文體門評言。 夫能玄噱阱r恥f歸聞蹦蹦誤識康鯽耕恥撒昕一齡棚輔理晶瞥 之粘木,石之合玉@翩翩僻都撒輔札組活始懶恥仗的主矣 3 .,並駕齊驅,而一戰統輻@;敏文之法,有似於此。去留隨心,修鐘 其步驟,總巒而已。故善附者異旨如肝膽@,拙會者同音如糊糊他@,

  1. Jī Zhōngsǎn jí 嵇中散集:

首士詩歌胡社代首十詩言六作重

「有顏回者好學,不幸短命死矣。」@不及立堅烏顏回眛於養生而短折,還不如童烏夭於天命。不,底本作 「下」。周樹人校曰:「各本作不o 」今據改。立置祠,漢文學家揚雄之子,九歲即能與其父討論《太玄》,早 卒。《法吉.間神》 「育而不苗者,吾家之童烏乎!九齡而與我玄文。」注 「童鳥,子雲之子也。仲尼悼 顏淵(回〉苗而不霄,子雲傷童烏育而不苗。」又,戴明揚引黃節語 「至於童烏之年,短於顏子,乃由天命, 不關養生。是顏子眛於養生而短折,不如血董周之要於天命也。」@早祖早死。徊,通「姐」。《說文「》姐, 往死也。」@白令不辜自貪酒色,仍不悟酒色為何物,則謂酒色無罪,故加擅自身死亡。 同語譯凶勞心勞神疲敝傷人,肆意縱欲使人喪生。顏回好學可惜短命,還不如童烏委於天命。放縱 自己毫不顧忌,無不早早喪命。酒色何物執迷不悟,自謂無罪以致乏絕。詩歌因而這樣唱 酒色使人 枯竭。 僻靜棄恥駒,志以予訟點起@盼你御條,齡和配做@車銷一鑿,如齡加一豁@ 0oo MmtrxZ 〈- AAtume --苟血-叉 T -L句 UTumzznz 被髮行歌。’和氣四靈通。歌以言之,避、心于玄默。 開注釋凶@玄默幽深恬默,無憂無為。@過而復悔二句《莊子.大宗師》 「古之真人 過而弗悔, 當而不自得也。」意思是 古代的真人(天道體現者丫有了過失,也不懊悔;作得適當,也不自鳴得意。過 者,謂於事有所過失也;當者,調行之得當也。眾人之情,於事有所過失則後悔,作之得當,則自以為得意, 真人不然。故曰:「過而弗悔,當而不自得也。」復,「弗」字之韻。@垂釣一整二句垂釣於一講一塹,如 同歡樂於一圖(天下)。如,吳鈔原本作「如」’周校本誤「好」。今徑改。《漢書.敘「傳班》桐報桓生書曰:


II. PDF Expert v. 3.5.2

  1. Wénxīn diāolóng 文心雕龍:

其步 晝; 之粘 驟, 並駕 木, 夫 總 齊驅 石 轡而 , 之合 已o 而 玉 一爵 故善 穀統 舢駟 附者 輻圜 游齬唰 必亂 通尾 孤, 夫文 宜訕 寸以 夫 信 畫者 一體 言雖 綱頜 文 異旨 ;馭 淜帆枑 如肝 文之 蒐跆岫 體籌六 通製 需, 囍鞝咯 淜滕 〕o 者蓋 焉事 鯽晰 誹尪鵬 寡, 賊圉 鞝鵰妞 棄, 儀亳 陽而 貞百 整, 出條 慮於 派者 ,致一 依源 膽園' 法, 斲毗 有酚喉 偏善 而失 能玄 ;義 冒, 博則 變 , 多, 譯= 凡 心離龍 惊 緋駟馴 不流 尺接 鈑圉 排、 冒, 以 ' 岫渺 寸附 率 諧腆 尺冒 謹髮 , 而 會之 無 驅 術 雰絲 萬塗 也o@於 文章 下 , 篇 類 圉多 楸 諏黯 則偏 冒 故多 帥庄 枯文 然, 尤園 涮鱗斲 枉 易貌 尺以 ' 之亂 同歸 ;扶, 衚撇誤 識 直尋 射者 枝派 鉛沁 接o伽缸 拙會 似於 王矣o 淜唰 附者 且才 毗以 之巧 牆菌' , 順陰 園, ' 而藏 使 理枝 者同 此o 是 理瞞 甚眾 分不 方圜 學具 銳精 昌美 冒細 之績, 巧' 跡囥 眾理 者循 籌四 雖緊' 幹, 二 音如 去留 以駟 僵' 冒o 同, 意, 湖隨牡然 若思見 〕, 是四 首而以 幟魯 心, 異力 後節 統緒 緒各 浮雜 ,修,文 失異箇 改 短在 而 自會 宗昌 , , 此命 必疏 篇 體統 尾 無倒 附辭 周密 置 會 , 之乖' 義' 章難 手 六轡 ' , 或製 約圜 於造 齊, 如琴 如膠 辭味 首以 則義 之經 籌五 晷也 〕o 昌o 故 表裏 韋 務總 脈 或 辭 蹄無 此附 而 口' 大體 穨本

  1. Jī Zhōngsǎn jí 嵇中散集:

j3 首七詩歌胡秋代首十詩言六作重 同真者當【 被竇^一 .枯自【往不顏卒「 歡樂 人不 ,謂 而不 注 〝'E丫 竭o己語死關養淵o《法下」「有 於然於自釋 丁一ˊ紐亳譯也二生(回〉{=o顏回 一o事得】 仃 — 】 不o口周 國故有也 者 (日所o@玄 」 蓁〈校 天 : 過失 意 默 ˊ無勞不》 ', 下 x 〈 歌蠹 智 顧 @是苗.樹 @ 忌勞心自顏子而問神人好學 厂 秀 :不 昧 靶不不 : 。 「和於 , 〉也思幽`神辜幸 一 早 過氣養 o;是〈遊子「「短 深 ˋ— 而ˊ 】 疲 早生 如弗當澧恬 四鯛 敝自而雲育各命 u ,吳 悔' 者, 古代 默, 塞@ 于 喪命 傷 貪酒 短 傷立 而不 本作 死矣 折 鈔謂的 玄 ,不o 弓 當無T o人色 里苗 烏者 原而行真憂 ˋ o o 本n育 o u , 肆不, 」 作「 不自 之得 人 無為 歌 @ 色 意縱 仍不 如立 而 吾家 令 @不 蠶 獸酒 」 如 得也 當 〈天 o 以 ˊ 何 悟 里 不 據 及 o 欲之 xˋ 苗 改立 酒鳥 」, 也o 道 @ 言 ) 物 使 二 垚 、 ˊ色之 周 o」 眾 體現 過而 之 遏 執 人 委 里 立 里烏 實 o 几為鳥 ˋ迷喪 校者復遊而 於又,里顏 : 復人x何乎鳥 厂 本,之〉復不夭戴! 物 誤「 「弗 情 , 悔二 囉 悔 悟, o o , 命 明 九 昧 改 o 過 也 子 o 失不. 《 @垂 則 懊 大 o 得 壼 以 可 罪 早 : 文 雄之 短折 漠書 釣 後 悔; 宗師 .一悔》′ x 回 於 矢 好」 」 ,於 有了 句 弔 當 則 也 揚 齡 文 力 顏而 謂 回」與子 字玄ˋ引 犬 T養 弓ˋ黃 o之辜過《 ˊ不x 晝好洒 我家生 u壼 令徑有所失,默自 無 n色節 霍 噂I 玄揚而 誤莊ˋ`罪學@語 @ o 力 祖o ˊ 致惜, 乏 短 故 早 「 」 子, , 絕 命 加 死 至 注 遣 牙 . 於:九 , ˋ立 7日 生, o不 ˊ速o 祖 敘壑作 x 歲如立 力 ,垂自里「 么 傳 二 作 得 : 釣 歌 不 身 通 鳥 立里 即能 里 》 句 之得 適 「 一 ˋ : 當古 厂x 因 如 死亡 「 之 鳥 與 烏夭 嗣 於一 則自 不自 . . 唱 於 《 說 之 一 而童 「班釣,真人 壑這樣鳥委短於父討天命 垂當,之 霞 也o雲 .顏 如論 .子子 詩遺 , 姐年, :天文《 o —′ v o 仲底 日,意o 悔 使放 「命尼, 本 : 如 , 過 , 奮 人 縱 姐, , 悼 早 作 . 報桓 溝 以 嗚 . 鄴 》 , 也 太 不 生書 一壑 為得 得意 過而弗 一國 酒 命 乃 玄 , 由 xˊ 》 . ˊ′ o 天 〝 色: 漠 o隴 ,其 o」子於 _

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.