如何将背景的一部分颜色(黑色)更改为白色? [英] How to change a part of the color of the background, which is black, to white?

查看:93
本文介绍了如何将背景的一部分颜色(黑色)更改为白色?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在研究 PyTesseract OCR 并将 PDF 转换为 JPEG,以便对图像进行 OCR.图像的一部分具有黑色背景和白色文本,Tesseract 无法识别,而我图像的所有其他部分都可以很好地读取.有没有办法更改具有黑色背景的图像部分?我尝试了一些 SO 资源,但似乎没有帮助.我正在使用 Python 3、Open CV 版本 4 和 PyTesseract

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

推荐答案

opencv 有一个按位不能正确反转图像的功能

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)

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....

这篇关于如何将背景的一部分颜色(黑色)更改为白色?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆