【Python】Python绘图可视化等笔记
matplotlib plot显示图片时,鼠标点击实现图片的上下翻页 或点击下一图fig = plt.Figure()sorted(imgs)id = 0while id < len(imgs):img = plt.imread(imgs[id])# exit(0)plt.imshow(img)ax = plt.gca()ax.text(0, 0 + 30, str(id) + ''+img
·
matplotlib plot显示图片时,鼠标点击实现图片的上下翻页 或点击下一图
fig = plt.Figure()
sorted(imgs)
id = 0
while id < len(imgs):
img = plt.imread(imgs[id])
# exit(0)
# plt.subplot(1, 2, 1) 多张时 就前面加
plt.imshow(img)
ax = plt.gca()
ax.text(0, 0 + 30, str(id) + ' '+imgInfo['file_name'], fontsize=10, color='white',
bbox={'facecolor': 'r', 'alpha': 0.5})
plt.pause(0.01)
key_press = 0
while True: # 翻页
pos = plt.ginput(n=1, timeout=1000) # n is times 获得鼠标点的位置
# print(pos)
if len(pos) > 0:
if pos[0][0] > img.shape[1]/2: # 如果位置x大于图片宽度一半 则下一张
id += 1
break
if pos[0][0] < img.shape[1]/2: # 如果位置x小于图片宽度一半则上一张
id -= 1
break
# while not key_press: # 仅实现下一页
# key_press = plt.waitforbuttonpress()
# print(key_press)
# plt.waitforbuttonpress()
plt.cla()
cv2绘制框
img_orgin = cv2.imread(path)
h, w = img_orgin.shape[:2]
l = max(h, w)
fontScale = l/1000
thickness = max(1, l//300)
cv2.rectangle(img_orgin, (x0, y0), (x1, y1), (255, 0, 0), thickness=thickness)
dis_name = class_names[category]
cv2.putText(img_orgin, f'{clc} {confidence}', (x0, y0+l//40), cv2.FONT_HERSHEY_SIMPLEX,
fontScale=fontScale, color=(0, 255, 255),
thickness=thickness)
cv2.imwrite(save_path, img_orgin)
更多推荐
所有评论(0)