PADDLEOCR
Introduction to OCR OCR နိဒါန်း
Optical Character Recognition is a technique that recognizes and converts the text into a machine readable format by analyzing and understanding the pattern.OCR can recognizes handwritten text,printed and text in the wild.OCR help us to read and with OCR can predict the output accurately and that too in a matter of milliseconds.
အလင်းအက္ခရာမှတ်မိခြင်းသည် ပုံစံကို ဆန်းစစ်နားလည်ခြင်းဖြင့် စာသားကို မှတ်မိပြီး စက်ဖတ်နိုင်သောပုံစံအဖြစ် ပြောင်းလဲပေးသည့် နည်းပညာတစ်ခုဖြစ်သည်။ OCR သည် လက်ရေးစာသား၊ ပုံနှိပ်ခြင်းနှင့် စာသားကို မှတ်မိနိုင်ပါသည်။ OCR က စာဖတ်ဖို့ ကူညီပေးပြီး OCR နဲ့ ထုတ်လုပ်မှုကို တိတိကျကျ ခန့်မှန်းနိုင်ပြီး အဲဒါကိုလည်း မီလီစက္ကန့်အတွင်း ခန့်မှန်းနိုင်ပါတယ်။
OCR is one of the first problems addressed in computer vision and deep learning development.
OCR သည် ကွန်ပျူတာအမြင်နှင့် နက်ရှိုင်းသော သင်ယူမှုဖွံ့ဖြိုးတိုးတက်မှုတွင် ပထမဆုံးဖြေရှင်းသည့် ပြဿနာများထဲမှ တစ်ခုဖြစ်သည်။
There are various types of OCR technique to implement and when I came to work with OCR ,I used Pytesseract ,EasyOCR and KerasOCR and finally PaddleOCR ,among these PAddle OCR gave me better results.The impact of PaddleOCr made me to write this article .
အကောင်အထည်ဖော်ရန် OCR နည်းပညာ အမျိုးမျိုးရှိပြီး OCR နှင့်အတူ အလုပ်လုပ်လာသောအခါ Pytesseract ၊ EasyOCR နှင့် KerasOCR နှင့် နောက်ဆုံး PaddleOCR ကို အသုံးပြုခဲ့ပြီး ဤပက်ဒယ် OCR အနက် ပိုကောင်းသော ရလဒ်များပေးခဲ့သည်။ PaddleOCr ရဲ့ အကျိုးသက်ရောက်မှုက ဒီဆောင်းပါးကို ရေးဖို့ ကျွန်မကို လှုံ့ဆော်ပေးခဲ့တယ်။
PaddleOCR: PaddleOCR :
PaddleOCR is an OCR framework or toolkit which provides multilingual practical OCR tools that help the users to apply and train different models in a few lines of code.PaddleOCR offers a series of high quality pre trained models.This contains three types of models to make OCR highly accurate and close to the commercial products.It also providesText detection,Text direction classifier and Text recognition.PaddleOCR offers various models in toolkita which includes the flagship PP-OCR and the latest algorithms such as SRN,NRTR and more.
PaddleOCR သည် သုံးစွဲသူများအား သင်္ကေတလိုင်းအနည်းငယ်တွင် ပုံစံအမျိုးမျိုးကို အသုံးပြုလေ့ကျင့်ပေးရန် ကူညီပေးသည့် ဘာသာစကားအမျိုးမျိုးဖြင့် လက်တွေ့ကျသော OCR ကိရိယာများကို ထောက်ပံ့ပေးသည့် OCR ဘောင် သို့မဟုတ် ကိရိယာတစ်ခုဖြစ်သည်။ PaddleOCR သည် အရည်အသွေးမြင့် ကြိုတင်လေ့ကျင့်ထားသော မော်ဒယ်များကို ကမ်းလှမ်းပေးသည်။ ၎င်း တွင် အိုစီအာရ် ကို အလွန် တိကျမှန်ကန် ပြီး စီးပွားရေး ထုတ်ကုန် များ နှင့် နီးကပ် အောင် ပြုလုပ် ရန် ပုံစံ သုံး မျိုး ပါဝင် သည် ။ စာသား ရှာဖွေ ခြင်း ၊ စာသား ဦးတည်ချက် ခွဲခြား ခြင်း နှင့် စာသား မှတ်မိ ခြင်း တို့ ကို လည်း ထောက်ပံ့ ပေး သည် ။ PaddleOCR သည် အဓိက ပီပီ-အိုစီအာရ် နှင့် အက်စ်အာအန်၊ အန်အာတီအာရ် နှင့် ပို သော နောက်ဆုံး အယ်လ်ဂိုရီသမ် များ ပါဝင် သော တူးကီတာ တွင် မျိုးစုံ သော ပုံစံ များ ကို ကမ်းလှမ်း သည် ။
PaddleOCR offers different models based on size:
PaddleOCR သည် အရွယ်အစား ပေါ် မူတည် ၍ ကွဲပြား သော ပုံစံ များ ကို ကမ်းလှမ်း သည် ။
- Lightweight models — Models which takes less memory and are faster but compromise on accuracy
ပေါ့ပါး သော မော်ဒယ် များ — မှတ်ဉာဏ် နည်းပါး ပြီး ပိုမြန် သော်လည်း တိကျမှန်ကန် မှု ကို အလျှော့ပေး သော ပုံစံ များ - Server models — Models which take more memory but are more accurate but compromise on speed.
ဆာဗာ မော်ဒယ် များ — မှတ်ဉာဏ် ပိုမို ယူ သော်လည်း ပိုမို တိကျသော်လည်း အမြန်နှုန်း ကို အလျှော့ပေး သော မော်ဒယ် များ ။
PaddleOCR supports 80 languages .But PP_OCR provides support for both Chinese and English .The paddleOCr are build on CRNN(CNN + RNN) architecture.
PaddleOCR သည် ဘာသာစကား ၈၀ ကို ထောက်ပံ့ သည် ။ သို့သော် PP_OCR သည် တရုတ် နှင့် အင်္ဂလိပ် နှစ် ခု စလုံး ကို ထောက်ပံ့ ပေး သည် ။ paddleOCr ကို CRNN (CNN + RNN) ဗိသုကာပေါ်တွင် တည်ဆောက်ထားသည်။
CRNN architecture: CRNN ဗိသုကာ:

CRNN is a combination of both Convolutional and Recurrent neural networks. Hence the name Convolutional Recurrent Neural Network (CRNN). This network consists of three layers, CNNs followed by RNNs and then the Transcription layer. CRNN uses CTC or Connectionist Temporal Classification Loss which is responsible for the alignment of predicted sequences.
CRNN သည် Convolutional နှင့် Recurrent နဗ်ကြော ကွန်ရက် နှစ် ခု စလုံး ၏ ပေါင်းစပ် မှု တစ် ခု ဖြစ် သည် ။ ထို့ကြောင့် Convolutional Recurrent Neural Network (CRNN) ဟုအမည်ပေးခဲ့သည်။ ဤ ကွန်ယက် တွင် အလွှာ သုံး လွှာ ပါဝင် သည် ၊ စီအန်အန် နောက် အာအန်အန်အန် နှင့် ကူးယူ ခြင်း အလွှာ တို့ ပါဝင် သည် ။ စီအာအန်အန် သည် ခန့်မှန်း ထား သော အစီအစဉ် များ ၏ ညှိနှိုင်း မှု အတွက် တာဝန် ရှိ သော စီတီစီ သို့မဟုတ် ဆက်သွယ်ရေး ကာလ ခွဲခြား မှု ဆုံးရှုံး မှု ကို အသုံးပြု သည် ။
Feature Extraction အသွင်အပြင်ထုတ်ယူခြင်း
The first layer is the convolutional neural network (CNN) which consists of Convolutional and max-pooling layers. These are responsible for extracting features from the input images and producing feature maps as outputs. To feed output to the next layer, feature maps are first converted into a sequence of feature vectors. According to the original paper, Each feature vector of a feature sequence is generated from left to right on the feature maps by column. This means the i-th feature vector is the concatenation of the i-th columns of all the maps.
ပထမအလွှာမှာ Convolutional နှင့် max-pooling အလွှာများပါဝင်သော convolutional နဗ်ကြောကွန်ရက် (CNN) ဖြစ်သည်။ ၎င်း တို့ သည် ထည့်သွင်း ထား သော ပုံရိပ် များ မှ အသွင်အပြင်များ ထုတ်ယူ ခြင်း နှင့် ထုတ်လုပ် မှု အဖြစ် အသွင်အပြင် မြေပုံ များ ထုတ်လုပ် ခြင်း အတွက် တာဝန် ရှိ သည် ။ နောက်အလွှာသို့ ထုတ်လုပ်ရန် အသွင်အပြင်မြေပုံများကို အသွင်အပြင်ဗက်တာများ အစဉ်အလာအဖြစ် ဦးဆုံး ပြောင်းလဲပေးသည်။ မူရင်း စာတမ်း အရ ၊ အသွင်အပြင် အစီအစဉ် တစ် ခု ၏ အသွင်အပြင် ဗက်တာ တစ် ခု စီ ကို ကော်လံ အလိုက် အသွင်အပြင် မြေပုံ ပေါ်တွင် လက်ဝဲ မှ ညာဘက် သို့ ထုတ်လုပ် ခဲ့ သည် ။ ဆိုလိုသည်မှာ အိုင်-တုမြောက် အသွင်အပြင်ဗက်တာသည် မြေပုံအားလုံး၏ i-အကြိမ်မြောက် ကော်လံများကို ဆက်စပ်ခြင်းဖြစ်သည်။
Due to the feature extraction, each column of the feature maps corresponds to a rectangular region of the input image, that region is called a receptive field. Each feature vector in the feature sequence is associated with the receptive field and can be called an appearance descriptor for that region.
အသွင်အပြင်ထုတ်ယူမှုကြောင့် အသွင်အပြင်မြေပုံ၏ ကော်လံတစ်ခုစီသည် အဝင်ပုံ၏ စတုတ္ထုပုံနှင့် ကိုက်ညီပြီး ထိုနယ်မြေကို လက်ခံသည့်ကွင်းဟု ခေါ်သည်။ အသွင်အပြင်အစဉ်အလာရှိ အသွင်အပြင်တစ်ခုစီသည် လက်ခံမှုနယ်ပယ်နှင့် ဆက်စပ်နေပြီး ထိုဒေသအတွက် အသွင်အပြင်ဖော်ပြကိရိယာဟု ခေါ်ဆိုနိုင်သည်။
Sequence Labeling အစဉ်အဆက်တံဆိပ်ခတ်ခြင်း
This layer is the Recurrent Neural Network (RNN) which is built on top of the Convolutional Neural Network. In CRNN, two Bi-directional LSTMs are used in the architecture to address the vanishing gradient problem and to have a deeper network. The recurrent layers predict the label for each feature vector or frame in the feature sequence received from CNN layers.
ဤ အလွှာ သည် Convolutional Neural Network ၏ ထိပ်ပိုင်း တွင် တည်ဆောက် ထား သော ပြန်လည် ဖြစ်ပွား သော နဗ်ကြော ကွန်ယက် ( RNN ) ဖြစ် သည် ။ စီအာအန်အန် တွင် ၊ ပျောက်ကွယ် နေ သော ရောင်စဉ်တန်း ပြဿနာ ကို ဖြေရှင်း ရန် နှင့် နက်ရှိုင်း သော ကွန်ယက် တစ် ခု ရှိ ရန် ဗိသုကာ တွင် နှစ် ဘက် အယ်လ်အက်စ်တီအမ် နှစ် ခု ကို အသုံးပြု ခဲ့ သည် ။ ထပ်ခါထပ်ခါ အလွှာများက CNN အလွှာများမှ လက်ခံရရှိသော အသွင်အပြင်အစဉ်အလာတွင် အသွင်အပြင်တစ်ခုစီအတွက် အမှတ်အသားကို ခန့်မှန်းသည်။
Transcription မှတ်တမ်း
This layer is responsible for translating the per-frame predictions into a final sequence according to the highest probability. These predictions are used to compute CTC or Connectionist Temporal Classification loss which makes the model learn and decode the output.
ဤ အလွှာ သည် အ မြင့် ဆုံး ဖြစ်နိုင်ခြေ အရ ဘောင် တစ် ခု စီ ခန့်မှန်း ချက် များ ကို နောက်ဆုံး အစီအစဉ် တစ် ခု အဖြစ် ဘာသာ ပြန် ရန် တာဝန် ရှိ သည် ။ ဤ ခန့်မှန်း ချက် များ ကို စီတီစီ သို့မဟုတ် ဆက်သွယ်ရေး သမား အချိန် ခွဲခြား မှု ဆုံးရှုံး မှု ကို တွက်ချက် ရန် အသုံးပြု ခဲ့ သည် ၊ ၎င်း သည် ပုံစံ ကို သင်ယူ ပြီး ထုတ်ထွက် မှု ကို ဖော်ထုတ် သည် ။
Installation: တပ်ဆင် ခြင်း -
pip install paddlepaddle-gpu
pip install paddleocr
Once you done with installation.perform
install.perform ပြီးသွားပြီဆိုလျှင်
from paddleocr import PaddleOCR,draw_ocr
import os
import cv2
import matplotlib.pyplot as plt
ocr = PaddleOCR(use_angle_cls = True)
This package by default provides all of the models of the system which are detection, angle classification and recognition. It provides several arguments to access only the required functionalities.
ဤ ပက်ကေ့ချ် သည် စံနှုန်း အားဖြင့် ရှာဖွေ ခြင်း ၊ ထောင့် ခွဲခြား ခြင်း နှင့် အသိအမှတ်ပြု ခြင်း တို့ ဖြစ် သော စနစ် ၏ ပုံစံ များ အားလုံး ကို ထောက်ပံ့ ပေး သည် ။ ၎င်း သည် လိုအပ် သော လုပ်ဆောင် ချက် များ ကို သာ အသုံးပြု ရန် အငြင်းပွား မှု များ စွာ ကို ထောက်ပံ့ ပေး သည် ။
- lang: The language which we want to recognise is passed here. For example, en for English, ch for Chinese, french for French, etc. The OCR can recognise English and Chinese by default.
lang: ကျွန်တော်တို့ အသိအမှတ်ပြုချင်တဲ့ ဘာသာစကားကို ဒီမှာ လက်ဆင့်ကမ်းထားတယ်။ ဥပမာ၊ အင်္ဂလိပ်အတွက် en, တရုတ်အတွက် ch, ပြင်သစ်အတွက် ပြင်သစ် စတာ။ OCR သည် အင်္ဂလိပ် နှင့် တရုတ် ကို စံထား ချက် ဖြင့် အသိအမှတ်ပြု နိုင် သည် ။ - rec_algorithm: Takes the recognition algorithm to be used as arguments. The OCR uses CRNN as its default recognition algorithm.
rec_algorithm: အသိအမှတ်ပြု အယ်ဂိုရီသမ်ကို အငြင်းပွားများအဖြစ် အသုံးပြုသည်။ OCR သည် CRNN ကို ၎င်း ၏ စံထား အသိအမှတ်ပြု အယ်ဂိုရီသမ် အဖြစ် အသုံးပြု သည် ။ - det_algorithm: Takes the text detection algorithm to be used as arguments. The OCR uses a DB text detector as its default detector.
det_algorithm: စာသားရှာဖွေရေး အယ်ဂိုရီသမ်ကို အငြင်းပွားများအဖြစ် အသုံးပြုသည်။ OCR သည် DB စာသား ရှာဖွေ ရေး ကိရိယာ ကို ၎င်း ၏ စံထား ချက် ရှာဖွေ သူ အဖြစ် အသုံးပြု သည် ။ - use_angle_cls: Specifies if angle classifier is to be used or not and takes bool as the argument.
use_angle_cls: ထောင့်ခွဲခြားကိရိယာကို အသုံးပြုရန် သို့မဟုတ် မသုံးရန် သတ်မှတ်ပြီး အငြင်းပွားမှုအဖြစ် ဘိုလ်ကိုယူသည်။
result = ocr.ocr(img_path)
This function would also take arguments .
ဤလုပ်ဆောင်ချက်သည် အချေအတင်များကိုလည်း ယူမည်။
- img: This is the first parameter in the ocr function. In this, the image array or the image path is passed to perform OCR.
img: ဒါက ocr လုပ်ဆောင်ချက်ထဲက ပထမဆုံး ကိရိယာပါ။ ဒီထဲမှာ OCR လုပ်ဖို့ ရုပ်ပုံ အရေပြား (သို့) ရုပ်ပုံ လမ်းကြောင်းကို ဖြတ်သွားတယ်။ - det: Takes bool as an argument and specifies whether to use a detector or not.
det: bool ကို အငြင်းပွား မှု တစ် ခု အဖြစ် ယူ ပြီး ရှာဖွေ ရေး ကိရိယာ တစ် ခု ကို အသုံးပြု ရန် ၊ မ အသုံးပြု ရန် သတ်မှတ် သည် ။ - rec: Takes bool as argument and specifies whether to use a recognizer or not.
rec: bool ကို အငြင်းပွား အဖြစ် ယူ ပြီး မှတ်မိ သူ တစ် ခု ကို အသုံးပြု ရန် ၊ မ အသုံးပြု ရန် သတ်မှတ် သည် ။ - cls: Takes bool as argument and specifies whether to use an angle classifier or not.
cls: bool ကို အငြင်းပွား အဖြစ် ယူ ပြီး ထောင့် ခွဲခြား မှု တစ် ခု ကို အသုံးပြု ရန် ၊ မ အသုံးပြု ရန် သတ်မှတ် သည် ။
By default, all three det, rec and cls are set as True.
စံထားချက်အရ det, rec နှင့် cls သုံးခုစလုံးကို True အဖြစ် သတ်မှတ်ထားသည်။
def save_ocr(img_path,out_path,result,font):
save_path = os.path.join(out_path,img_path.split('/')[-1]+ 'output')
image = cv2.imread(img_path)
boxes = [line[0] for line in result]
texts = [line[1][0] for line in result]
scores = [lines[1][1] for line in result]
im_show = draw_ocr(image,boxes,txts,scores,font_path = font)
cv2.imwrite(save_path , imshow)
img = cv2.imshow(im_show,cv2.COLOR_BGR2RGB)
plt.imshow(img)
Detection angle classification and recognition
ရှာဖွေ တွေ့ ရှိ သော ထောင့် အမျိုးအစား ခွဲခြား ခြင်း နှင့် အသိအမှတ်ပြု ခြင်း
from paddleocr import PaddleOCR,draw_ocr
ocr = PaddleOCR(use_angle = True,lang = 'en')
img_path ='path/to/image.jpg'
result = ocr.ocr(img_path,cls = True)
for idx in range(len(result)):
res = result[idx]
for line in res:
print(line)
#draw result
from PIL import Image
result = result[0]
image = Image.open(img_path).convert('RGB')
boxes = [line[0] for line in result]
txts = [line[1][0] for line in result]
scores = [lines[1][1] for line in result]
im_show = draw_ocr(images,boxes,txts,scores,font_path = '/path/to/PaddleOCR/doc/fonts/simfang.ttf')
im_show.save('result.jpg')
Output: ထုတ်လုပ်ချက် -
[[[442.0, 173.0], [1169.0, 173.0], [1169.0, 225.0], [442.0, 225.0]], ['ACKNOWLEDGEMENTS', 0.99283075]]
[[[393.0, 340.0], [1207.0, 342.0], [1207.0, 389.0], [393.0, 387.0]], ['We would like to thank all the designers and', 0.9357758]]
[[[399.0, 398.0], [1204.0, 398.0], [1204.0, 433.0], [399.0, 433.0]], ['contributors whohave been involved in the', 0.9592447]]
......
Detection and recognition
ရှာဖွေခြင်းနှင့် အသိအမှတ်ပြုခြင်း
from paddleocr import PaddleOCR,draw_ocr
ocr = PaddleOCR(lang = 'en')
img_path = 'imag.jpg'
result = ocr.ocr(img_path,cls = False)
for idx in range(len(result)):
res = result[idx]
for line in res:
print(line)
#draw result
from PIL import Image
result = result[0]
image = Image.open(img_path).convert('RGB')
boxes = [line[0] for line in result]
txts = [line[1][0]for line in result]
scores = [lines[1][1] for line in result]
im_show = draw_ocr(images,boxes,txts,scores,font_path = '/path/to/PaddleOCR/doc/fonts/simfang.ttf')
im_show = Image.fromarray(im_show)
im_show.save('result.jpg')
Classification and recognition
အမျိုးအစားခွဲခြားခြင်းနှင့် အသိအမှတ်ပြုခြင်း
from Paddleocr import PaddleOCR
ocr = PaddleOCR(use_angle_cls = True,lang = 'en')
img_path = 'img.png'
result = ocr.ocr(img_path,det = False,cls = True)
for idx in rangE(len(result)):
res = result[idx]
for line in res:
print(line)
Output: ထုတ်လုပ်ချက် -
['PAIN', 0.990372]
Only Detection: ရှာဖွေ တွေ့ ရှိ မှု သာလျှင် -
from Paddleocr import PaddleOCR,draw_ocr
ocr = PaddleOCR()
img_path ='img.jpg'
result =ocr.ocr(img_path,rec = False)
for idx in range(result)):
res = result[idx]
for line in res:
print(line)
#draw result
from PIL import Image
result = result[0]
image = Image.open(img_path).convert('RGB')
im_show = draw_ocr(image,result,txt=None,font_path = 'path/to/PaddleOCr/font/simg.tff')
im_show = Image.fromarray(im_show)
im_show.save('result.jpg')
Output: ထုတ်လုပ်ချက် -
Output will be list,which contains only bounding box
ထုတ်လုပ်မှုက အကန့်သတ်ထားတဲ့ လေးထောင့်ကွက်ကိုပဲ ပါဝင်တဲ့ စာရင်း ဖြစ်လိမ့်မယ်
[[756.0, 812.0], [805.0, 812.0], [805.0, 830.0], [756.0, 830.0]]
[[820.0, 803.0], [1085.0, 801.0], [1085.0, 836.0], [820.0, 838.0]]
[[393.0, 801.0], [715.0, 805.0], [715.0, 839.0], [393.0, 836.0]]
Only Recognition: အသိအမှတ်ပြုခြင်းသာ–
from paddleocr import PaddleOCR
ocr = PaddleOCR(lang='en')
img_path = 'img.png'
result = ocr.ocr(img_path,det = False,cls=False)
for idx in range(len(result)):
res = result[idx]
for line in res:
print(line)
Output: ထုတ်လုပ်ချက် -
Get DhanushKumar’s stories in your inbox
DhanushKumar ရဲ့ ဇာတ်လမ်းတွေကို သင့်အိတ်ထဲမှာ ရယူပါ
Join Medium for free to get updates from this writer.
ဤ စာရေးဆရာ ထံ မှ သတင်း အချက်အလက် များ ရရှိ ရန် အခမဲ့ မီဒီယာ နှင့် ပူးပေါင်း ပါ ။
The output will contain recognition text and confidence
ထုတ်လုပ်မှုတွင် အသိအမှတ်ပြုစာသားနှင့် ယုံကြည်စိတ်ချမှု ပါဝင်လိမ့်မည်
['PAIN', 0.990372]
Only classification: အမျိုးအစား သာလျှင် -
from paddleocr import PaddleOCR
ocr = PaddleOCR(use_angle_cls = True)
img_path = ('img.png')
result = ocr.ocr(img_path,det = False,rec = False,clsc= True)
for idx in range(len(result)):
res = result[idx]
for line in res:
print(line)
Output: ထုတ်လုပ်ချက် -
The output will contains classification result
ထုတ်လုပ်မှုတွင် အမျိုးအစားခွဲခြားမှု ရလဒ် ပါဝင်လိမ့်မည်
['0', 0.99999964]
Use command line: ကွန်မန်းလိုင်းကိုသုံးပါ
The command for အတွက် ညွှန်ကြားချက်
paddleocr -h
- detection classification and recognition
ရှာဖွေတွေ့ရှိခြင်း၊ အမျိုးအစားခွဲခြားခြင်းနှင့် အသိအမှတ်ပြုခြင်း
paddleocr --image_dir PaddleOCR/doc/imgs_en/img_12.jpg --use_angle_cls true --lang en
Use custom model ကိုယ်ပိုင် ပုံစံကို အသုံးပြုပါ
When the built in model cannot meet the needs,you need to use your own trained model.To convert the det and rec model to inference model,then use it as follows:
တည်ဆောက်ထားသော ပုံစံသည် လိုအပ်ချက်များကို မဖြည့်ဆည်းပေးနိုင်သည့်အခါ သင့်ကိုယ်ပိုင် လေ့ကျင့်ထားသော ပုံစံကို အသုံးပြုဖို့လိုသည်။ det and rec model ကို ကောက်ချက်ချ မှု ပုံစံ သို့ ပြောင်းလဲ ရန် ၊ အောက် ပါ အတိုင်း အသုံးပြု ပါ ။
from paddleocr import PaddleOCR,draw_ocr
ocr = PaddleOCR(det_model_dir = '{model_dir}',rec_model_dir = '{rec_model}' , rec_char_dict_path = '{rec_char_dict_path}',cls_model_dir ='{cls_model}')
img_path = 'img.jpg'
result = ocrocr(img_path,cls = True)
for idx in range(len(result)):
res = result[idx]
for line in res:
print(line)
#draw result
from PIL import Image
result = result[0]
image = Image.open(img_path).convert('RGB')
boxes = [line[0] for line in result]
txts = [line[1][0] for line in result]
scores = [line[1][1] for line in result]
im_show = draw_ocr(image, boxes, txts, scores, font_path='/path/to/PaddleOCR/doc/fonts/simfang.ttf')
im_show = Image.fromarray(im_show)
im_show.save('result.jpg')
Numpy array
numpy array as input only when used by code
numpy array ကို သင်္ကေတဖြင့် အသုံးပြုသည့်အခါမှသာ ထည့်သွင်း
import cv2
from Paddleocr import PaddleOCR,draw_ocr,download_with_progression
ocr = PaddleOCR(use_angle_cls = True,lang="ch")
img_path = 'img.jpg'
img = cv2.imread(img_path)
result = ocr.ocr(img,cls = True)
for idx in range(len(result)):
res = result[idx]
for line in res:
print(line)
#show rsult
from PIL import Image
result = result[0]
download_with_progressbar(img_path, 'tmp.jpg')
image = Image.open('tmp.jpg').convert('RGB')
boxes = [line[0] for line in result]
txts = [line[1][0] for line in result]
scores = [line[1][1] for line in result]
im_show = draw_ocr(image, boxes, txts, scores, font_path='/path/to/PaddleOCR/doc/fonts/simfang.ttf')
im_show = Image.fromarray(im_show)
im_show.save('result.jpg')
PDF File PDF ဖိုင်
from paddleocr import PaddleOCR, draw_ocr
ocr = PaddleOCR(use_angle_cls=True, lang="ch", page_num=2) # need to run only once to download and load model into memory
img_path = './xxx.pdf'
result = ocr.ocr(img_path, cls=True)
for idx in range(len(result)):
res = result[idx]
for line in res:
print(line)
import fitz
from PIL import Image
import cv2
import numpy as np
imgs = []
with fitz.open(img_path) as pdf:
for pg in range(0,pdf.pageCount):
page = pdf[pg]
mat = fitz.Matrix(2,2)
pm = page.getPixmap(matrix = mat,alpha = False)
if pm.width > 2000 or pm.height > 2000:
pm = page.getPixmap(matrix = fitz.Matrix(1,1),alpha = False)
img = Image.frombytes("RGB", [pm.width, pm.height], pm.samples)
img = cv2.cvtColor(np.array(img), cv2.COLOR_RGB2BGR)
imgs.append(img)
for idx in range(len(result)):
res = result[idx]
image = imgs[idx]
boxes = [line[0] for line in res]
txts = [line[1][0] for line in res]
scores = [line[1][1] for line in res]
im_show = draw_ocr(image, boxes, txts, scores, font_path='doc/fonts/simfang.ttf')
im_show = Image.fromarray(im_show)
im_show.save('result_page_{}.jpg'.format(idx))
Text Recognition using PaddleOCR
PaddleOCR ကိုသုံးပြီး စာသားမှတ်မိခြင်း
from paddleocr import PaddleOCR
from PIL import Image
ocr = PaddleOCR()
cropped_img_path = 'cropped_text_region.jpg'
cropped_img = Image.open(cropped_img_path)
result = ocr.ocr_for_single_line(cropped_img)
recognized_text = result[0][0]
print('Recognized Text:', recognized_text)
PaddleOCR Parameters: PaddleOCR ကိရိယာများ:
det_model_dir: The directory containing the text detection model.
det_model_dir: စာသားရှာဖွေရေး ပုံစံပါဝင်သော ဖိုင်တွဲ။
rec_model_dir: The directory containing the text recognition model.
rec_model_dir: စာသားမှတ်မိမှုပုံစံပါဝင်သော ဖိုင်တွဲ။
use_angle_cls: A boolean indicating whether to use angle classification in text detection.
use_angle_cls: စာသားရှာဖွေရာတွင် ထောင့်အမျိုးအစားကို အသုံးပြုရန် မသုံးရန် ညွှန်ပြသည့် ဘူလီယံဖြစ်သည်။
use_gpu: A boolean indicating whether to use GPU for inference.
use_gpu: ကောက်ချက်ချမှုအတွက် GPU အသုံးပြုရန် မလိုကို ညွှန်ပြသည့် ဘိုလီယံဖြစ်သည်။
gpu_id: The ID of the GPU to use (if use_gpu is set to True).
gpu_id: သုံးစွဲရန် GPU ၏ ID (use_gpu ကို True အဖြစ် သတ်မှတ်ထားလျှင်)
ir_optim: A boolean indicating whether to enable IR optimization for text detection.
ir_optim: စာသားရှာဖွေရေးအတွက် IR အကောင်းဆုံးကို အသုံးပြုရန် မလိုကို ညွှန်ပြသည့် ဘိုလီယံဖြစ်သည်။
PaddleOCR Methods: PaddleOCR နည်းလမ်းများ:
PaddleOCR(det_model_dir=None, rec_model_dir=None, use_angle_cls=False, use_gpu=False, gpu_id=0, rec_char_type=’ch’, max_text_length=128, det_algorithm=’DB’, rec_algorithm=’CRNN’, det_db_thresh=0.3, det_db_box_thresh=0.5, det_db_unclip_ratio=2.0, det_east_score_thresh=0.8, det_east_cover_thresh=0.1, det_east_nms_thresh=0.2): The constructor for initializing the PaddleOCR instance. It allows you to set various configuration options for text detection and recognition.
PaddleOCR(det_model_dir=None, rec_model_dir=None, use_angle_cls=False, use_gpu=False, gpu_id=0, rec_char_type='ch', max_text_length=128, det_algorithm='DB', rec_algorithm='CRNN', det_db_thresh=0.3, det_db_box_thresh=0.5, det_db_unclip_ratio=2.0, det_east_score_thresh=0.8, det_east_cover_thresh=0.1, det_east_nms_thresh=0.2): PaddleOCR ဖြစ်ရပ်ကို အစပြုရန် တည်ဆောက်သူဖြစ်သည်။ စာသားရှာဖွေခြင်းနှင့် မှတ်မိခြင်းအတွက် အမျိုးမျိုးသော စီစဉ်ဖန်တီးမှု ရွေးချယ်စရာများကို သတ်မှတ်ရန် ခွင့်ပြုသည်။
ocr(image, det=True, rec=True, cls=False): This method performs OCR on the input image. It detects text regions (if det is True), recognizes text content (if rec is True), and can also classify text (if cls is True). It returns a list of results, where each result contains information about detected text regions and recognized text.
ocr(image, det=True, rec=True, cls=False): ဤနည်းလမ်းသည် ထည့်သွင်းထားသော ရုပ်ပုံပေါ်တွင် OCR ကို ဆောင်ရွက်သည်။ စာသားနယ်မြေများကို ရှာဖွေတွေ့ရှိသည်(det မှန်လျှင်)၊ စာသားအကြောင်းအရာကို အသိအမှတ်ပြု(rec မှန်လျှင်)နှင့် စာသားကိုလည်း အမျိုးအစားခွဲနိုင်ပါသည်။ ရလဒ်တစ်ခုစီတွင် ရှာဖွေတွေ့ရှိခဲ့သော စာသားနယ်မြေများနှင့် အသိအမှတ်ပြုထားသော စာသားများနှင့်ပတ်သက်သော အချက်အလက်များပါဝင်သည့် ရလဒ်စာရင်းကို ပြန်ပေးသည်။
ocr_for_single_line(image): This method performs text recognition on a single line of text within an image. It takes an input image and returns the recognized text as a string.
ocr_for_single_line(ရုပ်ပုံ)– ဤနည်းသည် ရုပ်ပုံတစ်ခုအတွင်း စာသားစာကြောင်းတစ်ကြောင်းပေါ်တွင် စာသားမှတ်မိစေသည်။ ၎င်းသည် ထည့်သွင်းထားသော ရုပ်ပုံတစ်ခုကို ယူပြီး အသိအမှတ်ပြုထားသော စာသားကို ကြိုးတစ်ခုအဖြစ် ပြန်ပေးသည်။
get_rotate_crop_image(image, points): Given an input image and a set of four points representing a rotated text region, this method extracts and returns the rotated text region as a new image.
get_rotate_crop_image(image, points): ထည့်သွင်းထားသော ရုပ်ပုံနှင့် လှည့်ပတ်ထားသော စာသားနယ်ပယ်ကို ကိုယ်စားပြုသော အမှတ် လေးခုကို ပေးထားခြင်းဖြင့် ဤနည်းလမ်းသည် လှည့်ပတ်ထားသော စာသားနယ်ပယ်ကို ရုပ်ပုံအသစ်အဖြစ် ထုတ်ယူပြီး ပြန်ပေးသည်။
draw_ocr(image, result, font_path=None): This method draws bounding boxes and recognized text on the input image based on the OCR results. It returns an annotated image.
draw_ocr(image, result, font_path=None): ဤနည်းလမ်းသည် OCR ရလဒ်များအပေါ် အခြေခံ၍ အဝင်ပုံပေါ်တွင် အကန့်သတ်ထားသော လေးထောင့်ကွက်များကို ဆွဲယူပြီး စာသားကို အသိအမှတ်ပြုသည်။ မှတ်ချက်ပေးထားတဲ့ ရုပ်ပုံကို ပြန်ပေးတယ်။
bulk_post_process(): This method is used for post-processing when performing bulk detection and recognition. It helps merge overlapping text regions.
bulk_post_process(): ဤနည်းကို အများအပြား ရှာဖွေတွေ့ရှိခြင်းနှင့် အသိအမှတ်ပြုခြင်းကို ပြုလုပ်သည့်အခါ စီမံခန့်ခွဲမှုအတွက် အသုံးပြုသည်။ ၎င်း သည် အထပ်ထပ် စာသား နယ်မြေ များ ကို ပေါင်းစပ် ရန် ကူညီ သည် ။
set_lan(lang=’ch’): This method sets the language for text recognition. The default is ‘ch’ for Chinese, but you can change it to ‘en’ or other supported languages.
set_lan(lang='ch'): ဤနည်းစနစ်သည် စာသားမှတ်မိရန် ဘာသာစကားကို သတ်မှတ်ပေးသည်။ စံထားချက်က တရုတ်အတွက် 'ch' ဖြစ်ပေမဲ့ 'en' ဒါမှမဟုတ် တခြား ထောက်ပံ့ထားတဲ့ ဘာသာစကားတွေအဖြစ် ပြောင်းလဲနိုင်ပါတယ်။
switch_use_gpu(flag): This method allows you to dynamically switch between using CPU and GPU for inference.
switch_use_gpu(အလံ)– ဤနည်းလမ်းက ကောက်ချက်ချရန် CPU နှင့် GPU အသုံးပြုခြင်းအကြား အပြောင်းအလဲကို ခွင့်ပြုသည်။
run(**kwargs): This method is a general interface for running text detection, recognition, and other functionalities. You can pass various arguments to control the specific tasks you want to perform.
run(**kwargs): ဤနည်းလမ်းသည် စာသားရှာဖွေခြင်း၊ မှတ်မိခြင်းနှင့် အခြားလုပ်ဆောင်မှုများကို လုပ်ဆောင်ရန် ယေဘုယျ ကြားခံမြင်ကွင်းတစ်ခုဖြစ်သည်။ သင်လုပ်ဆောင်လိုသည့် သတ်သတ်မှတ်မှတ်အလုပ်များကို ထိန်းချုပ်ရန် အငြင်းပွားမှုအမျိုးမျိုးကို သင်ပေးနိုင်ပါသည်။
functionalities of PaddleOCR:
PaddleOCR ၏ လုပ်ဆောင် ချက် များ -
Text Detection: စာသားရှာဖွေခြင်း:
PaddleOCR can detect text regions within an image, even when the text is in complex layouts or irregular shapes.
PaddleOCR သည် စာသားသည် ရှုပ်ထွေးသောနေရာများ သို့မဟုတ် ပုံမှန်မဟုတ်သော ပုံသဏ္ဌာန်များတွင်ရှိလျှင်ပင် ရုပ်ပုံတစ်ခုအတွင်း စာသားနယ်မြေများကို ရှာဖွေတွေ့ရှိနိုင်သည်။
It supports different text detection models such as DB (Deep Bonding), PSENet (Polygon Shrink Text Detector), and more.
DB (Deep Bonding), PSENet (Polygon Shrink Text Detector) စတဲ့ စာသားရှာဖွေရေး ပုံစံအမျိုးမျိုးကို ထောက်ပံ့ပေးတယ်။
Text detection can be performed for multiple languages and scripts.
စာသားရှာဖွေခြင်းကို ဘာသာစကားအမျိုးမျိုးနှင့် အက္ခရာများအတွက် ပြုလုပ်နိုင်ပါသည်။
Text Recognition: စာသားမှတ်မိခြင်း:
After text detection, PaddleOCR recognizes the text content within the detected regions.
စာသားရှာဖွေပြီးနောက် PaddleOCR က ရှာဖွေတွေ့ရှိထားသော နယ်မြေများအတွင်း စာသားအကြောင်းအရာကို အသိအမှတ်ပြုသည်။
It supports a wide range of recognition models, including CRNN (Convolutional Recurrent Neural Network), Rosetta, and more.
၎င်းသည် CRNN (Convolutional Recurrent Neural Network) ၊ ရိုဇက်တာနှင့် ပိုများသော အသိအမှတ်ပြုမှုပုံစံအမျိုးမျိုးကို ထောက်ပံ့ပေးသည်။
The framework allows you to recognize text in multiple languages and character sets.
ဒီဘောင်က စာသားကို ဘာသာစကားအမျိုးမျိုးနဲ့ အက္ခရာအစုံတွေကို မှတ်မိစေတယ်။
Text Spotting: စာသား အရိပ်အယောင် -
Text spotting combines text detection and recognition to locate and recognize text instances in an image.
စာသား ရှာဖွေ ခြင်း သည် ရုပ်ပုံ တစ် ခု တွင် စာသား ဖြစ်ရပ် များ ကို ရှာဖွေ ပြီး အသိအမှတ်ပြု ရန် စာသား ရှာဖွေ ခြင်း နှင့် အသိအမှတ်ပြု ခြင်း ကို ပေါင်းစပ် ထား သည် ။
PaddleOCR provides models and tools to perform end-to-end text spotting tasks.
PaddleOCR သည် စာသား ရှာဖွေ ခြင်း အလုပ် များ ကို အဆုံးသတ် ဆောင်ရွက် ရန် ပုံစံ များ နှင့် ကိရိယာ များ ကို ထောက်ပံ့ ပေး သည် ။
Multiple Languages and Scripts:
ဘာသာစကားအမျိုးမျိုးနှင့် အက္ခရာများ–
PaddleOCR is designed to work with text in various languages and scripts, making it versatile for international applications.
PaddleOCR သည် နိုင်ငံတကာ အသုံးအနှုန်းများအတွက် အမျိုးမျိုးသော ဘာသာစကားနှင့် စာသားများဖြင့် အလုပ်လုပ်ရန် ဒီဇိုင်းရေးဆွဲထားသည်။
Multi-Modal OCR: အမျိုးမျိုး OCR :
It supports OCR on different types of data, including images, scanned documents, and videos.
၎င်းသည် ရုပ်ပုံများ၊ စကဲန်စာရွက်စာတမ်းများနှင့် ဗီဒီယိုများအပါအဝင် အချက်အလက်အမျိုးမျိုးပေါ်တွင် OCRကို ထောက်ပံ့ပေးသည်။
Pre-trained Models: ကြိုတင်လေ့ကျင့်ထားသော မော်ဒယ်များ:
PaddleOCR offers pre-trained models for both text detection and recognition, which can be fine-tuned on your specific data if needed.
PaddleOCR သည် စာသားရှာဖွေခြင်းနှင့် မှတ်မိခြင်းနှစ်ခုစလုံးအတွက် ကြိုတင်လေ့ကျင့်ထားသော မော်ဒယ်များကို ကမ်းလှမ်းထားပြီး လိုအပ်ပါက သင်၏သတ်သတ်မှတ်မှတ် အချက်အလက်များကို အသေးစိတ်ညှိနိုင်ပါသည်။
Fine-tuning: အသေးစိတ်ညှိခြင်း:
You can fine-tune the pre-trained models on your custom datasets to improve recognition accuracy for domain-specific tasks.
သင်သည် သင်၏ကိုယ်ပိုင် အချက်အလက်များပေါ်တွင် ကြိုတင်လေ့ကျင့်ထားသော မော်ဒယ်များကို အသေးစိတ်ညှိ၍ နယ်ပယ် သတ်သတ်မှတ်မှတ် အလုပ်များအတွက် မှတ်မိမှု တိကျမှုကို တိုးတက်စေနိုင်သည်။
Post-processing: စီမံခန့်ခွဲမှု:
PaddleOCR includes post-processing techniques to improve text detection and recognition results, such as non-maximum suppression (NMS) for text boxes and language modeling for recognition.
PaddleOCR တွင် စာသား ရှာဖွေ တွေ့ ရှိ ခြင်း နှင့် မှတ်မိ မှု ရလဒ် များ ကို တိုးတက် စေ ရန် အထောက်အကူ နည်းပညာ များ ပါဝင် သည် ။
Performance Optimization:
စွမ်းဆောင်မှု အကောင်းဆုံး -
It leverages hardware acceleration features like GPU and supports model quantization for efficient inference.
၎င်း သည် ဂျီပီအေ ကဲ့သို့ ဟာ့ဒ်ဝဲလ် အရှိန်မြှင့် ခြင်း အသွင်အပြင်များ ကို အသုံးချ ပြီး ထိရောက် သော ကောက်ချက်ချ မှု အတွက် ပုံစံ အရေအတွက် သတ်မှတ် ခြင်း ကို ထောက်ပံ့ ပေး သည် ။
Command-Line Interface (CLI):
ကွန်မန်းလိုင်း ကြားခံမြင်ကွင်း (CLI):
PaddleOCR provides a CLI tool for easy text detection and recognition on images and documents.
PaddleOCR သည် ရုပ်ပုံ များ နှင့် စာရွက်စာတမ်း များ ပေါ်တွင် လွယ်ကူ သော စာသား ရှာဖွေ ခြင်း နှင့် မှတ်မိ ခြင်း အတွက် CLI ကိရိယာ တစ် ခု ကို ထောက်ပံ့ ပေး သည် ။
Integration and Deployment:
ပေါင်းစပ်ခြင်းနှင့် ဖြန့်ချိခြင်း:
You can integrate PaddleOCR into your applications using Python APIs and deploy it on various platforms, including servers, cloud, and edge devices.
Python API ကိုသုံးပြီး PaddleOCR ကို သင့်အပ္ပလီကေးရှင်းထဲသို့ ပေါင်းစပ်ပြီး ဆာဗာ၊ 클라우드နှင့် အစွန်း ကိရိယာများအပါအဝင် အမျိုးမျိုးသော ပရိုဂရမ်များပေါ်တွင် ဖြန့်ချိနိုင်ပါသည်။
Support for Scene Text Detection:
မြင်ကွင်း စာသား ရှာဖွေရေးအတွက် ထောက်ပံ့မှု:
PaddleOCR can detect text in scenes with complex backgrounds and varying text sizes and orientations.
PaddleOCR သည် ရှုပ်ထွေးသောနောက်ခံနှင့် စာသားအရွယ်အစားနှင့် ဦးတည်ချက်အမျိုးမျိုးရှိသည့် မြင်ကွင်းများတွင် စာသားကို ရှာဖွေတွေ့ရှိနိုင်သည်။
Support for Different Text Sizes:
စာသားအရွယ်အစားအမျိုးမျိုးအတွက် ထောက်ပံ့မှု:
It can handle text of various sizes, from small text in documents to large text in outdoor signs.
စာရွက်စာတမ်းထဲက စာသားငယ်ကနေ အပြင်ဘက်ဆိုင်းဘုတ်တွေမှာရှိတဲ့ စာသားကြီးအထိ အရွယ်အစားအမျိုးမျိုးရှိတဲ့ စာသားတွေကို ကိုင်တွယ်နိုင်တယ်။
Scalability and Parallel Processing:
တိုး ချဲ့ နိုင် ခြင်း နှင့် အပြိုင် စီမံ ခန့်ခွဲ မှု :
PaddleOCR supports batch processing and can be optimized for parallel execution to process multiple images simultaneously.
PaddleOCR သည် အဆင့်အတန်း စီမံခန့်ခွဲမှုကို ထောက်ပံ့ပေးပြီး ပုံရိပ်အများအပြားကို တစ်ပြိုင်တည်း စီမံဆောင်ရွက်ရန် အကောင်းဆုံးဖြစ်နိုင်ပါသည်။
OCR Data Augmentation: OCR အချက်အလက် တိုးချဲ့ခြင်း:
Data augmentation techniques are available to enhance model robustness and accuracy.
အချက်အလက် တိုးမြှင့် ခြင်း နည်းပညာ များ သည် ပုံစံ ခိုင်ခံ့ မှု နှင့် တိကျမှန်ကန် မှု ကို တိုးမြှင့် ရန် ရရှိ နိုင် ပါ သည် ။
Model Evaluation Metrics:
ပုံစံ အကဲဖြတ် တိုင်းတာ ချက် များ :
PaddleOCR provides evaluation metrics such as precision, recall, and F1-score to assess the performance of text detection and recognition models.
PaddleOCR သည် စာသား ရှာဖွေ ခြင်း နှင့် အသိအမှတ်ပြု မှု ပုံစံ များ ၏ လုပ်ဆောင် မှု ကို အကဲဖြတ် ရန် တိကျမှန်ကန် မှု ၊ မှတ်မိ ခြင်း ၊ နှင့် F1 - ရမှတ် ကဲ့သို့ အကဲဖြတ် မှု တိုင်းတာ မှု များ ကို ထောက်ပံ့ ပေး သည် ။