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

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

59 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 567
结巴分词的全模式、精确模式和搜索引擎模式用法与实例
结巴分词的全模式、精确模式和搜索引擎模式用法与实例

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

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

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

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

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

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

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

0 428
推荐插件
帝国cms百度文字识别ocr接口对接插件
帝国cms百度文字识别ocr接口对接插件

许多网站会做一些小功能小插件给客户使用以增强用户黏性,比如图片转文字,这种...

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

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

0 351
帝国cms百度、必应bing、神马推送增强收录三合一插件
帝国cms百度、必应bing、神马推送增强收录三合一插件

因客户需要一键推送到多平台,下载鸥开发了这款一键推送至百度、必应、神马插...

0 71
帝国cms网站会员登录与退出历史记录日志插件
帝国cms网站会员登录与退出历史记录日志插件

帝国cms默认只有上次登录时间与ip,没有一个记录清单,所以今天,我们分享这个帝...

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

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

0 669
帝国CMS内网用户静态站点文章访客统计插件
帝国CMS内网用户静态站点文章访客统计插件

本插件适用于内网用户,可查看单篇文章访问者ip地址。如果添加访问者ip组,可查...

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

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

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

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

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