GithubHelp home page GithubHelp logo

cfculhane / ankiocr Goto Github PK

View Code? Open in Web Editor NEW
16.0 16.0 5.0 262.65 MB

Anki Addon to create searchable text from images in notes, using Tesseract OCR

License: MIT License

Python 2.01% HTML 26.61% Ruby 0.36% C 42.79% Roff 20.06% C++ 6.05% Shell 0.32% CSS 0.95% JavaScript 0.48% Makefile 0.08% CMake 0.29%

ankiocr's People

Contributors

cfculhane avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

ankiocr's Issues

Support for easyOCR

Since easyOCR / google has a way better support for non-latin languages, it'd be great if the addon is engine agnostic.

Error message (probably because the cards name contains "ä,ü,ö")

Hello,

when im trying to to use the ankiocr I'll get an error message on some cards . Not on every card but on such which have a special letter like "ä ö ü" in the name of the card.

For example:
If the cards name is: "Hola ÜK.jpg" it will not work

This is the error message:

__Error encountered during processing. Debug info:
Anki Version: 2.1.49 , AnkiOCR Version: 0.7.1
Platform: Darwin , Python Version: 3.8.6 (v3.8.6:db455296be, Sep 23 2020, 13:31:39)
[Clang 6.0 (clang-600.0.57)]Traceback (most recent call last):
File "/UsersLibrary/Application Support/Anki2/addons21/450181164/gui.py", line 58, in on_run_ocr
ocr.run_ocr_on_notes(note_ids=selected_nids)
File "/Users/Library/Application Support/Anki2/addons21/450181164/ocr.py", line 309, in run_ocr_on_notes
notes_query = self.run_ocr_on_query(note_ids=note_ids)
File "/Users//Library/Application Support/Anki2/addons21/450181164/ocr.py", line 277, in run_ocr_on_query
batched_txts, batched_txts_dir, batch_mapping = self.gen_batched_txts(notes_to_process=notes_query.notes,
File "/Users//Library/Application Support/Anki2/addons21/450181164/ocr.py", line 228, in gen_batched_txts
batch_txt_pth.write_text("\n".join([str(i.img_pth) for i in batched_imgs]))
File "pathlib.py", line 1255, in write_text
UnicodeEncodeError: 'ascii' codec can't encode character '\xdc' in position 78: ordinal not in range(128)

Error after Anki 2.1.64

Hello, first of all, thank you for this amazing addon. Unfortunately, it no longer works on Anki versions after 2.1.64. When I try to use it, I get the error below:

Error encountered during processing. Debug info:
Anki Version: 23.10 , AnkiOCR Version: 0.7.1
Platform: Windows , Python Version: 3.9.15 (main, Nov 6 2022, 02:45:15) [MSC v.1929 64 bit (AMD64)]Traceback (most recent call last):
File "C:\Users\XXXXX\AppData\Roaming\Anki2\addons21\450181164\gui.py", line 58, in on_run_ocr
ocr.run_ocr_on_notes(note_ids=selected_nids)
File "C:\Users\XXXXX\AppData\Roaming\Anki2\addons21\450181164\ocr.py", line 309, in run_ocr_on_notes
notes_query = self.run_ocr_on_query(note_ids=note_ids)
File "C:\Users\XXXXX\AppData\Roaming\Anki2\addons21\450181164\ocr.py", line 279, in run_ocr_on_query
raw_results = self._ocr_batch_process(batched_txts=batched_txts)
File "C:\Users\XXXXX\AppData\Roaming\Anki2\addons21\450181164\ocr.py", line 97, in _ocr_batch_process
raw_results[batched_img_txt] = future.result()
File "concurrent.futures._base", line 439, in result
File "concurrent.futures._base", line 391, in __get_result
File "concurrent.futures.thread", line 58, in run
File "C:\Users\XXXXX\AppData\Roaming\Anki2\addons21\450181164\ocr.py", line 265, in _ocr_img
return pytesseract.image_to_string(str(img_pth), lang="+".join(languages or ["eng"]),
File "C:\Users\XXXXX\AppData\Roaming\Anki2\addons21\450181164_vendor\pytesseract\pytesseract.py", line 416, in image_to_string
return {
File "C:\Users\XXXXX\AppData\Roaming\Anki2\addons21\450181164_vendor\pytesseract\pytesseract.py", line 419, in
Output.STRING: lambda: run_and_get_output(*args),
File "C:\Users\XXXXX\AppData\Roaming\Anki2\addons21\450181164_vendor\pytesseract\pytesseract.py", line 287, in run_and_get_output
run_tesseract(**kwargs)
File "C:\Users\XXXXX\AppData\Roaming\Anki2\addons21\450181164_vendor\pytesseract\pytesseract.py", line 263, in run_tesseract
raise TesseractError(proc.returncode, get_errors(error_string))
450181164._vendor.pytesseract.pytesseract.TesseractError: (1, "read_params_file: Can't open txt Tesseract Open Source OCR Engine v5.0.0-alpha.20200328 with Leptonica Error in fopenReadStream: file not found Error in pixRead: image file not found: C:\Users\XXXXX\AppData\Roaming\Anki2\Usuário 1\collection.media\paste-32998233735169.jpg Image file C:\Users\XXXXX\AppData\Roaming\Anki2\Usuário 1\collection.media\paste-32998233735169.jpg cannot be read! Error during processing.")

Error - Cannot import q-menu

I am running anki Version ⁨2.1.45 (6ffa7440)⁩ Python 3.9.0 Qt 5.15.2 PyQt 5.15.4.

On startup, I receive the following error:

An add-on you installed failed to load. If problems persist, please go to the Tools>Add-ons menu, and disable or delete the add-on.

When loading '⁨AnkiOCR⁩':
⁨Traceback (most recent call last):
  File "c:\pyenv\lib\site-packages\aqt\addons.py", line 217, in loadAddons
    __import__(addon.dir_name)
  File "C:\Users\me\AppData\Roaming\Anki2\addons21\450181164\__init__.py", line 6, in <module>
    from . import gui
  File "C:\Users\me\AppData\Roaming\Anki2\addons21\450181164\gui.py", line 7, in <module>
    from aqt.browser import Browser, QMenu
ImportError: cannot import name 'QMenu' from 'aqt.browser' (c:\pyenv\lib\site-packages\aqt\browser\__init__.py)

Let me know if you need more info. I wasn't sure what to put in the issue title of this post.

issue with the new version

Hi,

Sorry to be the bearer of bad news.
The new version doesn't seem to work all that well. As with the previous version the gui completely freezes when running OCR, so I can't really know if it's progressing or not on large collection. But overall this seems WAY slower than before. I tried lowering the batch size to 1 to try and see if it worked better but it didn't change a thing.

I am pretty sure it just runs in circle at some point when I scan more than 2 batches at once but I can't know if the progress bar doesn't appear.

It would be great to have the progress bar work. This way we could also have a "cancel" button, otherwise I had to force quit anki and manually kill each tesseract process.

Displaying the time it took to run at the end would be helpful too to organize myself when I want to scan a huge deck but that is minor.

System : ubuntu 18 with anki 2.1.35

AnkiOCR crashes on "new_field" output option

Hello Chris,
Anki OCR is working for me as long as I use "tooltip" option as output location.
When I am switching to "new_field", Anki is crashing.
Is there a solution?
regards,
Philipp

=================
configuration
{
"batch_size": 5,
"languages": [
"rus"
],
"num_threads": 2,
"override_tesseract_exec": false,
"overwrite_existing": true,
"tesseract_exec_path": "",
"tesseract_install_valid": true,
"text_output_location": "new_field",
"use_batching": true,
"use_multithreading": true
}

============================
A fatal error occurred, and Anki must close. Please report this message on the forums.
Anki 2.1.57 (6b7d372c) Python 3.9.15 Qt 6.4.2 PyQt 6.4.0
Platform: Windows-10-10.0.19045
Flags: frz=True ao=True sv=?
Add-ons, last update check: 2023-02-14 21:51:13

Caught exception:
Traceback (most recent call last):
File "aqt.progress", line 118, in handler
File "aqt.utils", line 1188, in
File "aqt.browser.browser", line 542, in on_all_or_selected_rows_changed
File "aqt.browser.table.table", line 103, in get_single_selected_card
File "aqt.browser.table.model", line 222, in get_card
File "aqt.browser.table.state", line 148, in get_card
File "anki.collection", line 462, in get_card
File "anki.cards", line 60, in init
File "anki.cards", line 68, in load
File "anki._backend_generated", line 1844, in get_card
File "anki._backend", line 150, in _run_command
pyo3_runtime.PanicException: called Result::unwrap() on an Err value: PoisonError { .. }

AnkiOCR should ignore links

Hi,

I noticed a very annoying issue. Sometimes an image is not really in collection.media but is actually a link to an image, that anki fetches.

When you have a card like that and run AnkiOCR on a large collection that includes it, it will go through all the selected cards then show a cryptic error and most importantly won't save any of the OCR'd cards that have not faileed.

To solve those issues I have to read the error, then find the card that uses this image, then manually use an image instead of a link, then re run OCR on all the cards.

I think AnkiOCR should at least ignore the links, or fetch the image and OCR it then store the plaintext as usual without saving the media.

In any case, is there no way to not have done the OCR for nothing? It can take quite come time to run.

Here's the error message :

Cancelled OCR processing with message :
['Traceback (most recent call last):\n', ' File "/home/USERNAME/.local/share/Anki2/addons21/450181164/gui.py", line 54, in on_run_ocr\n ocr.run_ocr_on_notes(note_ids=selected_nids)\n', ' File "/home/USERNAME/.local/share/Anki2/addons21/450181164/ocr.py", line 303, in run_ocr_on_notes\n notes_query = self.run_ocr_on_query(query=query_str)\n', ' File "/home/USERNAME/.local/share/Anki2/addons21/450181164/ocr.py", line 272, in run_ocr_on_query\n raw_results = self._ocr_batch_process(batched_txts=batched_txts)\n', ' File "/home/USERNAME/.local/share/Anki2/addons21/450181164/ocr.py", line 94, in _ocr_batch_process\n raw_results[batched_img_txt] = future.result()\n', ' File "concurrent/futures/_base.py", line 432, in result\n', ' File "concurrent/futures/_base.py", line 388, in __get_result\n', ' File "concurrent/futures/thread.py", line 57, in run\n', ' File "/home/USERNAME/.local/share/Anki2/addons21/450181164/ocr.py", line 259, in _ocr_img\n return pytesseract.image_to_string(str(img_pth), lang="+".join(languages or ["eng"]))\n', ' File "/home/USERNAME/.local/share/Anki2/addons21/450181164/_vendor/pytesseract/pytesseract.py", line 368, in image_to_string\n return {\n', ' File "/home/USERNAME/.local/share/Anki2/addons21/450181164/_vendor/pytesseract/pytesseract.py", line 371, in \n Output.STRING: lambda: run_and_get_output(*args),\n', ' File "/home/USERNAME/.local/share/Anki2/addons21/450181164/_vendor/pytesseract/pytesseract.py", line 280, in run_and_get_output\n run_tesseract(**kwargs)\n', ' File "/home/USERNAME/.local/share/Anki2/addons21/450181164/_vendor/pytesseract/pytesseract.py", line 257, in run_tesseract\n raise TesseractError(proc.returncode, get_errors(error_string))\n', "450181164._vendor.pytesseract.pytesseract.TesseractError: (1, 'Tesseract Open Source OCR Engine v4.0.0-beta.1 with Leptonica Error in fopenReadStream: file not found Error in pixRead: image file not found: /home/USERNAME/.local/share/Anki2/Main/collection.media/https:/www.i-scanimaging.com/fileadmin/processed/1/d/preview_eea8daa970_113904783.jpg Image file /home/USERNAME/.local/share/Anki2/Main/collection.media/https:/www.i-scanimaging.com/fileadmin/processed/1/d/preview_eea8daa970_113904783.jpg cannot be read! Error during processing.')\n"]

Thanks!

tricks I found that could be mentionned

Hi,

Not really a trick but I figured that I could use re"<img *WORD*" to search for cards that contain this word in a picture.

Also, -"re:(<img.*title=.*)" "re:(<img.*>)" shows you cards that contain pictures that have not been OCR'ed. But beware, it won't show cards that contain multiple pictures if only some of them have not been OCR'ed, for example if you added one of the image later.

I think this should be mentionned in the README and in the addon page as it could be quite useful to people.

Have a nice day!

Error

Hi, AnkiOCR doesn't work, I have this error when trying to run it on a note. It only works when I run it on a note without image lol

Error encountered during processing. Debug info:
Anki Version: 2.1.65 , AnkiOCR Version: 0.7.1
Platform: Darwin , Python Version: 3.9.15 (main, Nov 6 2022, 11:31:59)
[Clang 14.0.3 ]Traceback (most recent call last):
File "/Users/greg/Library/Application Support/Anki2/addons21/450181164/gui.py", line 58, in on_run_ocr
ocr.run_ocr_on_notes(note_ids=selected_nids)
File "/Users/greg/Library/Application Support/Anki2/addons21/450181164/ocr.py", line 309, in run_ocr_on_notes
notes_query = self.run_ocr_on_query(note_ids=note_ids)
File "/Users/greg/Library/Application Support/Anki2/addons21/450181164/ocr.py", line 277, in run_ocr_on_query
batched_txts, batched_txts_dir, batch_mapping = self._gen_batched_txts(notes_to_process=notes_query.notes,
File "/Users/greg/Library/Application Support/Anki2/addons21/450181164/ocr.py", line 228, in _gen_batched_txts
batch_txt_pth.write_text("\n".join([str(i.img_pth) for i in batched_imgs]))
File "pathlib", line 1286, in write_text
UnicodeEncodeError: 'ascii' codec can't encode characters in position 86-87: ordinal not in range(128)

Can you help me please ? I'm on macOS 14.0

Tesseract's parameterizable thresholding method to prevent unrecognized text on bright background colors

I had problems recognizing text on bright background colors and I found the solution in the thread below:

tesseract-ocr/tesseract#1990

I'm not from the programming area and to solve my problem, I changed the line below in the file C:\Users\xxxxx\AppData\Roaming\Anki2\addons21\450181164_vendor\pytesseract.pytesseract.py , but I believe that a parameterizable and more professional solution is possible.

cmd_args += (tesseract_cmd, input_filename, output_filename_base, '-c', 'thresholding_method=2')

Thanks again for this amazing addon.
Hugs,
Gabriel

FR: proper spacing parsing using another module

Hi,

I just pushed a hackish module that wrapps pytesseract to preserve the spacing as much as possible.

Here's the link: https://pypi.org/project/OCR-with-format/

If you manage to find the time to include it in your repo I think it would be nice :)

Here's the basic usage:

import OCR_with_format
 OCR_with_format.OCR_with_format(img_path="./test.png", quiet=True)

Thanks and have a nice day!

"TypeError: find_notes() got an unexpected keyword argument 'query'" when running OCR

Just installed the addon.

Im using Anki version 2.1.42.
When trying to run ocr I get the following error:

Error encountered during processing, attempting to stop AnkiOCR gracefully. Error below:
Traceback (most recent call last):
   File "C:\Users\Max\AppData\Roaming\Anki2\addons21\450181164\gui.py", line 54, in on_run_ocr
    ocr.run_ocr_on_notes(note_ids=selected_nids)
   File "C:\Users\Max\AppData\Roaming\Anki2\addons21\450181164\ocr.py", line 303, in run_ocr_on_notes
    notes_query = self.run_ocr_on_query(query=query_str)
   File "C:\Users\Max\AppData\Roaming\Anki2\addons21\450181164\ocr.py", line 266, in run_ocr_on_query
    notes_query = NotesQuery(col=self.col, query=query)
   File "<string>", line 7, in __init__
   File "C:\Users\Max\AppData\Roaming\Anki2\addons21\450181164\api.py", line 216, in __post_init__
    self.notes = [OCRNote(note_id=nid, col=self.col) for nid in self.col.findNotes(query=self.query)]
 TypeError: find_notes() got an unexpected keyword argument 'query'

It doesn't matter whether I'm trying to run ocr on a single note or on multiple notes, the error remains.

AnkiOCR error

Hi, I've encountered an error message
image
seems like it tried to show "\U0001F50A", which is a speaker emoji in html form but failed.

Error While Processing New Notes

Hello!
Was just trying to convert some notes and get this error. Not very proficient with coding or reading our error logs, so I figured I'd put it here in case there's an issue or anybody can help me out.

Cancelled OCR processing with message :

['Traceback (most recent call last):\n', ' File "/Users/joshl/Library/Application Support/Anki2/addons21/450181164/gui.py", line 58, in on_run_ocr\n ocr.run_ocr_on_notes(note_ids=selected_nids)\n', ' File "/Users/joshl/Library/Application Support/Anki2/addons21/450181164/ocr.py", line 308, in run_ocr_on_notes\n notes_query = self.run_ocr_on_query(note_ids=note_ids)\n', ' File "/Users/joshl/Library/Application Support/Anki2/addons21/450181164/ocr.py", line 278, in run_ocr_on_query\n raw_results = self._ocr_batch_process(batched_txts=batched_txts)\n', ' File "/Users/joshl/Library/Application Support/Anki2/addons21/450181164/ocr.py", line 96, in _ocr_batch_process\n raw_results[batched_img_txt] = future.result()\n', ' File "concurrent/futures/_base.py", line 432, in result\n', ' File "concurrent/futures/_base.py", line 388, in __get_result\n', ' File "concurrent/futures/thread.py", line 57, in run\n', ' File "/Users/joshl/Library/Application Support/Anki2/addons21/450181164/ocr.py", line 264, in _ocr_img\n return pytesseract.image_to_string(str(img_pth), lang="+".join(languages or ["eng"]),\n', ' File "/Users/joshl/Library/Application Support/Anki2/addons21/450181164/_vendor/pytesseract/pytesseract.py", line 368, in image_to_string\n return {\n', ' File "/Users/joshl/Library/Application Support/Anki2/addons21/450181164/_vendor/pytesseract/pytesseract.py", line 371, in \n Output.STRING: lambda: run_and_get_output(*args),\n', ' File "/Users/joshl/Library/Application Support/Anki2/addons21/450181164/_vendor/pytesseract/pytesseract.py", line 280, in run_and_get_output\n run_tesseract(**kwargs)\n', ' File "/Users/joshl/Library/Application Support/Anki2/addons21/450181164/_vendor/pytesseract/pytesseract.py", line 257, in run_tesseract\n raise TesseractError(proc.returncode, get_errors(error_string))\n', "450181164._vendor.pytesseract.pytesseract.TesseractError: (-6, 'dyld: Library not loaded: ../../../leptonica/1.80.0/lib/liblept.5.dylib Referenced from: /Users/joshl/Library/Application Support/Anki2/addons21/450181164/deps/mac/tesseract/4.1.1/bin/tesseract Reason: image not found')\n"]

Feature request: Integrate PaddleOCR Instead of Tesseract

Description:
I would like to suggest integrating PaddleOCR as an alternative to Tesseract for OCR tasks. PaddleOCR provides several significant advantages, including robust multilingual support, the ability to leverage GPU acceleration, and superior layout handling capabilities. Additionally, it could be relatively straightforward to package, which could simplify the integration process.
Benefits:

  • Multilingual support
  • Optional GPU acceleration
  • Layout and table handling
  • Easy to package?

Link: PaddleOCR GitHub

image

Image missing after OCR

Some image gone missing after OCR, leaving only the text.
image
I've checked the file and found out that these pictures' style were left blank which caused this issue, I've already manually edited each card and recovered all media, just want to leave this info here for the dev to check it out and for anyone that might have similar problems.

Incompatibility with clozes

Hi,

Just a quick heads up to point out that if an image contains "::" in the text, it will break clozes as it will appear as a hint.

Not sure of how to best handle this case though.

Have a nice day!

cannot run on more than 1000 cards

Hi,

In case you didn't know, there seems to be a limit to how many cards the user can send to AnkiOCR, it's a minor annoyance to me as I often share very large decks with colleagues.

Here's the error :

Error encountered during processing, attempting to stop AnkiOCR gracefully. > Error below:
Traceback (most recent call last):
File "/home/USERNAME/.local/share/Anki2/addons21/450181164/gui.py", line 54, in on_run_ocr
ocr.run_ocr_on_notes(note_ids=selected_nids)
File "/home/USERNAME/.local/share/Anki2/addons21/450181164/ocr.py", line 303, in run_ocr_on_notes
notes_query = self.run_ocr_on_query(query=query_str)
File "/home/USERNAME/.local/share/Anki2/addons21/450181164/ocr.py", line 266, in run_ocr_on_query
notes_query = NotesQuery(col=self.col, query=query)
File "", line 7, in init
File "/home/USERNAME/.local/share/Anki2/addons21/450181164/api.py", line 216, in post_init
self.notes = [OCRNote(note_id=nid, col=self.col) for nid in self.col.findNotes(query=self.query)]
File "anki/collection.py", line 453, in find_notes
File "anki/rsbackend_gen.py", line 88, in search_notes
File "anki/rsbackend.py", line 267, in _run_command
anki.rsbackend.DBError: DBError { info: "SqliteFailure(Error { code: Unknown, extended_code: 1 }, Some("Expression tree is too large (maximum depth 1000)"))", kind: Other }

Doesn't find Tesseract-ocr

Hi,
I followed the instructions carefully and installed tesseract-ocr, libtesseract-dev, language pack and even the snap version but it still doesn't work. I am on Linux ubuntu 18.04.

I get the message processed for X cards when there are no imgs in the card but when there is an image I get the error : Could not find a valid Tesseract-OCR installation! Please visit the addon page in at https://ankiweb.net/shared/info/450181164 for install instructions

Can you tell me where I can find logs ? I have a decent chance of solving this myself if I can get them, to avoid bothering you.

Include Standalone Tesseract for Mac

I recently discovered you could update the dynamic shared libraries of tesseract with otool. All it takes is a simple shell script to change your installed tesseract into a standalone folder. I added it for my own app and thought it might help this project as well.

#!/bin/sh

if ! command -v tesseract &> /dev/null
then
    brew install tesseract
fi

if [ "$EUID" -ne 0 ]
  then echo "Please run as root"
  exit
fi

mkdir tesseract_standalone
cp -r /usr/local/Cellar/tesseract tesseract_standalone/
cp -r /usr/local/Cellar/leptonica tesseract_standalone/
cp -r /usr/local/Cellar/libpng tesseract_standalone/
cp -r /usr/local/Cellar/libtiff tesseract_standalone/
cp -r /usr/local/Cellar/webp tesseract_standalone/
cp -r /usr/local/Cellar/openjpeg tesseract_standalone/
cp -r /usr/local/Cellar/jpeg tesseract_standalone/
cp -r /usr/local/Cellar/giflib tesseract_standalone/

cd tesseract_standalone/tesseract/4.1.1/bin/
install_name_tool -change /usr/local/opt/leptonica/lib/liblept.5.dylib ../../../leptonica/1.80.0/lib/liblept.5.dylib tesseract 
install_name_tool -change /usr/local/Cellar/tesseract/4.1.1/lib/libtesseract.4.dylib @executable_path/../lib/libtesseract.4.dylib tesseract
install_name_tool -change /usr/local/opt/leptonica/lib/liblept.5.dylib ../../../leptonica/1.80.0/lib/liblept.5.dylib ../../../tesseract/4.1.1/lib/libtesseract.4.dylib
install_name_tool -change /usr/local/opt/libpng/lib/libpng16.16.dylib ../../../libpng/1.6.37/lib/libpng16.16.dylib ../../../leptonica/1.80.0/lib/liblept.5.dylib
install_name_tool -change /usr/local/opt/jpeg/lib/libjpeg.9.dylib ../../../jpeg/9d/lib/libjpeg.9.dylib ../../../leptonica/1.80.0/lib/liblept.5.dylib
install_name_tool -change /usr/local/opt/giflib/lib/libgif.7.dylib ../../../giflib/5.2.1/lib/libgif.7.dylib ../../../leptonica/1.80.0/lib/liblept.5.dylib
install_name_tool -change /usr/local/opt/libtiff/lib/libtiff.5.dylib ../../../libtiff/4.2.0/lib/libtiff.5.dylib ../../../leptonica/1.80.0/lib/liblept.5.dylib
install_name_tool -change /usr/local/opt/webp/lib/libwebp.7.dylib ../../../webp/1.2.0/lib/libwebp.7.dylib ../../../leptonica/1.80.0/lib/liblept.5.dylib
install_name_tool -change /usr/local/opt/openjpeg/lib/libopenjp2.7.dylib ../../../openjpeg/2.4.0/lib/libopenjp2.2.4.0.dylib ../../../leptonica/1.80.0/lib/liblept.5.dylib
install_name_tool -change /usr/local/opt/jpeg/lib/libjpeg.9.dylib ../../../jpeg/9d/lib/libjpeg.9.dylib ../../../libtiff/4.2.0/lib/libtiff.5.dylib

Idea of an alternative to adding the OCR to a new field

Hi,

I have been thinking about doing an addon like this for a while. Congrats for doing this!

I had another approach though that you might find interesting.

I really didn't like the idea to add OCR fields to all the note types that can contain text so my idea was instead to add the text content as an HTML comment in the field containing the picture. Visually, it does not change a thing to the card and is searchable through the anki browser. I also mean you can restrict search per field, as sometimes my pictures are added in "sources" field or in "More", "Cloze body" etc.

I think this could be a very interesting feature to add. What do you think? It would be worth asking Damien if it is reasonnable to do or if comments are sometimes cleaned up or whatever.

Another possibility was to add the text content in the "alt" argument of the "img" html attribute, like in this example But I barely know HTML and have no idea what kind of issues this could create.

What do you think?

Either way the content would need to start with some kind of identifier like ___ocrtext_unixtime=23094203984209___ and ___endOCRtext___ to avoid adding text over and over in case someone runs the script regularly or wants to edit tesseract settings. At least that's how I designed it.

Recurring error

Hi, I frequently have this error message :

Cancelled OCR processing with message :
['Traceback (most recent call last):\n', ' File "/home/USERNAME/.local/share/Anki2/addons21/450181164/gui.py", line 56, in on_run_ocr\n ocr.run_ocr_on_notes(note_ids=selected_nids)\n', ' File "/home/USERNAME/.local/share/Anki2/addons21/450181164/ocr.py", line 306, in run_ocr_on_notes\n notes_query = self.run_ocr_on_query(note_ids=note_ids)\n', ' File "/home/USERNAME/.local/share/Anki2/addons21/450181164/ocr.py", line 285, in run_ocr_on_query\n raw_results = self._ocr_unbatched_process(image_paths=image_paths)\n', ' File "/home/USERNAME/.local/share/Anki2/addons21/450181164/ocr.py", line 149, in _ocr_unbatched_process\n raw_results[image_path] = future.result()\n', ' File "concurrent/futures/_base.py", line 432, in result\n', ' File "concurrent/futures/_base.py", line 388, in __get_result\n', ' File "concurrent/futures/thread.py", line 57, in run\n', ' File "/home/USERNAME/.local/share/Anki2/addons21/450181164/ocr.py", line 262, in _ocr_img\n return pytesseract.image_to_string(str(img_pth), lang="+".join(languages or ["eng"]),\n', ' File "/home/USERNAME/.local/share/Anki2/addons21/450181164/_vendor/pytesseract/pytesseract.py", line 368, in image_to_string\n return {\n', ' File "/home/USERNAME/.local/share/Anki2/addons21/450181164/_vendor/pytesseract/pytesseract.py", line 371, in \n Output.STRING: lambda: run_and_get_output(*args),\n', ' File "/home/USERNAME/.local/share/Anki2/addons21/450181164/_vendor/pytesseract/pytesseract.py", line 280, in run_and_get_output\n run_tesseract(**kwargs)\n', ' File "/home/USERNAME/.local/share/Anki2/addons21/450181164/_vendor/pytesseract/pytesseract.py", line 257, in run_tesseract\n raise TesseractError(proc.returncode, get_errors(error_string))\n', '450181164._vendor.pytesseract.pytesseract.TesseractError: (-11, "read_params_file: Can't open txt read_params_file: Can't open txt Tesseract Open Source OCR Engine v4.0.0-beta.1 with Leptonica Detected 33 diacritics contains_unichar_id(unichar_id):Error:Assert failed:in file ../ccutil/unicharset.h, line 513")\n']

My OS is ubuntu 18, anki version is 2.1.35. I have the latest ankiOCR available for this anki version.

It happens without me understanding what kind of notes causes it. I had it with some text of my lesson that used weird characters (like the female and male thingie like ♂️ ) but it also happenned to random image occlusions.

Unfortunately, this error can happen after having ankiocr running through hundreds of cards in a row without saving the changes :/ So I have to redo it over and over again until I find the culprit cards.

Let me know if I can help you troubleshoot that :)

Cancled OCR, Image Not Found (Image Occlusion Card)

OCR failed on my image occlusion cards. I'm running Anki Version ⁨2.1.39 (576f0043)⁩. See error message below and attached screenshot:

Cancelled OCR processing with message :
['Traceback (most recent call last):\n', ' File "/Users/justinbrandt/Library/Application Support/Anki2/addons21/450181164/gui.py", line 58, in on_run_ocr\n ocr.run_ocr_on_notes(note_ids=selected_nids)\n', ' File "/Users/justinbrandt/Library/Application Support/Anki2/addons21/450181164/ocr.py", line 308, in run_ocr_on_notes\n notes_query = self.run_ocr_on_query(note_ids=note_ids)\n', ' File "/Users/justinbrandt/Library/Application Support/Anki2/addons21/450181164/ocr.py", line 278, in run_ocr_on_query\n raw_results = self._ocr_batch_process(batched_txts=batched_txts)\n', ' File "/Users/justinbrandt/Library/Application Support/Anki2/addons21/450181164/ocr.py", line 96, in _ocr_batch_process\n raw_results[batched_img_txt] = future.result()\n', ' File "concurrent/futures/_base.py", line 432, in result\n', ' File "concurrent/futures/_base.py", line 388, in __get_result\n', ' File "concurrent/futures/thread.py", line 57, in run\n', ' File "/Users/justinbrandt/Library/Application Support/Anki2/addons21/450181164/ocr.py", line 264, in _ocr_img\n return pytesseract.image_to_string(str(img_pth), lang="+".join(languages or ["eng"]),\n', ' File "/Users/justinbrandt/Library/Application Support/Anki2/addons21/450181164/_vendor/pytesseract/pytesseract.py", line 368, in image_to_string\n return {\n', ' File "/Users/justinbrandt/Library/Application Support/Anki2/addons21/450181164/_vendor/pytesseract/pytesseract.py", line 371, in \n Output.STRING: lambda: run_and_get_output(*args),\n', ' File "/Users/justinbrandt/Library/Application Support/Anki2/addons21/450181164/_vendor/pytesseract/pytesseract.py", line 280, in run_and_get_output\n run_tesseract(**kwargs)\n', ' File "/Users/justinbrandt/Library/Application Support/Anki2/addons21/450181164/_vendor/pytesseract/pytesseract.py", line 257, in run_tesseract\n raise TesseractError(proc.returncode, get_errors(error_string))\n', "450181164._vendor.pytesseract.pytesseract.TesseractError: (-6, 'dyld: Library not loaded: ../../../leptonica/1.80.0/lib/liblept.5.dylib Referenced from: /Users/justinbrandt/Library/Application Support/Anki2/addons21/450181164/deps/mac/tesseract/4.1.1/bin/tesseract Reason: image not found')\n"]

image

AttributeError: 'ErrorHandler' object has no attribute 'flush'

Anki 2.1.35 (84dcaa86) Python 3.9.1 Qt 5.15.2 PyQt 5.15.2
Platform: Linux
Flags: frz=False ao=True sv=2
Add-ons, last update check: 2021-01-28 23:51:24

Error encountered during processing, attempting to stop AnkiOCR gracefully. Error below:
Traceback (most recent call last):
File "/home/onexming/.local/share/Anki2/addons21/450181164/gui.py", line 54, in on_run_ocr
ocr.run_ocr_on_notes(note_ids=selected_nids)
File "/home/onexming/.local/share/Anki2/addons21/450181164/ocr.py", line 303, in run_ocr_on_notes
notes_query = self.run_ocr_on_query(query=query_str)
File "/home/onexming/.local/share/Anki2/addons21/450181164/ocr.py", line 272, in run_ocr_on_query
raw_results = self._ocr_batch_process(batched_txts=batched_txts)
File "/home/onexming/.local/share/Anki2/addons21/450181164/ocr.py", line 78, in _ocr_batch_process
pbar = tqdm(total=num_batches) if ANKI_ENV is False else None
File "/home/onexming/.local/lib/python3.9/site-packages/tqdm/std.py", line 1092, in init
self.refresh(lock_args=self.lock_args)
File "/home/onexming/.local/lib/python3.9/site-packages/tqdm/std.py", line 1386, in refresh
self.display()
File "/home/onexming/.local/lib/python3.9/site-packages/tqdm/std.py", line 1519, in display
self.moveto(pos)
File "/home/onexming/.local/lib/python3.9/site-packages/tqdm/std.py", line 1475, in moveto
self.fp.flush()
File "/home/onexming/.local/lib/python3.9/site-packages/tqdm/utils.py", line 169, in getattr
return getattr(self._wrapped, name)
AttributeError: 'ErrorHandler' object has no attribute 'flush'

Suspends my Anki

Hello! I have tried it a bit and always ran into a problem.

First, I tried OCR with many cards. I got a result window immediately. But no cards were OCRed. I could click the result window away. However, my cursor was still looking like an hourglass. It seems like Anki was suspended.
I could perform some actions, such as open the add-on window, edit an edit config.
I could not resume reviewing my cards. I could not close the browser. I could not close Anki normally.
After restarting Anki, I took a look in the browser and found out that no images had OCR results.

Later, I ran the add-on on only one card. This added the OCRed text to the note. But apart from that, it suspended Anki as in the other run.

Maybe it is because I use an older version of Anki.

Win 10
Version 2.1.22 (0ecc189a)
Python 3.8.0 Qt 5.14.1 PyQt 5.14.1

Hope to be able to highlight and find the word in the text created or at least the image

Hi cfculhane,

I have some long Anki notes, and I think it will be very useful if when searching for a word in a card, it highlights the word or at least, bring the user to the image.

It may have to be combined with his shortcut
https://ankiweb.net/shared/info/225180905 ( Highlight Search results in browser)

  • simply put highlight the word that you searched for as you press enter like what happens in a Microsoft document.

Image of an example of a highlighted word in the image ( done in Microsoft OneNote)
Screenshot 2022-09-27 at 11 38 14 PM

On the side note, your add on works prefectly otherwise in getting doing OCR. Thank you for taking the time to make such an amazing add on for the Anki community.

Kind regards,
Jeryl

setting ''new_field'' option in config throws error when OCR run

The tooltip option if selected in config ,OCR works fine. But if i choose new_field , then this error comes.
I just want an easily copyable version of the text within the Image available in usual study window itself...Its difficult to go to browser each time i want to copy paste the title tooltip by opening HTML VIEWER.


A fatal error occurred, and Anki must close. Please report this message on the forums.
Anki 2.1.45 (355e66e8) Python 3.8.6 Qt 5.14.2 PyQt 5.14.2
Platform: Windows 8.1
Flags: frz=True ao=True sv=?
Add-ons, last update check: 2021-09-18 14:36:06

Caught exception:
Traceback (most recent call last):
File "aqt\progress.py", line 54, in handler
File "aqt\utils.py", line 962, in
File "aqt\browser\browser.py", line 421, in onRowChanged
File "aqt\browser\table\table.py", line 83, in get_current_card
File "aqt\browser\table\model.py", line 177, in get_card
File "aqt\browser\table\state.py", line 142, in get_card
File "anki\collection.py", line 315, in get_card
File "anki\cards.py", line 59, in init
File "anki\cards.py", line 67, in load
File "anki_backend\generated.py", line 930, in get_card
File "anki_backend_init_.py", line 126, in _run_command
pyo3_runtime.PanicException: called Result::unwrap() on an Err value: PoisonError { .. }

feature request : periodic check

Hi,

I am an absolute fan of your addon and it became absolutely indispensable, thank you very much!

I regularly search my db for "<img -title" to scan new cards that don't have been OCR'd yet and was thinking that it would be useful to have it periodically check for that.

Say before synchronisation, a hook could be used to see if there is any non OCR'ed card. Just saying :)

Thanks again!

How I fixed my latest install error

Hi!

I recently did a fresh ubuntu reinstall my ankiOCR install was not working. I fixed it apparently and wanted to share it here.

The error appeared when running the OCR command and was the following:

Error encountered during processing. Debug info: 
Anki Version: 2.1.49 , AnkiOCR Version: 0.7.1
Platform: Linux , Python Version: 3.8.1 (default, Dec 21 2019, 15:35:48) 
[GCC 5.4.0 20160609]Traceback (most recent call last):
  File "/home/USER/.local/share/Anki2/addons21/450181164/gui.py", line 58, in on_run_ocr
    ocr.run_ocr_on_notes(note_ids=selected_nids)
  File "/home/USER/.local/share/Anki2/addons21/450181164/ocr.py", line 309, in run_ocr_on_notes
    notes_query = self.run_ocr_on_query(note_ids=note_ids)
  File "/home/USER/.local/share/Anki2/addons21/450181164/ocr.py", line 279, in run_ocr_on_query
    raw_results = self._ocr_batch_process(batched_txts=batched_txts)
  File "/home/USER/.local/share/Anki2/addons21/450181164/ocr.py", line 97, in _ocr_batch_process
    raw_results[batched_img_txt] = future.result()
  File "concurrent/futures/_base.py", line 432, in result
  File "concurrent/futures/_base.py", line 388, in __get_result
  File "concurrent/futures/thread.py", line 57, in run
  File "/home/USER/.local/share/Anki2/addons21/450181164/ocr.py", line 265, in _ocr_img
    return pytesseract.image_to_string(str(img_pth), lang="+".join(languages or ["eng"]),
  File "/home/USER/.local/share/Anki2/addons21/450181164/_vendor/pytesseract/pytesseract.py", line 416, in image_to_string
    return {
  File "/home/USER/.local/share/Anki2/addons21/450181164/_vendor/pytesseract/pytesseract.py", line 419, in <lambda>
    Output.STRING: lambda: run_and_get_output(*args),
  File "/home/USER/.local/share/Anki2/addons21/450181164/_vendor/pytesseract/pytesseract.py", line 287, in run_and_get_output
    run_tesseract(**kwargs)
  File "/home/USER/.local/share/Anki2/addons21/450181164/_vendor/pytesseract/pytesseract.py", line 263, in run_tesseract
    raise TesseractError(proc.returncode, get_errors(error_string))
450181164._vendor.pytesseract.pytesseract.TesseractError: (1, "/usr/local/bin/tesseract: /usr/local/share/anki/bin/liblzma.so.5: version `XZ_5.2' not found (required by /lib/x86_64-linux-gnu/libarchive.so.13)")

My fix was simple :
cd /usr/local/share/anki/bin ; mv liblzma.so.5 liblzma.so.5_renamed_to_avoid_ankiOCR_crash_see_issue

Have a nice day and thanks a lot for the addon :)

[Anki Version 23.10.10 ( Nov 2023)] Addon Install Error : No module named 'PyQt5

Error Log

Anki 23.10.1 (fac9e0ee) Python 3.9.15 Qt 6.6.0 PyQt 6.6.0
Platform: Windows-10-10.0.22631
Flags: frz=True ao=True sv=3
Add-ons, last update check: 2023-12-17 23:10:32

When loading AnkiOCR:
Traceback (most recent call last):
  File "aqt.addons", line 245, in loadAddons
  File "C:\Users\User\AppData\Roaming\Anki2\addons21\450181164\__init__.py", line 6, in <module>
    from . import gui
  File "C:\Users\User\AppData\Roaming\Anki2\addons21\450181164\gui.py", line 6, in <module>
    from PyQt5.QtWidgets import QMenu
ModuleNotFoundError: No module named 'PyQt5'

Environment

  • Anki Version 23.10.1 ( Nov 2023) (fac9e0ee)⁩
  • Python 3.9.15 Qt 6.6.0 PyQt 6.6.0
  • Windows 11 (2023)

Steps to replicate

  1. Install from anki using the code provided in the AnkiWeb
  2. Start Anki

Remarks

I know the error is simple to resolve but I think its better for the addon to install modules by themselves

a simple

pip install PyQt5

will fix it but I don't know if there would be more errors after that.

@cfculhane please look into it , this hasn't been updated in a long time.

Error

Error encountered during processing.Debug info:
Anki Version: 2.1.49,AnkiOCR Version: 0.7.1
Platform: Darwin,Python Version: 3.8.6
(v3.8.6:db455296be Sep 23 2020,13:31:39)
[Clang 6.0 (clang-600.0.57)Traceback (most recent call last):
File "/Users/yzy/Library/Application Support/Anki2/addons21/450181164/gui.py",line 58,in on_run _ocr
ocr.run_ocr _on_notes(note_ids=selected_nids)
File "/Users/yzy/Library/Application Support/Anki2/addons21/450181164/ocr.py",line 309,in run_ocr_on_notes
notes_query = self.run_ocr -on_query(note_ids=note_ids)
File "/Users/yzy/Library/Application Support/Anki2/addons21/450181164/ocr.py",line 277,in run_ocr_on_query
batched_txts,batched_txts_dir,batch_mapping =self.gen_batched_txts(notes_to process=notes_query.notes,
File "/Users/yzy/Library/Application Support/Anki2/addons21/450181164/ocr.py",line 228,in_gen_batched_txts
batch_txt_pth.write_text("In" .join(Lstr(i.img_pth) for iin batched_imgsl))
File "pathlib.py",line 1255,in write_text
UnicodeEncodeError: "ascii' codec can't encode characters in
position 45-46: ordinal not in range(128)

我按照要求下载了语言包, 但不知如何安装进这款插件, 你能帮帮我吗TvT

我下载了"chi"语言包, 也更改了相关设置: 比如在eng后添加chi, 我还把chi包放到了tessdata文件夹中.
但不知为何不起作用, 并且不断报错.

您能简单的提示我一下吗,

谁能帮帮我. 我很需要这个插件, 我有很多的图像遮挡需要识别, 我面临着高考.
为此, 我也已经回退到支持这款插件的版本, 放弃了23.10 (我想让你了解, 我已经为此做出了很多努力, 也许只差''你回复我''这最后一步, 就能帮到我了!!)

提前感谢您阅读我的文字,
请回复我吧!!

Error upon run

Ive been using this addon for a month now, and it works great. The update on 1/19/20 has created an error for me (no longer runs). See below:

Caught exception:
Traceback (most recent call last):
File "/Users/-----------/Library/Application Support/Anki2/addons21/450181164/gui.py", line 108, in
act_run_ocr.triggered.connect(lambda b=browser: on_run_ocr(browser))
File "/Users/-----------/Library/Application Support/Anki2/addons21/450181164/gui.py", line 24, in on_run_ocr
num_batches = ceil(num_notes / config["batch_size"])
TypeError: 'NoneType' object is not subscriptable

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.