索引错误:标量变量的索引无效

时间:2018-09-17 12:56:29

标签: python-3.x list point-clouds

由于某种原因,我试图使用this数据集中的检测注释中提到的尺寸来创建边界框(我使用的是polyterrasse),以下代码适用于25帧,然后突然出现错误:

IndexError: invalid index to scalar variable.

frame_path=glob.glob("path/to/pointcloud/folder/*.ezd")
bbox_path= glob.glob("path/to/detection/annotation/folder/*.ezd.bbox")
bbox=[]
cbox_dim=[]

for i in range(len(bbox_path)):
  #convert the frame into pcd format and then load via PCL 
  bbox=np.loadtxt(bbox_path[i], dtype=np.float32)  # load tracklets for the frame
    if bbox.size==0:
        continue
    cbox_dim=np.asarray(bbox)
    pc= pcl.PointCloud() #create pointcloud
    pc.from_array(obj) #load frame into the point cloud

    clipper=pc.make_cropbox()
    for j in range(len(cbox_dim)):
        tx = cbox_dim[j][0] #Error occurs: Invalid index to scalar variable 
        ty = cbox_dim[j][1]
        tz = cbox_dim[j][2]
        
        #similarly set rotation and dimensions
        

可能的原因是什么?

1 个答案:

答案 0 :(得分:1)

我下载了数据,将其解压缩并检查,结果证明文件polyterrasse026.ezd.bbox仅包含1行数据:

1.718750 5.066964 -0.327395 0.693458 0.684387 1.325830 0 0 0 0

这就是bbox_path[26]是一维数组的原因。这是您收到错误的原因。

编辑。

要验证bbox是否为2D数组,可以使用bbox.ndim == 2bbox.size显示的是数组中元素的数量,而不是维度的数量。

您的问题的本质是,如果文件仅包含一行数据,np.loadtxt()将返回一维数组。您可以这样处理此问题:

if bbox.ndim == 1:
    bbox = np.array([bbox])
相关问题