python_viz.hpp 44 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350
  1. #ifndef OPENCV_PYTHON_VIZ_HPP
  2. #define OPENCV_PYTHON_VIZ_HPP
  3. #include "opencv2/viz.hpp"
  4. namespace cv { namespace viz {
  5. struct CV_EXPORTS_W_SIMPLE CV_WRAP_AS(Color) PyColor
  6. {
  7. CV_WRAP PyColor() {}
  8. CV_WRAP PyColor(double gray) : c(gray) {}
  9. CV_WRAP PyColor(double blue, double green, double red) : c(blue, green, red) {}
  10. PyColor(const Color& v) : c(v) { }
  11. operator Color() const { return c; }
  12. CV_WRAP static PyColor black() { return PyColor(Color::black()); }
  13. CV_WRAP static PyColor white() { return PyColor(Color::white()); }
  14. CV_WRAP static PyColor blue() { return PyColor(Color::blue()); }
  15. CV_WRAP static PyColor green() { return PyColor(Color::green()); }
  16. CV_WRAP static PyColor red() { return PyColor(Color::red()); }
  17. CV_WRAP static PyColor cyan() { return PyColor(Color::cyan()); }
  18. CV_WRAP static PyColor yellow() { return PyColor(Color::yellow()); }
  19. CV_WRAP static PyColor magenta() { return PyColor(Color::magenta()); }
  20. CV_WRAP static PyColor gray() { return PyColor(Color::gray()); }
  21. CV_WRAP static PyColor silver() { return PyColor(Color::silver()); }
  22. CV_WRAP static PyColor mlab() { return PyColor(Color::mlab()); }
  23. CV_WRAP static PyColor navy() { return PyColor(Color::navy()); }
  24. CV_WRAP static PyColor maroon() { return PyColor(Color::maroon()); }
  25. CV_WRAP static PyColor teal() { return PyColor(Color::teal()); }
  26. CV_WRAP static PyColor olive() { return PyColor(Color::olive()); }
  27. CV_WRAP static PyColor purple() { return PyColor(Color::olive()); }
  28. CV_WRAP static PyColor azure() { return PyColor(Color::olive()); }
  29. CV_WRAP static PyColor chartreuse() { return PyColor(Color::olive()); }
  30. CV_WRAP static PyColor rose() { return PyColor(Color::olive()); }
  31. CV_WRAP static PyColor lime() { return PyColor(Color::olive()); }
  32. CV_WRAP static PyColor gold() { return PyColor(Color::olive()); }
  33. CV_WRAP static PyColor orange() { return PyColor(Color::olive()); }
  34. CV_WRAP static PyColor orange_red() { return PyColor(Color::olive()); }
  35. CV_WRAP static PyColor indigo() { return PyColor(Color::olive()); }
  36. CV_WRAP static PyColor brown() { return PyColor(Color::olive()); }
  37. CV_WRAP static PyColor apricot() { return PyColor(Color::olive()); }
  38. CV_WRAP static PyColor pink() { return PyColor(Color::olive()); }
  39. CV_WRAP static PyColor raspberry() { return PyColor(Color::olive()); }
  40. CV_WRAP static PyColor cherry() { return PyColor(Color::olive()); }
  41. CV_WRAP static PyColor violet() { return PyColor(Color::olive()); }
  42. CV_WRAP static PyColor amethyst() { return PyColor(Color::amethyst()); }
  43. CV_WRAP static PyColor bluberry() { return PyColor(Color::bluberry()); }
  44. CV_WRAP static PyColor celestial_blue() { return PyColor(Color::celestial_blue()); }
  45. CV_WRAP static PyColor turquoise() { return PyColor(Color::turquoise()); }
  46. static PyColor not_set() { return PyColor(Color::not_set()); }
  47. CV_WRAP double get_blue() { return c[0]; }
  48. CV_WRAP double get_green() { return c[1]; }
  49. CV_WRAP double get_red() { return c[2]; }
  50. Color c;
  51. };
  52. struct CV_EXPORTS_W_SIMPLE CV_WRAP_AS(Affine3d) PyAffine3d
  53. #ifndef OPENCV_BINDING_PARSER
  54. : public Affine3d
  55. #endif
  56. {
  57. CV_WRAP PyAffine3d()
  58. {
  59. // nothing
  60. }
  61. inline PyAffine3d(const Affine3d& base) : Affine3d(base)
  62. {
  63. // nothing
  64. }
  65. CV_WRAP PyAffine3d(const Vec3d &rvec, const Vec3d &t = Vec3d::all(0))
  66. : Affine3d(rvec, t)
  67. {
  68. // nothing
  69. }
  70. CV_WRAP PyAffine3d(const Mat &rot, const Vec3f &t = Vec3d::all(0))
  71. : Affine3d(rot, t)
  72. {
  73. // nothing
  74. }
  75. CV_WRAP PyAffine3d translate(const Vec3d &t)
  76. {
  77. return Affine3d::translate(t);
  78. }
  79. CV_WRAP PyAffine3d rotate(const Vec3d &t)
  80. {
  81. return Affine3d::rotate(t);
  82. }
  83. CV_WRAP PyAffine3d product(const PyAffine3d &t)
  84. {
  85. return ((const Affine3d&)(*this)) * (const Affine3d&)t;
  86. }
  87. CV_WRAP static PyAffine3d Identity()
  88. {
  89. return Affine3d::Identity();
  90. }
  91. CV_WRAP PyAffine3d inv()
  92. {
  93. return Affine3d::inv();
  94. }
  95. CV_WRAP Mat mat()
  96. {
  97. return Mat(matrix);
  98. }
  99. };
  100. struct CV_EXPORTS_W_SIMPLE CV_WRAP_AS(WLine) PyWLine
  101. {
  102. CV_WRAP PyWLine()
  103. {
  104. }
  105. /** @brief Constructs a WLine.
  106. @param pt1 Start point of the line.
  107. @param pt2 End point of the line.
  108. @param color Color of the line.
  109. */
  110. CV_WRAP PyWLine(const Point3d &pt1, const Point3d &pt2, const PyColor& color)
  111. {
  112. widget = cv::makePtr<cv::viz::WLine>(pt1, pt2, color);
  113. }
  114. CV_WRAP void setRenderingProperty(int property, double value)
  115. {
  116. CV_Assert(widget);
  117. widget->setRenderingProperty(property, value);
  118. }
  119. Ptr<cv::viz::WLine> widget;
  120. };
  121. struct CV_EXPORTS_W_SIMPLE CV_WRAP_AS(WPlane) PyWPlane
  122. {
  123. public:
  124. /** @brief Constructs a default plane with center point at origin and normal oriented along z-axis.
  125. @param size Size of the plane
  126. @param color Color of the plane.
  127. */
  128. CV_WRAP PyWPlane(const Point2d& size = Point2d(1.0, 1.0), const PyColor& color = Color(255, 255,255))
  129. {
  130. widget = cv::makePtr<cv::viz::WPlane>(size, color);
  131. }
  132. /** @brief Constructs a repositioned plane
  133. @param center Center of the plane
  134. @param normal Plane normal orientation
  135. @param new_yaxis Up-vector. New orientation of plane y-axis.
  136. @param size
  137. @param color Color of the plane.
  138. */
  139. CV_WRAP PyWPlane(const Point3d& center, const Vec3d& normal, const Vec3d& new_yaxis,
  140. const Point2d& size = Point2d(1.0, 1.0), const PyColor& color = Color(255, 255, 255))
  141. {
  142. widget = cv::makePtr<cv::viz::WPlane>(center, normal, new_yaxis, size, color);
  143. }
  144. CV_WRAP void setRenderingProperty(int property, double value)
  145. {
  146. CV_Assert(widget);
  147. widget->setRenderingProperty(property, value);
  148. }
  149. Ptr<cv::viz::WPlane> widget;
  150. };
  151. /** @brief This 3D Widget defines a sphere. :
  152. */
  153. struct CV_EXPORTS_W_SIMPLE CV_WRAP_AS(WSphere) PyWSphere
  154. {
  155. public:
  156. CV_WRAP PyWSphere()
  157. {
  158. }
  159. /** @brief Constructs a WSphere.
  160. @param center Center of the sphere.
  161. @param radius Radius of the sphere.
  162. @param sphere_resolution Resolution of the sphere.
  163. @param color Color of the sphere.
  164. */
  165. CV_WRAP PyWSphere(const cv::Point3d &center, double radius, int sphere_resolution = 10, const PyColor& color = Color(255, 255,255))
  166. {
  167. widget = cv::makePtr<cv::viz::WSphere>(center, radius, sphere_resolution, color);
  168. }
  169. CV_WRAP void setRenderingProperty(int property, double value)
  170. {
  171. CV_Assert(widget);
  172. widget->setRenderingProperty(property, value);
  173. }
  174. Ptr<cv::viz::WSphere> widget;
  175. };
  176. /** @brief This 3D Widget defines an arrow.
  177. */
  178. struct CV_EXPORTS_W_SIMPLE CV_WRAP_AS(WArrow) PyWArrow
  179. {
  180. public:
  181. CV_WRAP PyWArrow()
  182. {
  183. }
  184. /** @brief Constructs an WArrow.
  185. @param pt1 Start point of the arrow.
  186. @param pt2 End point of the arrow.
  187. @param thickness Thickness of the arrow. Thickness of arrow head is also adjusted
  188. accordingly.
  189. @param color Color of the arrow.
  190. Arrow head is located at the end point of the arrow.
  191. */
  192. CV_WRAP PyWArrow(const Point3d& pt1, const Point3d& pt2, double thickness = 0.03, const PyColor& color = Color(255, 255, 255))
  193. {
  194. widget = cv::makePtr<cv::viz::WArrow>(pt1, pt2, thickness, color);
  195. }
  196. CV_WRAP void setRenderingProperty(int property, double value)
  197. {
  198. CV_Assert(widget);
  199. widget->setRenderingProperty(property, value);
  200. }
  201. Ptr<cv::viz::WArrow> widget;
  202. };
  203. /** @brief This 3D Widget defines a cube.
  204. */
  205. struct CV_EXPORTS_W_SIMPLE CV_WRAP_AS(WCube) PyWCube
  206. {
  207. public:
  208. /** @brief Constructs a WCube.
  209. @param min_point Specifies minimum (or maximum) point of the bounding box.
  210. @param max_point Specifies maximum (or minimum) point of the bounding box, opposite to the first parameter.
  211. @param wire_frame If true, cube is represented as wireframe.
  212. @param color Color of the cube.
  213. ![Cube Widget](images/cube_widget.png)
  214. */
  215. CV_WRAP PyWCube(const Point3d& min_point = Vec3d::all(-0.5), const Point3d& max_point = Vec3d::all(0.5),
  216. bool wire_frame = true, const PyColor& color = Color(255, 255, 255))
  217. {
  218. widget = cv::makePtr<cv::viz::WCube>(min_point, max_point, wire_frame, color);
  219. }
  220. CV_WRAP void setRenderingProperty(int property, double value)
  221. {
  222. CV_Assert(widget);
  223. widget->setRenderingProperty(property, value);
  224. }
  225. Ptr<cv::viz::WCube> widget;
  226. };
  227. /** @brief This 3D Widget defines a PyWCircle.
  228. */
  229. struct CV_EXPORTS_W_SIMPLE CV_WRAP_AS(WCircle) PyWCircle
  230. {
  231. public:
  232. PyWCircle() {}
  233. /** @brief Constructs default planar circle centered at origin with plane normal along z-axis
  234. @param radius Radius of the circle.
  235. @param thickness Thickness of the circle.
  236. @param color Color of the circle.
  237. */
  238. CV_WRAP PyWCircle(double radius, double thickness = 0.01, const PyColor& color = Color::white())
  239. {
  240. widget = cv::makePtr<WCircle>(radius, thickness, color);
  241. }
  242. /** @brief Constructs repositioned planar circle.
  243. @param radius Radius of the circle.
  244. @param center Center of the circle.
  245. @param normal Normal of the plane in which the circle lies.
  246. @param thickness Thickness of the circle.
  247. @param color Color of the circle.
  248. */
  249. CV_WRAP PyWCircle(double radius, const Point3d& center, const Vec3d& normal, double thickness = 0.01, const PyColor& color = Color::white())
  250. {
  251. widget = cv::makePtr<WCircle>(radius, center, normal, thickness, color);
  252. }
  253. CV_WRAP void setRenderingProperty(int property, double value)
  254. {
  255. CV_Assert(widget);
  256. widget->setRenderingProperty(property, value);
  257. }
  258. Ptr<cv::viz::WCircle> widget;
  259. };
  260. /** @brief This 3D Widget defines a cone. :
  261. */
  262. struct CV_EXPORTS_W_SIMPLE CV_WRAP_AS(WCone) PyWCone
  263. {
  264. public:
  265. PyWCone() {}
  266. /** @brief Constructs default cone oriented along x-axis with center of its base located at origin
  267. @param length Length of the cone.
  268. @param radius Radius of the cone.
  269. @param resolution Resolution of the cone.
  270. @param color Color of the cone.
  271. */
  272. CV_WRAP PyWCone(double length, double radius, int resolution = 6, const PyColor& color = Color::white())
  273. {
  274. widget = cv::makePtr<WCone>(length, radius, resolution, color);
  275. }
  276. /** @brief Constructs repositioned planar cone.
  277. @param radius Radius of the cone.
  278. @param center Center of the cone base.
  279. @param tip Tip of the cone.
  280. @param resolution Resolution of the cone.
  281. @param color Color of the cone.
  282. */
  283. CV_WRAP PyWCone(double radius, const Point3d& center, const Point3d& tip, int resolution = 6, const PyColor& color = Color::white())
  284. {
  285. widget = cv::makePtr<WCone>(radius, center, tip, resolution, color);
  286. }
  287. CV_WRAP void setRenderingProperty(int property, double value)
  288. {
  289. CV_Assert(widget);
  290. widget->setRenderingProperty(property, value);
  291. }
  292. Ptr<cv::viz::WCone> widget;
  293. };
  294. /** @brief This 3D Widget defines a PyWCylinder. :
  295. */
  296. struct CV_EXPORTS_W_SIMPLE CV_WRAP_AS(WCylinder) PyWCylinder
  297. {
  298. public:
  299. CV_WRAP PyWCylinder() {}
  300. /** @brief Constructs a WCylinder.
  301. @param axis_point1 A point1 on the axis of the cylinder.
  302. @param axis_point2 A point2 on the axis of the cylinder.
  303. @param radius Radius of the cylinder.
  304. @param numsides Resolution of the cylinder.
  305. @param color Color of the cylinder.
  306. */
  307. CV_WRAP PyWCylinder(const Point3d& axis_point1, const Point3d& axis_point2, double radius, int numsides = 30, const PyColor& color = Color::white())
  308. {
  309. widget = cv::makePtr<WCylinder>(axis_point1, axis_point2, radius, numsides, color);
  310. }
  311. Ptr<cv::viz::WCylinder> widget;
  312. };
  313. /** @brief This 3D Widget represents camera position in a scene by its axes or viewing frustum. :
  314. */
  315. struct CV_EXPORTS_W_SIMPLE CV_WRAP_AS(WCameraPosition) PyWCameraPosition
  316. {
  317. public:
  318. /** @brief Creates camera coordinate frame at the origin.
  319. ![Camera coordinate frame](images/cpw1.png)
  320. */
  321. CV_WRAP PyWCameraPosition(double scale = 1.0)
  322. {
  323. widget = cv::makePtr<cv::viz::WCameraPosition>(scale);
  324. }
  325. /** @brief Display the viewing frustum
  326. @param K Intrinsic matrix of the camera or fov Field of view of the camera (horizontal, vertical).
  327. @param scale Scale of the frustum.
  328. @param color Color of the frustum.
  329. Creates viewing frustum of the camera based on its intrinsic matrix K.
  330. ![Camera viewing frustum](images/cpw2.png)
  331. */
  332. CV_WRAP PyWCameraPosition(InputArray K, double scale = 1.0, const PyColor& color = Color(255, 255, 255))
  333. {
  334. if (K.kind() == _InputArray::MAT)
  335. {
  336. Mat k = K.getMat();
  337. if (k.rows == 3 && k.cols == 3)
  338. {
  339. Matx33d x = k;
  340. widget = cv::makePtr<cv::viz::WCameraPosition>(x, scale, color);
  341. }
  342. else if (k.total() == 2)
  343. widget = cv::makePtr<cv::viz::WCameraPosition>(Vec2d(k.at<double>(0), k.at<double>(1)), scale, color);
  344. else
  345. CV_Error(cv::Error::StsVecLengthErr, "unknown size");
  346. }
  347. else
  348. CV_Error(cv::Error::StsUnsupportedFormat, "unknown type");
  349. }
  350. /** @brief Display image on the far plane of the viewing frustum
  351. @param K Intrinsic matrix of the camera.
  352. @param image BGR or Gray-Scale image that is going to be displayed on the far plane of the frustum.
  353. @param scale Scale of the frustum and image.
  354. @param color Color of the frustum.
  355. Creates viewing frustum of the camera based on its intrinsic matrix K, and displays image on
  356. the far end plane.
  357. ![Camera viewing frustum with image](images/cpw3.png)
  358. */
  359. CV_WRAP PyWCameraPosition(InputArray K, InputArray image, double scale = 1.0, const PyColor& color = Color(255, 255, 255))
  360. {
  361. if (K.kind() == _InputArray::MAT)
  362. {
  363. Mat k = K.getMat();
  364. if (k.rows == 3 && k.cols == 3)
  365. {
  366. Matx33d x = k;
  367. widget = cv::makePtr<cv::viz::WCameraPosition>(x, image, scale, color);
  368. }
  369. else if (k.total() == 2)
  370. widget = cv::makePtr<cv::viz::WCameraPosition>(Vec2d(k.at<double>(0), k.at<double>(1)), image, scale, color);
  371. else
  372. CV_Error(cv::Error::StsVecLengthErr, "unknown size");
  373. }
  374. else
  375. CV_Error(cv::Error::StsUnsupportedFormat, "unknown type");
  376. }
  377. /** @brief Display image on the far plane of the viewing frustum
  378. @param fov Field of view of the camera (horizontal, vertical).
  379. @param image BGR or Gray-Scale image that is going to be displayed on the far plane of the frustum.
  380. @param scale Scale of the frustum and image.
  381. @param color Color of the frustum.
  382. Creates viewing frustum of the camera based on its intrinsic matrix K, and displays image on
  383. the far end plane.
  384. ![Camera viewing frustum with image](images/cpw3.png)
  385. */
  386. CV_WRAP PyWCameraPosition(const Point2d &fov, InputArray image, double scale = 1.0, const PyColor& color = Color(255, 255, 255))
  387. {
  388. widget = cv::makePtr<cv::viz::WCameraPosition>(fov, image, scale, color);
  389. }
  390. Ptr<cv::viz::WCameraPosition> widget;
  391. };
  392. /////////////////////////////////////////////////////////////////////////////
  393. /// Compound widgets
  394. /** @brief This 3D Widget represents a coordinate system. :
  395. */
  396. struct CV_EXPORTS_W_SIMPLE CV_WRAP_AS(WCoordinateSystem) PyWCoordinateSystem
  397. {
  398. public:
  399. /** @brief Constructs a WCoordinateSystem.
  400. @param scale Determines the size of the axes.
  401. */
  402. CV_WRAP PyWCoordinateSystem(double scale = 1.0)
  403. {
  404. widget = cv::makePtr<cv::viz::WCoordinateSystem>(scale);
  405. }
  406. Ptr<cv::viz::WCoordinateSystem> widget;
  407. };
  408. /////////////////////////////////////////////////////////////////////////////
  409. /// Clouds
  410. /** @brief This 3D Widget defines a point cloud. :
  411. @note In case there are four channels in the cloud, fourth channel is ignored.
  412. */
  413. struct CV_EXPORTS_W_SIMPLE CV_WRAP_AS(WCloud) PyWCloud
  414. {
  415. public:
  416. CV_WRAP PyWCloud()
  417. {
  418. // nothing
  419. }
  420. /** @brief Constructs a WCloud.
  421. @param cloud Set of points which can be of type: CV_32FC3, CV_32FC4, CV_64FC3, CV_64FC4.
  422. @param color A single Color for the whole cloud.
  423. Points in the cloud belong to mask when they are set to (NaN, NaN, NaN).
  424. */
  425. CV_WRAP PyWCloud(InputArray cloud, const PyColor& color = Color::white())
  426. {
  427. widget = cv::makePtr<cv::viz::WCloud>(cloud, color);
  428. }
  429. CV_WRAP PyWCloud(InputArray cloud, InputArray colors)
  430. {
  431. widget = cv::makePtr<cv::viz::WCloud>(cloud, colors);
  432. }
  433. CV_WRAP PyWCloud(InputArray cloud, InputArray colors, InputArray normals)
  434. {
  435. widget = cv::makePtr<cv::viz::WCloud>(cloud, colors, normals);
  436. }
  437. /** @brief Constructs a WCloud.
  438. @param cloud Set of points which can be of type: CV_32FC3, CV_32FC4, CV_64FC3, CV_64FC4.
  439. @param color A single Color for the whole cloud.
  440. @param normals Normals for each point in cloud.
  441. Size and type should match with the cloud parameter.
  442. Points in the cloud belong to mask when they are set to (NaN, NaN, NaN).
  443. */
  444. CV_WRAP PyWCloud(InputArray cloud, const PyColor& color, InputArray normals)
  445. {
  446. widget = cv::makePtr<cv::viz::WCloud>(cloud, color, normals);
  447. }
  448. CV_WRAP void setRenderingProperty(int property, double value)
  449. {
  450. CV_Assert(widget);
  451. widget->setRenderingProperty(property, value);
  452. }
  453. Ptr<cv::viz::WCloud> widget;
  454. };
  455. /** @brief This 3D Widget defines a poly line. :
  456. */
  457. struct CV_EXPORTS_W_SIMPLE CV_WRAP_AS(WPolyLine) PyWPolyLine
  458. {
  459. public:
  460. CV_WRAP PyWPolyLine()
  461. {
  462. }
  463. CV_WRAP PyWPolyLine(InputArray points, InputArray colors)
  464. {
  465. widget = cv::makePtr<cv::viz::WPolyLine>(points, colors);
  466. }
  467. /** @brief Constructs a WPolyLine.
  468. @param points Point set.
  469. @param color Color of the poly line.
  470. */
  471. CV_WRAP PyWPolyLine(InputArray points, const PyColor& color = Color::white())
  472. {
  473. widget = cv::makePtr<cv::viz::WPolyLine>(points, color);
  474. }
  475. CV_WRAP void setRenderingProperty(int property, double value)
  476. {
  477. CV_Assert(widget);
  478. widget->setRenderingProperty(property, value);
  479. }
  480. Ptr<cv::viz::WPolyLine> widget;
  481. };
  482. /////////////////////////////////////////////////////////////////////////////
  483. /// Text and image widgets
  484. /** @brief This 2D Widget represents text overlay.
  485. */
  486. struct CV_EXPORTS_W_SIMPLE CV_WRAP_AS(WText) PyWText
  487. {
  488. public:
  489. CV_WRAP PyWText()
  490. {
  491. }
  492. /** @brief Constructs a WText.
  493. @param text Text content of the widget.
  494. @param pos Position of the text.
  495. @param font_size Font size.
  496. @param color Color of the text.
  497. */
  498. CV_WRAP PyWText(const String &text, const Point &pos, int font_size = 20, const PyColor& color = Color::white())
  499. {
  500. widget = cv::makePtr<cv::viz::WText>(text, pos, font_size, color);
  501. }
  502. /** @brief Sets the text content of the widget.
  503. @param text Text content of the widget.
  504. */
  505. CV_WRAP void setText(const String &text)
  506. {
  507. widget->setText(text);
  508. }
  509. /** @brief Returns the current text content of the widget.
  510. */
  511. CV_WRAP String getText() const
  512. {
  513. return widget->getText();
  514. }
  515. Ptr<cv::viz::WText> widget;
  516. };
  517. /** @brief This 3D Widget represents 3D text. The text always faces the camera.
  518. */
  519. struct CV_EXPORTS_W_SIMPLE CV_WRAP_AS(WText3D) PyWText3D
  520. {
  521. public:
  522. CV_WRAP PyWText3D()
  523. {}
  524. /** @brief Constructs a WText3D.
  525. @param text Text content of the widget.
  526. @param position Position of the text.
  527. @param text_scale Size of the text.
  528. @param face_camera If true, text always faces the camera.
  529. @param color Color of the text.
  530. */
  531. CV_WRAP PyWText3D(const String &text, const Point3d &position, double text_scale = 1., bool face_camera = true, const PyColor& color = Color::white())
  532. {
  533. widget = cv::makePtr<WText3D>(text, position, text_scale, face_camera, color);
  534. }
  535. /** @brief Sets the text content of the widget.
  536. @param text Text content of the widget.
  537. */
  538. CV_WRAP void setText(const String &text)
  539. {
  540. widget->setText(text);
  541. }
  542. /** @brief Returns the current text content of the widget.
  543. */
  544. CV_WRAP String getText() const
  545. {
  546. return widget->getText();
  547. }
  548. Ptr<cv::viz::WText3D> widget;
  549. };
  550. /** @brief This 2D Widget represents an image overlay. :
  551. */
  552. struct CV_EXPORTS_W_SIMPLE CV_WRAP_AS(WImageOverlay) PyWImageOverlay
  553. {
  554. public:
  555. CV_WRAP PyWImageOverlay()
  556. {
  557. }
  558. /** @brief Constructs an WImageOverlay.
  559. @param image BGR or Gray-Scale image.
  560. @param rect Image is scaled and positioned based on rect.
  561. */
  562. CV_WRAP PyWImageOverlay(InputArray image, const Rect &rect)
  563. {
  564. widget = cv::makePtr<WImageOverlay>(image, rect);
  565. }
  566. /** @brief Sets the image content of the widget.
  567. @param image BGR or Gray-Scale image.
  568. */
  569. CV_WRAP void setImage(InputArray image)
  570. {
  571. widget->setImage(image);
  572. }
  573. CV_WRAP void setRenderingProperty(int property, double value)
  574. {
  575. CV_Assert(widget);
  576. widget->setRenderingProperty(property, value);
  577. }
  578. Ptr<cv::viz::WImageOverlay> widget;
  579. };
  580. /** @brief This 3D Widget represents an image in 3D space. :
  581. */
  582. struct CV_EXPORTS_W_SIMPLE CV_WRAP_AS(WImage3D) PyWImage3D
  583. {
  584. CV_WRAP PyWImage3D()
  585. {
  586. }
  587. public:
  588. /** @brief Constructs an WImage3D.
  589. @param image BGR or Gray-Scale image.
  590. @param size Size of the image.
  591. */
  592. CV_WRAP PyWImage3D(InputArray image, const Point2d &size)
  593. {
  594. widget = cv::makePtr<WImage3D>(image, size);
  595. }
  596. /** @brief Constructs an WImage3D.
  597. @param image BGR or Gray-Scale image.
  598. @param size Size of the image.
  599. @param center Position of the image.
  600. @param normal Normal of the plane that represents the image.
  601. @param up_vector Determines orientation of the image.
  602. */
  603. CV_WRAP PyWImage3D(InputArray image, const Point2d &size, const Vec3d &center, const Vec3d &normal, const Vec3d &up_vector)
  604. {
  605. widget = cv::makePtr<WImage3D>(image, size, center, normal, up_vector);
  606. }
  607. /** @brief Sets the image content of the widget.
  608. @param image BGR or Gray-Scale image.
  609. */
  610. CV_WRAP void setImage(InputArray image)
  611. {
  612. widget->setImage(image);
  613. }
  614. /** @brief Sets the image size of the widget.
  615. @param size the new size of the image.
  616. */
  617. CV_WRAP void setSize(const Size& size)
  618. {
  619. widget->setSize(size);
  620. }
  621. Ptr<cv::viz::WImage3D> widget;
  622. };
  623. /** @brief This 3D Widget defines a grid. :
  624. */
  625. struct CV_EXPORTS_W_SIMPLE CV_WRAP_AS(WGrid) PyWGrid
  626. {
  627. public:
  628. PyWGrid() {}
  629. /** @brief Constructs a WGrid.
  630. @param cells Number of cell columns and rows, respectively.
  631. @param cells_spacing Size of each cell, respectively.
  632. @param color Color of the grid.
  633. */
  634. CV_WRAP PyWGrid(InputArray cells, InputArray cells_spacing, const PyColor& color = Color::white());
  635. //! Creates repositioned grid
  636. CV_WRAP PyWGrid(const Point3d& center, const Vec3d& normal, const Vec3d& new_yaxis,
  637. const Vec2i &cells = Vec2i::all(10), const Vec2d &cells_spacing = Vec2d::all(1.0), const PyColor& color = Color::white())
  638. {
  639. widget = cv::makePtr<WGrid>(center, normal, new_yaxis, cells, cells_spacing, color);
  640. }
  641. CV_WRAP void setRenderingProperty(int property, double value)
  642. {
  643. CV_Assert(widget);
  644. widget->setRenderingProperty(property, value);
  645. }
  646. Ptr<cv::viz::WGrid> widget;
  647. };
  648. /////////////////////////////////////////////////////////////////////////////
  649. /// Trajectories
  650. /** @brief This 3D Widget represents a trajectory. :
  651. */
  652. struct CV_EXPORTS_W_SIMPLE CV_WRAP_AS(WTrajectory) PyWTrajectory
  653. {
  654. public:
  655. enum { FRAMES = 1, PATH = 2, BOTH = FRAMES + PATH };
  656. PyWTrajectory() {}
  657. /** @brief Constructs a WTrajectory.
  658. @param path List of poses on a trajectory. Takes std::vector\<Affine\<T\>\> with T == [float | double]
  659. @param display_mode Display mode. This can be PATH, FRAMES, and BOTH.
  660. @param scale Scale of the frames. Polyline is not affected.
  661. @param color Color of the polyline that represents path.
  662. Frames are not affected.
  663. Displays trajectory of the given path as follows:
  664. - PATH : Displays a poly line that represents the path.
  665. - FRAMES : Displays coordinate frames at each pose.
  666. - PATH & FRAMES : Displays both poly line and coordinate frames.
  667. */
  668. CV_WRAP PyWTrajectory(InputArray path, int display_mode = WTrajectory::PATH, double scale = 1.0, const PyColor& color = Color::white())
  669. {
  670. widget = cv::makePtr<cv::viz::WTrajectory>(path, display_mode, scale, color);
  671. }
  672. CV_WRAP void setRenderingProperty(int property, double value)
  673. {
  674. CV_Assert(widget);
  675. widget->setRenderingProperty(property, value);
  676. }
  677. Ptr<cv::viz::WTrajectory> widget;
  678. };
  679. /** @brief This 3D Widget represents a trajectory. :
  680. */
  681. struct CV_EXPORTS_W_SIMPLE CV_WRAP_AS(WTrajectoryFrustums) PyWTrajectoryFrustums
  682. {
  683. public:
  684. PyWTrajectoryFrustums() {}
  685. /** @brief Constructs a WTrajectoryFrustums.
  686. @param path List of poses on a trajectory. Takes std::vector\<Affine\<T\>\> with T == [float | double]
  687. @param K Intrinsic matrix of the camera or fov Field of view of the camera (horizontal, vertical).
  688. @param scale Scale of the frustums.
  689. @param color Color of the frustums.
  690. Displays frustums at each pose of the trajectory.
  691. */
  692. CV_WRAP PyWTrajectoryFrustums(InputArray path, InputArray K, double scale = 1.0, const PyColor& color = Color::white());
  693. CV_WRAP void setRenderingProperty(int property, double value)
  694. {
  695. CV_Assert(widget);
  696. widget->setRenderingProperty(property, value);
  697. }
  698. Ptr<cv::viz::WTrajectoryFrustums> widget;
  699. };
  700. /** @brief This 3D Widget represents a trajectory using spheres and lines
  701. where spheres represent the positions of the camera, and lines represent the direction from
  702. previous position to the current. :
  703. */
  704. struct CV_EXPORTS_W_SIMPLE CV_WRAP_AS(WTrajectorySpheres) PyWTrajectorySpheres
  705. {
  706. public:
  707. PyWTrajectorySpheres() {}
  708. /** @brief Constructs a WTrajectorySpheres.
  709. @param path List of poses on a trajectory. Takes std::vector\<Affine\<T\>\> with T == [float | double]
  710. @param line_length Max length of the lines which point to previous position
  711. @param radius Radius of the spheres.
  712. @param from Color for first sphere.
  713. @param to Color for last sphere. Intermediate spheres will have interpolated color.
  714. */
  715. CV_WRAP PyWTrajectorySpheres(InputArray path, double line_length = 0.05, double radius = 0.007,
  716. const PyColor& from = Color::red(), const PyColor& to = Color::white())
  717. {
  718. widget = cv::makePtr<WTrajectorySpheres>(path, line_length, radius, from, to);
  719. }
  720. CV_WRAP void setRenderingProperty(int property, double value)
  721. {
  722. CV_Assert(widget);
  723. widget->setRenderingProperty(property, value);
  724. }
  725. Ptr<cv::viz::WTrajectorySpheres> widget;
  726. };
  727. struct CV_EXPORTS_W_SIMPLE CV_WRAP_AS(WPaintedCloud) PyWPaintedCloud
  728. {
  729. public:
  730. //! Paint cloud with default gradient between cloud bounds points
  731. PyWPaintedCloud()
  732. {
  733. }
  734. CV_WRAP PyWPaintedCloud(InputArray cloud)
  735. {
  736. widget = cv::makePtr<WPaintedCloud>(cloud);
  737. }
  738. //! Paint cloud with default gradient between given points
  739. CV_WRAP PyWPaintedCloud(InputArray cloud, const Point3d& p1, const Point3d& p2)
  740. {
  741. widget = cv::makePtr<WPaintedCloud>(cloud, p1, p2);
  742. }
  743. //! Paint cloud with gradient specified by given colors between given points
  744. CV_WRAP PyWPaintedCloud(InputArray cloud, const Point3d& p1, const Point3d& p2, const PyColor& c1, const PyColor& c2)
  745. {
  746. widget = cv::makePtr<WPaintedCloud>(cloud, p1, p2, c1, c2);
  747. }
  748. CV_WRAP void setRenderingProperty(int property, double value)
  749. {
  750. CV_Assert(widget);
  751. widget->setRenderingProperty(property, value);
  752. }
  753. Ptr<cv::viz::WPaintedCloud> widget;
  754. };
  755. /** @brief This 3D Widget defines a collection of clouds. :
  756. @note In case there are four channels in the cloud, fourth channel is ignored.
  757. */
  758. struct CV_EXPORTS_W_SIMPLE CV_WRAP_AS(WCloudCollection) PyWCloudCollection
  759. {
  760. public:
  761. CV_WRAP PyWCloudCollection()
  762. {
  763. widget = cv::makePtr<WCloudCollection>();
  764. }
  765. /** @brief Adds a cloud to the collection.
  766. @param cloud Point set which can be of type: CV_32FC3, CV_32FC4, CV_64FC3, CV_64FC4.
  767. @param colors Set of colors. It has to be of the same size with cloud.
  768. @param pose Pose of the cloud. Points in the cloud belong to mask when they are set to (NaN, NaN, NaN).
  769. */
  770. CV_WRAP void addCloud(InputArray cloud, InputArray colors, const PyAffine3d &pose = PyAffine3d::Identity())
  771. {
  772. widget->addCloud(cloud, colors, pose);
  773. }
  774. /** @brief Adds a cloud to the collection.
  775. @param cloud Point set which can be of type: CV_32FC3, CV_32FC4, CV_64FC3, CV_64FC4.
  776. @param color A single Color for the whole cloud.
  777. @param pose Pose of the cloud. Points in the cloud belong to mask when they are set to (NaN, NaN, NaN).
  778. */
  779. CV_WRAP void addCloud(InputArray cloud, const PyColor& color = Color::white(), const PyAffine3d& pose = PyAffine3d::Identity())
  780. {
  781. widget->addCloud(cloud, color, pose);
  782. }
  783. /** @brief Finalizes cloud data by repacking to single cloud.
  784. Useful for large cloud collections to reduce memory usage
  785. */
  786. CV_WRAP void finalize()
  787. {
  788. widget->finalize();
  789. }
  790. CV_WRAP void setRenderingProperty(int property, double value)
  791. {
  792. CV_Assert(widget);
  793. widget->setRenderingProperty(property, value);
  794. }
  795. Ptr<cv::viz::WCloudCollection> widget;
  796. };
  797. /** @brief This 3D Widget represents normals of a point cloud. :
  798. */
  799. struct CV_EXPORTS_W_SIMPLE CV_WRAP_AS(WCloudNormals) PyWCloudNormals
  800. {
  801. public:
  802. PyWCloudNormals()
  803. {
  804. }
  805. /** @brief Constructs a WCloudNormals.
  806. @param cloud Point set which can be of type: CV_32FC3, CV_32FC4, CV_64FC3, CV_64FC4.
  807. @param normals A set of normals that has to be of same type with cloud.
  808. @param level Display only every level th normal.
  809. @param scale Scale of the arrows that represent normals.
  810. @param color Color of the arrows that represent normals.
  811. @note In case there are four channels in the cloud, fourth channel is ignored.
  812. */
  813. CV_WRAP PyWCloudNormals(InputArray cloud, InputArray normals, int level = 64, double scale = 0.1, const PyColor& color = Color::white())
  814. {
  815. widget = cv::makePtr<WCloudNormals>(cloud, normals, level, scale, color);
  816. }
  817. CV_WRAP void setRenderingProperty(int property, double value)
  818. {
  819. CV_Assert(widget);
  820. widget->setRenderingProperty(property, value);
  821. }
  822. Ptr<cv::viz::WCloudNormals> widget;
  823. };
  824. CV_WRAP_AS(makeTransformToGlobal) static inline
  825. PyAffine3d makeTransformToGlobalPy(const Vec3d& axis_x, const Vec3d& axis_y, const Vec3d& axis_z, const Vec3d& origin = Vec3d::all(0));
  826. CV_WRAP_AS(makeCameraPose) static inline
  827. PyAffine3d makeCameraPosePy(const Vec3d& position, const Vec3d& focal_point, const Vec3d& y_dir);
  828. /** @brief The Viz3d class represents a 3D visualizer window. This class is implicitly shared.
  829. */
  830. class CV_EXPORTS_AS(Viz3d) PyViz3d
  831. #ifndef OPENCV_BINDING_PARSER
  832. : public Viz3d
  833. #endif
  834. {
  835. public:
  836. CV_WRAP static cv::Ptr<PyViz3d> create(const std::string& window_name = std::string())
  837. {
  838. return makePtr<PyViz3d>(window_name);
  839. }
  840. /** @brief The constructors.
  841. @param window_name Name of the window.
  842. */
  843. CV_WRAP PyViz3d(const std::string& window_name = std::string()) : Viz3d(window_name) {}
  844. CV_WRAP void showWidget(const String &id, PyWLine &widget);
  845. CV_WRAP void showWidget(const String &id, PyWLine &widget, PyAffine3d &pose);
  846. CV_WRAP void showWidget(const String &id, PyWSphere &widget);
  847. CV_WRAP void showWidget(const String &id, PyWSphere &widget, PyAffine3d &pose);
  848. CV_WRAP void showWidget(const String &id, PyWCameraPosition &widget);
  849. CV_WRAP void showWidget(const String &id, PyWCameraPosition &widget, PyAffine3d &pose);
  850. CV_WRAP void showWidget(const String &id, PyWArrow &widget);
  851. CV_WRAP void showWidget(const String &id, PyWArrow &widget, PyAffine3d &pose);
  852. CV_WRAP void showWidget(const String &id, PyWCircle &widget);
  853. CV_WRAP void showWidget(const String &id, PyWCircle &widget, PyAffine3d &pose);
  854. CV_WRAP void showWidget(const String &id, PyWPlane &widget);
  855. CV_WRAP void showWidget(const String &id, PyWPlane &widget, PyAffine3d &pose);
  856. CV_WRAP void showWidget(const String &id, PyWCone &widget);
  857. CV_WRAP void showWidget(const String &id, PyWCone &widget, PyAffine3d &pose);
  858. CV_WRAP void showWidget(const String &id, PyWCube &widget);
  859. CV_WRAP void showWidget(const String &id, PyWCube &widget, PyAffine3d &pose);
  860. CV_WRAP void showWidget(const String &id, PyWCylinder &widget);
  861. CV_WRAP void showWidget(const String &id, PyWCylinder &widget, PyAffine3d &pose);
  862. CV_WRAP void showWidget(const String &id, PyWCoordinateSystem &widget);
  863. CV_WRAP void showWidget(const String &id, PyWPaintedCloud &widget);
  864. CV_WRAP void showWidget(const String &id, PyWPaintedCloud &widget, PyAffine3d &pose);
  865. CV_WRAP void showWidget(const String &id, PyWCloudCollection &widget);
  866. CV_WRAP void showWidget(const String &id, PyWCloudCollection &widget, PyAffine3d &pose);
  867. CV_WRAP void showWidget(const String &id, PyWGrid &widget);
  868. CV_WRAP void showWidget(const String &id, PyWGrid &widget, PyAffine3d &pose);
  869. CV_WRAP void showWidget(const String &id, const cv::Ptr<WMesh> &widget);
  870. CV_WRAP void showWidget(const String &id, const cv::Ptr<WMesh> &widget, PyAffine3d &pose);
  871. CV_WRAP void showWidget(const String &id, PyWPolyLine &widget);
  872. CV_WRAP void showWidget(const String &id, PyWPolyLine &widget, PyAffine3d &pose);
  873. CV_WRAP void showWidget(const String &id, PyWCloud &widget);
  874. CV_WRAP void showWidget(const String &id, PyWCloud &widget, PyAffine3d &pose);
  875. CV_WRAP void showWidget(const String &id, PyWImage3D &widget, PyAffine3d &pose);
  876. CV_WRAP void showWidget(const String &id, PyWImage3D &widget);
  877. CV_WRAP void showWidget(const String &id, PyWImageOverlay &widget, PyAffine3d &pose);
  878. CV_WRAP void showWidget(const String &id, PyWImageOverlay &widget);
  879. CV_WRAP void showWidget(const String &id, PyWText &widget);
  880. CV_WRAP void showWidget(const String &id, PyWText &widget, PyAffine3d &pose);
  881. CV_WRAP void showWidget(const String &id, PyWText3D &widget);
  882. CV_WRAP void showWidget(const String &id, PyWText3D &widget, PyAffine3d &pose);
  883. CV_WRAP void showWidget(const String &id, PyWCloudNormals &widget, PyAffine3d &pose);
  884. CV_WRAP void showWidget(const String &id, PyWCloudNormals &widget);
  885. CV_WRAP void showWidget(const String &id, PyWTrajectory &widget, PyAffine3d &pose);
  886. CV_WRAP void showWidget(const String &id, PyWTrajectory &widget);
  887. CV_WRAP void showWidget(const String &id, PyWTrajectorySpheres &widget, PyAffine3d &pose);
  888. CV_WRAP void showWidget(const String &id, PyWTrajectorySpheres &widget);
  889. CV_WRAP void showWidget(const String &id, PyWTrajectoryFrustums &widget, PyAffine3d &pose);
  890. CV_WRAP void showWidget(const String &id, PyWTrajectoryFrustums &widget);
  891. /** @brief Removes a widget from the window.
  892. @param id The id of the widget that will be removed.
  893. */
  894. CV_WRAP
  895. void removeWidget(const String &id)
  896. { return Viz3d::removeWidget(id); }
  897. /** @brief Removes all widgets from the window.
  898. */
  899. CV_WRAP
  900. void removeAllWidgets()
  901. { return Viz3d::removeAllWidgets(); }
  902. /** @brief Removed all widgets and displays image scaled to whole window area.
  903. @param image Image to be displayed.
  904. @param window_size Size of Viz3d window. Default value means no change.
  905. */
  906. CV_WRAP
  907. void showImage(InputArray image, const Size& window_size = Size(-1, -1))
  908. { return Viz3d::showImage(image, window_size); }
  909. /** @brief Sets pose of a widget in the window.
  910. @param id The id of the widget whose pose will be set. @param pose The new pose of the widget.
  911. */
  912. CV_WRAP
  913. void setWidgetPose(const String &id, const PyAffine3d &pose)
  914. { return Viz3d::setWidgetPose(id, pose); }
  915. /** @brief Updates pose of a widget in the window by pre-multiplying its current pose.
  916. @param id The id of the widget whose pose will be updated. @param pose The pose that the current
  917. pose of the widget will be pre-multiplied by.
  918. */
  919. CV_WRAP
  920. void updateWidgetPose(const String &id, const PyAffine3d &pose)
  921. { return Viz3d::updateWidgetPose(id, pose); }
  922. /** @brief Returns the current pose of a widget in the window.
  923. @param id The id of the widget whose pose will be returned.
  924. */
  925. CV_WRAP
  926. PyAffine3d getWidgetPose(const String &id) const
  927. { return (PyAffine3d)Viz3d::getWidgetPose(id); }
  928. #if 0
  929. /** @brief Sets the intrinsic parameters of the viewer using Camera.
  930. @param camera Camera object wrapping intrinsic parameters.
  931. */
  932. void setCamera(const Camera &camera);
  933. /** @brief Returns a camera object that contains intrinsic parameters of the current viewer.
  934. */
  935. Camera getCamera() const;
  936. #endif
  937. /** @brief Returns the current pose of the viewer.
  938. */
  939. CV_WRAP PyAffine3d getViewerPose() const
  940. { return (PyAffine3d)Viz3d::getViewerPose(); }
  941. /** @brief Sets pose of the viewer.
  942. @param pose The new pose of the viewer.
  943. */
  944. CV_WRAP
  945. void setViewerPose(const PyAffine3d &pose)
  946. { return Viz3d::setViewerPose(pose); }
  947. /** @brief Resets camera viewpoint to a 3D widget in the scene.
  948. @param id Id of a 3D widget.
  949. */
  950. CV_WRAP
  951. void resetCameraViewpoint(const String &id)
  952. { return Viz3d::resetCameraViewpoint(id); }
  953. /** @brief Resets camera.
  954. */
  955. CV_WRAP
  956. void resetCamera()
  957. { return Viz3d::resetCamera(); }
  958. /** @brief Transforms a point in world coordinate system to window coordinate system.
  959. @param pt Point in world coordinate system.
  960. @param window_coord Output point in window coordinate system.
  961. */
  962. CV_WRAP void convertToWindowCoordinates(const Point3d &pt, CV_OUT Point3d &window_coord)
  963. { return Viz3d::convertToWindowCoordinates(pt, window_coord); }
  964. #if 0
  965. /** @brief Transforms a point in window coordinate system to a 3D ray in world coordinate system.
  966. @param window_coord Point in window coordinate system. @param origin Output origin of the ray.
  967. @param direction Output direction of the ray.
  968. */
  969. void converTo3DRay(const Point3d &window_coord, Point3d &origin, Vec3d &direction);
  970. #endif
  971. /** @brief Returns the current size of the window.
  972. */
  973. CV_WRAP
  974. Size getWindowSize() const
  975. { return Viz3d::getWindowSize(); }
  976. /** @brief Sets the size of the window.
  977. @param window_size New size of the window.
  978. */
  979. CV_WRAP
  980. void setWindowSize(const Size& window_size)
  981. { return Viz3d::setWindowSize(window_size); }
  982. /** @brief Returns the name of the window which has been set in the constructor.
  983. * `Viz - ` is prepended to the name if necessary.
  984. */
  985. CV_WRAP
  986. String getWindowName() const
  987. { return Viz3d::getWindowName(); }
  988. /** @brief Returns the Mat screenshot of the current scene.
  989. */
  990. CV_WRAP
  991. cv::Mat getScreenshot() const
  992. { return Viz3d::getScreenshot(); }
  993. /** @brief Saves screenshot of the current scene.
  994. @param file Name of the file.
  995. */
  996. CV_WRAP
  997. void saveScreenshot(const String &file)
  998. { return Viz3d::saveScreenshot(file); }
  999. /** @brief Sets the position of the window in the screen.
  1000. @param window_position coordinates of the window
  1001. */
  1002. CV_WRAP
  1003. void setWindowPosition(const Point& window_position)
  1004. { return Viz3d::setWindowPosition(window_position); }
  1005. /** @brief Sets or unsets full-screen rendering mode.
  1006. @param mode If true, window will use full-screen mode.
  1007. */
  1008. CV_WRAP
  1009. void setFullScreen(bool mode = true)
  1010. { return Viz3d::setFullScreen(mode); }
  1011. /** @brief Sets background color.
  1012. */
  1013. CV_WRAP
  1014. void setBackgroundColor(const PyColor& color, const PyColor& color2 = Color::not_set())
  1015. { return Viz3d::setBackgroundColor(color, color2); }
  1016. CV_WRAP
  1017. void setBackgroundTexture(InputArray image = noArray())
  1018. { return Viz3d::setBackgroundTexture(image); }
  1019. CV_WRAP
  1020. void setBackgroundMeshLab()
  1021. { return Viz3d::setBackgroundMeshLab(); }
  1022. /** @brief The window renders and starts the event loop.
  1023. */
  1024. CV_WRAP
  1025. void spin()
  1026. { return Viz3d::spin(); }
  1027. /** @brief Starts the event loop for a given time.
  1028. @param time Amount of time in milliseconds for the event loop to keep running.
  1029. @param force_redraw If true, window renders.
  1030. */
  1031. CV_WRAP
  1032. void spinOnce(int time = 1, bool force_redraw = false)
  1033. { return Viz3d::spinOnce(time, force_redraw); }
  1034. /** @brief Create a window in memory instead of on the screen.
  1035. */
  1036. CV_WRAP
  1037. void setOffScreenRendering()
  1038. { return Viz3d::setOffScreenRendering(); }
  1039. /** @brief Remove all lights from the current scene.
  1040. */
  1041. CV_WRAP
  1042. void removeAllLights()
  1043. { return Viz3d::removeAllLights(); }
  1044. #if 0
  1045. /** @brief Add a light in the scene.
  1046. @param position The position of the light.
  1047. @param focalPoint The point at which the light is shining
  1048. @param color The color of the light
  1049. @param diffuseColor The diffuse color of the light
  1050. @param ambientColor The ambient color of the light
  1051. @param specularColor The specular color of the light
  1052. */
  1053. void addLight(const Vec3d &position, const Vec3d &focalPoint = Vec3d(0, 0, 0), const Color &color = Color::white(),
  1054. const Color &diffuseColor = Color::white(), const Color &ambientColor = Color::black(),
  1055. const Color &specularColor = Color::white());
  1056. #endif
  1057. /** @brief Returns whether the event loop has been stopped.
  1058. */
  1059. CV_WRAP
  1060. bool wasStopped() const
  1061. { return Viz3d::wasStopped(); }
  1062. CV_WRAP
  1063. void close()
  1064. { return Viz3d::close(); }
  1065. /** @brief Sets rendering property of a widget.
  1066. @param id Id of the widget.
  1067. @param property Property that will be modified.
  1068. @param value The new value of the property.
  1069. Rendering property can be one of the following:
  1070. - **POINT_SIZE**
  1071. - **OPACITY**
  1072. - **LINE_WIDTH**
  1073. - **FONT_SIZE**
  1074. REPRESENTATION: Expected values are
  1075. - **REPRESENTATION_POINTS**
  1076. - **REPRESENTATION_WIREFRAME**
  1077. - **REPRESENTATION_SURFACE**
  1078. IMMEDIATE_RENDERING:
  1079. - Turn on immediate rendering by setting the value to 1.
  1080. - Turn off immediate rendering by setting the value to 0.
  1081. SHADING: Expected values are
  1082. - **SHADING_FLAT**
  1083. - **SHADING_GOURAUD**
  1084. - **SHADING_PHONG**
  1085. */
  1086. CV_WRAP
  1087. void setRenderingProperty(const String &id, int property, double value)
  1088. { return Viz3d::setRenderingProperty(id, property, value); }
  1089. /** @brief Returns rendering property of a widget.
  1090. @param id Id of the widget.
  1091. @param property Property.
  1092. Rendering property can be one of the following:
  1093. - **POINT_SIZE**
  1094. - **OPACITY**
  1095. - **LINE_WIDTH**
  1096. - **FONT_SIZE**
  1097. REPRESENTATION: Expected values are
  1098. - **REPRESENTATION_POINTS**
  1099. - **REPRESENTATION_WIREFRAME**
  1100. - **REPRESENTATION_SURFACE**
  1101. IMMEDIATE_RENDERING:
  1102. - Turn on immediate rendering by setting the value to 1.
  1103. - Turn off immediate rendering by setting the value to 0.
  1104. SHADING: Expected values are
  1105. - **SHADING_FLAT**
  1106. - **SHADING_GOURAUD**
  1107. - **SHADING_PHONG**
  1108. */
  1109. CV_WRAP
  1110. double getRenderingProperty(const String &id, int property)
  1111. { return Viz3d::getRenderingProperty(id, property); }
  1112. /** @brief Sets geometry representation of the widgets to surface, wireframe or points.
  1113. @param representation Geometry representation which can be one of the following:
  1114. - **REPRESENTATION_POINTS**
  1115. - **REPRESENTATION_WIREFRAME**
  1116. - **REPRESENTATION_SURFACE**
  1117. */
  1118. CV_WRAP
  1119. void setRepresentation(int representation)
  1120. { return Viz3d::setRepresentation(representation); }
  1121. CV_WRAP
  1122. void setGlobalWarnings(bool enabled = false)
  1123. { return Viz3d::setGlobalWarnings(enabled); }
  1124. };
  1125. }} // namespace
  1126. #endif // OPENCV_PYTHON_VIZ_HPP