hhcaz / CNS

CNS: Correspondence encoded Neural image Servo policy
MIT License
13 stars 1 forks source link

“TypeError ” when I run demo_sim_Erender.py #2

Open x18-1 opened 2 months ago

x18-1 commented 2 months ago

When i run demo_sim_Erender.py,I got the wrong:

Traceback (most recent call last):
  File "d:\code\CV\CNS\demo_sim_Erender.py", line 79, in <module>
    run_demo()
  File "d:\code\CV\CNS\demo_sim_Erender.py", line 40, in run_demo
    tar_img = env.init(i)  # uint8, bgr image
  File "d:\code\CV\CNS\cns\benchmark\environment.py", line 110, in init
    frame = self.camera.render(target_cwT, self.client)
  File "d:\code\CV\CNS\cns\utils\perception.py", line 112, in render
    rgb, z_buffer = np.ascontiguousarray(result[2][:, :, :3]), result[3]
TypeError: tuple indices must be integers or slices, not tuple

I have print the result[2],it's a tuple。 I dont’t konw how to solve it.

x18-1 commented 2 months ago

I change the code to:

        result = p.getCameraImage(
            width=self.intrinsic.width,
            height=self.intrinsic.height,
            viewMatrix=gl_view_matrix,
            projectionMatrix=self.gl_proj_matrix,
            renderer=p.ER_BULLET_HARDWARE_OPENGL,
            physicsClientId=client
        )

        rgb = np.reshape(result[2], [self.intrinsic.height, self.intrinsic.width, 4])[:,:,:3]
        rgb = rgb.astype(np.uint8)
        # print(rgb[0])
        z_buffer = np.reshape(result[3], [self.intrinsic.height, self.intrinsic.width])
        z_buffer = z_buffer.astype(np.uint8)
        # rgb, z_buffer = np.ascontiguousarray(result[2][:, :, :3]), result[3]

        depth = (
            1.0 * self.far * self.near / (self.far - (self.far - self.near) * z_buffer)
        )

        depth = depth.astype(np.float32)

it worked

hhcaz commented 2 months ago

Hi, thanks for your feedback. In this repo we use pybullet==3.2.6 with numpy enabled, and the function getCameraImage returns numpy arrays. Maybe your installed pybullet is not numpy enabled? You could check this via running:

python -c "import pybullet; print('NumPy enabled:', pybullet.isNumpyEnabled())"

Anyway, we have modified the code in cns/utils/perception.py to cope with this condition.