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

边栏推荐
- Sword finger offer II 091 Painting house: application of state machine DP
- 时创能源冲刺科创板:拟募资11亿 年营收7亿净利反降36%
- 時創能源沖刺科創板:擬募資11億 年營收7億淨利反降36%
- Very important very important very important very important very important very important very important very important very important
- Tool usage summary
- VFP function to summarize all numeric columns of grid to cursor
- Recommend a virtual machine software available for M1 computer
- 使用php脚本查看已开启的扩展
- 基于超算平台气象预警并行计算架构研究
- Capacity expansion mechanism of Dict Of redis (rehash)
猜你喜欢

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

Continue to cut the picture after the ArcGIS Server is disconnected

TCP如何處理三次握手和四次揮手期間的异常

架构师为你揭秘在阿里、腾讯、美团工作的区别

牛客网:分糖果问题

Explain websocket protocol in detail

Detailed explanation of spark specification

How TCP handles exceptions during three handshakes and four waves

CMU puts forward a new NLP paradigm - reconstructing pre training, and achieving 134 high scores in college entrance examination English

黑马畅购商城---3.商品管理
随机推荐
时创能源冲刺科创板:拟募资11亿 年营收7亿净利反降36%
Hangzhou / Beijing neitui Ali Dharma academy recruits academic interns in visual generation (talent plan)
Cesium draw point line surface
Niuke.com: Candy distribution
Caused by: org. xml. sax. SAXParseException; lineNumber: 1; columnNumber: 10; Processing matching '[xx][mm][ll]' is not allowed
Redis雪崩、穿透和击穿是什么?
Le détour d'un ingénieur en matériel
Evaluating the overall situation of each class in a university based on entropy weight method (formula explanation + simple tool introduction)
Old ou, a fox friend, has had a headache all day. The VFP format is always wrong when it is converted to JSON format. It is actually caused by disordered code
Network related encapsulation introduced by webrtc native M96 basic base module
架构师为你揭秘在阿里、腾讯、美团工作的区别
Spark history server performance improvement (I) -- Application List
记一次给OpenHarmony提交代码的过程
Is the online stock trading account opening ID card information safe?
Eureka accesses the console and reports an error: whitelabel error page
A detour taken by a hardware engineer
Countdownlatch source code analysis
How TCP handles exceptions during three handshakes and four waves
西山科技冲刺科创板:拟募资6.6亿 郭毅军夫妇有60%表决权
芯片的发展史和具体用途以及结构是什么样的