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))))
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