加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
showData.js 1.50 KB
一键复制 编辑 原始数据 按行查看 历史
yashujs 提交于 2021-02-22 17:48 . 1
function showData(dataList, imgPath, ocrType) {
log("显示数据 imgPath = " + imgPath);
var img = images.read(imgPath);
var canvas = new Canvas(img);
let rectanglePaint = new Paint();
rectanglePaint.setStrokeWidth(3);
rectanglePaint.setColor(colors.parseColor("#00ff00"));
rectanglePaint.setStyle(Paint.Style.STROKE); //空心矩形框
let textPaint = new Paint();
textPaint.setTextAlign(Paint.Align.CENTER);
textPaint.setTextSize(30);
textPaint.setStyle(Paint.Style.FILL);
textPaint.setColor(colors.parseColor("#f000ff"));
let fontMetrics = textPaint.getFontMetrics();
var len = dataList.size();
for (var i = 0; i < len; i++) {
let data = dataList.get(i);
let frame = data.frame;
let rect = [frame.get(0), frame.get(1), frame.get(4), frame.get(5)];
canvas.drawRect(rect[0], rect[1], rect[2], rect[3], rectanglePaint);
canvas.drawText(
data.text,
rect[0] + parseInt((rect[2] - rect[0]) / 2),
rect[3] + Math.abs(fontMetrics.top),
textPaint
);
}
var image = canvas.toImage();
let newFilename = files.getNameWithoutExtension(imgPath) + "_" + ocrType + ".png";
let newFilepath = "/sdcard/脚本/" + ocrType + "/" + newFilename;
files.createWithDirs(newFilepath);
images.save(image, newFilepath);
log("识别后的图片保存路径: " + newFilepath);
img.recycle();
return newFilepath;
}
events.on("exit", function () {
log("结束运行 模块脚本");
});
module.exports = showData;
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化