ovis_demo.py 1.2 KB

1234567891011121314151617181920212223242526272829303132333435
  1. import numpy as np
  2. import cv2 as cv
  3. # add some external resources
  4. cv.ovis.addResourceLocation("packs/Sinbad.zip")
  5. # camera intrinsics
  6. imsize = (800, 600)
  7. K = np.diag([800, 800, 1])
  8. K[:2, 2] = (400, 500) # offset pp
  9. # observer scene
  10. owin = cv.ovis.createWindow("VR", imsize)
  11. cv.ovis.createGridMesh("ground", (10, 10), (10, 10))
  12. owin.createEntity("ground", "ground", rot=(1.57, 0, 0))
  13. owin.createCameraEntity("cam", K, imsize, 5)
  14. owin.createEntity("sinbad", "Sinbad.mesh", tvec=(0, -5, 0), rot=(np.pi, 0, 0)) # externally defined mesh
  15. owin.createLightEntity("sun", (0, 0, -100))
  16. # setup and play idle animation
  17. owin.setEntityProperty("sinbad", cv.ovis.ENTITY_ANIMBLEND_MODE, 1) # 1 = cumulative
  18. owin.playEntityAnimation("sinbad", "IdleBase")
  19. owin.playEntityAnimation("sinbad", "IdleTop")
  20. # interaction scene
  21. iwin = cv.ovis.createWindow("AR", imsize, cv.ovis.SCENE_SEPARATE | cv.ovis.SCENE_INTERACTIVE)
  22. iwin.createEntity("sinbad", "Sinbad.mesh", tvec=(0, -5, 0), rot=(np.pi, 0, 0))
  23. iwin.createLightEntity("sun", (0, 0, -100))
  24. iwin.setCameraIntrinsics(K, imsize)
  25. while cv.ovis.waitKey(1) != 27:
  26. R, t = iwin.getCameraPose()
  27. owin.setEntityPose("cam", t, R)
  28. del iwin # must be destroyed in reverse creation order