程序执行提示AttributeError: 'point_cloud_generator' object has no attribute 'widthself',优化程序class point_cloud_generator(): def __init__(self, rgb_file, depth_file, save_ply, camera_intrinsics=[784.0, 779.0, 649.0, 405.0]): self.rgb_file = rgb_file self.depth_file = depth_file self.save_ply = save_ply self.rgb = cv2.imread(rgb_file) self.depth = cv2.imread(self.depth_file, -1) print("your depth image shape is:", self.depth.shape) self.width = self.rgb.shape[1] self.height = self.rgb.shape[0] self.camera_intrinsics = camera_intrinsics self.depth_scale = 1000 def compute(self): t1 = time.time() depth = np.asarray(self.depth, dtype=np.uint16).T # depth[depth==65535]=0 self.Z = depth / self.depth_scale fx, fy, cx, cy = self.camera_intrinsics X = np.zeros((self.width, self.height)) Y = np.zeros((self.width, self.height)) for i in range(self.width): X[i, :] = np.full(X.shape[1], i) self.X = ((X - cx / 2) * self.Z) / fx for i in range(self.height): Y[:, i] = np.full(Y.shape[0], i) self.Y = ((Y - cy / 2) * self.Z) / fy data_ply = np.zeros((6, self.width * self.height)) data_ply[0] = self.X.T.reshape(-1)[:self.widthself.height] data_ply[1] = -self.Y.T.reshape(-1)[:self.widthself.height] data_ply[2] = -self.Z.T.reshape(-1)[:self.widthself.height] img = np.array(self.rgb, dtype=np.uint8) data_ply[3] = img[:, :, 0:1].reshape(-1)[:self.widthself.height] data_ply[4] = img[:, :, 1:2].reshape(-1)[:self.widthself.height] data_ply[5] = img[:, :, 2:3].reshape(-1)[:self.widthself.height] self.data_ply = data_ply t2 = time.time() print('calcualte 3d point cloud Done.', t2 - t1)
时间: 2023-11-27 10:52:33 浏览: 161
在代码中有两处出现了 `self.widthself.height`,这应该是想要写成 `self.width * self.height`。你需要修改这两处,如下所示:
```
data_ply[0] = self.X.T.reshape(-1)[:self.width * self.height]
data_ply[1] = -self.Y.T.reshape(-1)[:self.width * self.height]
data_ply[2] = -self.Z.T.reshape(-1)[:self.width * self.height]
img = np.array(self.rgb, dtype=np.uint8)
data_ply[3] = img[:, :, 0:1].reshape(-1)[:self.width * self.height]
data_ply[4] = img[:, :, 1:2].reshape(-1)[:self.width * self.height]
data_ply[5] = img[:, :, 2:3].reshape(-1)[:self.width * self.height]
```
这样就可以避免出现 `AttributeError: 'point_cloud_generator' object has no attribute 'widthself'` 的错误了。
相关问题
AttributeError: 'point_cloud_generator' object has no attribute 'widthself'’
这个错误提示意思是在 `point_cloud_generator` 对象上没有 `widthself` 属性。很有可能是你的代码中写错了属性名。
你需要检查一下 `point_cloud_generator` 类中是否定义了 `widthself` 属性,或者你在使用该对象时是否正确地调用了属性名。建议你贴出相关代码,这样更易于排查问题。
AttributeError: 'async_generator' object has no attribute 'new_page'
这个错误是由于在async_generator对象上调用new_page属性时,该属性不存在所导致的。async_generator是一种异步迭代器,它提供了一种方便的方法来执行异步迭代操作。如果你在使用async_generator时遇到了这个错误,有可能是因为你的代码中没有定义new_page属性,或者该属性在定义时出现了错误。你可以仔细检查代码并尝试解决这个问题。
阅读全文
相关推荐
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![doc](https://img-home.csdnimg.cn/images/20241231044833.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)