当前位置:网站首页>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是想要打的标签名

边栏推荐
- Redis6 note02 configuration file, publish and subscribe, new data type, jedis operation
- Windows11 MySQL service is missing
- Subclass a inherits from parent class B, a a = new a(); Then the execution sequence of the constructor of parent class B, the static code block of parent class B, the non static code block of parent c
- How far is it from the DBF of VFP to the web salary query system?
- Niuke.com: Candy distribution
- Eureka accesses the console and reports an error: whitelabel error page
- Customize to prevent repeated submission of annotations (using redis)
- 一個硬件工程師走過的彎路
- 翌圣生物冲刺科创板:25%收入来自新冠产品销售 拟募资11亿
- TCP如何处理三次握手和四次挥手期间的异常
猜你喜欢

牛客网:分糖果问题

Nacos installation and use

ThingsPanel 發布物聯網手機客戶端(多圖)

云原生数据湖以存储、计算、数据管理等能力通过信通院评测认证

Use of Presto visualization client-yanagishima20.0

Continue to cut the picture after the ArcGIS Server is disconnected

Redis雪崩、穿透和击穿是什么?

按钮多次点击造成结果

Idea local launch Flink task

Spark history server and event log details
随机推荐
Keywords serializable serialization and deserialization
交易期货沪镍产品网上怎么开户
cnds
TCP如何处理三次握手和四次挥手期间的异常
牛客网:分糖果问题
How to use the markdown editor
SQL injection vulnerability (type chapter)
金太阳教育美股上市:市值3.6亿美元 成小盘中概股
客从何处来
翌圣生物冲刺科创板:25%收入来自新冠产品销售 拟募资11亿
時創能源沖刺科創板:擬募資11億 年營收7億淨利反降36%
Is industrial securities a state-owned enterprise? Is it safe to open an account in industrial securities?
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%
Multiple clicks of the button result in results
CMU puts forward a new NLP paradigm - reconstructing pre training, and achieving 134 high scores in college entrance examination English
.Net Core 中使用工厂模式
Whole process of web page request
Thingspanel releases Internet of things mobile client (multiple pictures)
A detour taken by a hardware engineer
Research on parallel computing architecture of meteorological early warning based on supercomputing platform