OCR,全名為光學字元辨識(Optical Character Recognition),是一種將圖像中的文字轉換為可編輯的數位文字的技術。實際上現在在實用上已經非常普遍,如停車場的車牌識別等等。

後來問了Gemini AI, 才知道Google 本身也有提供OCR, 只是檔案要先存在Google drive 裏。用app script 寫了函數如下:
function ocrFromGoogleDrive(fileId) {
// 1. 使用 DriveApp 服務取得檔案物件
var file = DriveApp.getFileById(fileId);
file.setSharing(DriveApp.Access.ANYONE_WITH_LINK, DriveApp.Permission.VIEW);
// 2. 準備要傳給 API 的資源物件
var resource = {
title: file.getName()
};
// 3. 透過 Drive API Advanced Service 執行 OCR讓 Google 自動偵測語言
var newFile = Drive.Files.insert(resource, file.getBlob(), {
ocr: true
});
// 4. 開啟轉換後的 Google 文件,讀取文字
var doc = DocumentApp.openById(newFile.id);
var text = doc.getBody().getText();
// 5. 處理完畢後,刪除暫時產生的 Google Doc 檔案
Drive.Files.remove(newFile.id);
return text;
}
如此,提供在Google drive裏的file id 給函數,就會回傳圖片上的文字了。「bot.學習.人」親試了一下,對韓文、日文、泰文翻譯的還可以哦。


























