python - 如何在 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()
解决方案
推荐阅读
- powershell - PowerShell 嵌套循环内循环不起作用?
- sql - SQL将值添加到现有表中的新列?
- python - python中的命令行参数
- r - 在R中的一个城市聚集长/纬度热点点的最佳方法?
- angular - 如何编写 power-shell 脚本来构建 Angular 项目
- javascript - 在一定时间后为变量赋值
- netsuite - [Web 服务操作] 已保存搜索的 NetSuite 记录类型
- scala - 在 Scala 的数据框中查找数组列的重复值
- python - 合并列是变量结构的数据框 - Pyspark
- javascript - 当 React.js 中的计时器计数 === 0 时,如何设置按钮不可见?