当前位置:网站首页>plt.gca()画框及打标签
plt.gca()画框及打标签
2022-06-25 11:46:00 【论搬砖的艺术】
画一个框及标签
主要就是从 json文件中,获取目标物的坐标位置。
对图片画好框的json文件信息。
代码
import json
from matplotlib import pyplot as plt
from PIL import Image
import numpy as np
jsonpath = '罗.json' # 加载json数据信息
with open(jsonpath,encoding = 'utf-8') as f:
data=json.load(f)
image = '罗.jpg'
img = Image.open(image)
np_img = np.array(img)
print(np_img.shape)
plt.figure(figsize=(15,9))
plt.imshow(img)
current_axis = plt.gca() # 画框对象
xmin = data['outputs']['object'][0]['bndbox']['xmin']
ymin = data['outputs']['object'][0]['bndbox']['ymin']
xmax = data['outputs']['object'][0]['bndbox']['xmax']
ymax = data['outputs']['object'][0]['bndbox']['ymax']
current_axis.add_patch(plt.Rectangle((xmin, ymin), xmax-xmin, ymax-ymin, color='green', fill=False, linewidth=2))
current_axis.text(xmin, ymin, 'c luo', size='x-large', color='white', bbox={
'facecolor':'green', 'alpha':1.0})#其中label是想要打的标签名
画多个框及标签
打好标签的图片json文件信息
代码:
import json
from matplotlib import pyplot as plt
from PIL import Image
import numpy as np
jsonpath = '梅.json' # 加载json数据信息
with open(jsonpath,encoding = 'utf-8') as f:
data=json.load(f)
image = '梅.jpg'
img = Image.open(image)
np_img = np.array(img)
print(np_img.shape)
plt.figure(figsize=(15,9))
plt.imshow(img)
current_axis = plt.gca() # 画框对象
data = data['outputs']['object']
for i in data:
print(i)
name = i['name']
xmin = i['bndbox']['xmin']
ymin = i['bndbox']['ymin']
xmax = i['bndbox']['xmax']
ymax = i['bndbox']['ymax']
current_axis.add_patch(plt.Rectangle((xmin, ymin), xmax-xmin, ymax-ymin, color='green', fill=False, linewidth=2))
current_axis.text(xmin, ymin, name, size='x-large', color='white', bbox={
'facecolor':'green', 'alpha':1.0})#其中label是想要打的标签名
边栏推荐
- Thingspanel releases Internet of things mobile client (multiple pictures)
- RPC typical framework
- Niuke.com: Candy distribution
- Cesium building loading (with height)
- Comment TCP gère - t - il les exceptions lors de trois poignées de main et de quatre vagues?
- Countdownlatch source code analysis
- Share 7 immortal wallpaper websites, let the new wallpaper give you a little joy, and don't fall into the repetition year after year.
- Niuke.com: host scheduling
- The temporary table from XML to VFP is simple and easy to use and worth collecting
- Evaluating the overall situation of each class in a university based on entropy weight method (formula explanation + simple tool introduction)
猜你喜欢
Two ways of redis persistence -- detailed explanation of RDB and AOF
Database Series: MySQL index optimization summary (comprehensive version)
CFCA Anxin sign access
Using DBF of VFP to web salary query system
Shichuang Energy sprint Technology Innovation Board: le chiffre d'affaires annuel prévu de 1,1 milliard de RMB est de 0,7 milliard de RMB, en baisse de 36%
redis的dict的扩容机制(rehash)
牛客网:旋转数组
Real software developers will use this method to predict the future
翌圣生物冲刺科创板:25%收入来自新冠产品销售 拟募资11亿
4 life distributions
随机推荐
西山科技冲刺科创板:拟募资6.6亿 郭毅军夫妇有60%表决权
SQL injection vulnerability (type chapter)
Real software developers will use this method to predict the future
Shichuang Energy sprint Technology Innovation Board: le chiffre d'affaires annuel prévu de 1,1 milliard de RMB est de 0,7 milliard de RMB, en baisse de 36%
CFCA Anxin sign access
Uncover gaussdb (for redis): comprehensive comparison of CODIS
Deeply understand Flink SQL execution process based on flink1.12
TCP如何处理三次握手和四次挥手期间的异常
黑马畅购商城---2.分布式文件存储FastDFS
Golden sun education listed in the U.S.: a small cap medium cap stock with a market value of USD 360million
客从何处来
Source code analysis of AQS & reentrantlock
Niuke.com: Candy distribution
Detailed explanation of Spark's support source code for Yan priority
Multiple clicks of the button result in results
Why can't the form be closed? The magic of revealing VFP object references
建造者模式
Flink batch key points (personal translation)
基于超算平台气象预警并行计算架构研究
JSON format processing