当前位置:网站首页>Paddleocr image text extraction
Paddleocr image text extraction
2022-04-23 07:22:00 【Lin Jinpeng】
PaddleOCR Image text extraction
demand
A need at work , You need to extract the license plate number in the picture . Pictured , The license plate is in the fixed position of the picture . Start using pytesseract, Especially unfriendly to Chinese recognition , After all, it's a foreigner's thing . Colleagues recommend PaddleOCR, The things developed by Chinese people are different , The recognition accuracy can reach 90% above . But both have common problems , White characters on black background cannot be recognized / The range is too small, the identification is not allowed to wait .
One . Cut the license plate number area
# np.fromfil Construct an array from data in a text or binary file
# cv2.imdecode() Convert the read data ( decode ) In image format ; It is mainly used to recover images from network transmission data
# cv2.IMREAD_UNCHANGED: Read the full picture , Include alpha passageway , You can write directly -1
img = cv2.imdecode(np.fromfile(imgSrc, dtype=np.uint8), cv2.IMREAD_UNCHANGED)
cropImg = img[y1:y2, x1:x2] # The order is up and down about
So Baidu found Zhang Tu , It happens to be black on a white background Writing in the middle , The results magically identify the results 100% The identification is correct . After comparison , I concluded that the white font was unrecognizable , Then invert the small graph .
Two . Process the small picture of the license plate
height, width, deep = cropImg.shape
gray = cv2.cvtColor(cropImg, cv2.COLOR_BGR2GRAY) # cv2.COLOR_BGR2GRAY take BGR Convert format to grayscale image
dst = np.zeros((height, width, 1), np.uint8) # Generate a pure black picture
for i in range(0, height): # Reverse phase Turn to black on white
for j in range(0, width):
grayPixel = gray[i, j]
dst[i, j] = 255 - grayPixel
# After this step , It's done Turn to black on white , But the white low background is not the brightest
# Reuse cv2.threshold To binarize , Make the black part darker , White is whiter
ret, img = cv2.threshold(dst, 0, 255, cv2.THRESH_BINARY + cv2.THRESH_OTSU)
The result of inverting the small graph is as follows , Look carefully and find that the white background is not very white , Reuse cv.threshold To binarize ( Neither black nor white ), By comparing binary images , The sense of hierarchy comes out .
Identify again , The recognition result finally came out , But I found the last one 7 Identified as 2, In principle, such simple words should not be recognized wrong . So I thought that the boundary of the picture used to test and identify is very wide , Writing in the middle , Then the small graph is filled with white background boundary 150 Pixel .
3、 ... and . Fill in the boundary
# cv2.BORDER_CONSTANT Fixed value filling method
imgsrc = cv2.copyMakeBorder(img, 150, 150, 150, 150, cv2.BORDER_CONSTANT, value=[255, 255, 255])
Four . Identification steps
ocr = PaddleOCR(use_angle_cls=True, use_gpu=False) # Use CPU Preloading , no need GPU
text = ocr.ocr(img, cls=True)
result = str(text[0][1][0]).replace(' license plate :', '').upper()
版权声明
本文为[Lin Jinpeng]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204230609472920.html
边栏推荐
猜你喜欢
机器学习 二:基于鸢尾花(iris)数据集的逻辑回归分类
【点云系列】SG-GAN: Adversarial Self-Attention GCN for Point Cloud Topological Parts Generation
【2021年新书推荐】Enterprise Application Development with C# 9 and .NET 5
Google AdMob advertising learning
1.1 PyTorch和神经网络
[2021 book recommendation] red hat rhcsa 8 cert Guide: ex200
【点云系列】 场景识别类导读
[Point Cloud Series] SG - Gan: Adversarial Self - attachment GCN for Point Cloud Topological parts Generation
C# EF mysql更新datetime字段报错Modifying a column with the ‘Identity‘ pattern is not supported
Component based learning (3) path and group annotations in arouter
随机推荐
深度学习模型压缩与加速技术(一):参数剪枝
Component based learning (1) idea and Implementation
[2021 book recommendation] Red Hat Certified Engineer (RHCE) Study Guide
Visual studio 2019 installation and use
MySQL notes 5_ Operation data
What did you do during the internship
PaddleOCR 图片文字提取
素数求解的n种境界
Use originpro express for free
【点云系列】Unsupervised Multi-Task Feature Learning on Point Clouds
Migrating your native/mobile application to Unified Plan/WebRTC 1.0 API
DCMTK (dcm4che) works together with dicoogle
[point cloud series] pnp-3d: a plug and play for 3D point clouds
Chapter 1 numpy Foundation
[recommendation of new books in 2021] practical IOT hacking
机器学习 三: 基于逻辑回归的分类预测
Face_ Recognition face detection
MySQL的安装与配置——详细教程
[2021 book recommendation] kubernetes in production best practices
【2021年新书推荐】Enterprise Application Development with C# 9 and .NET 5