viz_sample_02.py 1.2 KB

12345678910111213141516171819202122232425262728293031323334
  1. import numpy as np
  2. import cv2 as cv
  3. my_window = cv.viz_Viz3d("Coordinate Frame")
  4. axe = cv.viz_WCoordinateSystem()
  5. axis = cv.viz_WLine((-1.0,-1.0,-1.0), (1.0,1.0,1.0), cv.viz_Color().green())
  6. axis.setRenderingProperty(cv.viz.LINE_WIDTH, 4.0);
  7. my_window.showWidget("axe",axis)
  8. plan = cv.viz_WPlane((-1.0,-1.0,-1.0), (1.0,.0,.0), (-.0,.0,-1.0))
  9. #my_window.showWidget("plan", plan)
  10. cube = cv.viz_WCube((0.5,0.5,0.0), (0.0,0.0,-0.5), True, cv.viz_Color().blue())
  11. my_window.showWidget("Cube Widget",cube)
  12. pi = np.arccos(-1)
  13. print("First event loop is over")
  14. my_window.spin()
  15. print("Second event loop is over")
  16. my_window.spinOnce(1, True)
  17. translation_phase = 0.0
  18. translation = 0.0
  19. rot_mat = np.zeros(shape=(3, 3), dtype=np.float32)
  20. rot_vec = np.zeros(shape=(1,3),dtype=np.float32)
  21. while not my_window.wasStopped():
  22. rot_vec[0, 0] += np.pi * 0.01
  23. rot_vec[0, 1] += np.pi * 0.01
  24. rot_vec[0, 2] += np.pi * 0.01
  25. translation_phase += pi * 0.01
  26. translation = np.sin(translation_phase)
  27. pose = cv.viz_Affine3d(rot_vec, (translation, translation, translation))
  28. my_window.setWidgetPose("Cube Widget",pose)
  29. my_window.spinOnce(1, True);
  30. print("Last event loop is over")