I have a bunch of documents in which I want to highlight certain paragraphs/keyphrases. I have a list of the most frequently appearing sentences and I want to search for these paragraphs/keyphrases in the document and if they appear, highlight them. The length of these paragraphs/keyphrases will be longer than 3-4 words. Below is an example doc:
One approach I am currently trying (and failing) is using Pytesseract. These are the steps:
image_to_datafunction in Pytesseract to extract the words and their bounding boxes (bbox) from the document image.
- From the extracted words, find the sentence using
- If there is a match, then store the words and their bbox coordinates in a dictionary and then use
cv2.rectangle()to highlight them.
The issue with the above approach is the presence of duplicate words. For example in the above image if I want to highlight the sentence
Your acts or omissions. For the words
omissions, I am getting the correct coordinates but for the word
or, since it is appearing once above the actual sentence (
property damage "or" personal and advertising), the actual coordinate of the word
or in the sentence
Your acts or omissions is being replaced by the coordinates of
or appearing in the sentence above
property damage "or" personal and advertising.
This is happening for all duplicate keywords appearing. How can I solve this issue? I am also open to any other approach be it AI based or non AI based. Basically I need to highlight certain sentences occuring in a document, that's all!
Thanks in advance!