Skip to content

Commit

Permalink
ocr 修复过细图片导致识别丢失
Browse files Browse the repository at this point in the history
  • Loading branch information
xushengfeng committed May 12, 2024
1 parent 1eb8189 commit bd2b729
Showing 1 changed file with 11 additions and 11 deletions.
22 changes: 11 additions & 11 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,17 +53,17 @@ async function x(img: ImageData) {
}

const _r = 0.6;
if (h < w * _r) {
const _h = Math.floor(w * _r);
const newData = new Uint8ClampedArray(w * _h * 4);
newData.set(img.data);
newData.set(new Uint8ClampedArray(w * (_h - h) * 4), img.data.length);
let _img = new ImageData(w, _h);
for (let i in newData) {
_img.data[i] = newData[i];
}
img = _img;
h = _h;
const _h = h,
_w = w;
if (_h < _w * _r || _w < _h * _r) {
if (_h < _w * _r) h = Math.floor(_w * _r);
if (_w < _h * _r) w = Math.floor(_h * _r);
const c = document.createElement("canvas");
const ctx = c.getContext("2d");
c.width = w;
c.height = h;
ctx.putImageData(img, 0, 0);
img = ctx.getImageData(0, 0, w, h);
}

let { transposedData, image } = beforeDet(img, detShape[0], detShape[1]);
Expand Down

0 comments on commit bd2b729

Please sign in to comment.