-
Notifications
You must be signed in to change notification settings - Fork 5.8k
python binding for viz #2882
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
python binding for viz #2882
Conversation
@alalek I don't know how to slove that
|
This is weird behavior from VTK. There is call of I can try to enable virtual display (xfvb) for tests, but it is bad practice to crash tests in non-supported environment. Perhaps we should check for DISPLAY environment variable on non-Windows (Linux) and skip such tests. |
Is it possible to have a review? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for contribution!
@@ -115,27 +114,87 @@ namespace cv | |||
static Color not_set(); | |||
}; | |||
|
|||
struct CV_EXPORTS_W_SIMPLE PyColor |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should not have Python-specific classes in public C++ header.
Please move this to viz/misc/python/python_bridge.hpp
(see gapi module for example)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I need PyColor viz3d.hpp
If I move PyColor defintion in python_bridge.hpp then it will generate error
Viz3d(const Viz3d&); | ||
Viz3d& operator=(const Viz3d&); | ||
~Viz3d(); | ||
CV_WRAP ~Viz3d(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we really need to wrap destructors?
/** | ||
PyAffine3 is an overloaded structure, provided for convenience. | ||
*/ | ||
struct CV_EXPORTS_W_SIMPLE PyAffine3 { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
PyAffine3
need to move out from public C++ headers
and similar classes below
modules/viz/src/viz3d.cpp
Outdated
cv::viz::Viz3d::Viz3d(const String& window_name) : impl_(0) { create(window_name); } | ||
cv::Ptr<cv::viz::Viz3d> cv::viz::Viz3d::Viz3d::create(const String& window_name) | ||
{ | ||
cv::utils::logging::setLogLevel(cv::utils::logging::LOG_LEVEL_WARNING); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
cv::utils::logging::setLogLevel(cv::utils::logging::LOG_LEVEL_WARNING);
should no be called from OpenCV code. Remove that.
modules/viz/src/vizcore.cpp
Outdated
axis_x[1], axis_y[1], axis_z[1], | ||
axis_x[2], axis_y[2], axis_z[2]); | ||
axis_x[1], axis_y[1], axis_z[1], | ||
axis_x[2], axis_y[2], axis_z[2]); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please avoid unnecessary changes.
modules/viz/samples/viz_sample_03.py
Outdated
os.add_dll_directory(r'G:\Lib\install\opencv\x64\vc15\bin') | ||
os.add_dll_directory(r'G:\Lib\install\vtk\bin') | ||
os.add_dll_directory(r'G:\Lib\install\ceres-solver\bin') | ||
os.add_dll_directory(r'G:\Lib\install\glog\bin') | ||
os.add_dll_directory(r'F:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v11.2\bin') | ||
os.add_dll_directory(r'F:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v11.2') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is for Python 3.8+ on Windows only.
There is no good solution for that from Python team.
There is some attempt to handle OpenCV paths through <build_dir>/python_loader
.
Anyway such hacks should be removed from the source code.
modules/viz/samples/viz_sample_03.py
Outdated
return pose | ||
|
||
def load_bunny(): | ||
with open(r'G:\Lib\opencv_contrib\modules\viz\samples\data\bunny.ply', 'r') as f: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no absolute paths
@@ -0,0 +1,436 @@ | |||
#exec(open(r'G:\Lib\opencv_contrib\modules\viz\samples\viz_sample_03.py').read()) | |||
import cv2 as cv | |||
import numpy as np |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
numpy should go first
public: | ||
PyWCloudNormals() | ||
{ | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no tabs please
myWindow.setViewerPosePy(camera_pose) | ||
|
||
class viz_test(NewOpenCVTests): | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lets skip VIZ tests by default (because they are UI tests):
def setUp(self):
super(viz_test, self).setUp()
if not bool(os.environ.get('OPENCV_PYTEST_RUN_VIZ', False)):
self.skipTest("Use OPENCV_PYTEST_RUN_VIZ=1 to enable VIZ UI tests")
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well done!
I will take a look on moving of "PyColor" and other classes problem a bit later.
BTW, Did you try to run it with enabled "Debug" mode (Debug assertions)? I see some failures:
$ OPENCV_PYTHON_DEBUG=1 OPENCV_PYTEST_RUN_VIZ=1 OPENCV_PYTEST_FILTER=test_simple* ./setup_vars.sh python3 <opencv>/modules/python/test/test.py -v --repo <opencv>
...
======================================================================
ERROR: test_viz_show_camera_positions (test_simple.viz_test)
----------------------------------------------------------------------
cv2.error: OpenCV(4.5.2-pre) /home/alalek/projects/opencv/dev/modules/core/include/opencv2/core/mat.inl.hpp:872: error: (-215:Assertion failed) (unsigned)(i1 * DataType<_Tp>::channels) < (unsigned)(size.p[1] * channels()) in function 'at'
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "/home/alalek/projects/opencv/contrib/modules/viz/misc/python/test/test_simple.py", line 408, in test_viz_show_camera_positions
viz.showWidget("pos2", cv.viz_PyWCameraPosition((0.78, 0.78), lena, 2.2, cv.viz_PyColor().green()), poses[0])
SystemError: <class 'cv2.viz_PyWCameraPosition'> returned a result with an error set
======================================================================
ERROR: test_viz_show_simple_widgets (test_simple.viz_test)
----------------------------------------------------------------------
cv2.error: OpenCV(4.5.2-pre) /home/alalek/projects/opencv/dev/modules/core/include/opencv2/core/mat.inl.hpp:872: error: (-215:Assertion failed) (unsigned)(i1 * DataType<_Tp>::channels) < (unsigned)(size.p[1] * channels()) in function 'at'
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "/home/alalek/projects/opencv/contrib/modules/viz/misc/python/test/test_simple.py", line 83, in test_viz_show_simple_widgets
viz.showWidget("grid1", cv.viz_PyWGrid((7,7), (0.75,0.75), cv.viz_PyColor().gray()), cv.viz_PyAffine3().translate((0.0, 0.0, -1.0)))
SystemError: <class 'cv2.viz_PyWGrid'> returned a result with an error set
======================================================================
ERROR: test_viz_show_trajectories (test_simple.viz_test)
----------------------------------------------------------------------
cv2.error: OpenCV(4.5.2-pre) /home/alalek/projects/opencv/dev/modules/core/include/opencv2/core/mat.inl.hpp:872: error: (-215:Assertion failed) (unsigned)(i1 * DataType<_Tp>::channels) < (unsigned)(size.p[1] * channels()) in function 'at'
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "/home/alalek/projects/opencv/contrib/modules/viz/misc/python/test/test_simple.py", line 382, in test_viz_show_trajectories
viz.showWidget("sub5", cv.viz_PyWTrajectoryFrustums(sub5, (0.78, 0.78), 0.15, cv.viz_PyColor().magenta())) #BUG
SystemError: <class 'cv2.viz_PyWTrajectoryFrustums'> returned a result with an error set
======================================================================
ERROR: test_viz_tutorial3_camera_view (test_simple.viz_test)
----------------------------------------------------------------------
cv2.error: OpenCV(4.5.2-pre) /home/alalek/projects/opencv/dev/modules/core/include/opencv2/core/mat.inl.hpp:872: error: (-215:Assertion failed) (unsigned)(i1 * DataType<_Tp>::channels) < (unsigned)(size.p[1] * channels()) in function 'at'
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "/home/alalek/projects/opencv/contrib/modules/viz/misc/python/test/test_simple.py", line 52, in test_viz_tutorial3_camera_view
tutorial3(True, self.find_file("viz/dragon.ply"))
File "/home/alalek/projects/opencv/contrib/modules/viz/misc/python/test/test_simple.py", line 35, in tutorial3
myWindow.showWidget("CPW_FRUSTUM", cv.viz_PyWCameraPosition((0.889484, 0.523599)), camera_pose)
SystemError: <class 'cv2.viz_PyWCameraPosition'> returned a result with an error set
======================================================================
ERROR: test_viz_tutorial3_global_view (test_simple.viz_test)
----------------------------------------------------------------------
cv2.error: OpenCV(4.5.2-pre) /home/alalek/projects/opencv/dev/modules/core/include/opencv2/core/mat.inl.hpp:872: error: (-215:Assertion failed) (unsigned)(i1 * DataType<_Tp>::channels) < (unsigned)(size.p[1] * channels()) in function 'at'
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "/home/alalek/projects/opencv/contrib/modules/viz/misc/python/test/test_simple.py", line 49, in test_viz_tutorial3_global_view
tutorial3(False, self.find_file("viz/dragon.ply"))
File "/home/alalek/projects/opencv/contrib/modules/viz/misc/python/test/test_simple.py", line 35, in tutorial3
myWindow.showWidget("CPW_FRUSTUM", cv.viz_PyWCameraPosition((0.889484, 0.523599)), camera_pose)
SystemError: <class 'cv2.viz_PyWCameraPosition'> returned a result with an error set
----------------------------------------------------------------------
Ran 22 tests in 30.685s
FAILED (errors=5)
@@ -0,0 +1,440 @@ | |||
import os |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
modules/viz/misc/python/test/test_simple.py
Please rename to test_viz_simple.py
(similar to python tests of other modules).
self.skipTest("Use OPENCV_PYTEST_RUN_VIZ=1 to enable VIZ UI tests") | ||
|
||
def test_viz_tutorial3_global_view(self): | ||
tutorial3(False, self.find_file("viz\dragon.ply")) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
viz\dragon.ply
Use forward slash (/) instead in this file.
Hi, |
|
||
} | ||
else if (k.rows == 2 && k.cols == 1) | ||
widget = cv::makePtr<cv::viz::WCameraPosition>(Vec2d(k.at<double>(0, 0), k.at<double>(0, 1)), image, scale, color.c); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There are several exceptions from Python tests here (in debug builds).
It is better to replace:
- check:
else if (k.total() == 2)
- use
.at()
with single arg:k.at<double>(0), k.at<double>(1)
Causes by "undefined" 1D layout represented as 2D Mat (it may be row-based or column-based).
Please replace similar cases of .at()
usage of 1D arrays below (use single argument form).
CV_Error(-5, "unknown size"); | ||
} | ||
else | ||
CV_Error(-5, "unknown type"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
-5
Avoid using of magic numbers. Use enum values instead.
|
Something is weird. I can see buildbot is ok with win64 but not on my configuration
My opencv repo is even with master and I deleted build opencv repo |
Buildbot's Win64 configuration doesn't have VTK. Do you have upgraded main "opencv" repository? |
class CV_EXPORTS_W_SIMPLE Color | ||
#ifndef OPENCV_BINDING_PARSER | ||
: public Scalar | ||
#endif |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/cc @mshabunin Perhaps we need some CV_WRAP_WITHOUT_BASE
marker for bindings.
my opencv repo is now 2 commits behin master. Is it ok? |
without VTK viz is off no error compilation and link ok -DENABLE_PRECOMPILED_HEADERS=OFF and VTK on error :
|
@LaurentBerger I'm able to reproduce this build problem. Investigating... Problem comes from opencv_core. Bug is triggered by this change: -class Color : public Scalar
+class CV_EXPORTS Color : public Scalar |
- fix 'int resolution = 6.0' bug - fix other MSVC build warnings
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well done! Thank you 👍
relative to opencv/opencv#19490
See details at https://github.com/opencv/opencv/wiki/How_to_contribute#making-a-good-pull-request
Patch to opencv_extra has the same branch name.