def test_viz_show_painted_clouds(self): cloud, _, _ = cv.viz.readCloud(self.find_file("viz/dragon.ply")) viz = cv.viz_Viz3d("show_painted_clouds") viz.setBackgroundMeshLab() viz.showWidget("coosys", cv.viz_WCoordinateSystem()) pose1 = cv.viz_Affine3d((0.0, -np.pi / 2, 0.0), (-1.5, 0.0, 0.0)) pose2 = cv.viz_Affine3d((0.0, np.pi / 2, 0.0), (1.5, 0.0, 0.0)) viz.showWidget("cloud1", cv.viz_WPaintedCloud(cloud), pose1) viz.showWidget( "cloud2", cv.viz_WPaintedCloud(cloud, (0.0, -0.75, -1.0), (0.0, 0.75, 0.0)), pose2) viz.showWidget( "cloud3", cv.viz_WPaintedCloud(cloud, (0.0, 0.0, -1.0), (0.0, 0.0, 1.0), cv.viz_Color().blue(), cv.viz_Color().red())) viz.showWidget( "arrow", cv.viz_WArrow((0.0, 1.0, -1.0), (0.0, 1.0, 1.0), 0.009, cv.viz_Color())) viz.showWidget( "text2d", cv.viz_WText("Painted clouds", (20, 20), 20, cv.viz_Color(0, 255, 0))) viz.spinOnce(500, True)
def test_viz_show_cloud_collection(self): cloud, _, _ = cv.viz.readCloud(self.find_file("viz/dragon.ply")) ccol = cv.viz_WCloudCollection() pose = cv.viz_Affine3d() pose1 = cv.viz_Affine3d().translate((0, 0, 0)).rotate( (np.pi / 2, 0, 0)) ccol.addCloud( cloud, cv.viz_Color().white(), cv.viz_Affine3d().translate((0, 0, 0)).rotate((np.pi / 2, 0, 0))) ccol.addCloud(cloud, cv.viz_Color().blue(), cv.viz_Affine3d().translate((1, 0, 0))) ccol.addCloud(cloud, cv.viz_Color().red(), cv.viz_Affine3d().translate((2, 0, 0))) ccol.finalize() viz = cv.viz_Viz3d("show_cloud_collection") viz.setBackgroundColor(cv.viz_Color().mlab()) viz.showWidget("coosys", cv.viz_WCoordinateSystem()) viz.showWidget("ccol", ccol) viz.showWidget( "text2d", cv.viz_WText("Cloud collection", (20, 20), 20, cv.viz_Color(0, 255, 0))) viz.spinOnce(500, True)
def test_viz_show_simple_widgets(self): viz = cv.viz_Viz3d("show_simple_widgets") viz.setBackgroundMeshLab() viz.showWidget("coos", cv.viz_WCoordinateSystem()) viz.showWidget("cube", cv.viz_WCube()) viz.showWidget( "cub0", cv.viz_WCube((-1.0, -1, -1), (-0.5, -0.5, -0.5), False, cv.viz_Color().indigo())) viz.showWidget( "arro", cv.viz_WArrow((-0.5, -0.5, -0.5), (0.5, 0.5, 0.5), 0.009, cv.viz_Color().raspberry())) viz.showWidget("cir1", cv.viz_WCircle(0.5, 0.01, cv.viz_Color.bluberry())) viz.showWidget( "cir2", cv.viz_WCircle(0.5, (0.5, 0.0, 0.0), (1.0, 0.0, 0.0), 0.01, cv.viz_Color().apricot())) viz.showWidget( "cyl0", cv.viz_WCylinder((-0.5, 0.5, -0.5), (0.5, 0.5, -0.5), 0.125, 30, cv.viz_Color().brown())) viz.showWidget("con0", cv.viz_WCone(0.25, 0.125, 6, cv.viz_Color().azure())) viz.showWidget( "con1", cv.viz_WCone(0.125, (0.5, -0.5, 0.5), (0.5, -1.0, 0.5), 6, cv.viz_Color().turquoise())) text2d = cv.viz_WText("Different simple widgets", (20, 20), 20, cv.viz_Color().green()) viz.showWidget("text2d", text2d) text3d = cv.viz_WText3D("Simple 3D text", (0.5, 0.5, 0.5), 0.125, False, cv.viz_Color().green()) viz.showWidget("text3d", text3d) viz.showWidget("plane1", cv.viz_WPlane((0.25, 0.75))) viz.showWidget( "plane2", cv.viz_WPlane((0.5, -0.5, -0.5), (0.0, 1.0, 1.0), (1.0, 1.0, 0.0), (1.0, 0.5), cv.viz_Color().gold())) viz.showWidget( "grid1", cv.viz_WGrid((7, 7), (0.75, 0.75), cv.viz_Color().gray()), cv.viz_Affine3d().translate((0.0, 0.0, -1.0))) viz.spinOnce(500, True) text2d.setText("Different simple widgets (updated)") text3d.setText("Updated text 3D") viz.spinOnce(500, True)
def test_viz_show_mesh(self): mesh = cv.viz.readMesh(self.find_file("viz/dragon.ply")) viz = cv.viz_Viz3d("show_mesh") viz.showWidget("coosys", cv.viz_WCoordinateSystem()) viz.showWidget("mesh", cv.viz_WMesh(mesh), cv.viz_Affine3d().rotate((0, 0.8, 0))) viz.showWidget( "text2d", cv.viz_WText("Just mesh", (20, 20), 20, cv.viz_Color().green())) viz.spinOnce(500, True)
def test_viz_show_cloud_shaded_by_normals(self): mesh = cv.viz.readMesh(self.find_file("viz/dragon.ply")) mesh.normals = cv.viz.computeNormals(mesh) pose = cv.viz_Affine3d().rotate((0, 0.8, 0)) cloud = cv.viz_WCloud(mesh.cloud, cv.viz_Color().white(), mesh.normals) cloud.setRenderingProperty(cv.viz.SHADING, cv.viz.SHADING_GOURAUD) viz = cv.viz_Viz3d("show_cloud_shaded_by_normals") viz.showWidget("cloud", cloud, pose) viz.showWidget( "text2d", cv.viz_WText("Cloud shaded by normals", (20, 20), 20, cv.viz_Color().green())) viz.spinOnce(500, True)
def tutorial3(camera_pov, filename): myWindow = cv.viz_Viz3d("Coordinate Frame") myWindow.showWidget("axe", cv.viz_WCoordinateSystem()) cam_origin = (3.0, 3.0, 3.0) cam_focal_point = (3.0, 3.0, 2.0) cam_y_dir = (-1.0, 0.0, 0.0) camera_pose = cv.viz.makeCameraPose(cam_origin, cam_focal_point, cam_y_dir) transform = cv.viz.makeTransformToGlobal( (0.0, -1.0, 0.0), (-1.0, 0.0, 0.0), (0.0, 0.0, -1.0), cam_origin) dragon_cloud, _, _ = cv.viz.readCloud(filename) cloud_widget = cv.viz_WCloud(dragon_cloud, cv.viz_Color().green()) cloud_pose = cv.viz_Affine3d() cloud_pose = cv.viz_Affine3d().rotate((0, np.pi / 2, 0)).translate( (0, 0, 3)) cloud_pose_global = transform.product(cloud_pose) myWindow.showWidget("CPW_FRUSTUM", cv.viz_WCameraPosition((0.889484, 0.523599)), camera_pose) if not camera_pov: myWindow.showWidget("CPW", cv.viz_WCameraPosition(0.5), camera_pose) myWindow.showWidget("dragon", cloud_widget, cloud_pose_global) if camera_pov: myWindow.setViewerPose(camera_pose)
def test_viz_show_mesh_random_colors(self): mesh = cv.viz.readMesh(self.find_file("viz/dragon.ply")) mesh.colors = np.random.randint(0, 255, size=mesh.colors.shape, dtype=np.uint8) viz = cv.viz_Viz3d("show_mesh") viz.showWidget("coosys", cv.viz_WCoordinateSystem()) viz.showWidget("mesh", cv.viz_WMesh(mesh), cv.viz_Affine3d().rotate((0, 0.8, 0))) viz.setRenderingProperty("mesh", cv.viz.SHADING, cv.viz.SHADING_PHONG) viz.showWidget( "text2d", cv.viz_WText("Random color mesh", (20, 20), 20, cv.viz_Color().green())) viz.spinOnce(500, True)
def test_viz_show_sampled_normals(self): mesh = cv.viz.readMesh(self.find_file("viz/dragon.ply")) mesh.normals = cv.viz.computeNormals(mesh) pose = cv.viz_Affine3d().rotate((0, 0.8, 0)) viz = cv.viz_Viz3d("show_sampled_normals") viz.showWidget("mesh", cv.viz_WMesh(mesh), pose) viz.showWidget( "normals", cv.viz_WCloudNormals(mesh.cloud, mesh.normals, 30, 0.1, cv.viz_Color().green()), pose) viz.setRenderingProperty("normals", cv.viz.LINE_WIDTH, 2.0) viz.showWidget( "text2d", cv.viz_WText("Cloud or mesh normals", (20, 20), 20, cv.viz_Color().green())) viz.spinOnce(500, True)
def test_viz_show_cloud_bluberry(self): dragon_cloud, _, _ = cv.viz.readCloud(self.find_file("viz/dragon.ply")) pose = cv.viz_Affine3d() pose = pose.rotate((0, 0.8, 0)) viz = cv.viz_Viz3d("show_cloud_bluberry") viz.setBackgroundColor(cv.viz_Color().black()) viz.showWidget("coosys", cv.viz_WCoordinateSystem()) viz.showWidget("dragon", cv.viz_WCloud(dragon_cloud, cv.viz_Color().bluberry()), pose) viz.showWidget( "text2d", cv.viz_WText("Bluberry cloud", (20, 20), 20, cv.viz_Color().green())) viz.spinOnce(500, True)
def test_viz_show_image_3d(self): lena = cv.imread(self.find_file("viz/lena.png")) lena_gray = cv.cvtColor(lena, cv.COLOR_BGR2GRAY) viz = cv.viz_Viz3d("show_image_3d") viz.setBackgroundMeshLab() viz.showWidget("coos", cv.viz_WCoordinateSystem()) viz.showWidget("cube", cv.viz_WCube()) viz.showWidget( "arr0", cv.viz_WArrow((0.5, 0.0, 0.0), (1.5, 0.0, 0.0), 0.009, cv.viz_Color().raspberry())) x = cv.viz_WImage3D(lena, (1.0, 1.0)) viz.showWidget("img0", x, cv.viz_Affine3d((0.0, np.pi / 2, 0.0), (.5, 0.0, 0.0))) viz.showWidget( "arr1", cv.viz_WArrow((-0.5, -0.5, 0.0), (0.2, 0.2, 0.0), 0.009, cv.viz_Color().raspberry())) viz.showWidget( "img1", cv.viz_WImage3D(lena_gray, (1.0, 1.0), (-0.5, -0.5, 0.0), (1.0, 1.0, 0.0), (0.0, 1.0, 0.0))) viz.showWidget( "arr3", cv.viz_WArrow((-0.5, -0.5, -0.5), (0.5, 0.5, 0.5), 0.009, cv.viz_Color().raspberry())) viz.showWidget( "text2d", cv.viz_WText("Images in 3D", (20, 20), 20, cv.viz_Color().green())) i = 0 for num in range(50): img = lena * (np.sin(i * 7.5 * np.pi / 180) * 0.5 + 0.5) x.setImage(img.astype(np.uint8)) i = i + 1 viz.spinOnce(100, True) viz.showWidget( "text2d", cv.viz_WText("Images in 3D (stopped)", (20, 20), 20, cv.viz_Color().green())) viz.spinOnce(500, True)
def test_viz_show_cloud_masked(self): dragon_cloud, _, _ = cv.viz.readCloud(self.find_file("viz/dragon.ply")) qnan = np.NAN for idx in range(dragon_cloud.shape[0]): if idx % 15 != 0: dragon_cloud[idx, :] = qnan pose = cv.viz_Affine3d() pose = pose.rotate((0, 0.8, 0)) viz = cv.viz_Viz3d("show_cloud_masked") viz.showWidget("coosys", cv.viz_WCoordinateSystem()) viz.showWidget("dragon", cv.viz_WCloud(dragon_cloud), pose) viz.showWidget( "text2d", cv.viz_WText("Nan masked cloud", (20, 20), 20, cv.viz_Color().green())) viz.spinOnce(500, True)
def test_viz_show_cloud_random_color(self): dragon_cloud, _, _ = cv.viz.readCloud(self.find_file("viz/dragon.ply")) colors = np.random.randint(0, 255, size=(dragon_cloud.shape[0], dragon_cloud.shape[1], 3), dtype=np.uint8) pose = cv.viz_Affine3d() pose = pose.rotate((0, 0.8, 0)) viz = cv.viz_Viz3d("show_cloud_random_color") viz.setBackgroundMeshLab() viz.showWidget("coosys", cv.viz_WCoordinateSystem()) viz.showWidget("dragon", cv.viz_WCloud(dragon_cloud, colors), pose) viz.showWidget( "text2d", cv.viz_WText("Random color cloud", (20, 20), 20, cv.viz_Color().green())) viz.spinOnce(500, True)
axe = cv.viz_WCoordinateSystem() axis = cv.viz_WLine((-1.0,-1.0,-1.0), (1.0,1.0,1.0), cv.viz_Color().green()) axis.setRenderingProperty(cv.viz.LINE_WIDTH, 4.0); my_window.showWidget("axe",axis) plan = cv.viz_WPlane((-1.0,-1.0,-1.0), (1.0,.0,.0), (-.0,.0,-1.0)) #my_window.showWidget("plan", plan) cube = cv.viz_WCube((0.5,0.5,0.0), (0.0,0.0,-0.5), True, cv.viz_Color().blue()) my_window.showWidget("Cube Widget",cube) pi = np.arccos(-1) print("First event loop is over") my_window.spin() print("Second event loop is over") my_window.spinOnce(1, True) translation_phase = 0.0 translation = 0.0 rot_mat = np.zeros(shape=(3, 3), dtype=np.float32) rot_vec = np.zeros(shape=(1,3),dtype=np.float32) while not my_window.wasStopped(): rot_vec[0, 0] += np.pi * 0.01 rot_vec[0, 1] += np.pi * 0.01 rot_vec[0, 2] += np.pi * 0.01 translation_phase += pi * 0.01 translation = np.sin(translation_phase) pose = cv.viz_Affine3d(rot_vec, (translation, translation, translation)) my_window.setWidgetPose("Cube Widget",pose) my_window.spinOnce(1, True); print("Last event loop is over")
for idx in range(12,1889): d = ligne[idx].split(' ') pts3d[0,idx-12,:] = (float(d[0]), float(d[1]), float(d[2])) pts3d = 5 * pts3d return cv.viz_WCloud(pts3d) myWindow = cv.viz_Viz3d("Coordinate Frame") axe = cv.viz_WCoordinateSystem() myWindow.showWidget("axe",axe) cam_pos = (3.0, 3.0, 3.0) cam_focal_point = (3.0,3.0,2.0) cam_y_dir = (-1.0,0.0,0.0) cam_pose = cv.viz.makeCameraPose(cam_pos, cam_focal_point, cam_y_dir) print("OK") transform = cv.viz.makeTransformToGlobal((0.0,-1.0,0.0), (-1.0,0.0,0.0), (0.0,0.0,-1.0), cam_pos) pw_bunny = load_bunny() cloud_pose = cv.viz_Affine3d() cloud_pose = cloud_pose.translate((0, 0, 3)) cloud_pose_global = transform.product(cloud_pose) cpw = cv.viz_WCameraPosition(0.5) cpw_frustum = cv.viz_WCameraPosition(0.3) myWindow.showWidget("CPW", cpw); myWindow.showWidget("CPW_FRUSTUM", cpw_frustum) myWindow.setViewerPose(cam_pose) myWindow.showWidget("bunny", pw_bunny, cloud_pose_global) #myWindow.setWidgetPosePy("bunny") myWindow.spin(); print("Last event loop is over")