testrender_np.py 1.2 KB

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