下载鸥 > 网站下载 > 开发教程 > Python

paddleocr报错TypeError: not supported between instances of tuple and float

46 2024-06-12 00:36:04

收藏
paddleocr报错TypeError: not supported between instances of  tuple and float
运行paddleocr ,如下脚本后报错 TypeError: "<"not supported between instances of  tuple and float。
 

报错源码

由于paddleocr升级,老版本源码将会报错
import os
from paddleocr import PaddleOCR, draw_ocr
from PIL import Image
from datetime import datetime

img_path = "./images/"  # 图片路径
filename = "demo-4.png" # 图片名
save_path = "./images/output/"  # 存储路径
font_path = './fonts/PingFang.ttf'  # 字体路径

dirs = datetime.now().strftime('%Y%m%d')
this_img = img_path + filename # 测试图片路径

if __name__ == '__main__':
    ocr = PaddleOCR(use_angle_cls=True, lang='ch')
    result = ocr.ocr(this_img, cls=True)
    for line in result:
        print(line)

    image = Image.open(img_path).convert("RGB")
    boxes = [line[0] for line in result]
    txts = [line[1][0] for line in result]
    scores = [line[1][1] for line in result]
    im_show = draw_ocr(image, boxes, texts, scores, font_path=font_path)
    im_show = Image.fromarray(im_show)
    save_file_name = os.path.join(save_path + dirs, filename)
    os.makedirs(os.path.dirname(save_file_name), exist_ok=True)
    im_show.save(save_file_name)
 

修改如下

import os
from paddleocr import PaddleOCR, draw_ocr
from PIL import Image
from datetime import datetime

img_path = "./images/"  # 图片路径
filename = "demo-4.png" # 图片名
save_path = "./images/output/"  # 存储路径
font_path = './fonts/PingFang.ttf'  # 字体路径

dirs = datetime.now().strftime('%Y%m%d')
this_img = img_path + filename # 测试图片路径

if __name__ == '__main__':
    ocr = PaddleOCR(use_angle_cls=True, lang='ch')
    result = ocr.ocr(this_img, cls=True)
    for line in result:
        print(line)

    image = Image.open(this_img).convert('RGB')
    boxes = [detection[0] for line in result for detection in line] # Nested loop added
    texts = [detection[1][0] for line in result for detection in line] # Nested loop added
    scores = [detection[1][1] for line in result for detection in line] # Nested loop added
    im_show = draw_ocr(image, boxes, texts, scores, font_path=font_path)
    im_show = Image.fromarray(im_show)
    save_file_name = os.path.join(save_path + dirs, filename)
    os.makedirs(os.path.dirname(save_file_name), exist_ok=True)
    im_show.save(save_file_name)

这样,就可以正常输出对比图了。

本文地址:https://xzo.com.cn/develop/python/1251.html

有帮助,很赞!

信息来源:下载鸥
导出教程 下载word版教程
发表评论 共有条评论
关于Python

Python免费、开源、简单,且含有海量的库。其功能也十分强大,不仅可以做网站、做爬虫、还可以做大数据、做人脸识别,等等等等。如果是新手入门,我们建议是首选Python。

推荐Python开发教程
Python中文分词器准确度与性能测试(jieba、FoolNLTK、HanLP、THULAC、nlpir、ltp)
Python中文分词器准确度与性能测试(jieba、FoolNLTK、HanLP、THULAC、nlpir、ltp)

国内知名度比较高的Python中文分词有哈工大LTP、中科院计算所NLPIR、清华大...

0 539
结巴分词的全模式、精确模式和搜索引擎模式用法与实例
结巴分词的全模式、精确模式和搜索引擎模式用法与实例

结巴分词支持3种模式:全模式、精确模式和搜索引擎模式,不同的模式效果会有差...

0 377
python多线程的概念与好处
python多线程的概念与好处

但凡对电脑知识了解多一点的朋友可能就听说过进程,而如果对蜘蛛爬虫有了解,那...

0 401
怎样用python爬虫爬取百度搜索图片
怎样用python爬虫爬取百度搜索图片

python爬虫爬取百度图片是很多人python爬虫入门后一个重要的练手项目。一方...

40 363
python爬虫怎样入门?
python爬虫怎样入门?

爬虫软件很多,支持爬虫功能的语言也很多,而用python做爬虫,辅以包罗万象的pyth...

0 409
推荐插件
帝国cms在线考试系统模板插件
帝国cms在线考试系统模板插件

一直没看到好用的帝国cms在线考试插件,所以自己开发了一款。在线考试插件用...

0 1183
帝国cms百度AI图像无损放大api接口对接插件
帝国cms百度AI图像无损放大api接口对接插件

通过本插件,可以实现帝国cms网站对接百度云api实现图像无损放大的功能。经过...

0 354
帝国cms百度AI图像清晰度增强api接口对接插件
帝国cms百度AI图像清晰度增强api接口对接插件

通过本插件,可以实现帝国cms网站对接百度云api实现图像清晰度增强的功能。经...

0 422
帝国cms纳米数据接口(足球比赛中最新数据)
帝国cms纳米数据接口(足球比赛中最新数据)

帝国cms 对接纳米数据(www.nami.com)接口,本接口主要接收、整理足球比赛实时数...

0 191
帝国cms自动给正文关键词添加tag内链
帝国cms自动给正文关键词添加tag内链

帝国cms有自带的给关键词添加内链功能,但需要手动添加关键词,容易出现疏漏和...

0 679
帝国cms百度AI图像去雾api接口对接插件
帝国cms百度AI图像去雾api接口对接插件

通过本插件,可以实现帝国cms网站对接百度云api实现图像去雾的功能。经过实际...

0 374
帝国cms百度AI黑白图像上色api接口对接插件
帝国cms百度AI黑白图像上色api接口对接插件

百度开放了系列AI功能api如图像上色、图像去雾、图像修复、无损放大、清晰...

0 331
帝国cms联想词搜索高级搜索插件下载
帝国cms联想词搜索高级搜索插件下载

帝国CMS自带的搜索功能虽然强大,但也有很强的局限性 -- 必须关键词完全匹配...

0 633
客服QQ:341553759
扫码咨询 常见问题 >
官方交流群:90432500
点击加入