首页 > 解决方案 > 如何在 3d 图中绘制 2d 图像以计算对象深度作为 z 轴?

问题描述

在此处输入图像描述

我想在 3D 地图中绘制 2D 图像以计算对象的深度,并且我已经编写了一个代码,但是该代码给了我一个错误,用于计算距离 z 作为深度。

错误是shape mismatch: objects cannot be broadcast to a single shape

import cv2
import numpy as np
import  math
import scipy.ndimage as ndimage

from matplotlib import pyplot as plt
from mpl_toolkits.mplot3d import Axes3D


image2=cv2.imread('i1.jpg')
image2 = image2[:,:,1] # get the first channel
rows, cols = image2.shape
x, y= np.meshgrid(range(cols), range(rows)[::-1])

blurred = ndimage.gaussian_filter(image2,(5, 5))
fig = plt.figure(figsize=(6,6))
ax = fig.add_subplot(221)
ax.imshow(image2, cmap='gray')
ax = fig.add_subplot(222, projection='3d')
ax.elev= 5
ax.plot_surface(x,y,z,image2)
ax = fig.add_subplot(223)
ax.imshow(blurred, cmap='gray')
ax = fig.add_subplot(224, projection='3d')
ax.elev= 5
ax.plot_surface(x,y,z,blurred)
plt.show()

标签: pythonmatplotlib3dcomputer-visionnumpy-ndarray

解决方案


推荐阅读