How to change a part of the color of the background, which is black, to white?

风格不统一 提交于 2019-12-24 10:23:40

问题


I have been working on PyTesseract OCR and converting PDF to JPEG inorder to OCR the image. A part of the image has a black background and white text, which Tesseract is unable to identify, whereas all other parts of my image are being read perfectly well. Is there a way to change a part of the image that has black background? I tried a few SO resources, but doesn't seem to help. I am using Python 3, Open CV version 4 and PyTesseract


回答1:


opencv has a bitwise not function wich correctly reverses the image

you can put a mask / freeze on the rest of the image (the part that is correct already) and use something like this:

imageWithMask = cv2.bitwise_not(imageWithMask)

alternatively you can also perform the operation on a copy of the image and only copy over parts / pixels / regions you need....



来源:https://stackoverflow.com/questions/54573130/how-to-change-a-part-of-the-color-of-the-background-which-is-black-to-white

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!