未验证 提交 484510a9 编写于 作者: S shiyutang 提交者: GitHub

[BugFix] fix_textbbox in ImageDraw (#8455)

* fix_textbbox

* compact_py37

* update_req
上级 1632c27d
......@@ -20,6 +20,8 @@ import numpy as np
from PIL import Image, ImageDraw, ImageFile
ImageFile.LOAD_TRUNCATED_IMAGES = True
from collections import deque
from ppdet.utils.compact import imagedraw_textsize_c
def visualize_box_mask(im, results, labels, threshold=0.5):
......@@ -109,8 +111,7 @@ def draw_box(im, np_boxes, labels, threshold=0.5):
# draw label
text = "{} {:.4f}".format(labels[clsid], score)
left, top, right, bottom = draw.textbbox(text)
tw, th = right - left, bottom - top
tw, th = imagedraw_textsize_c(draw, text)
draw.rectangle(
[(xmin + 1, ymin - th), (xmin + tw + 1, ymin)], fill=color)
draw.text((xmin + 1, ymin - th), text, fill=(255, 255, 255))
......
......@@ -20,6 +20,7 @@ import numpy as np
from PIL import Image, ImageDraw, ImageFile
ImageFile.LOAD_TRUNCATED_IMAGES = True
import math
from ppdet.utils.compact import imagedraw_textsize_c
def visualize_box_mask(im, results, labels, threshold=0.5):
......@@ -159,8 +160,7 @@ def draw_box(im, np_boxes, labels, threshold=0.5):
# draw label
text = "{} {:.4f}".format(labels[clsid], score)
left, top, right, bottom = draw.textbbox(text)
tw, th = right - left, bottom - top
tw, th = imagedraw_textsize_c(draw, text)
draw.rectangle(
[(xmin + 1, ymin - th), (xmin + tw + 1, ymin)], fill=color)
draw.text((xmin + 1, ymin - th), text, fill=(255, 255, 255))
......@@ -498,8 +498,7 @@ def draw_press_box_lanes(im, np_boxes, labels, threshold=0.5):
# draw label
text = "{}".format(labels[clsid])
left, top, right, bottom = draw.textbbox(text)
tw, th = right - left, bottom - top
tw, th = imagedraw_textsize_c(draw, text)
draw.rectangle(
[(xmin + 1, ymax - th), (xmin + tw + 1, ymax)], fill=color)
draw.text((xmin + 1, ymax - th), text, fill=(0, 0, 255))
......@@ -572,8 +571,7 @@ def visualize_vehicle_retrograde(im, mot_res, vehicle_retrograde_res):
# draw label
text = "retrograde"
left, top, right, bottom = draw.textbbox(text)
tw, th = right - left, bottom - top
tw, th = imagedraw_textsize_c(draw, text)
draw.rectangle(
[(xmax + 1, ymin - th), (xmax + tw + 1, ymin)],
fill=(0, 255, 0))
......
......@@ -51,6 +51,8 @@ from .op_helper import (satisfy_sample_constraint, filter_and_process,
is_poly, get_border)
from ppdet.utils.logger import setup_logger
from ppdet.utils.compact import imagedraw_textsize_c
from ppdet.modeling.keypoint_utils import get_affine_transform, affine_transform
logger = setup_logger(__name__)
......@@ -2212,8 +2214,7 @@ class DebugVisibleImage(BaseOperator):
fill='green')
# draw label
text = str(gt_class[i][0])
left, top, right, bottom = draw.textbbox(text)
tw, th = right - left, bottom - top
tw, th = imagedraw_textsize_c(draw, text)
draw.rectangle(
[(xmin + 1, ymin - th), (xmin + tw + 1, ymin)], fill='green')
draw.text((xmin + 1, ymin - th), text, fill=(255, 255, 255))
......
......@@ -31,6 +31,7 @@ import copy
from .operators import register_op, BaseOperator
from ppdet.modeling.rbox_utils import poly2rbox_le135_np, poly2rbox_oc_np, rbox2poly_np
from ppdet.utils.logger import setup_logger
from ppdet.utils.compact import imagedraw_textsize_c
logger = setup_logger(__name__)
......@@ -433,8 +434,7 @@ class VisibleRBox(BaseOperator):
xmin = min(x1, x2, x3, x4)
ymin = min(y1, y2, y3, y4)
text = str(gt_class[i][0])
left, top, right, bottom = draw.textbbox(text)
tw, th = right - left, bottom - top
tw, th = imagedraw_textsize_c(draw, text)
draw.rectangle(
[(xmin + 1, ymin - th), (xmin + tw + 1, ymin)], fill='green')
draw.text((xmin + 1, ymin - th), text, fill=(255, 255, 255))
......
import PIL
def imagedraw_textsize_c(draw, text):
if int(PIL.__version__.split('.')[0]) < 10:
tw, th = draw.textsize(text)
else:
left, top, right, bottom = draw.textbbox((0, 0), text)
tw, th = right - left, bottom - top
return tw, th
\ No newline at end of file
......@@ -24,6 +24,7 @@ import math
from .colormap import colormap
from ppdet.utils.logger import setup_logger
from ppdet.utils.compact import imagedraw_textsize_c
logger = setup_logger(__name__)
__all__ = ['visualize_results']
......@@ -125,8 +126,7 @@ def draw_bbox(image, im_id, catid2name, bboxes, threshold):
# draw label
text = "{} {:.2f}".format(catid2name[catid], score)
left, top, right, bottom = draw.textbbox(text)
tw, th = right - left, bottom - top
tw, th = imagedraw_textsize_c(draw, text)
draw.rectangle(
[(xmin + 1, ymin - th), (xmin + tw + 1, ymin)], fill=color)
draw.text((xmin + 1, ymin - th), text, fill=(255, 255, 255))
......
......@@ -10,7 +10,7 @@ terminaltables
Cython
pycocotools
setuptools
Pillow>=10.0.0
Pillow
# for MOT evaluation and inference
lap
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册