testrender.py 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. import numpy as np
  2. import matplotlib.pyplot as plt
  3. import pybullet
  4. pybullet.connect(pybullet.GUI)
  5. pybullet.loadURDF("r2d2.urdf")
  6. camTargetPos = [0,0,0]
  7. cameraUp = [0,0,1]
  8. cameraPos = [1,1,1]
  9. yaw = 40
  10. pitch = 10.0
  11. roll=0
  12. upAxisIndex = 2
  13. camDistance = 4
  14. pixelWidth = 320
  15. pixelHeight = 240
  16. nearPlane = 0.01
  17. farPlane = 1000
  18. fov = 60
  19. #img_arr = pybullet.renderImage(pixelWidth, pixelHeight)
  20. #renderImage(w, h, view[16], projection[16])
  21. #img_arr = pybullet.renderImage(pixelWidth, pixelHeight, cameraPos, camTargetPos, cameraUp, nearPlane, farPlane)
  22. for pitch in range (0,360,10) :
  23. img_arr = pybullet.renderImage(pixelWidth, pixelHeight, camTargetPos, camDistance, yaw, pitch, roll, upAxisIndex, nearPlane, farPlane, fov)
  24. w=img_arr[0] #width of the image, in pixels
  25. h=img_arr[1] #height of the image, in pixels
  26. rgb=img_arr[2] #color data RGB
  27. dep=img_arr[3] #depth data
  28. #print 'width = %d height = %d' % (w,h)
  29. # reshape creates np array
  30. np_img_arr = np.reshape(rgb, (h, w, 4))
  31. np_img_arr = np_img_arr*(1./255.)
  32. #show
  33. plt.imshow(np_img_arr,interpolation='none')
  34. #plt.show()
  35. plt.pause(0.01)
  36. pybullet.resetSimulation()