可视化检测框和每个框的属性

部署运行你感兴趣的模型镜像

 

import os
import sys

import cv2
from tqdm import tqdm
from PIL import Image
from matplotlib import pyplot as plt
import argparse
import json

def vis_one_img(result_dict,target_dir):
    img_position=result_dict["name"]
    instances=result_dict["instances"]



    image = cv2.imread(img_position, cv2.IMREAD_COLOR)
    img = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)
    plt.ion()

    img_h, img_w, img_c = img.shape
    dpi = 200
    fig = plt.figure(figsize=(img_w / dpi, img_h / dpi))
    ax = fig.add_axes((0.05, 0.05, 0.85, 0.85))
    ax.axis('off')
    ax.set(aspect=1)
    ax.imshow(img)
    # plt.imshow(img)
    currentAxis = plt.gca()


 
    desk_text = ["including desk", "excluding desk"]
    action_text = ["other", "lie down", "hold your head", "turn your back"]
    pose_text = ["normal sitting", "stretching", "standing", "lying back"]
    if img_w > 1280:
        font_size = 6 #12
    else:
        font_size = 4 #10
    for i in range(len(instances)):
        roi = instances[i]['bbox']

        currentAxis.add_patch(plt.Rectangle((roi[0], roi[1]), roi[2] ,
                                            roi[3] , fill=False,
                                            edgecolor='c', linewidth=1))

        xy = (roi[0], roi[1])
        xytext = (0, 4)
        display = "desk:"+desk_text[instances[i]["desk"]]
        c = 'green'
        plt.annotate(display, xy=xy, xytext=xytext, fontsize=font_size,
                     textcoords='offset points', ha='center', va='bottom',
                     color=c,
                     bbox=dict(boxstyle='round,pad=0.2', fc='white', alpha=0.7),
                     arrowprops=dict(arrowstyle='->', connectionstyle='arc3,rad=0.95',
                                     color='white'))

        xy_m = (roi[0], roi[1])
        xytext_m = (0, 20)  # 40)
        display_m = "action:"+action_text[instances[i]["action"]]
        c_m = 'red'
        plt.annotate(display_m, xy=xy_m, xytext=xytext_m, fontsize=font_size,
                     textcoords='offset points', ha='center', va='bottom',
                     color=c_m,
                     bbox=dict(boxstyle='round,pad=0.2', fc='white', alpha=0.7),
                     arrowprops=dict(arrowstyle='->', connectionstyle='arc3,rad=0.95',
                                     color='white'))

        xy_m = (roi[0], roi[1])
        xytext_m = (0, 40)  # 40)
        display_m = "pose:"+pose_text[instances[i]["pose"]]
        c_m = 'green'
        plt.annotate(display_m, xy=xy_m, xytext=xytext_m, fontsize=font_size,
                     textcoords='offset points', ha='center', va='bottom',
                     color=c_m,
                     bbox=dict(boxstyle='round,pad=0.2', fc='white', alpha=0.7),
                     arrowprops=dict(arrowstyle='->', connectionstyle='arc3,rad=0.95',
                                     color='white'))


    if not os.path.exists(target_dir):
        os.makedirs(target_dir)
    plt.axis('off')
    plt.subplots_adjust(top=0.95, bottom=0.05, right=0.95, left=0.05, hspace=0.05, wspace=0.05)
    plt.margins(0, 0)

    plt.savefig(os.path.join(target_dir , img_position.split("/")[-1]), format='jpg', transparent=True, dpi=300, pad_inches=0)

    plt.show()
    # plt.pause(20)
    plt.close()

if __name__=='__main__':
    target_dir="sdk_vis"
    with open("results/sample_result.txt") as f:
        for line in f.readlines():
            result_dict=json.loads(line)
            vis_one_img(result_dict,target_dir)

 

您可能感兴趣的与本文相关的镜像

TensorFlow-v2.9

TensorFlow-v2.9

TensorFlow

TensorFlow 是由Google Brain 团队开发的开源机器学习框架,广泛应用于深度学习研究和生产环境。 它提供了一个灵活的平台,用于构建和训练各种机器学习模型

评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值