我想放置一个像这样的 2D 图像
\换行
enter image description here
进入 3D 空间,使图像显示在 Z = -10 和 z = 10 处。
我当前的输出是这样的。 enter image description here
问题是图像扭曲并向右旋转了 90 度。像素高度和宽度似乎与原始图片的高度和宽度匹配,但显然图像本身不匹配。
我在网上发现了一些类似的代码问题,但这些问题似乎对我不起作用。 (我使用的代码是我在网上找到的代码的混合,老实说我不明白每一步)
我使用的代码如下:
import numpy as np
import matplotlib.pyplot as plt
import cv2
# Read the image with Opencv
img = cv2.imread('input_image')
# Change the color from BGR to RGB
img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
# Orgird to store data
x, y = np.ogrid[0:img.shape[0], 0:img.shape[1]]
# In Python3 matplotlib assumes rgbdata in range 0.0 to 1.0
img = img.astype('float32')/255
fig = plt.Figure()
# gca do not work thus use figure objects inbuilt function.
ax = fig.add_subplot(projection='3d')
# minus 50 to place the image in the middle
ax.plot_surface(x-50, y-50, np.atleast_2d(0)-10, rstride=10, cstride=10, facecolors=img, label="TEST")
ax.plot_surface(x-50, y-50, np.atleast_2d(0)+10, rstride=10, cstride=10, facecolors=img, label="NO")
ax.set_xlabel('X')
ax.set_ylabel('Y')
ax.set_zlabel('Z')
fig.savefig('output_image')