Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use OpenCV+Python to remove the background color of text captured by mobile phone

2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/02 Report--

This article shows you how to use OpenCV+Python to remove the background color of mobile text. The content is concise and easy to understand, which will definitely brighten your eyes. I hope you can get something through the detailed introduction of this article.

Recently, mobile phones are often asked to shoot test papers, but after shooting, there is a big color difference with the actual black-and-white test papers, and the background turns gray after printing, which looks very uncomfortable. So I remembered a long time ago, I used a software called omnipotent scanning king, found that it has the function to remove this kind of text background color, but sometimes it is very crappy! I just want to manually write a simple python program to achieve. In the end, the test effect of the program I wrote is as follows:

On the left is the image taken with the mobile phone, and on the right is the result of processing with opencv-python.

Train of thought analysis

First of all, take a look at the input of the original picture, (primary school homework can not be found, let me print for him is the cause, he wants to handwrite, I said I will deal with the print out), the original picture taken by others:

I found that these images are basically black-and-white paper or some paper with dotted lines, I first thought of picking out the text part from the input image, not too accurate, roughly on it, so to get the mask of Chinese characters in the image, I thought of using the binarization method, I first tried the global binary OTSU and triangulation to get mask, and found that the effect is a bit tricky! The figure is as follows:

The end result is this, and when the light is a little uneven, it just turns over at binary time! Will lose information, so I thought of using adaptive binarization method, and finally chose: binary = cv.adaptiveThreshold (image, 255, cv.ADAPTIVE_THRESH_GAUSSIAN_C, cv.THRESH_BINARY_INV, 25,15) this function to complete binarization, to achieve mask extraction

After the extraction is completed, a simple dilation operation is achieved through a morphological operation to ensure that the pixel range of each word is large enough not to be lost. The final adaptive mask:

Then realize and operate with the original image to get the real text region, use the mask region to invert the mask1, and then complete the bitwise_and operation on the mask and the input grayscale image. The final effect can be obtained by adding the result to mask1. The figure is as follows:

It will not make the eyes see uncomfortable black as after the binary words. to get the complete source code of this example, please follow the official account and reply "text goes to background".

Download 1:leetcode Open Source Book

Reply: leetcode in the official account of "AI algorithm and Image processing", and you can download it. Each question is runtime beats 100% open source good books, you deserve to have!

The above content is how to use OpenCV+Python to remove the background color of text taken by mobile phone. Have you learned the knowledge or skills? If you want to learn more skills or enrich your knowledge reserve, you are welcome to follow the industry information channel.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report