implemented showImage

This commit is contained in:
Anatoly Baksheev 2014-01-11 22:43:58 +04:00
parent d90a068e0e
commit 1449823bcd
10 changed files with 74 additions and 23 deletions

View File

@ -43,7 +43,7 @@ You can download the code from :download:`here <../../../../samples/cpp/tutorial
cout << "First event loop is over" << endl;
/// Access window via its name
viz::Viz3d sameWindow = viz::get("Viz Demo");
viz::Viz3d sameWindow = viz::getWindowByName("Viz Demo");
/// Start event loop
sameWindow.spin();

View File

@ -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 updateWidgetPose(const String &id, const Affine3d &pose);
Affine3d getWidgetPose(const String &id) const;
void showImage(InputArray image, const Size& window_size = Size(-1, -1));
void setCamera(const Camera &camera);
Camera getCamera() const;
@ -182,6 +184,15 @@ Removes all widgets from the window.
.. 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
-------------------------
Sets pose of a widget in the window.

View File

@ -580,16 +580,16 @@ This 2D Widget represents an image overlay. ::
class CV_EXPORTS WImageOverlay : public Widget2D
{
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
---------------------------------
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 rect: Image is scaled and positioned based on rect.
@ -598,7 +598,7 @@ viz::WImageOverlay::setImage
----------------------------
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.
@ -612,23 +612,23 @@ This 3D Widget represents an image in 3D space. ::
{
public:
//! 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
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
-----------------------
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 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 normal: Normal of the plane that represents the image.
@ -640,7 +640,7 @@ viz::WImage3D::setImage
-----------------------
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.

View File

@ -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.
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
inline bool isNan(float x)
{

View File

@ -75,6 +75,8 @@ namespace cv
Widget getWidget(const String &id) const;
void removeAllWidgets();
void showImage(InputArray image, const Size& window_size = Size(-1, -1));
void setWidgetPose(const String &id, const Affine3d &pose);
void updateWidgetPose(const String &id, const Affine3d &pose);
Affine3d getWidgetPose(const String &id) const;

View File

@ -210,8 +210,8 @@ namespace cv
class CV_EXPORTS WImageOverlay : public Widget2D
{
public:
WImageOverlay(const Mat &image, const Rect &rect);
void setImage(const Mat &image);
WImageOverlay(InputArray image, const Rect &rect);
void setImage(InputArray image);
};
class CV_EXPORTS WImage3D : public Widget3D
@ -219,12 +219,12 @@ namespace cv
public:
//! 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
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
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);
};
/////////////////////////////////////////////////////////////////////////////

View File

@ -613,15 +613,16 @@ cv::String cv::viz::WText::getText() const
///////////////////////////////////////////////////////////////////////////////////////////////
/// 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);
vtkSmartPointer<vtkImageMatSource> source = vtkSmartPointer<vtkImageMatSource>::New();
source->SetImage(image);
Size sz = image.size();
// Scale the image based on the Rect, and flip to match y-ais orientation
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);
vtkSmartPointer<vtkImageReslice> image_reslice = vtkSmartPointer<vtkImageReslice>::New();
@ -640,11 +641,12 @@ cv::viz::WImageOverlay::WImageOverlay(const Mat &image, const Rect &rect)
vtkSmartPointer<vtkActor2D> actor = vtkSmartPointer<vtkActor2D>::New();
actor->SetMapper(image_mapper);
actor->SetPosition(rect.x, rect.y);
actor->GetProperty()->SetDisplayLocationToForeground();
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);
@ -661,10 +663,11 @@ void cv::viz::WImageOverlay::setImage(const Mat &image)
// Create the vtk image and set its parameters based on input image
vtkSmartPointer<vtkImageMatSource> source = vtkSmartPointer<vtkImageMatSource>::New();
source->SetImage(image);
Size sz = image.size();
// Scale the image based on the Rect, and flip to match y-ais orientation
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);
vtkSmartPointer<vtkImageReslice> image_reslice = vtkSmartPointer<vtkImageReslice>::New();
@ -687,7 +690,7 @@ template<> cv::viz::WImageOverlay cv::viz::Widget::cast<cv::viz::WImageOverlay>(
///////////////////////////////////////////////////////////////////////////////////////////////
/// 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);
@ -717,7 +720,7 @@ cv::viz::WImage3D::WImage3D(const Mat &image, const Size2d &size)
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);
@ -732,7 +735,7 @@ cv::viz::WImage3D::WImage3D(const Mat &image, const Size2d &size, const Vec3d &c
*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);

View File

@ -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); }
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::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::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); }

View File

@ -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); }
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

View File

@ -250,6 +250,20 @@ TEST(Viz, DISABLED_show_overlay_image)
//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)
{
Mat lena = imread(Path::combine(cvtest::TS::ptr()->get_data_path(), "lena.png"));