opencv 转 matplotlib 坐标

2D opencv -> 2D matplotlib

width = 200
height = 200
points = [[100,120],[130,140],[150,180]]
mask = np.zeros((200,200))
cv2.circle(mask,tuple(points[0]),3,(255,255,0),-1)
cv2.circle(mask,tuple(points[1]),3,(255,255,0),-1)
cv2.circle(mask,tuple(points[2]),3,(255,255,0),-1)
cv2.imshow('',mask)
cv2.imwrite('2dopencv.jpg',mask)
cv2.waitKey(1)

xy = np.asarray(points)
x_pos = xy[:,0]
y_pos = xy[:,1]
xy = np.asarray([np.asarray(x_pos), height-np.asarray(y_pos)])
plt.scatter(xy[0], xy[1], s=15, c='orange')
plt.xlim([0, 200])
plt.ylim([0, 200])
plt.pause(1)
plt.savefig('2dmatplotlib.jpg')

请添加图片描述
在这里插入图片描述

2D opencv + 时序 -> 3D matplotlib

width = 200
height = 200
points = [[180,180],[120,120],[10,10]]

mask = np.zeros((200,200,3))
cv2.circle(mask,tuple(points[0]),3,(255,0,0),-1)
cv2.circle(mask,tuple(points[1]),3,(0,255,0),-1)
cv2.circle(mask,tuple(points[2]),3,(0,0,255),-1)
cv2.imshow('',mask)
cv2.imwrite('3dopencv.jpg',mask)
cv2.waitKey(1)

xy = np.asarray(points)
x_pos = xy[:,0]
y_pos = xy[:,1]
xy = np.asarray([np.asarray(x_pos), height-np.asarray(y_pos)])
z_pos = np.asarray(list(range(len(points)))) # 时间序列 t1 -> t3
fig = plt.figure(1)
ax = Axes3D(fig)
ax.plot3D(xy[0],  z_pos,  xy[1], 'grey', alpha=0.75)
ax.scatter(xy[0], z_pos,  xy[1], 'red', alpha=0.75)
ax.set_ylim([-1,4])
ax.set_xlim([0,200])
ax.set_zlim([0,200])
plt.savefig('3matplotlib.jpg')
plt.show()

点的顺序是Blue --> Green --> Red
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值