Python Google文本检测api-Web演示结果与使用api不同

Python Google文本检测api-Web演示结果与使用api不同,python,google-cloud-platform,google-cloud-functions,google-cloud-vision,Python,Google Cloud Platform,Google Cloud Functions,Google Cloud Vision,我曾尝试使用谷歌视觉API文本检测功能和谷歌的web演示来OCR我的图像。这两个结果是不一样的 首先,我在url上试用了它。最后,我用python语言用GoogleAPI代码进行了尝试。两个结果不一样,我不知道为什么。你能帮我解决这个问题吗 我的形象: 我的api结果:“三星Galaxy M20Siêu Pin vôdoi,sac nhanh tuc thiMoiSAMSUNG4.990.000dTrêgop 0%Mua ngay” 我的web演示结果: 多谢各位 我的python代码如下:

我曾尝试使用谷歌视觉API文本检测功能和谷歌的web演示来OCR我的图像。这两个结果是不一样的

首先,我在url上试用了它。最后,我用python语言用GoogleAPI代码进行了尝试。两个结果不一样,我不知道为什么。你能帮我解决这个问题吗

  • 我的形象:

  • 我的api结果:
    “三星Galaxy M20Siêu Pin vôdoi,sac nhanh tuc thiMoiSAMSUNG4.990.000dTrêgop 0%Mua ngay”

  • 我的web演示结果: 多谢各位

我的python代码如下:

client=vision.ImageAnnotatorClient()
raw_byte=cv2.imencode('.jpg',image)[1].tostring()
post\u image=types.image(内容=原始字节)
image\u context=vision.types.ImageContext()
响应=客户端。文本\检测(图像=后期图像,图像\上下文=图像\上下文)

实际上,比较两个结果,我看到的唯一区别是结果的显示方式。Google Cloud拖放站点显示带有边框的结果,并尝试查找文本区域

python脚本得到的响应包含相同的信息。举几个例子:

text=response.text\u注释
打印([i.文本中i的说明])
#打印在图像中找到的所有单词
打印([i.文本中i的边界\多边形顶点])
#打印检测到的单词周围的所有框
请随时提出更多问题以进行澄清

其他一些想法:

  • 你在预处理你的图像吗
  • 图片的大小是多少

    • 这是打字脚本代码

      但我们的想法不是使用
      text\u检测
      ,而是使用类似
      document\u text\u检测
      (不确定python API具体提供了什么)

      使用
      documentTextDetection()
      而不是
      textDetection()
      为我解决了完全相同的问题

      const fs = require("fs");
      const path = require("path");
      const vision = require("@google-cloud/vision");
      
      async function quickstart() {
        let text = '';
        const fileName = "j056vt-_800w_800h_sb.jpg";
        const imageFile = fs.readFileSync(fileName);
        const image = Buffer.from(imageFile).toString("base64");
        const client = new vision.ImageAnnotatorClient();
      
        const request = {
          image: {
            content: image
          },
          imageContext: {
            languageHints: ["vi-VN"]
          }
        };
      
        const [result] = await client.documentTextDetection(request);
      
        // OUTPUT METHOD A
      
        for (const tmp of result.textAnnotations) {
            text += tmp.description + "\n";
        }
      
        console.log(text);
      
        const out = path.basename(fileName, path.extname(fileName)) + ".txt";
        fs.writeFileSync(out, text);
      
        // OUTPUT METHOD B
      
        const fullTextAnnotation = result.fullTextAnnotation;
        console.log(`Full text: ${fullTextAnnotation.text}`);
        fullTextAnnotation.pages.forEach(page => {
          page.blocks.forEach(block => {
            console.log(`Block confidence: ${block.confidence}`);
            block.paragraphs.forEach(paragraph => {
              console.log(`Paragraph confidence: ${paragraph.confidence}`);
              paragraph.words.forEach(word => {
                const wordText = word.symbols.map(s => s.text).join("");
                console.log(`Word text: ${wordText}`);
                console.log(`Word confidence: ${word.confidence}`);
                word.symbols.forEach(symbol => {
                  console.log(`Symbol text: ${symbol.text}`);
                  console.log(`Symbol confidence: ${symbol.confidence}`);
                });
              });
            });
          });
        });
      
      }
      
      quickstart();
      

      尝试使用document_text_检测,查看我尝试过的输出是否有任何差异,结果与我的预期完全不同。它与web演示不同