【Python】Python绘图可视化等笔记

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
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值