viz_sample_03.py 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. import numpy as np
  2. import cv2 as cv
  3. def load_bunny():
  4. with open(cv.samples.findFile("../viz/data/bunny.ply"), 'r') as f:
  5. s = f.read()
  6. ligne = s.split('\n')
  7. if len(ligne) == 5753:
  8. pts3d = np.zeros(shape=(1,1889,3), dtype=np.float32)
  9. pts3d_c = 255 * np.ones(shape=(1,1889,3), dtype=np.uint8)
  10. pts3d_n = np.ones(shape=(1,1889,3), dtype=np.float32)
  11. for idx in range(12,1889):
  12. d = ligne[idx].split(' ')
  13. pts3d[0,idx-12,:] = (float(d[0]), float(d[1]), float(d[2]))
  14. pts3d = 5 * pts3d
  15. return cv.viz_WCloud(pts3d)
  16. myWindow = cv.viz_Viz3d("Coordinate Frame")
  17. axe = cv.viz_WCoordinateSystem()
  18. myWindow.showWidget("axe",axe)
  19. cam_pos = (3.0, 3.0, 3.0)
  20. cam_focal_point = (3.0,3.0,2.0)
  21. cam_y_dir = (-1.0,0.0,0.0)
  22. cam_pose = cv.viz.makeCameraPose(cam_pos, cam_focal_point, cam_y_dir)
  23. print("OK")
  24. transform = cv.viz.makeTransformToGlobal((0.0,-1.0,0.0), (-1.0,0.0,0.0), (0.0,0.0,-1.0), cam_pos)
  25. pw_bunny = load_bunny()
  26. cloud_pose = cv.viz_Affine3d()
  27. cloud_pose = cloud_pose.translate((0, 0, 3))
  28. cloud_pose_global = transform.product(cloud_pose)
  29. cpw = cv.viz_WCameraPosition(0.5)
  30. cpw_frustum = cv.viz_WCameraPosition(0.3)
  31. myWindow.showWidget("CPW", cpw);
  32. myWindow.showWidget("CPW_FRUSTUM", cpw_frustum)
  33. myWindow.setViewerPose(cam_pose)
  34. myWindow.showWidget("bunny", pw_bunny, cloud_pose_global)
  35. #myWindow.setWidgetPosePy("bunny")
  36. myWindow.spin();
  37. print("Last event loop is over")