1 Star 0 Fork 0

Brook's/tr

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
test.py 1.22 KB
一键复制 编辑 原始数据 按行查看 历史
myhub 提交于 2020-06-06 11:21 . add thead support
# coding: utf-8
import tr
import sys, cv2, time, os
from PIL import Image, ImageDraw, ImageFont
import numpy as np
_BASEDIR = os.path.dirname(os.path.abspath(__file__))
os.chdir(_BASEDIR)
def test():
print("recognize", tr.recognize("imgs/line.png"))
img_path = "imgs/id_card.jpeg"
# img_path = "imgs/name_card.jpg"
img_pil = Image.open(img_path)
print(img_pil.size)
color_pil = img_pil.convert("RGB")
gray_pil = img_pil.convert("L")
img_draw = ImageDraw.Draw(color_pil)
colors = ['red', 'green', 'blue', "purple"]
t = time.time()
n = 1
for _ in range(n):
tr.detect(gray_pil, flag=tr.FLAG_RECT)
print("time", (time.time() - t) / n)
results = tr.run(gray_pil, flag=tr.FLAG_ROTATED_RECT)
for i, rect in enumerate(results):
cx, cy, w, h, a = tuple(rect[0])
print(i, "\t", rect[1], rect[2])
box = cv2.boxPoints(((cx, cy), (w, h), a))
box = np.int0(np.round(box))
for p1, p2 in [(0, 1), (1, 2), (2, 3), (3, 0)]:
img_draw.line(xy=(box[p1][0], box[p1][1], box[p2][0], box[p2][1]), fill=colors[i % len(colors)], width=2)
color_pil.show()
if __name__ == "__main__":
test()
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/liushaojun/tr.git
git@gitee.com:liushaojun/tr.git
liushaojun
tr
tr
master

搜索帮助