1
0
mirror of https://github.com/opencv/opencv_contrib.git synced 2025-10-21 06:11:09 +08:00
Files
opencv_contrib/modules/viz/samples/viz_sample_02.py
LaurentBerger 5e0ff400fc Merge pull request #2882 from LaurentBerger:python_viz
* python binding for viz

tutorial widget pose

reset

test_tutorial 2 & 3

sample py

9 test sur 22

test PyWCloudNormal

16 sur 22

end?

python test

* oops

* bug

* comment but( this is not solved https://github.com/opencv/opencv_contrib/pull/2882#discussion_r591659839

* review 2

* oversight

* oversight oops

* viz: move out Py* classes from public C++ headers

* viz: recover PyColor

Co-authored-by: Alexander Alekhin <alexander.a.alekhin@gmail.com>
2021-04-02 10:21:37 +00:00

34 lines
1.2 KiB
Python

import numpy as np
import cv2 as cv
my_window = cv.viz_Viz3d("Coordinate Frame")
axe = cv.viz_PyWCoordinateSystem()
axis = cv.viz_PyWLine((-1.0,-1.0,-1.0), (1.0,1.0,1.0), cv.viz_PyColor().green())
axis.setRenderingProperty(cv.viz.LINE_WIDTH, 4.0);
my_window.showWidget("axe",axis)
plan = cv.viz_PyWPlane((-1.0,-1.0,-1.0), (1.0,.0,.0), (-.0,.0,-1.0))
#my_window.showWidget("plan", plan)
cube = cv.viz_PyWCube((0.5,0.5,0.0), (0.0,0.0,-0.5), True, cv.viz_PyColor().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_PyAffine3(rot_vec, (translation, translation, translation))
my_window.setWidgetPosePy("Cube Widget", pose)
my_window.spinOnce(1, True)
print("Last event loop is over")