|
@@ -12,11 +12,11 @@
|
|
|
# See the License for the specific language governing permissions and
|
|
# See the License for the specific language governing permissions and
|
|
|
# limitations under the License.
|
|
# limitations under the License.
|
|
|
|
|
|
|
|
-
|
|
|
|
|
import os
|
|
import os
|
|
|
import numpy as np
|
|
import numpy as np
|
|
|
import json
|
|
import json
|
|
|
from pathlib import Path
|
|
from pathlib import Path
|
|
|
|
|
+import PIL
|
|
|
from PIL import Image, ImageDraw, ImageFont
|
|
from PIL import Image, ImageDraw, ImageFont
|
|
|
|
|
|
|
|
from ......utils.fonts import PINGFANG_FONT_FILE_PATH
|
|
from ......utils.fonts import PINGFANG_FONT_FILE_PATH
|
|
@@ -62,8 +62,13 @@ def draw_label(image, label, label_map_dict):
|
|
|
for font_size in range(max_font_size, min_font_size - 1, -1):
|
|
for font_size in range(max_font_size, min_font_size - 1, -1):
|
|
|
font = ImageFont.truetype(
|
|
font = ImageFont.truetype(
|
|
|
PINGFANG_FONT_FILE_PATH, font_size, encoding="utf-8")
|
|
PINGFANG_FONT_FILE_PATH, font_size, encoding="utf-8")
|
|
|
- text_width_tmp, text_height_tmp = draw.textsize(
|
|
|
|
|
- label_map_dict[int(label)], font)
|
|
|
|
|
|
|
+ if tuple(map(int, PIL.__version__.split('.'))) <= (10, 0, 0):
|
|
|
|
|
+ text_width_tmp, text_height_tmp = draw.textsize(
|
|
|
|
|
+ label_map_dict[int(label)], font)
|
|
|
|
|
+ else:
|
|
|
|
|
+ left, top, right, bottom = draw.textbbox(
|
|
|
|
|
+ (0, 0), label_map_dict[int(label)], font)
|
|
|
|
|
+ text_width_tmp, text_height_tmp = right - left, bottom - top
|
|
|
if text_width_tmp <= image_size[0]:
|
|
if text_width_tmp <= image_size[0]:
|
|
|
break
|
|
break
|
|
|
else:
|
|
else:
|
|
@@ -71,7 +76,13 @@ def draw_label(image, label, label_map_dict):
|
|
|
color_list = colormap(rgb=True)
|
|
color_list = colormap(rgb=True)
|
|
|
color = tuple(color_list[0])
|
|
color = tuple(color_list[0])
|
|
|
font_color = tuple(font_colormap(3))
|
|
font_color = tuple(font_colormap(3))
|
|
|
- text_width, text_height = draw.textsize(label_map_dict[int(label)], font)
|
|
|
|
|
|
|
+ if tuple(map(int, PIL.__version__.split('.'))) <= (10, 0, 0):
|
|
|
|
|
+ text_width, text_height = draw.textsize(label_map_dict[int(label)],
|
|
|
|
|
+ font)
|
|
|
|
|
+ else:
|
|
|
|
|
+ left, top, right, bottom = draw.textbbox(
|
|
|
|
|
+ (0, 0), label_map_dict[int(label)], font)
|
|
|
|
|
+ text_width, text_height = right - left, bottom - top
|
|
|
|
|
|
|
|
rect_left = 3
|
|
rect_left = 3
|
|
|
rect_top = 3
|
|
rect_top = 3
|