OCR(光学的文字認識)は、画像などに含まれた文字をテキストデータとして読み取る技術です。 Tesseract.jsを使うとブラウザ上で簡単にOCRを実装できます。
サンプル
添付ファイル内の文字を文字列フィールドに保存します。
フォーム設定
コード
tesseract.jsを読み込み後、下記sample.jsを読み込みます。
・sample.js
(function() {"use strict";kintone.events.on(['app.record.create.show','app.record.edit.show'],function(event){document.addEventListener('change',function(e){if(e.target.type!=='file')return;if(!e.target.files[0].type.match('image.\*'))return;varreader=newFileReader();reader.addEventListener('load',function(){Tesseract.recognize(reader.result, {lang:"jpn"}).progress(function(p){event.record.文字列.value=p.status+' : '+Math.round(p.progress\*100)+'%';kintone.app.record.set(event);
}).then(function(result){event.record.文字列.value=result.text;kintone.app.record.set(event);
});
});reader.readAsDataURL(e.target.files[0]);
},true);
});
})();
※文字認識の精度は、文字サイズや画質に依存します。