Skip to content

Commit 7d094e7

Browse files
committed
update CVShowBoxes 方法
1 parent 4665892 commit 7d094e7

5 files changed

Lines changed: 67 additions & 2 deletions

File tree

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
## OpencvToolsV1.1.5
1+
## OpencvToolsV1.1.6
22
Opencv相关操作
33

44
### 打包为wheel文件
@@ -18,3 +18,4 @@ pip wheel --wheel-dir=./wheel_dir ./
1818
* 日志输出Ascend芯片解码
1919
* 优化Ascend芯片解码
2020
* device类型统一使用ascend
21+
* update CVShowBoxes 方法

opencv_tools/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,6 @@
33
DIRECTORY_IMAGES = 'JPEGImages/'
44
DIRECTORY_PREANNOTATIONS = "PredictAnnotations/"
55
from opencv_tools.jade_opencv_process import *
6+
from opencv_tools.version import version as __version__
67

78

opencv_tools/jade_visualize.py

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,15 @@
1313
from PIL import Image, ImageFont, ImageDraw
1414
from opencv_tools.jade_opencv_process import GetRandomColor,ReadChinesePath
1515
from jade import getOperationSystem
16+
import random
17+
18+
def _to_color(indx):
19+
""" return (b, r, g) tuple"""
20+
b = random.randint(1,10) / 10
21+
g = random.randint(1,10) / 10
22+
r = random.randint(1,10) / 10
23+
return b * 255, r * 255, g * 255
24+
1625
def get_color_map_list(num_classes):
1726
"""
1827
Args:
@@ -43,6 +52,8 @@ def draw_box(im, results,show_score=True,font_path=None,font_size=24):
4352
Returns:
4453
im (PIL.Image.Image): visualized image
4554
"""
55+
56+
im = Image.fromarray(im)
4657
np_boxes = results['boxes']
4758
labels_text = results["labels"]
4859
scores = results["scores"]
@@ -74,6 +85,7 @@ def draw_box(im, results,show_score=True,font_path=None,font_size=24):
7485
draw.rectangle(
7586
[(xmin + 1, ymin - th), (xmin + tw + 1, ymin)], fill=color)
7687
draw.text((xmin + 1, ymin - th), text, fill=(255, 255, 255),font=font)
88+
im = np.array(im)
7789
return im
7890

7991

@@ -603,6 +615,48 @@ def CVShowKeypointsBoxes(img_path, keypoints, bboxes=[], scores=[], waitkey=1):
603615
cv2.imshow("result", im)
604616
cv2.waitKey(waitkey)
605617

618+
619+
#opencv显示boxes
620+
def CVShowBoxes(image,boxes,label_texts,scores,label_ids=None,num_classes=90,waitkey=-1,named_windows="result"):
621+
base = int(np.ceil(pow(num_classes, 1. / 3)))
622+
colors = [_to_color(x) for x in range(num_classes)]
623+
if type(image) == str:
624+
image = cv2.imread(image)
625+
image2 = image.copy()
626+
for i in range(len(boxes)):
627+
if boxes[i][0] <= 1.1 and boxes[i][1] <= 1.1 and boxes[i][2] <= 1.1 and boxes[i][3] <= 1.1:
628+
xmin = int(boxes[i][0]*image.shape[1]) if int(boxes[i][0]*image.shape[1]) > 0 else 0
629+
ymin = int(boxes[i][1]*image.shape[0]) if (int(boxes[i][1]*image.shape[0])) > 0 else 0
630+
xmax = int(boxes[i][2]*image.shape[1]) if int(boxes[i][2]*image.shape[1]) > 0 else 0
631+
ymax = int(boxes[i][3]*image.shape[0]) if int(boxes[i][3]*image.shape[0]) > 0 else 0
632+
else:
633+
xmin = int(boxes[i][0])
634+
ymin = int(boxes[i][1])
635+
xmax = int(boxes[i][2])
636+
ymax = int(boxes[i][3])
637+
if boxes is not None:
638+
image2 = cv2.rectangle(image2, (xmin, ymin), (xmax, ymax), GetRandomColor(), 3, 3)
639+
if label_texts is not None:
640+
if scores is not None:
641+
image2 = Add_Chinese_Label(img=image2, label=label_texts[i] + ":" + str(int(scores[i] * 100)),
642+
pt1=(xmin, ymin))
643+
else:
644+
image2 = Add_Chinese_Label(img=image2, label=label_texts[i],
645+
pt1=(xmin, ymin))
646+
if label_ids is not None:
647+
image2 = cv2.rectangle(image2, (xmin, ymin), (xmax, ymax), colors[int(label_ids[i])], 3, 3)
648+
else:
649+
image2 = cv2.rectangle(image2, (xmin, ymin), (xmax, ymax), GetRandomColor(), 3, 3)
650+
651+
652+
if waitkey >= 0:
653+
cv2.namedWindow(named_windows, 0)
654+
# cv2.resizeWindow("result", 840, 680)
655+
cv2.imshow(named_windows,image2)
656+
cv2.waitKey(waitkey)
657+
else:
658+
return image2
659+
606660
# OCR识别结果
607661
def draw_ocr(image, boxes, txts, scores, draw_txt=True, drop_score=0.5):
608662
"""

opencv_tools/version.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#!/usr/bin/env python
2+
# -*- coding: utf-8 -*-
3+
# @File : version.py
4+
# @Author : jade
5+
# @Date : 2022/12/14 13:42
6+
# @Email : jadehh@1ive.com
7+
# @Software : Samples
8+
# @Desc :
9+
version = "1.1.6"

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
find_packages("opencv_tools", pack_list)
1313
setup(
1414
name="opencv_tools",
15-
version="1.1.5",
15+
version="1.1.6",
1616
keywords=("pip", "opencv_tools", ""),
1717
description="opencv_tools",
1818
long_description="",

0 commit comments

Comments
 (0)