Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

浏览器环境部署报错 Uncaught ReferenceError: require is not defined #3

Open
Pylogmon opened this issue Jul 26, 2023 · 1 comment

Comments

@Pylogmon
Copy link

Pylogmon commented Jul 26, 2023

感谢作者在 PaddleOCR 的 js 部署方面做的工作,我尝试使用 esearch-OCR 在浏览器环境部署,但是遇到了一些问题,不知道应该如何解决。

主要操作:

import * as ocr from "esearch-ocr";
async function start() {
  const res = await axios.get("/ocr_keys_v1.txt");
  console.log(res);
  await ocr.init({
    detPath: "ocr_det.onnx",
    recPath: "ocr_rec.onnx",
    dic: res.data,
    node: false,
  });
  let img = document.getElementById("ocr-image");
  let canvas = document.createElement("canvas");
  canvas.width = img.width;
  canvas.height = img.height;
  canvas.getContext("2d").drawImage(img, 0, 0);
  const result = await ocr.ocr(
    canvas.getContext("2d").getImageData(0, 0, img.width, img.height)
  );
  setResult(result.reduce((total, cur) => total + `${cur.text}\n`));
}

本地 pnpm dev 没有问题,一旦build之后就会报错 Uncaught ReferenceError: require is not defined

@xushengfeng
Copy link
Owner

这似乎是onnxruntime在vite下的部署问题
需要手动引入onnxruntime https://unpkg.com/[email protected]/dist/ort.min.js
然后在init函数制定ort:window['ort']

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants