Commit 1449823b authored by Anatoly Baksheev's avatar Anatoly Baksheev

implemented showImage

parent d90a068e
...@@ -43,7 +43,7 @@ You can download the code from :download:`here <../../../../samples/cpp/tutorial ...@@ -43,7 +43,7 @@ You can download the code from :download:`here <../../../../samples/cpp/tutorial
cout << "First event loop is over" << endl; cout << "First event loop is over" << endl;
/// Access window via its name /// Access window via its name
viz::Viz3d sameWindow = viz::get("Viz Demo"); viz::Viz3d sameWindow = viz::getWindowByName("Viz Demo");
/// Start event loop /// Start event loop
sameWindow.spin(); sameWindow.spin();
......
...@@ -102,6 +102,8 @@ The Viz3d class represents a 3D visualizer window. This class is implicitly shar ...@@ -102,6 +102,8 @@ The Viz3d class represents a 3D visualizer window. This class is implicitly shar
void setWidgetPose(const String &id, const Affine3d &pose); void setWidgetPose(const String &id, const Affine3d &pose);
void updateWidgetPose(const String &id, const Affine3d &pose); void updateWidgetPose(const String &id, const Affine3d &pose);
Affine3d getWidgetPose(const String &id) const; Affine3d getWidgetPose(const String &id) const;
void showImage(InputArray image, const Size& window_size = Size(-1, -1));
void setCamera(const Camera &camera); void setCamera(const Camera &camera);
Camera getCamera() const; Camera getCamera() const;
...@@ -182,6 +184,15 @@ Removes all widgets from the window. ...@@ -182,6 +184,15 @@ Removes all widgets from the window.
.. ocv:function:: void removeAllWidgets() .. ocv:function:: void removeAllWidgets()
viz::Viz3d::showImage
---------------------
Removed all widgets and displays image scaled to whole window area.
.. ocv:function:: void showImage(InputArray image, const Size& window_size = Size(-1, -1));
:param image: Image to be displayed.
:param size: Size of Viz3d window. Default value means no change.
viz::Viz3d::setWidgetPose viz::Viz3d::setWidgetPose
------------------------- -------------------------
Sets pose of a widget in the window. Sets pose of a widget in the window.
......
...@@ -580,16 +580,16 @@ This 2D Widget represents an image overlay. :: ...@@ -580,16 +580,16 @@ This 2D Widget represents an image overlay. ::
class CV_EXPORTS WImageOverlay : public Widget2D class CV_EXPORTS WImageOverlay : public Widget2D
{ {
public: public:
WImageOverlay(const Mat &image, const Rect &rect); WImageOverlay(InputArray image, const Rect &rect);
void setImage(const Mat &image); void setImage(InputArray image);
}; };
viz::WImageOverlay::WImageOverlay viz::WImageOverlay::WImageOverlay
--------------------------------- ---------------------------------
Constructs an WImageOverlay. Constructs an WImageOverlay.
.. ocv:function:: WImageOverlay(const Mat &image, const Rect &rect) .. ocv:function:: WImageOverlay(InputArray image, const Rect &rect)
:param image: BGR or Gray-Scale image. :param image: BGR or Gray-Scale image.
:param rect: Image is scaled and positioned based on rect. :param rect: Image is scaled and positioned based on rect.
...@@ -598,7 +598,7 @@ viz::WImageOverlay::setImage ...@@ -598,7 +598,7 @@ viz::WImageOverlay::setImage
---------------------------- ----------------------------
Sets the image content of the widget. Sets the image content of the widget.
.. ocv:function:: void setImage(const Mat &image) .. ocv:function:: void setImage(InputArray image)
:param image: BGR or Gray-Scale image. :param image: BGR or Gray-Scale image.
...@@ -612,23 +612,23 @@ This 3D Widget represents an image in 3D space. :: ...@@ -612,23 +612,23 @@ This 3D Widget represents an image in 3D space. ::
{ {
public: public:
//! Creates 3D image at the origin //! Creates 3D image at the origin
WImage3D(const Mat &image, const Size2d &size); WImage3D(InputArray image, const Size2d &size);
//! Creates 3D image at a given position, pointing in the direction of the normal, and having the up_vector orientation //! Creates 3D image at a given position, pointing in the direction of the normal, and having the up_vector orientation
WImage3D(const Mat &image, const Size2d &size, const Vec3d &position, const Vec3d &normal, const Vec3d &up_vector); WImage3D(InputArray image, const Size2d &size, const Vec3d &position, const Vec3d &normal, const Vec3d &up_vector);
void setImage(const Mat &image); void setImage(InputArray image);
}; };
viz::WImage3D::WImage3D viz::WImage3D::WImage3D
----------------------- -----------------------
Constructs an WImage3D. Constructs an WImage3D.
.. ocv:function:: WImage3D(const Mat &image, const Size2d &size) .. ocv:function:: WImage3D(InputArray image, const Size2d &size)
:param image: BGR or Gray-Scale image. :param image: BGR or Gray-Scale image.
:param size: Size of the image. :param size: Size of the image.
.. ocv:function:: WImage3D(const Mat &image, const Size2d &size, const Vec3d &position, const Vec3d &normal, const Vec3d &up_vector) .. ocv:function:: WImage3D(InputArray image, const Size2d &size, const Vec3d &position, const Vec3d &normal, const Vec3d &up_vector)
:param position: Position of the image. :param position: Position of the image.
:param normal: Normal of the plane that represents the image. :param normal: Normal of the plane that represents the image.
...@@ -640,7 +640,7 @@ viz::WImage3D::setImage ...@@ -640,7 +640,7 @@ viz::WImage3D::setImage
----------------------- -----------------------
Sets the image content of the widget. Sets the image content of the widget.
.. ocv:function:: void setImage(const Mat &image) .. ocv:function:: void setImage(InputArray image)
:param image: BGR or Gray-Scale image. :param image: BGR or Gray-Scale image.
......
...@@ -66,6 +66,9 @@ namespace cv ...@@ -66,6 +66,9 @@ namespace cv
//! Unregisters all Viz windows from internal database. After it 'getWindowByName()' will create new windows instead getting existing from the database. //! Unregisters all Viz windows from internal database. After it 'getWindowByName()' will create new windows instead getting existing from the database.
CV_EXPORTS void unregisterAllWindows(); CV_EXPORTS void unregisterAllWindows();
//! Displays image in specified window
CV_EXPORTS Viz3d imshow(const String& window_name, InputArray image, const Size& window_size = Size(-1, -1));
//! checks float value for Nan //! checks float value for Nan
inline bool isNan(float x) inline bool isNan(float x)
{ {
......
...@@ -75,6 +75,8 @@ namespace cv ...@@ -75,6 +75,8 @@ namespace cv
Widget getWidget(const String &id) const; Widget getWidget(const String &id) const;
void removeAllWidgets(); void removeAllWidgets();
void showImage(InputArray image, const Size& window_size = Size(-1, -1));
void setWidgetPose(const String &id, const Affine3d &pose); void setWidgetPose(const String &id, const Affine3d &pose);
void updateWidgetPose(const String &id, const Affine3d &pose); void updateWidgetPose(const String &id, const Affine3d &pose);
Affine3d getWidgetPose(const String &id) const; Affine3d getWidgetPose(const String &id) const;
......
...@@ -210,8 +210,8 @@ namespace cv ...@@ -210,8 +210,8 @@ namespace cv
class CV_EXPORTS WImageOverlay : public Widget2D class CV_EXPORTS WImageOverlay : public Widget2D
{ {
public: public:
WImageOverlay(const Mat &image, const Rect &rect); WImageOverlay(InputArray image, const Rect &rect);
void setImage(const Mat &image); void setImage(InputArray image);
}; };
class CV_EXPORTS WImage3D : public Widget3D class CV_EXPORTS WImage3D : public Widget3D
...@@ -219,12 +219,12 @@ namespace cv ...@@ -219,12 +219,12 @@ namespace cv
public: public:
//! Creates 3D image in a plane centered at the origin with normal orientaion along z-axis, //! Creates 3D image in a plane centered at the origin with normal orientaion along z-axis,
//! image x- and y-axes are oriented along x- and y-axes of 3d world //! image x- and y-axes are oriented along x- and y-axes of 3d world
WImage3D(const Mat &image, const Size2d &size); WImage3D(InputArray image, const Size2d &size);
//! Creates 3D image at a given position, pointing in the direction of the normal, and having the up_vector orientation //! Creates 3D image at a given position, pointing in the direction of the normal, and having the up_vector orientation
WImage3D(const Mat &image, const Size2d &size, const Vec3d &center, const Vec3d &normal, const Vec3d &up_vector); WImage3D(InputArray image, const Size2d &size, const Vec3d &center, const Vec3d &normal, const Vec3d &up_vector);
void setImage(const Mat &image); void setImage(InputArray image);
}; };
///////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////
......
...@@ -613,15 +613,16 @@ cv::String cv::viz::WText::getText() const ...@@ -613,15 +613,16 @@ cv::String cv::viz::WText::getText() const
/////////////////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////////////////
/// image overlay widget implementation /// image overlay widget implementation
cv::viz::WImageOverlay::WImageOverlay(const Mat &image, const Rect &rect) cv::viz::WImageOverlay::WImageOverlay(InputArray image, const Rect &rect)
{ {
CV_Assert(!image.empty() && image.depth() == CV_8U); CV_Assert(!image.empty() && image.depth() == CV_8U);
vtkSmartPointer<vtkImageMatSource> source = vtkSmartPointer<vtkImageMatSource>::New(); vtkSmartPointer<vtkImageMatSource> source = vtkSmartPointer<vtkImageMatSource>::New();
source->SetImage(image); source->SetImage(image);
Size sz = image.size();
// Scale the image based on the Rect, and flip to match y-ais orientation // Scale the image based on the Rect, and flip to match y-ais orientation
vtkSmartPointer<vtkTransform> transform = vtkSmartPointer<vtkTransform>::New(); vtkSmartPointer<vtkTransform> transform = vtkSmartPointer<vtkTransform>::New();
transform->Scale(image.cols/(double)rect.width, image.rows/(double)rect.height, 1.0); transform->Scale(sz.width/(double)rect.width, sz.height/(double)rect.height, 1.0);
transform->RotateX(180); transform->RotateX(180);
vtkSmartPointer<vtkImageReslice> image_reslice = vtkSmartPointer<vtkImageReslice>::New(); vtkSmartPointer<vtkImageReslice> image_reslice = vtkSmartPointer<vtkImageReslice>::New();
...@@ -640,11 +641,12 @@ cv::viz::WImageOverlay::WImageOverlay(const Mat &image, const Rect &rect) ...@@ -640,11 +641,12 @@ cv::viz::WImageOverlay::WImageOverlay(const Mat &image, const Rect &rect)
vtkSmartPointer<vtkActor2D> actor = vtkSmartPointer<vtkActor2D>::New(); vtkSmartPointer<vtkActor2D> actor = vtkSmartPointer<vtkActor2D>::New();
actor->SetMapper(image_mapper); actor->SetMapper(image_mapper);
actor->SetPosition(rect.x, rect.y); actor->SetPosition(rect.x, rect.y);
actor->GetProperty()->SetDisplayLocationToForeground();
WidgetAccessor::setProp(*this, actor); WidgetAccessor::setProp(*this, actor);
} }
void cv::viz::WImageOverlay::setImage(const Mat &image) void cv::viz::WImageOverlay::setImage(InputArray image)
{ {
CV_Assert(!image.empty() && image.depth() == CV_8U); CV_Assert(!image.empty() && image.depth() == CV_8U);
...@@ -661,10 +663,11 @@ void cv::viz::WImageOverlay::setImage(const Mat &image) ...@@ -661,10 +663,11 @@ void cv::viz::WImageOverlay::setImage(const Mat &image)
// Create the vtk image and set its parameters based on input image // Create the vtk image and set its parameters based on input image
vtkSmartPointer<vtkImageMatSource> source = vtkSmartPointer<vtkImageMatSource>::New(); vtkSmartPointer<vtkImageMatSource> source = vtkSmartPointer<vtkImageMatSource>::New();
source->SetImage(image); source->SetImage(image);
Size sz = image.size();
// Scale the image based on the Rect, and flip to match y-ais orientation // Scale the image based on the Rect, and flip to match y-ais orientation
vtkSmartPointer<vtkTransform> transform = vtkSmartPointer<vtkTransform>::New(); vtkSmartPointer<vtkTransform> transform = vtkSmartPointer<vtkTransform>::New();
transform->Scale(image.cols/(double)size.width, image.rows/(double)size.height, 1.0); transform->Scale(sz.width/(double)size.width, sz.height/(double)size.height, 1.0);
transform->RotateX(180); transform->RotateX(180);
vtkSmartPointer<vtkImageReslice> image_reslice = vtkSmartPointer<vtkImageReslice>::New(); vtkSmartPointer<vtkImageReslice> image_reslice = vtkSmartPointer<vtkImageReslice>::New();
...@@ -687,7 +690,7 @@ template<> cv::viz::WImageOverlay cv::viz::Widget::cast<cv::viz::WImageOverlay>( ...@@ -687,7 +690,7 @@ template<> cv::viz::WImageOverlay cv::viz::Widget::cast<cv::viz::WImageOverlay>(
/////////////////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////////////////
/// image 3D widget implementation /// image 3D widget implementation
cv::viz::WImage3D::WImage3D(const Mat &image, const Size2d &size) cv::viz::WImage3D::WImage3D(InputArray image, const Size2d &size)
{ {
CV_Assert(!image.empty() && image.depth() == CV_8U); CV_Assert(!image.empty() && image.depth() == CV_8U);
...@@ -717,7 +720,7 @@ cv::viz::WImage3D::WImage3D(const Mat &image, const Size2d &size) ...@@ -717,7 +720,7 @@ cv::viz::WImage3D::WImage3D(const Mat &image, const Size2d &size)
WidgetAccessor::setProp(*this, actor); WidgetAccessor::setProp(*this, actor);
} }
cv::viz::WImage3D::WImage3D(const Mat &image, const Size2d &size, const Vec3d &center, const Vec3d &normal, const Vec3d &up_vector) cv::viz::WImage3D::WImage3D(InputArray image, const Size2d &size, const Vec3d &center, const Vec3d &normal, const Vec3d &up_vector)
{ {
CV_Assert(!image.empty() && image.depth() == CV_8U); CV_Assert(!image.empty() && image.depth() == CV_8U);
...@@ -732,7 +735,7 @@ cv::viz::WImage3D::WImage3D(const Mat &image, const Size2d &size, const Vec3d &c ...@@ -732,7 +735,7 @@ cv::viz::WImage3D::WImage3D(const Mat &image, const Size2d &size, const Vec3d &c
*this = image3d; *this = image3d;
} }
void cv::viz::WImage3D::setImage(const Mat &image) void cv::viz::WImage3D::setImage(InputArray image)
{ {
CV_Assert(!image.empty() && image.depth() == CV_8U); CV_Assert(!image.empty() && image.depth() == CV_8U);
......
...@@ -112,6 +112,17 @@ void cv::viz::Viz3d::showWidget(const String &id, const Widget &widget, const Af ...@@ -112,6 +112,17 @@ void cv::viz::Viz3d::showWidget(const String &id, const Widget &widget, const Af
void cv::viz::Viz3d::removeWidget(const String &id) { impl_->removeWidget(id); } void cv::viz::Viz3d::removeWidget(const String &id) { impl_->removeWidget(id); }
cv::viz::Widget cv::viz::Viz3d::getWidget(const String &id) const { return impl_->getWidget(id); } cv::viz::Widget cv::viz::Viz3d::getWidget(const String &id) const { return impl_->getWidget(id); }
void cv::viz::Viz3d::removeAllWidgets() { impl_->removeAllWidgets(); } void cv::viz::Viz3d::removeAllWidgets() { impl_->removeAllWidgets(); }
void cv::viz::Viz3d::showImage(InputArray image, const Size& window_size)
{
removeAllWidgets();
if (window_size.width > 0 && window_size.height > 0)
setWindowSize(window_size);
showWidget("showImage", WImageOverlay(image, Rect(Point(0,0), getWindowSize())));
}
void cv::viz::Viz3d::setWidgetPose(const String &id, const Affine3d &pose) { impl_->setWidgetPose(id, pose); } void cv::viz::Viz3d::setWidgetPose(const String &id, const Affine3d &pose) { impl_->setWidgetPose(id, pose); }
void cv::viz::Viz3d::updateWidgetPose(const String &id, const Affine3d &pose) { impl_->updateWidgetPose(id, pose); } void cv::viz::Viz3d::updateWidgetPose(const String &id, const Affine3d &pose) { impl_->updateWidgetPose(id, pose); }
cv::Affine3d cv::viz::Viz3d::getWidgetPose(const String &id) const { return impl_->getWidgetPose(id); } cv::Affine3d cv::viz::Viz3d::getWidgetPose(const String &id) const { return impl_->getWidgetPose(id); }
......
...@@ -122,6 +122,13 @@ cv::String cv::viz::VizStorage::generateWindowName(const String &window_name) ...@@ -122,6 +122,13 @@ cv::String cv::viz::VizStorage::generateWindowName(const String &window_name)
cv::viz::Viz3d cv::viz::getWindowByName(const String &window_name) { return Viz3d (window_name); } cv::viz::Viz3d cv::viz::getWindowByName(const String &window_name) { return Viz3d (window_name); }
void cv::viz::unregisterAllWindows() { VizStorage::unregisterAll(); } void cv::viz::unregisterAllWindows() { VizStorage::unregisterAll(); }
cv::viz::Viz3d cv::viz::imshow(const String& window_name, InputArray image, const Size& window_size)
{
Viz3d viz = getWindowByName(window_name);
viz.showImage(image, window_size);
return viz;
}
/////////////////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////////////////
/// Read/write clouds. Supported formats: ply, stl, xyz, obj /// Read/write clouds. Supported formats: ply, stl, xyz, obj
......
...@@ -250,6 +250,20 @@ TEST(Viz, DISABLED_show_overlay_image) ...@@ -250,6 +250,20 @@ TEST(Viz, DISABLED_show_overlay_image)
//viz.spin(); //viz.spin();
} }
TEST(Viz, DISABLED_show_image_method)
{
Mat lena = imread(Path::combine(cvtest::TS::ptr()->get_data_path(), "lena.png"));
Viz3d viz("show_image_method");
viz.showImage(lena);
viz.spinOnce(1500, true);
viz.showImage(lena, lena.size());
viz.spinOnce(1500, true);
cv::viz::imshow("show_image_method", make_gray(lena)).spin();
}
TEST(Viz, DISABLED_show_image_3d) TEST(Viz, DISABLED_show_image_3d)
{ {
Mat lena = imread(Path::combine(cvtest::TS::ptr()->get_data_path(), "lena.png")); Mat lena = imread(Path::combine(cvtest::TS::ptr()->get_data_path(), "lena.png"));
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment