ကျွန်တော်တို့ အတော်များများအတွက်တော့ ပုံနှိပ်ထားတဲ့ စာလုံးတွေကို scan ဖတ်ထားတဲ့ ရုပ်ပုံဖိုင်တွေက ဖြစ်ဖြစ်၊ ပြင်လို့မရအောင် flat လုပ်ထားတဲ့ pdf ဖိုင်တွေကနေ ဖြစ်ဖြစ် စာသားတွေကို ဆွဲထုတ်ယူနိုင်ဖို့ဆိုတာ အမြဲတောင့်တခဲ့ရတဲ့ မျှော်လင့်ချက် တစ်ခုပါ။ ဒီလိုလုပ်ပေးတဲ့ OCR နည်းပညာကို အင်္ဂလိပ်စာအတွက် ရတာကို မြင်ဖူးခဲ့စဉ်ကတည်းက ငါတို့ မြန်မာစာအတွက်လည်း ဒီလိုရရင် သိပ်ကောင်းမှာပဲလို့ မျှော်လင့်ခဲ့ကြ မချင့်မရဲ ဖြစ်ခဲ့ကြရတာပါ။ ခုတော့ ယူနီကုဒ် မြန်မာစာစနစ်ရဲ့ အထောက်အပံ့နဲ့အတူ ဒီမျှော်လင့်ချက်က တစ်စိတ်တစ်ပိုင်း ပြည့်ဝလာခဲ့ပါပြီ။
ဒီလို ဖြည့်ဆည်းပေးလာသူကတော့ Google ပဲ ဖြစ်ပါတယ်။ Printer တွေ scanner တွေနဲ့ တိုက်ရိုက်ချိတ်ပြီး သုံးလို့ မရသေးဘဲ အင်တာနက် ချိတ်ဆက်ထားဖို့ လိုသေးပေမယ့်လည်း အတိုင်းအတာတစ်ခုအထိ အဆင်ပြေလှတာမို့ သုံးနည်းကို ဘာသာပြန် မျှဝေပေးလိုက်ပါတယ်။
ဒီလို သုံးဖို့အတွက် Google ရဲ့ အခမဲ့ အကောင့်တစ်ခုတော့ ရှိဖို့လိုပါမယ်။ မြန်မာအများစု Gmail သုံးကြတာမို့ ဒီကိစ္စက ပူစရာတော့ မလိုပါဘူး။ ပြီးရင် Google ကပဲ အခမဲ့ ပေးသုံးတဲ့ Google Sheet ကို သုံးပြီး လုပ်ရမှာပါ။ မိတ်ဆွေအနေနဲ့ Java Script အခြေခံသိပြီး Google Sheet နဲ့ Google API Console အကြောင်း သိထားရင် ပိုကောင်းတယ်ဆိုပေမယ့် မသိလည်း လိုက်လုပ်လို့ ရလောက်အောင် ရိုးရှင်းပါတယ်။
Google Sheet အသစ်တစ်ခု ဖွင့်ပါ
https://docs.google.com/spreadsheets/u/0/ ကို ကလစ်နှိပ်ပြီး သွားရုံပါပဲ။

Script Editor ထဲ ဝင်ပါ
Tools မီနူးထဲက Script editor… ကို နှိပ်ပါ။


ကုဒ်တွေ ထည့်ပါမယ်
အောက်မှာ ပြထားတဲ့ Java Script ကုဒ်တွေက Google Sheet မှာ မီနူးအသစ်တစ်ခု ဖန်တီးဖို့ပါ။
function onOpen() {
var ui = SpreadsheetApp.getUi();
ui.createMenu('OCR Tools')
.addItem('Extract Cell', 'doOCR')
.addItem('Extract All Cell', 'doOCRALL')
.addSeparator()
.addSubMenu(ui.createMenu('About US')
.addItem('Infomation', 'menuItem2'))
.addToUi();
}
ရုပ်ပုံရှိတဲ့ URL ကနေ စာသားတွေကို ဆွဲထုတ်ပေးဖို့အတွက် အောက်က ကုဒ်တွေကို ဆက်သုံးရပါမယ်။
function doOCR() {
//
var activeCol = SpreadsheetApp.getActiveSheet().getActiveCell().getColumn();
var activeRow = SpreadsheetApp.getActiveSheet().getActiveCell().getRow();
var valueURL = SpreadsheetApp.getActiveSheet().getRange(activeRow, activeCol).getValue();
var image = UrlFetchApp.fetch(valueURL).getBlob();
var file = {
title: 'OCR File',
mimeType: 'image/png'
};
// OCR is supported for PDF and image formats
file = Drive.Files.insert(file, image, {ocr: true});
var doc = DocumentApp.openByUrl(file.embedLink);
var body = doc.getBody().getText();
// Print the Google Document URL in the console
Logger.log("body: %s", body);
Logger.log("File URL: %s", file.embedLink);
//Get link Doc that Generated
SpreadsheetApp.getActiveSheet().getRange(activeRow, activeCol + 2).setValue(file.embedLink);
//Get Content of Doc that Generated
SpreadsheetApp.getActiveSheet().getRange(activeRow, activeCol + 1).setValue(body);
}
URL က ရုပ်ပုံ အများကြီးကို တပြိုင်တည်း စာသား ဆွဲထုတ်ပေးဖို့အတွက်တော့ အောက်က ကုဒ်တွေအတိုင်း function တစ်ခု ထပ်ဖန်တီးရပါတယ်။
function doOCRALL() {
var selected = SpreadsheetApp.getActiveSheet().getActiveRange().getValues().length;
for (var i = 0; i < selected; i++) {
var activeCol = SpreadsheetApp.getActiveSheet().getActiveCell().getColumn();
var activeRow = SpreadsheetApp.getActiveSheet().getActiveCell().getRow();
var valueURL = SpreadsheetApp.getActiveSheet().getRange(activeRow + i, activeCol).getValue();
var image = UrlFetchApp.fetch(valueURL).getBlob();
var file = {
title: 'OCR File',
mimeType: 'image/png'
};
// OCR is supported for PDF and image formats
file = Drive.Files.insert(file, image, {ocr: true});
var doc = DocumentApp.openByUrl(file.embedLink);
var body = doc.getBody().getText();
//Get link Doc that Generated
SpreadsheetApp.getActiveSheet().getRange(activeRow + i, activeCol + 2).setValue(file.embedLink);
//Get Content of Doc that Generated
SpreadsheetApp.getActiveSheet().getRange(activeRow + i, activeCol + 1).setValue(body);
}
}
ဒီအထိ ပြသွားတဲ့ ကုဒ်တွေကို နားမလည်လို့ စိတ်ရှုပ်နေလား၊ ကျွန်တော်လည်း နားလည်လှတယ် မဟုတ်လို့ ရှင်းမပြတတ်ပါဘူး။ ဒါပေမယ့် စိတ်မပူပါနဲ့လေ၊ အစောက ဖွင့်ထားတဲ့ script editor ထဲက လက်ရှိ ရှိနေတဲ့ စာတွေ အားလုံးကို ဖျက်၊ အောက်က ကုဒ်တွေ အားလုံး အစ အဆုံး copy ကူးပြီး paste လုပ်ထည့်လိုက်ဗျာ။
function doOCRALL() {
var selected = SpreadsheetApp.getActiveSheet().getActiveRange().getValues().length;
for (var i = 0; i < selected; i++) {
var activeCol = SpreadsheetApp.getActiveSheet().getActiveCell().getColumn();
var activeRow = SpreadsheetApp.getActiveSheet().getActiveCell().getRow();
var valueURL = SpreadsheetApp.getActiveSheet().getRange(activeRow + i, activeCol).getValue();
var image = UrlFetchApp.fetch(valueURL).getBlob();
var file = {
title: 'OCR File',
mimeType: 'image/png'
};
// OCR is supported for PDF and image formats
file = Drive.Files.insert(file, image, {ocr: true});
var doc = DocumentApp.openByUrl(file.embedLink);
var body = doc.getBody().getText();
//Get link Doc that Generated
SpreadsheetApp.getActiveSheet().getRange(activeRow + i, activeCol + 2).setValue(file.embedLink);
//Get Content of Doc that Generated
SpreadsheetApp.getActiveSheet().getRange(activeRow + i, activeCol + 1).setValue(body);
}
}
function doOCR() {
//
var activeCol = SpreadsheetApp.getActiveSheet().getActiveCell().getColumn();
var activeRow = SpreadsheetApp.getActiveSheet().getActiveCell().getRow();
var valueURL = SpreadsheetApp.getActiveSheet().getRange(activeRow, activeCol).getValue();
var image = UrlFetchApp.fetch(valueURL).getBlob();
var file = {
title: 'OCR File',
mimeType: 'image/png'
};
// OCR is supported for PDF and image formats
file = Drive.Files.insert(file, image, {ocr: true});
var doc = DocumentApp.openByUrl(file.embedLink);
var body = doc.getBody().getText();
// Print the Google Document URL in the console
Logger.log("body: %s", body);
Logger.log("File URL: %s", file.embedLink);
//Get link Doc that Generated
SpreadsheetApp.getActiveSheet().getRange(activeRow, activeCol + 2).setValue(file.embedLink);
//Get Content of Doc that Generated
SpreadsheetApp.getActiveSheet().getRange(activeRow, activeCol + 1).setValue(body);
}
function onOpen() {
var ui = SpreadsheetApp.getUi();
// Or DocumentApp or FormApp.
ui.createMenu('OCR Tools')
.addItem('Extract Cell', 'doOCR')
.addItem('Extract All Cell', 'doOCRALL')
.addSeparator()
.addSubMenu(ui.createMenu('About US')
.addItem('Infomation', 'menuItem2'))
.addToUi();
}
function menuItem2() {
SpreadsheetApp.getUi() // Or DocumentApp or FormApp.
.alert('AIO Team');
}
ပြီးရင် အဲဒီ script project ကို နာမည်ပေးပြီး save လုပ်လိုက်ပါ။
Google Drive API Service ဖွင့်ခြင်း
အစောက လုပ်ထားတဲ့ script editor ရဲ့ Resources ဆိုတဲ့ မီနူးထဲက Advanced Google services… ကို သွားပါ။ ပေါ်လာတဲ့ စာရင်းထဲက Drive API ဆိုတာကို ရှာပြီး On ပေးပါ။
ပြီးရင် အဲဒီ အောက်မှာ အဝါရောင်ကွက်လေးနဲ့ ပြနေတဲ့ Google API Console ကို နှိပ်ပါ။

ထပ်ပွင့်လာတဲ့ browser tab ထဲက Google Drive API ကို ဖွင့်ပြီး Enable ဆိုတာကို နှိပ် ပြီးသွားရင် အဲဒီ tab ကို ပိတ်လိုက်ပါ။


ပြီးရင် အစောက ပွင့်နေတဲ့ Advance Google Services ဆိုတဲ့ box ကို Ok နှိပ်ပြီး ထွက်ပါ။
Google Sheet တွင် စမ်းသပ်ခြင်း
အစောက ဖွင့်ထားတဲ့ Google Sheet ကို ပြန်သွားပြီး refresh လုပ်ပေးပါ။
‘OCR Tool’ ဆိုတဲ့ မီနူးအသစ်တစ်ခု ပေါ်လာပါလိမ့်မယ်။
အသုံးပြုပုံ
ကိုယ် စာသား ဆွဲထုတ်ချင်တဲ့ ရုပ်ပုံရှိတဲ့ URL ကို ကူးယူလာပြီး cell ကွက် တစ်ကွက်ထဲကို paste လုပ်ထည့်ပါ။
၁။ တစ်ပုံချင်းစီ ဖတ်ချင်ရင်
ဖတ်ချင်တဲ့ URL ထည့်ထားတဲ့ cell ကွက်ကို select မှတ်၊
အသစ်ပေါ်လာတဲ့ ‘OCR Tool’ မီနူးထဲက “Extract Cell” ကို နှိပ်ပါ။
မှတ်ထားတဲ့ cell ကွက်ရဲ့ ဘေးကပ်လျှက် column မှာ ဆွဲထုတ်ယူလာပေးတဲ့ စာသားတွေကို တွေ့ရမှာ ဖြစ်သလို နောက်ထပ် ကပ်လျှပ် column မှာတော့ မူရင်း ရုပ်ပုံရော၊ စာသား ဆွဲထုတ်ပေးထားတာပါ ပါတဲ့ Google Doc ဖိုင်ရှိရာ link ကို တွေ့ရပါလိမ့်မယ်။


၂။ ပုံအများကြီးကို တပြိုင်တည်း ဖတ်ချင်ရင်
ဖတ်ချင်တဲ့ cell ကွက်တွေကို select မှတ်
OCR Tools မီနူးထဲက Extract all ကို ရွေးလိုက်ရုံပါပဲ။
အားလုံးပြီးသွားရင်တော့ သူ့ဆီက ထွက်လာတဲ့ Google Doc ဖိုင်ကိုသွား၊ Microsoft Word ရဲ့ format ဖြစ်တဲ့ .docx နဲ့ ဒေါင်းယူလိုက်ရင် ကိုယ်ကြိုက်သလို သုံးလို့ရမယ့် စာသားတွေနဲ့ ဖိုင်တစ်ခု ရလာပြီပေါ့ဗျာ။ ထွက်လာတဲ့ စာသားတွေက ဘာဖောင့်လည်း မမေးနဲ့ဗျာ၊ ယူနီကုဒ်ပဲ ရမယ်ဗျို့။ အဲဒီလုပ်ထားတဲ့ Google Sheet လေးကိုလည်း နာမည်လေး သေချာပေးပြီး သိမ်းထားရင် နောက် လိုအပ်တိုင်း သုံးလို့ရသပေါ့ဗျာ။
ကွန်ပျူတာသုံး မြန်မာစာစနစ် တစ်နေ့တစ်ခြား ပိုလို့ တိုးတက် ထွန်းကားပါစေ။
ဒီနည်းက ကွန်ပျူတာ browser ပေါ်မှာ သုံးမှပဲ အဆင်ပြေပါမယ်။ ဒီနည်းကို စတင် ရေးသား ဖော်ပြပေးခဲ့တဲ့ AIO အဖွဲ့ကိုလည်း ကျေးဇူးအများကြီး တင်ပါတယ်။ မူရင်း ဆောင်းပါးကို ဒီမှာ သွားဖတ်နိုင်ပါတယ်။
ဤ postသည် ကို Mie Maung ၏ Medium အကောင့် တွင် စတင်ဖော်ပြခဲ့ခြင်းဖြစ်သည်။