2013-03-18 23:52:46 +08:00
|
|
|
/*M///////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
//
|
|
|
|
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
|
|
|
|
//
|
|
|
|
// By downloading, copying, installing or using the software you agree to this license.
|
|
|
|
// If you do not agree to this license, do not download, install,
|
|
|
|
// copy or use the software.
|
|
|
|
//
|
|
|
|
//
|
|
|
|
// License Agreement
|
|
|
|
// For Open Source Computer Vision Library
|
|
|
|
//
|
|
|
|
// Copyright (C) 2000-2008, Intel Corporation, all rights reserved.
|
|
|
|
// Copyright (C) 2008-2013, Willow Garage Inc., all rights reserved.
|
|
|
|
// Third party copyrights are property of their respective owners.
|
|
|
|
//
|
|
|
|
// Redistribution and use in source and binary forms, with or without modification,
|
|
|
|
// are permitted provided that the following conditions are met:
|
|
|
|
//
|
|
|
|
// * Redistribution's of source code must retain the above copyright notice,
|
|
|
|
// this list of conditions and the following disclaimer.
|
|
|
|
//
|
|
|
|
// * Redistribution's in binary form must reproduce the above copyright notice,
|
|
|
|
// this list of conditions and the following disclaimer in the documentation
|
|
|
|
// and / or other materials provided with the distribution.
|
|
|
|
//
|
|
|
|
// * The name of the copyright holders may not be used to endorse or promote products
|
|
|
|
// derived from this software without specific prior written permission.
|
|
|
|
//
|
|
|
|
// This software is provided by the copyright holders and contributors "as is" and
|
|
|
|
// any express or implied warranties, including, but not limited to, the implied
|
|
|
|
// warranties of merchantability and fitness for a particular purpose are disclaimed.
|
|
|
|
// In no event shall the Intel Corporation or contributors be liable for any direct,
|
|
|
|
// indirect, incidental, special, exemplary, or consequential damages
|
|
|
|
// (including, but not limited to, procurement of substitute goods or services;
|
|
|
|
// loss of use, data, or profits; or business interruption) however caused
|
|
|
|
// and on any theory of liability, whether in contract, strict liability,
|
|
|
|
// or tort (including negligence or otherwise) arising in any way out of
|
|
|
|
// the use of this software, even if advised of the possibility of such damage.
|
|
|
|
//
|
|
|
|
//M*/
|
|
|
|
#include "test_precomp.hpp"
|
|
|
|
#include <opencv2/viz.hpp>
|
2013-07-18 16:39:34 +08:00
|
|
|
#include <opencv2/highgui.hpp>
|
2013-03-18 23:52:46 +08:00
|
|
|
#include <string>
|
|
|
|
|
2013-07-13 22:23:46 +08:00
|
|
|
using namespace cv;
|
2013-03-18 23:52:46 +08:00
|
|
|
|
|
|
|
cv::Mat cvcloud_load()
|
|
|
|
{
|
2013-07-09 00:56:13 +08:00
|
|
|
cv::Mat cloud(1, 20000, CV_32FC3);
|
2013-09-06 23:32:35 +08:00
|
|
|
std::ifstream ifs("/Users/nerei/cloud_dragon.ply");
|
2013-03-18 23:52:46 +08:00
|
|
|
|
|
|
|
std::string str;
|
|
|
|
for(size_t i = 0; i < 11; ++i)
|
|
|
|
std::getline(ifs, str);
|
|
|
|
|
2013-07-09 00:56:13 +08:00
|
|
|
cv::Point3f* data = cloud.ptr<cv::Point3f>();
|
|
|
|
for(size_t i = 0; i < 20000; ++i)
|
|
|
|
ifs >> data[i].x >> data[i].y >> data[i].z;
|
2013-03-18 23:52:46 +08:00
|
|
|
|
|
|
|
return cloud;
|
|
|
|
}
|
|
|
|
|
2013-09-15 22:26:53 +08:00
|
|
|
bool constant_cam = true;
|
|
|
|
cv::viz::Widget cam_1, cam_coordinates;
|
2013-07-13 22:23:46 +08:00
|
|
|
|
2013-09-15 22:26:53 +08:00
|
|
|
void keyboard_callback(const viz::KeyboardEvent & event, void * cookie)
|
|
|
|
{
|
|
|
|
if (event.keyDown())
|
|
|
|
{
|
|
|
|
if (event.getKeySym() == "space")
|
|
|
|
{
|
|
|
|
viz::Viz3d &viz = *((viz::Viz3d *) cookie);
|
|
|
|
constant_cam = !constant_cam;
|
|
|
|
if (constant_cam)
|
|
|
|
{
|
|
|
|
viz.showWidget("cam_1", cam_1);
|
|
|
|
viz.showWidget("cam_coordinate", cam_coordinates);
|
|
|
|
viz.showWidget("cam_text", viz::WText("Global View", Point2i(5,5), 28));
|
|
|
|
viz.resetCamera();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
viz.showWidget("cam_text", viz::WText("Cam View", Point2i(5,5), 28));
|
|
|
|
viz.removeWidget("cam_1");
|
|
|
|
viz.removeWidget("cam_coordinate");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2013-07-13 22:23:46 +08:00
|
|
|
|
2013-09-15 22:26:53 +08:00
|
|
|
TEST(Viz_viz3d, accuracy)
|
|
|
|
{
|
2013-07-13 22:23:46 +08:00
|
|
|
cv::viz::Viz3d viz("abc");
|
|
|
|
|
2013-09-15 22:26:53 +08:00
|
|
|
cv::viz::Mesh3d bunny_mesh = cv::viz::Mesh3d::loadMesh("bunny.ply");
|
|
|
|
cv::viz::WMesh bunny_widget(bunny_mesh);
|
|
|
|
bunny_widget.setColor(cv::viz::Color::cyan());
|
2013-07-13 22:23:46 +08:00
|
|
|
|
2013-09-15 22:26:53 +08:00
|
|
|
cam_1 = cv::viz::WCameraPosition(cv::Vec2f(0.6, 0.4), 0.2, cv::viz::Color::green());
|
|
|
|
cam_coordinates = cv::viz::WCameraPosition(0.2);
|
2013-07-13 22:23:46 +08:00
|
|
|
|
2013-09-15 22:26:53 +08:00
|
|
|
viz.showWidget("bunny", bunny_widget);
|
|
|
|
viz.showWidget("cam_1", cam_1, viz::makeCameraPose(Point3f(1.0,0.0,0.0), Point3f(0.0,0.0,0.0), Point3f(0.0,1.0,0.0)));
|
|
|
|
viz.showWidget("cam_coordinate", cam_coordinates, viz::makeCameraPose(Point3f(1.0,0.0,0.0), Point3f(0.0,0.0,0.0), Point3f(0.0,1.0,0.0)));
|
2013-07-13 21:45:46 +08:00
|
|
|
|
2013-09-15 22:26:53 +08:00
|
|
|
std::vector<Affine3f> cam_path;
|
2013-07-13 21:45:46 +08:00
|
|
|
|
2013-09-15 22:26:53 +08:00
|
|
|
for (int i = 0, j = 0; i <= 360; ++i, j+=5)
|
|
|
|
{
|
2013-10-15 21:34:20 +08:00
|
|
|
cam_path.push_back(viz::makeCameraPose(Vec3d(0.5*cos(double(i)*CV_PI/180.0), 0.5*sin(double(j)*CV_PI/180.0), 0.5*sin(double(i)*CV_PI/180.0)), Vec3f(0.f, 0.f, 0.f), Vec3f(0.f, 1.f, 0.f)));
|
2013-09-15 22:26:53 +08:00
|
|
|
}
|
2013-09-18 19:50:55 +08:00
|
|
|
|
2013-09-15 22:26:53 +08:00
|
|
|
int path_counter = 0;
|
|
|
|
int cam_path_size = cam_path.size();
|
|
|
|
|
|
|
|
// OTHER WIDGETS
|
|
|
|
cv::Mat img = imread("opencv.png");
|
2013-09-18 19:50:55 +08:00
|
|
|
|
2013-09-15 22:26:53 +08:00
|
|
|
int downSample = 4;
|
2013-09-18 19:50:55 +08:00
|
|
|
|
2013-09-15 22:26:53 +08:00
|
|
|
int row_max = img.rows/downSample;
|
|
|
|
int col_max = img.cols/downSample;
|
2013-09-18 19:50:55 +08:00
|
|
|
|
2013-09-18 00:55:10 +08:00
|
|
|
cv::Mat *clouds = new cv::Mat[img.cols/downSample];
|
|
|
|
cv::Mat *colors = new cv::Mat[img.cols/downSample];
|
2013-09-18 19:50:55 +08:00
|
|
|
|
2013-09-15 22:26:53 +08:00
|
|
|
for (int col = 0; col < col_max; ++col)
|
|
|
|
{
|
|
|
|
clouds[col] = Mat::zeros(img.rows/downSample, 1, CV_32FC3);
|
|
|
|
colors[col] = Mat::zeros(img.rows/downSample, 1, CV_8UC3);
|
|
|
|
for (int row = 0; row < row_max; ++row)
|
|
|
|
{
|
2013-10-15 21:34:20 +08:00
|
|
|
clouds[col].at<Vec3f>(row) = Vec3f(downSample * float(col) / img.cols, 1.f-(downSample * float(row) / img.rows), 0.f);
|
2013-09-15 22:26:53 +08:00
|
|
|
colors[col].at<Vec3b>(row) = img.at<Vec3b>(row*downSample,col*downSample);
|
|
|
|
}
|
|
|
|
}
|
2013-09-18 19:50:55 +08:00
|
|
|
|
2013-09-15 22:26:53 +08:00
|
|
|
for (int col = 0; col < col_max; ++col)
|
|
|
|
{
|
|
|
|
std::stringstream strstrm;
|
|
|
|
strstrm << "cloud_" << col;
|
|
|
|
viz.showWidget(strstrm.str(), viz::WCloud(clouds[col], colors[col]));
|
|
|
|
viz.getWidget(strstrm.str()).setRenderingProperty(viz::POINT_SIZE, 3.0);
|
|
|
|
viz.getWidget(strstrm.str()).setRenderingProperty(viz::OPACITY, 0.45);
|
|
|
|
}
|
2013-09-18 19:50:55 +08:00
|
|
|
|
2013-09-15 22:26:53 +08:00
|
|
|
viz.showWidget("trajectory", viz::WTrajectory(cam_path, viz::WTrajectory::DISPLAY_PATH, viz::Color::yellow()));
|
|
|
|
viz.showWidget("cam_text", viz::WText("Global View", Point2i(5,5), 28));
|
|
|
|
viz.registerKeyboardCallback(keyboard_callback, (void *) &viz);
|
2013-07-15 18:02:20 +08:00
|
|
|
|
2013-09-15 22:26:53 +08:00
|
|
|
int angle = 0;
|
2013-09-18 19:50:55 +08:00
|
|
|
|
2013-07-13 22:23:46 +08:00
|
|
|
while(!viz.wasStopped())
|
2013-06-07 17:18:26 +08:00
|
|
|
{
|
2013-09-18 19:50:55 +08:00
|
|
|
if (path_counter == cam_path_size)
|
2013-09-15 22:26:53 +08:00
|
|
|
{
|
|
|
|
path_counter = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!constant_cam)
|
|
|
|
{
|
|
|
|
viz.setViewerPose(cam_path[path_counter]);
|
|
|
|
}
|
2013-09-18 19:50:55 +08:00
|
|
|
|
2013-09-15 22:26:53 +08:00
|
|
|
if (angle == 360) angle = 0;
|
2013-07-13 22:23:46 +08:00
|
|
|
|
2013-09-15 22:26:53 +08:00
|
|
|
cam_1.cast<viz::WCameraPosition>().setPose(cam_path[path_counter]);
|
|
|
|
cam_coordinates.cast<viz::WCameraPosition>().setPose(cam_path[path_counter++]);
|
2013-09-18 19:50:55 +08:00
|
|
|
|
2013-09-15 22:26:53 +08:00
|
|
|
for (int i = 0; i < col_max; ++i)
|
|
|
|
{
|
|
|
|
std::stringstream strstrm;
|
|
|
|
strstrm << "cloud_" << i;
|
2013-10-15 21:34:20 +08:00
|
|
|
viz.setWidgetPose(strstrm.str(), Affine3f().translate(Vec3f(-0.5f, 0.f, (float)(-0.7 + 0.2*sin((angle+i*10)*CV_PI / 180.0)))));
|
2013-09-15 22:26:53 +08:00
|
|
|
}
|
|
|
|
angle += 10;
|
|
|
|
viz.spinOnce(42, true);
|
2013-06-07 17:18:26 +08:00
|
|
|
}
|
2013-03-18 23:52:46 +08:00
|
|
|
}
|