解决:open3d中Unable to cast Python instance to C++ type (compile in debug mode for details)
Posted 沉迷单车的追风少年
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了解决:open3d中Unable to cast Python instance to C++ type (compile in debug mode for details)相关的知识,希望对你有一定的参考价值。
项目场景:
三维点云重建
问题描述:
pcd.points = o3d.utility.Vector3dVector(source_data) # numpy.array转换成point cloud
RuntimeError: Unable to cast Python instance to C++ type (compile in debug mode for details)
原因分析:
这个报错的表现意思是不能将Python实例转换成C++类型,需要你debug模式下详细查一查。
如果打开debug模式去查的话,半天又没了,还查不出来。坑得一批。
核心在于没有reshape!
将上面的一句代码:
source_data = source_data[:, 0:3]
改成:
source_data = source_data[:, 0:3].reshape(-1, 3)
解决方案:
原先报错代码:
import numpy as np
import open3d as o3d
# filePath = './GEN_Ours_chair_1631677128/out.npy'
filePath = './GEN_Ours_airplane_1631630214/out.npy'
np.set_printoptions(suppress=True) # 取消默认科学计数法,open3d无法读取科学计数法表示
loadData = np.load(filePath)
print("----type----")
print(type(loadData))
print("----shape----")
print(loadData.shape)
print("----data----")
print(loadData)
# source_data = np.load(filePath)[:,0:3][:,0:3]
point_cloud = o3d.geometry.PointCloud()
source_data = np.load(filePath)
# source_data = np.squeeze(source_data)
print(source_data.shape)
# print(source_data)
pcd = o3d.geometry.PointCloud()
# source_data = source_data[:, 0:3].reshape(-1, 3)
source_data = source_data[:, 0:3]
pcd.points = o3d.utility.Vector3dVector(source_data) # numpy.array转换成point cloud
o3d.visualization.draw_geometries([pcd])
print("finish!")
改正后:
import numpy as np
import open3d as o3d
# filePath = './GEN_Ours_chair_1631677128/out.npy'
filePath = './GEN_Ours_airplane_1631630214/out.npy'
np.set_printoptions(suppress=True) # 取消默认科学计数法,open3d无法读取科学计数法表示
loadData = np.load(filePath)
print("----type----")
print(type(loadData))
print("----shape----")
print(loadData.shape)
print("----data----")
print(loadData)
# source_data = np.load(filePath)[:,0:3][:,0:3]
point_cloud = o3d.geometry.PointCloud()
source_data = np.load(filePath)
# source_data = np.squeeze(source_data)
print(source_data.shape)
# print(source_data)
pcd = o3d.geometry.PointCloud()
source_data = source_data[:, 0:3].reshape(-1, 3)
# source_data = source_data[:, 0:3]
pcd.points = o3d.utility.Vector3dVector(source_data) # numpy.array转换成point cloud
o3d.visualization.draw_geometries([pcd])
print("finish!")
运行效果:
这是一个飞机啊,有多少人能看出来。。。。。。。。
以上是关于解决:open3d中Unable to cast Python instance to C++ type (compile in debug mode for details)的主要内容,如果未能解决你的问题,请参考以下文章
EF Core Error:Unable to cast object of type ‘System.DBNull‘ to type ‘System.String‘
Unable to cast object of type 'System.Int32' to type 'System.String'.
unable to inject dll into target怎么解决?
解决javax.persistence.EntityNotFoundException: Unable to find