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')
![opencv 转 matplotlib 坐标_第1张图片](http://img.e-com-net.com/image/info8/b32462f5557b4d27849563fa053f6f80.jpg)
![opencv 转 matplotlib 坐标_第2张图片](http://img.e-com-net.com/image/info8/de186e4013c24c17a3710200e788de68.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
![opencv 转 matplotlib 坐标_第3张图片](http://img.e-com-net.com/image/info8/8ea18dbbbe3e46648f44df05c59c4992.jpg)
![opencv 转 matplotlib 坐标_第4张图片](http://img.e-com-net.com/image/info8/610c7665ca9f465ba87aa929e55a2867.jpg)
![opencv 转 matplotlib 坐标_第5张图片](http://img.e-com-net.com/image/info8/2dda8235ef9747d29b2c2224265aac4d.jpg)