paddleOCR 自动标注cls

网上找不到,方便大家,自己写一个。
paddleOCR 自动标注cls
鼠标单点击切换
键盘q下一个
鼠标中键退出

dir_path:图形所在文件
label_path: 标记labeltxt文件

import os
import cv2
from shutil import copyfile

'''
paddleOCR 自动标注cls 
单点击切换
中键退出    
dir_path:图形所在文件
label_path: 标记labeltxt文件
'''

# 待搜索的目录路径
dir_path = r"E:\0_study\13_paddle\PaddleOCR-release-2.5\train_data\cls\train"
label_path = r"E:\0_study\13_paddle\PaddleOCR-release-2.5\train_data\cls\train.txt"

img_list_path = []
cv2.namedWindow("show", 0)
cv2.resizeWindow("show", 800, 600)
font = cv2.FONT_HERSHEY_SIMPLEX


def on_mouse(event, x, y, flags, param):
    global img, data, q
    img2 = img.copy()
    if event == cv2.EVENT_LBUTTONDOWN:  # 左键点击
        if data == 0:
            data = 180
            cv2.putText(img2, "cls:   " + str(data), (30, 30), font, 1, (0, 0, 255), 2)
            cv2.imshow("show", img2)
        else:
            data = 0
            cv2.putText(img2, "cls:   " + str(data), (30, 30), font, 1, (0, 0, 255), 2)
            cv2.imshow("show", img2)
    if event == cv2.EVENT_MBUTTONDBLCLK:  # 左键点击
        q = 0


cv2.setMouseCallback('show', on_mouse)

# elif event == cv2.EVENT_MOUSEMOVE and (flags & cv2.EVENT_FLAG_LBUTTON):  # 按住左键拖曳
#     cv2.rectangle(img2, point1, (x, y), (255, 0, 0), 5)
#     cv2.imshow('image', img2)

q = 1
with open(label_path, 'w', encoding='utf-8') as f:
    for file in os.listdir(dir_path):
        # 利用os.path.join()方法取得路径全名,并存入cur_path变量,否则每次只能遍历一层目录
        cur_path = os.path.join(dir_path, file)
        img = cv2.imread(cur_path)
        img = cv2.resize(img, (800, 600))
        data = 0
        img2 = img.copy()
        cv2.putText(img2, "cls:   " + str(data), (30, 30), font, 1, (0, 0, 255), 2)
        cv2.imshow("show", img2)
        cv2.waitKey(1)
        while 1:
            if (cv2.waitKey(1) == ord('q')) or (q == 0):
                break
        f.write(cur_path + "\t" + str(data) + "\n")
        if q == 0:
            break
        # 判断是否是文件夹
    f.close()

  • 2
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值