PaddleOCR | Awesome multilingual OCR toolkits based on PaddlePaddle (practical ultra lightweight OCR system, sup | Machine Learning library
kandi X-RAY | PaddleOCR Summary
Support
Quality
Security
License
Reuse
- Train a model
- Convert preds to float32
- Build the laloader
- Evaluate a model
- Create a predictor
- Get output tensors
- Return the current GPU id
- Evaluate the image
- Return the intersection of two polygons
- Run the analysis
- Recognize the image
- Run soft_nms algorithm
- Get the warp transformation matrix
- Sort boxes according to layout
- Generate one - hot attention layer
- Process start tag
- Match all match results
- Recognize the table
- Evaluate E2EE evaluation
- Export a single model
- Mouse move event handler
- Preprocess training
- Export the label
- Load function label annotations
- Evaluate E2E
- Generate a configuration dictionary
PaddleOCR Key Features
PaddleOCR Examples and Code Snippets
PD_CpuMathLibraryNumThreads PD_CudnnEnabled PD_DeleteAnalysisConfig PD_DeletePaddleBuf PD_DeletePaddleTensor PD_DeletePass PD_DeletePredictor PD_DeleteZeroCopyTensor PD_DestroyZeroCopyTensor PD_DisableGlogInfo PD_DisableGpu PD_EnableCUDNN PD_EnableMKLDNN PD_EnableMemoryOptim PD_EnableMkldnnBfloat16 PD_EnableMkldnnQuantizer PD_EnableProfile PD_EnableTensorRtEngine PD_EnableUseGpu PD_FractionOfGpuMemoryForPool PD_GetInputName PD_GetInputNum PD_GetOutputName PD_GetOutputNum PD_GetPaddleTensorDType PD_GetPaddleTensorData PD_GetPaddleTensorName PD_GetPaddleTensorShape PD_GetZeroCopyOutput PD_GpuDeviceId PD_InitZeroCopyTensor PD_IrOptim PD_IsValid PD_MemoryOptimEnabled PD_MemoryPoolInitSizeMb PD_MkldnnBfloat16Enabled PD_MkldnnEnabled PD_MkldnnQuantizerEnabled PD_ModelDir PD_ModelFromMemory PD_NewAnalysisConfig PD_NewPaddleBuf PD_NewPaddleTensor PD_NewPredictor PD_NewZeroCopyTensor PD_PaddleBufData PD_PaddleBufEmpty PD_PaddleBufLength PD_PaddleBufReset PD_PaddleBufResize PD_ParamsFile PD_PredictorRun PD_PredictorZeroCopyRun PD_ProfileEnabled PD_ProgFile PD_SetCpuMathLibraryNumThreads PD_SetInValid PD_SetMkldnnCacheCapacity PD_SetModel PD_SetModelBuffer PD_SetOptimCacheDir PD_SetPaddleTensorDType PD_SetPaddleTensorData PD_SetPaddleTensorName PD_SetPaddleTensorShape PD_SetParamsFile PD_SetProgFile PD_SetZeroCopyInput PD_SpecifyInputName PD_SwitchIrDebug PD_SwitchIrOptim PD_SwitchSpecifyInputNames PD_SwitchUseFeedFetchOps PD_TensorrtEngineEnabled PD_UseFeedFetchOpsEnabled PD_UseGpu PD_ZeroCopyRun
python server.py ''' * Debugger is active! * Debugger PIN: 109-572-001 * Running on http://127.0.0.1:8090/ (Press CTRL+C to quit) '''
python test-post.py ''' { "服务状态": "success", "识别时间": "3.2900s", "识别结果": [ "健康宝", "2022年06月02日", "19:38:23", "未见异常②", "④核酸", "阴性", "时间", "#疫苗", "查看", "名", "姓", "李*", "身份证号", "61***", "**28", "查询时间", "06-0214:30", "失效时间", "06-0224:00", "返回首页", ] } '''
git clone git@github.com:PaddlePaddle/PaddleOCR.git
#检测预训练模型: mkdir models cd models wget https://paddleocr.bj.bcebos.com/PP-OCRv3/chinese/ch_PP-OCRv3_det_distill_train.tar tar -xf ch_PP-OCRv3_det_distill_train.tar #识别预训练模型: wget https://paddleocr.bj.bcebos.com/PP-OCRv3/chinese/ch_PP-OCRv3_rec_train.tar tar -xf ch_PP-OCRv3_rec_train.tar cd ..
cd PaddleOCR pip install -r requirements.txt
Trending Discussions on PaddleOCR
Trending Discussions on PaddleOCR
QUESTION
I am trying to replace lines using sed, and usually this works fine, but I am now encountering a string which does not seem to play ball with sed :(
file: test.py
$ cat test.py
BASE_DIR = os.path.expanduser("~/.teststring/")
I replace this line using:
sed -i '/BASE_DIR = os.path.expanduser("~/.paddleocr/")/c\BASE_DIR = os.path.expanduser("/tmp/.teststring/")' test.py
I get:
sed: -e expression #1, char 35: unknown command: `.'
Not sure what is causing this. I tried escaping the .
using \.
but this does not help either :(
ANSWER
Answered 2022-Mar-07 at 14:41I think your first "
should be a '
Also, you need to escape the \
which aren't part of the sed syntax e.g.:
sed -i '/BASE_DIR = os.path.expanduser("~\/.paddleocr\/")/c\\BASE_DIR = os.path.expanduser("\/tmp\/.teststring/")' test.py
QUESTION
one problem with optical character recognition (ocr) is it can't recognize numbers properly when numbers are inside square boxes. one failure example with tesseract is discussed here : Tesseract - How can I recognize numbers in box? i was testing with paddleocr here : https://www.paddlepaddle.org.cn/hub/scene/ocr you can quickly try that api too,,for this input image :
again when i try image like this :
it returns all the numbers successfully.most of the times these number recognition(both printed and handwritten) failing when they are inside square boxes.for recognizing numbers inside square boxes we need to convert these so called numbers in box image into numbers in image by removing all the square boxes. i have some images like below :
see, the full square box outside numbers are not fully visible,,only some part of the square boxes are visible.i want to convert these images into image where i will have only the numbers by removing square boxes or some part of square boxes that is present in these images after then hopefully number/digit recognition will work. i tried this code :
import cv2
import numpy as np
import matplotlib.pyplot as plt
img = cv2.imread('/content/21.png')
gray=cv2.cvtColor(img,cv2.COLOR_BGR2GRAY)
linek = np.zeros((11,11),dtype=np.uint8)
linek[...,5]=1
x=cv2.morphologyEx(gray, cv2.MORPH_OPEN, linek ,iterations=800)
gray-=x
plt.imshow(gray)
cv2.imwrite('21_output.jpg', gray)
import cv2
import numpy as np
import matplotlib.pyplot as plt
#https://stackoverflow.com/questions/57961119/how-to-remove-all-the-detected-lines-from-the-original-image-using-python
image = cv2.imread('/content/17.png')
gray = cv2.cvtColor(image,cv2.COLOR_BGR2GRAY)
thresh = cv2.threshold(gray, 0, 255, cv2.THRESH_BINARY_INV + cv2.THRESH_OTSU)[1]
# Remove vertical
vertical_kernel = cv2.getStructuringElement(cv2.MORPH_RECT, (1,10))
detected_lines = cv2.morphologyEx(thresh, cv2.MORPH_OPEN, vertical_kernel, iterations=2)
cnts = cv2.findContours(detected_lines, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)
cnts = cnts[0] if len(cnts) == 2 else cnts[1]
for c in cnts:
cv2.drawContours(image, [c], -1, (255,255,255), 2)
image = thresh - detected_lines
plt.imshow( image)
ANSWER
Answered 2021-Nov-01 at 15:01the code below for me is doing decent job but it's hyper parameter sensitive :
import cv2
import imutils
import numpy as np
import matplotlib.pyplot as plt
from matplotlib import pyplot as plt
def square_number_box_denoiser(image_path="/content/9.png",is_resize = False, resize_width = 768):
'''
ref : https://pretagteam.com/question/removing-horizontal-lines-in-image-opencv-python-matplotlib
Args :
image_path (str) : path of the image containing numbers/digits inside square box
is_resize (int) : whether to resize the input image or not? default : False
resize_width (int) : resizable image width for resizing the image by maintaining aspect ratio. default : 768
'''
img=cv2.imread(image_path)
if(is_resize):
print("resizing...")
img = imutils.resize(img, width=resize_width)
image = cv2.rotate(img, cv2.ROTATE_90_CLOCKWISE)
gray = cv2.cvtColor(image,cv2.COLOR_BGR2GRAY)
thresh = cv2.threshold(gray, 0, 255, cv2.THRESH_BINARY_INV + cv2.THRESH_OTSU)[1]
# Remove horizontal
horizontal_kernel = cv2.getStructuringElement(cv2.MORPH_RECT, (25,1))
detected_lines = cv2.morphologyEx(thresh, cv2.MORPH_OPEN, horizontal_kernel, iterations=2)
cnts = cv2.findContours(detected_lines, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)
cnts = cnts[0] if len(cnts) == 2 else cnts[1]
for c in cnts:
cv2.drawContours(image, [c], -1, (255,255,255), 2)
# Repair image
repair_kernel = cv2.getStructuringElement(cv2.MORPH_RECT, (1,6))
result = 255 - cv2.morphologyEx(255 - image, cv2.MORPH_CLOSE, repair_kernel, iterations=2)
# create figure
fig = plt.figure(figsize=(20, 20))
# setting values to rows and column variables
rows = 3
columns = 3
fig.add_subplot(rows, columns, 1)
plt.imshow(img)
fig.add_subplot(rows, columns, 2)
plt.imshow(thresh)
fig.add_subplot(rows, columns, 3)
plt.imshow(detected_lines)
fig.add_subplot(rows, columns, 4)
plt.imshow(image)
fig.add_subplot(rows, columns, 5)
plt.imshow(result)
result = cv2.rotate(result,cv2.ROTATE_90_COUNTERCLOCKWISE)
fig.add_subplot(rows, columns, 6)
plt.imshow(result)
cv2.imwrite("result.jpg", result)
plt.show()
QUESTION
I'm currently trying to run a piece of code using PaddleOCR, but I'm stuck at importing PaddleOCR. It gives me the error OSError: [WinError 126] The specified module could not be found.
from paddleocr import PaddleOCR, draw_ocr
Gives Error :
---------------------------------------------------------------------------
OSError Traceback (most recent call last)
~\AppData\Local\Temp/ipykernel_16624/4181743072.py in
----> 1 from paddleocr import PaddleOCR, draw_ocr
~\Anaconda3\envs\NUS_PY37\lib\site-packages\paddleocr\__init__.py in
13 # limitations under the License.
14 import paddleocr
---> 15 from .paddleocr import *
16
17 __version__ = paddleocr.VERSION
~\Anaconda3\envs\NUS_PY37\lib\site-packages\paddleocr\paddleocr.py in
24 from pathlib import Path
25
---> 26 from tools.infer import predict_system
27 from ppocr.utils.logging import get_logger
28
~\Anaconda3\envs\NUS_PY37\lib\site-packages\paddleocr\tools\infer\predict_system.py in
29 from PIL import Image
30 import tools.infer.utility as utility
---> 31 import tools.infer.predict_rec as predict_rec
32 import tools.infer.predict_det as predict_det
33 import tools.infer.predict_cls as predict_cls
~\Anaconda3\envs\NUS_PY37\lib\site-packages\paddleocr\tools\infer\predict_rec.py in
29
30 import tools.infer.utility as utility
---> 31 from ppocr.postprocess import build_post_process
32 from ppocr.utils.logging import get_logger
33 from ppocr.utils.utility import get_image_file_list, check_and_read_gif
~\Anaconda3\envs\NUS_PY37\lib\site-packages\paddleocr\ppocr\postprocess\__init__.py in
22 __all__ = ['build_post_process']
23
---> 24 from .db_postprocess import DBPostProcess, DistillationDBPostProcess
25 from .east_postprocess import EASTPostProcess
26 from .sast_postprocess import SASTPostProcess
~\Anaconda3\envs\NUS_PY37\lib\site-packages\paddleocr\ppocr\postprocess\db_postprocess.py in
20 import cv2
21 import paddle
---> 22 from shapely.geometry import Polygon
23 import pyclipper
24
~\Anaconda3\envs\NUS_PY37\lib\site-packages\shapely\geometry\__init__.py in
2
3
----> 4 from .base import CAP_STYLE, JOIN_STYLE
5 from .geo import box, shape, asShape, mapping
6 from .point import Point, asPoint
~\Anaconda3\envs\NUS_PY37\lib\site-packages\shapely\geometry\base.py in
17
18 from shapely.affinity import affine_transform
---> 19 from shapely.coords import CoordinateSequence
20 from shapely.errors import WKBReadingError, WKTReadingError
21 from shapely.geos import WKBWriter, WKTWriter
~\Anaconda3\envs\NUS_PY37\lib\site-packages\shapely\coords.py in
6 from ctypes import byref, c_double, c_uint
7
----> 8 from shapely.geos import lgeos
9 from shapely.topology import Validating
10
~\Anaconda3\envs\NUS_PY37\lib\site-packages\shapely\geos.py in
152 if os.getenv('CONDA_PREFIX', ''):
153 # conda package.
--> 154 _lgeos = CDLL(os.path.join(sys.prefix, 'Library', 'bin', 'geos_c.dll'))
155 else:
156 try:
~\Anaconda3\envs\NUS_PY37\lib\ctypes\__init__.py in __init__(self, name, mode, handle, use_errno, use_last_error)
362
363 if handle is None:
--> 364 self._handle = _dlopen(self._name, mode)
365 else:
366 self._handle = handle
OSError: [WinError 126] The specified module could not be found
ANSWER
Answered 2021-Oct-01 at 15:10conda install -c conda-forge shapely
resolved by this line of code
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install PaddleOCR
You can use PaddleOCR like any standard Python library. You will need to make sure that you have a development environment consisting of a Python distribution including header files, a compiler, pip, and git installed. Make sure that your pip, setuptools, and wheel are up to date. When using pip it is generally recommended to install packages in a virtual environment to avoid changes to the system.
Support
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesExplore Kits - Develop, implement, customize Projects, Custom Functions and Applications with kandi kits
Save this library and start creating your kit
Share this Page