parent
195755ec80
commit
2563390a25
16 changed files with 940 additions and 5932 deletions
@ -0,0 +1,59 @@ |
|||||||
|
An overview of the contrib modules and a small explanation |
||||||
|
---------------------------------------------------------- |
||||||
|
|
||||||
|
This list gives an overview of all modules available inside the contrib repository. |
||||||
|
These are also the correct names for disabling the building of a specific module by adding |
||||||
|
|
||||||
|
``` |
||||||
|
$ cmake -D OPENCV_EXTRA_MODULES_PATH=<opencv_contrib>/modules -D BUILD_opencv_reponame=OFF <opencv_source_directory> |
||||||
|
``` |
||||||
|
|
||||||
|
1. **opencv_adas**: Advanced Driver Assistance Systems module with Forward Collision Warning. |
||||||
|
|
||||||
|
2. **opencv_bgsegm**: Improved Adaptive Background Mixture Model for Real-time Tracking / Visual Tracking of Human Visitors under Variable-Lighting Conditions. |
||||||
|
|
||||||
|
3. **opencv_bioinspired**: Biologically inspired vision models and derivated tools. |
||||||
|
|
||||||
|
4. **opencv_ ccalib**: Custom Calibration Pattern for 3D reconstruction. |
||||||
|
|
||||||
|
5. **opencv_cvv**: GUI for Interactive Visual Debugging of Computer Vision Programs. |
||||||
|
|
||||||
|
6. **opencv_datasets**: Interface for interfacing with existing computer vision databases. |
||||||
|
|
||||||
|
7. **opencv_datasettools**: Tools for working with different datasets. |
||||||
|
|
||||||
|
8. **opencv_face**: Recently added face recognition software which is not yet stabalized. |
||||||
|
|
||||||
|
9. **opencv_latentsvm**: Implementation of the LatentSVM detector algorithm. |
||||||
|
|
||||||
|
10. **opencv_line_descriptor**: Binary descriptors for lines extracted from an image. |
||||||
|
|
||||||
|
11. **opencv_matlab**: OpenCV Matlab Code Generator. |
||||||
|
|
||||||
|
12. **opencv_optflow**: Optical Flow Algorithms for tracking points. |
||||||
|
|
||||||
|
13. **opencv_reg**: Image Registration module. |
||||||
|
|
||||||
|
14. **opencv_rgbd**: RGB-Depth Processing module. |
||||||
|
|
||||||
|
15. **opencv_saliency**: Saliency API, understanding where humans focus given a scene. |
||||||
|
|
||||||
|
16. **opencv_surface_matching**: Surface Matching Algorithm Through 3D Features. |
||||||
|
|
||||||
|
17. **opencv_text**: Scene Text Detection and Recognition in Natural Scene Images. |
||||||
|
|
||||||
|
18. **opencv_tracking**: Long-term optical tracking API. |
||||||
|
|
||||||
|
19. **opencv_xfeatures2d**: Extra 2D Features Framework containing experimental and non-free 2D feature algorithms. |
||||||
|
|
||||||
|
20. **opencv_ximgproc**: Extended Image Processing: Structured Forests / Domain Transform Filter / Guided Filter / Adaptive Manifold Filter / Joint Bilateral Filter / Superpixels. |
||||||
|
|
||||||
|
21. **opencv_xobjdetect**: Integral Channel Features Detector Framework. |
||||||
|
|
||||||
|
22. **opencv_xphoto**: Additional photo processing algorithms: Color balance / Denoising / Inpainting. |
||||||
|
|
||||||
|
<<<<<<< 54d9fdeb5ed51d326de3d2f1383f8e330f114381 |
||||||
|
23. **opencv_stereo**: Stereo Correspondence done with different descriptors: Census / CS-Census / MCT / BRIEF / MV / RT. |
||||||
|
======= |
||||||
|
23. **opencv_stereo**: Stereo Correspondence done with different descriptors: Census / CS-Census / MCT / BRIEF / MV / RT. |
||||||
|
>>>>>>> modify README under modules |
@ -0,0 +1,2 @@ |
|||||||
|
set(the_description "CNN for 3D object recognition and pose estimation including a completed Sphere View on 3D objects") |
||||||
|
ocv_define_module(cnn_3dobj opencv_core opencv_imgproc opencv_viz opencv_highgui OPTIONAL WRAP python) |
@ -0,0 +1,18 @@ |
|||||||
|
CNN for 3D object recognition and pose estimation including a completed Sphere View of 3D objects from .ply files, when the windows shows the coordinate, press 'q' to go on image generation. |
||||||
|
============================================ |
||||||
|
Building Process: |
||||||
|
$ cd <opencv_source_directory> |
||||||
|
$ mkdir build |
||||||
|
$ cd build |
||||||
|
$ cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local -D WITH_TBB=ON -D BUILD_NEW_PYTHON_SUPPORT=ON -D WITH_V4L=ON -D WITH_QT=ON -D WITH_OPENGL=ON -D WITH_VTK=ON -D OPENCV_EXTRA_MODULES_PATH=<opencv_contrib>/modules .. |
||||||
|
$ make -j4 |
||||||
|
$ sudo make install |
||||||
|
$ cd <opencv_contrib>/modules/cnn_3dobj/samples |
||||||
|
$ mkdir build |
||||||
|
$ cd build |
||||||
|
$ cmake .. |
||||||
|
$ make |
||||||
|
$ ./sphereview_test 350 2 ../ape.ply |
||||||
|
============================================== |
||||||
|
Then press 'q' to run the demo for images generation, parameter '350' represent the radius of the sphere and '2' stand for the depth of the sphere building iteration and '../ape.ply' represent the .ply model |
||||||
|
============================================== |
@ -0,0 +1,6 @@ |
|||||||
|
@Article{hinterstoisser2008panter, |
||||||
|
author = {Hinterstoisser, S. and Benhimane, S. and and Lepetit, V. and Navab, N.}, |
||||||
|
title = {Simultaneous Recognition and Homography Extraction of Local Patches with a Simple Linear Classifier}, |
||||||
|
booktitle = {BMVC British Machine Vision Conference 2008}, |
||||||
|
year = {2008} |
||||||
|
} |
@ -0,0 +1,105 @@ |
|||||||
|
/*
|
||||||
|
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 |
||||||
|
(3-clause BSD License) |
||||||
|
|
||||||
|
Copyright (C) 2000-2015, Intel Corporation, all rights reserved. |
||||||
|
Copyright (C) 2009-2011, Willow Garage Inc., all rights reserved. |
||||||
|
Copyright (C) 2009-2015, NVIDIA Corporation, all rights reserved. |
||||||
|
Copyright (C) 2010-2013, Advanced Micro Devices, Inc., all rights reserved. |
||||||
|
Copyright (C) 2015, OpenCV Foundation, all rights reserved. |
||||||
|
Copyright (C) 2015, Itseez 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: |
||||||
|
|
||||||
|
* Redistributions of source code must retain the above copyright notice, |
||||||
|
this list of conditions and the following disclaimer. |
||||||
|
|
||||||
|
* Redistributions 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. |
||||||
|
|
||||||
|
* Neither the names of the copyright holders nor the names of the contributors |
||||||
|
may 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 copyright holders 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. |
||||||
|
*/ |
||||||
|
|
||||||
|
#ifndef __OPENCV_CNN_3DOBJ_HPP__ |
||||||
|
#define __OPENCV_CNN_3DOBJ_HPP__ |
||||||
|
#ifdef __cplusplus |
||||||
|
|
||||||
|
#include <opencv2/calib3d.hpp> |
||||||
|
#include <opencv2/viz/vizcore.hpp> |
||||||
|
#include <opencv2/highgui.hpp> |
||||||
|
#include <fstream> |
||||||
|
#include <vector> |
||||||
|
#include <iostream> |
||||||
|
|
||||||
|
/** @defgroup cnn_3dobj CNN based on Caffe aimming at 3D object recognition and pose estimation
|
||||||
|
*/ |
||||||
|
namespace cv |
||||||
|
{ |
||||||
|
namespace cnn_3dobj |
||||||
|
{ |
||||||
|
|
||||||
|
//! @addtogroup cnn_3dobj
|
||||||
|
//! @{
|
||||||
|
|
||||||
|
/** @brief Icosohedron based camera view generator.
|
||||||
|
|
||||||
|
The class create some sphere views of camera towards a 3D object meshed from .ply files @cite hinterstoisser2008panter . |
||||||
|
*/ |
||||||
|
class CV_EXPORTS_W IcoSphere |
||||||
|
{ |
||||||
|
|
||||||
|
|
||||||
|
private: |
||||||
|
float X; |
||||||
|
float Z; |
||||||
|
|
||||||
|
public: |
||||||
|
|
||||||
|
|
||||||
|
std::vector<float> vertexNormalsList; |
||||||
|
std::vector<float> vertexList; |
||||||
|
std::vector<cv::Point3d> CameraPos; |
||||||
|
std::vector<cv::Point3d> CameraPos_temp; |
||||||
|
float radius; |
||||||
|
IcoSphere(float radius_in, int depth_in); |
||||||
|
/** @brief Make all view points having the some distance from the focal point used by the camera view.
|
||||||
|
*/ |
||||||
|
CV_WRAP void norm(float v[]); |
||||||
|
/** @brief Add new view point between 2 point of the previous view point.
|
||||||
|
*/ |
||||||
|
CV_WRAP void add(float v[]); |
||||||
|
/** @brief Generating new view points from all triangles.
|
||||||
|
*/ |
||||||
|
CV_WRAP void subdivide(float v1[], float v2[], float v3[], int depth); |
||||||
|
|
||||||
|
}; |
||||||
|
//! @}
|
||||||
|
|
||||||
|
}} |
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#endif /* CNN_3DOBJ_HPP_ */ |
||||||
|
#endif |
@ -0,0 +1,9 @@ |
|||||||
|
cmake_minimum_required(VERSION 2.8) |
||||||
|
SET(CMAKE_CXX_FLAGS_DEBUG "$ENV{CXXFLAGS} -O0 -Wall -g -ggdb ") |
||||||
|
SET(CMAKE_CXX_FLAGS_RELEASE "$ENV{CXXFLAGS} -O3 -Wall") |
||||||
|
project(sphereview_test) |
||||||
|
find_package(OpenCV REQUIRED) |
||||||
|
set(SOURCES sphereview_3dobj_demo.cpp) |
||||||
|
include_directories(${OpenCV_INCLUDE_DIRS}) |
||||||
|
add_executable(sphereview_test ${SOURCES}) |
||||||
|
target_link_libraries(sphereview_test ${OpenCV_LIBS}) |
@ -0,0 +1,351 @@ |
|||||||
|
0 0.707107 0.707107 |
||||||
|
0.211325 0.57735 0.788675 |
||||||
|
-0.211325 0.57735 0.788675 |
||||||
|
0.408248 0.408248 0.816497 |
||||||
|
0 0.447214 0.894427 |
||||||
|
0.211325 0.57735 0.788675 |
||||||
|
-0.408248 0.408248 0.816497 |
||||||
|
-0.211325 0.57735 0.788675 |
||||||
|
0.211325 0.57735 0.788675 |
||||||
|
-0.211325 0.57735 0.788675 |
||||||
|
0.707107 0 0.707107 |
||||||
|
0.382683 0 0.92388 |
||||||
|
0.57735 0.211325 0.788675 |
||||||
|
0 0 1 |
||||||
|
0.214187 0.214187 0.953021 |
||||||
|
0.57735 0.211325 0.788675 |
||||||
|
0.57735 0.211325 0.788675 |
||||||
|
-0.707107 0 0.707107 |
||||||
|
-0.57735 0.211325 0.788675 |
||||||
|
-0.382683 0 0.92388 |
||||||
|
-0.214187 0.214187 0.953021 |
||||||
|
-0.57735 0.211325 0.788675 |
||||||
|
-0.57735 0.211325 0.788675 |
||||||
|
-0.707107 0.707107 0 |
||||||
|
-0.57735 0.788675 0.211325 |
||||||
|
-0.408248 0.816497 0.408248 |
||||||
|
-0.211325 0.788675 0.57735 |
||||||
|
0 0.707107 -0.707107 |
||||||
|
0 0.92388 -0.382683 |
||||||
|
0 1 4.21468e-08 |
||||||
|
0 0.92388 0.382683 |
||||||
|
0.211325 0.788675 -0.57735 |
||||||
|
0 0.92388 -0.382683 |
||||||
|
0.408248 0.816497 -0.408248 |
||||||
|
0.214186 0.953021 -0.214187 |
||||||
|
0 1 0 |
||||||
|
0.707107 0.707107 0 |
||||||
|
0.57735 0.788675 0.211325 |
||||||
|
0.57735 0.788675 -0.211325 |
||||||
|
0.408248 0.816497 0.408248 |
||||||
|
0.447214 0.894427 0 |
||||||
|
0 0.92388 0.382683 |
||||||
|
0.211325 0.788675 0.57735 |
||||||
|
0.214186 0.953021 0.214187 |
||||||
|
0.788675 0.57735 0.211325 |
||||||
|
0.816497 0.408248 0.408248 |
||||||
|
0.788675 0.211325 0.57735 |
||||||
|
0.707107 -0.707107 0 |
||||||
|
0.788675 -0.57735 0.211325 |
||||||
|
0.92388 -0.382683 0 |
||||||
|
0.816497 -0.408248 0.408248 |
||||||
|
0.953021 -0.214186 0.214187 |
||||||
|
1 4.21468e-08 0 |
||||||
|
0.788675 -0.211325 0.57735 |
||||||
|
0.894427 1.63234e-08 0.447214 |
||||||
|
0.92388 0.382683 0 |
||||||
|
0.953021 0.214187 0.214187 |
||||||
|
0.707107 0 -0.707107 |
||||||
|
0.788675 -0.211325 -0.57735 |
||||||
|
0.57735 0.211325 -0.788675 |
||||||
|
0.816497 -0.408248 -0.408248 |
||||||
|
0.408248 0.408248 -0.816497 |
||||||
|
0.57735 0.211325 -0.788675 |
||||||
|
0.57735 0.211325 -0.788675 |
||||||
|
0.816497 -0.408248 -0.408248 |
||||||
|
0.788675 -0.57735 -0.211325 |
||||||
|
0.211325 0.57735 -0.788675 |
||||||
|
0.408248 0.408248 -0.816497 |
||||||
|
0.788675 0.211325 -0.57735 |
||||||
|
0.816497 0.408248 -0.408248 |
||||||
|
0.639602 0.426401 -0.639602 |
||||||
|
0.788675 0.57735 -0.211325 |
||||||
|
0.408248 0.816497 -0.408248 |
||||||
|
0.639602 0.639602 -0.426401 |
||||||
|
0.211325 0.57735 -0.788675 |
||||||
|
0.211325 0.788675 -0.57735 |
||||||
|
0.426401 0.639602 -0.639602 |
||||||
|
0.211325 0.57735 -0.788675 |
||||||
|
0.211325 0.57735 -0.788675 |
||||||
|
-0.707107 0 -0.707107 |
||||||
|
-0.382683 0 -0.92388 |
||||||
|
0 0 -1 |
||||||
|
0.382683 0 -0.92388 |
||||||
|
0 -0.707107 -0.707107 |
||||||
|
0.211325 -0.57735 -0.788675 |
||||||
|
0.408248 -0.408248 -0.816497 |
||||||
|
0.211325 -0.57735 -0.788675 |
||||||
|
0.211325 -0.57735 -0.788675 |
||||||
|
0.57735 -0.211325 -0.788675 |
||||||
|
0.57735 -0.211325 -0.788675 |
||||||
|
0.57735 -0.211325 -0.788675 |
||||||
|
0.788675 -0.57735 -0.211325 |
||||||
|
0.57735 -0.788675 -0.211325 |
||||||
|
0.639602 -0.639602 -0.426401 |
||||||
|
0.408248 -0.816497 -0.408248 |
||||||
|
0.639602 -0.426401 -0.639602 |
||||||
|
0.211325 -0.788675 -0.57735 |
||||||
|
0.426401 -0.639602 -0.639602 |
||||||
|
0 -0.707107 0.707107 |
||||||
|
0.211325 -0.788675 0.57735 |
||||||
|
0 -0.92388 0.382683 |
||||||
|
0.408248 -0.816497 0.408248 |
||||||
|
0.214187 -0.953021 0.214186 |
||||||
|
0 -1 -4.21468e-08 |
||||||
|
0.57735 -0.788675 0.211325 |
||||||
|
0.447214 -0.894427 -1.63234e-08 |
||||||
|
0 -0.92388 -0.382683 |
||||||
|
0.214187 -0.953021 -0.214187 |
||||||
|
-0.707107 -0.707107 0 |
||||||
|
-0.57735 -0.788675 0.211325 |
||||||
|
-0.408248 -0.816497 0.408248 |
||||||
|
-0.211325 -0.788675 0.57735 |
||||||
|
-0.57735 -0.211325 0.788675 |
||||||
|
-0.408248 -0.408248 0.816497 |
||||||
|
-0.57735 -0.211325 0.788675 |
||||||
|
-0.57735 -0.211325 0.788675 |
||||||
|
-0.211325 -0.57735 0.788675 |
||||||
|
-0.211325 -0.57735 0.788675 |
||||||
|
-0.211325 -0.57735 0.788675 |
||||||
|
0.57735 -0.211325 0.788675 |
||||||
|
0.408248 -0.408248 0.816497 |
||||||
|
0.57735 -0.211325 0.788675 |
||||||
|
0.57735 -0.211325 0.788675 |
||||||
|
0.211325 -0.57735 0.788675 |
||||||
|
0.211325 -0.57735 0.788675 |
||||||
|
0.211325 -0.57735 0.788675 |
||||||
|
0.788675 -0.211325 0.57735 |
||||||
|
0.816497 -0.408248 0.408248 |
||||||
|
0.57735 0.211325 0.788675 |
||||||
|
-nan -nan -nan |
||||||
|
-nan -nan -nan |
||||||
|
-nan -nan -nan |
||||||
|
-nan -nan -nan |
||||||
|
-nan -nan -nan |
||||||
|
-nan -nan -nan |
||||||
|
-nan -nan -nan |
||||||
|
-nan -nan -nan |
||||||
|
06898 7.62273e-09 0.59069 |
||||||
|
0.788675 -0.211325 0.57735 |
||||||
|
0.874728 0.208721 0.437364 |
||||||
|
0.894427 1.63234e-08 0.447214 |
||||||
|
0.849313 0.106637 0.517007 |
||||||
|
0.809511 -0.31246 0.497052 |
||||||
|
0.874728 -0.208721 0.437364 |
||||||
|
0.849313 -0.106637 0.517007 |
||||||
|
0.83147 0.55557 0 |
||||||
|
0.92388 0.382683 0 |
||||||
|
0.867278 0.486184 0.10702 |
||||||
|
0.988185 0.108374 0.108374 |
||||||
|
0.980785 0.19509 0 |
||||||
|
0.953021 0.214187 0.214187 |
||||||
|
0.947388 0.301277 0.108113 |
||||||
|
0.895337 0.314938 0.314938 |
||||||
|
0.888679 0.403872 0.217112 |
||||||
|
0.935925 -0.108508 0.335068 |
||||||
|
0.935925 0.108508 0.335068 |
||||||
|
0.975663 2.28828e-08 0.219275 |
||||||
|
0.707107 0 -0.707107 |
||||||
|
0.754344 -0.106574 -0.64777 |
||||||
|
0.64777 0.106574 -0.754344 |
||||||
|
0.788675 -0.211325 -0.57735 |
||||||
|
0.57735 0.211325 -0.788675 |
||||||
|
0.816497 -0.408248 -0.408248 |
||||||
|
0.809511 -0.31246 -0.497052 |
||||||
|
0.408248 0.408248 -0.816497 |
||||||
|
0.497052 0.31246 -0.809511 |
||||||
|
0.57735 0.211325 -0.788675 |
||||||
|
0.57735 0.211325 -0.788675 |
||||||
|
0.64777 0.106574 -0.754344 |
||||||
|
0.707107 -7.71341e-09 -0.707107 |
||||||
|
0.788675 -0.57735 -0.211325 |
||||||
|
0.754344 -0.64777 -0.106574 |
||||||
|
0.816497 -0.408248 -0.408248 |
||||||
|
0.809511 -0.497052 -0.31246 |
||||||
|
0.788675 -0.57735 -0.211325 |
||||||
|
0.809511 -0.31246 -0.497052 |
||||||
|
0.809511 -0.497052 -0.31246 |
||||||
|
0.106574 0.64777 -0.754344 |
||||||
|
0.211325 0.57735 -0.788675 |
||||||
|
0.211325 0.57735 -0.788675 |
||||||
|
0.31246 0.497052 -0.809511 |
||||||
|
0.408248 0.408248 -0.816497 |
||||||
|
0.211325 0.57735 -0.788675 |
||||||
|
0.211325 0.57735 -0.788675 |
||||||
|
0.497052 0.31246 -0.809511 |
||||||
|
0.31246 0.497052 -0.809511 |
||||||
|
0.497052 0.31246 -0.809511 |
||||||
|
0.754344 0.106574 -0.64777 |
||||||
|
0.788675 0.211325 -0.57735 |
||||||
|
0.690768 0.213724 -0.690768 |
||||||
|
0.816497 0.408248 -0.408248 |
||||||
|
0.735924 0.421839 -0.529592 |
||||||
|
0.809511 0.31246 -0.497052 |
||||||
|
0.639602 0.426401 -0.639602 |
||||||
|
0.720687 0.321787 -0.614055 |
||||||
|
0.529592 0.421839 -0.735924 |
||||||
|
0.614055 0.321787 -0.720687 |
||||||
|
0.754344 0.64777 -0.106574 |
||||||
|
0.690768 0.690768 -0.213724 |
||||||
|
0.788675 0.57735 -0.211325 |
||||||
|
0.408248 0.816497 -0.408248 |
||||||
|
0.529592 0.735924 -0.421839 |
||||||
|
0.497052 0.809511 -0.31246 |
||||||
|
0.639602 0.639602 -0.426401 |
||||||
|
0.614055 0.720687 -0.321787 |
||||||
|
0.809511 0.497052 -0.31246 |
||||||
|
0.735924 0.529592 -0.421839 |
||||||
|
0.720687 0.614055 -0.321787 |
||||||
|
0.106574 0.64777 -0.754344 |
||||||
|
0.106574 0.754344 -0.64777 |
||||||
|
0.213724 0.690768 -0.690768 |
||||||
|
0.211325 0.788675 -0.57735 |
||||||
|
0.421839 0.529592 -0.735924 |
||||||
|
0.31246 0.497052 -0.809511 |
||||||
|
0.426401 0.639602 -0.639602 |
||||||
|
0.321787 0.614055 -0.720687 |
||||||
|
0.31246 0.809511 -0.497052 |
||||||
|
0.421839 0.735924 -0.529592 |
||||||
|
0.321787 0.720687 -0.614055 |
||||||
|
0.646997 0.539164 -0.539164 |
||||||
|
0.539164 0.646997 -0.539164 |
||||||
|
0.539164 0.539164 -0.646997 |
||||||
|
-0.707107 0 -0.707107 |
||||||
|
-0.55557 0 -0.83147 |
||||||
|
-0.382683 0 -0.92388 |
||||||
|
0 0 -1 |
||||||
|
-0.19509 0 -0.980785 |
||||||
|
0.55557 0 -0.83147 |
||||||
|
0.382683 0 -0.92388 |
||||||
|
0.19509 0 -0.980785 |
||||||
|
0 -0.707107 -0.707107 |
||||||
|
0.106574 -0.64777 -0.754344 |
||||||
|
0.211325 -0.57735 -0.788675 |
||||||
|
0.408248 -0.408248 -0.816497 |
||||||
|
0.31246 -0.497052 -0.809511 |
||||||
|
0.31246 -0.497052 -0.809511 |
||||||
|
0.211325 -0.57735 -0.788675 |
||||||
|
0.106574 -0.64777 -0.754344 |
||||||
|
0.64777 -0.106574 -0.754344 |
||||||
|
0.57735 -0.211325 -0.788675 |
||||||
|
0.57735 -0.211325 -0.788675 |
||||||
|
0.497052 -0.31246 -0.809511 |
||||||
|
0.754344 -0.64777 -0.106574 |
||||||
|
0.64777 -0.754344 -0.106574 |
||||||
|
0.690768 -0.690768 -0.213724 |
||||||
|
0.57735 -0.788675 -0.211325 |
||||||
|
0.735924 -0.529592 -0.421839 |
||||||
|
0.639602 -0.639602 -0.426401 |
||||||
|
0.720687 -0.614055 -0.321787 |
||||||
|
0.408248 -0.816497 -0.408248 |
||||||
|
0.497052 -0.809511 -0.31246 |
||||||
|
0.529592 -0.735924 -0.421839 |
||||||
|
0.614055 -0.720687 -0.321787 |
||||||
|
0.690768 -0.213724 -0.690768 |
||||||
|
0.529592 -0.421839 -0.735924 |
||||||
|
0.639602 -0.426401 -0.639602 |
||||||
|
0.614055 -0.321787 -0.720687 |
||||||
|
0.735924 -0.421839 -0.529592 |
||||||
|
0.720687 -0.321787 -0.614055 |
||||||
|
0.106574 -0.754344 -0.64777 |
||||||
|
0.211325 -0.788675 -0.57735 |
||||||
|
0.213724 -0.690768 -0.690768 |
||||||
|
0.421839 -0.735924 -0.529592 |
||||||
|
0.31246 -0.809511 -0.497052 |
||||||
|
0.426401 -0.639602 -0.639602 |
||||||
|
0.321787 -0.720687 -0.614055 |
||||||
|
0.421839 -0.529592 -0.735924 |
||||||
|
0.321787 -0.614055 -0.720687 |
||||||
|
0.646997 -0.539164 -0.539164 |
||||||
|
0.539164 -0.539164 -0.646997 |
||||||
|
0.539164 -0.646997 -0.539164 |
||||||
|
0 -0.707107 0.707107 |
||||||
|
0.106574 -0.754344 0.64777 |
||||||
|
0 -0.83147 0.55557 |
||||||
|
0.211325 -0.788675 0.57735 |
||||||
|
0.10702 -0.867278 0.486184 |
||||||
|
0 -0.92388 0.382683 |
||||||
|
0.408248 -0.816497 0.408248 |
||||||
|
0.314938 -0.895337 0.314938 |
||||||
|
0.31246 -0.809511 0.497052 |
||||||
|
0.214187 -0.953021 0.214186 |
||||||
|
0.217112 -0.888679 0.403872 |
||||||
|
0 -1 -4.21468e-08 |
||||||
|
0 -0.980785 0.19509 |
||||||
|
0.108374 -0.988185 0.108374 |
||||||
|
0.108113 -0.947388 0.301277 |
||||||
|
0.64777 -0.754344 0.106574 |
||||||
|
0.59069 -0.806898 -7.62273e-09 |
||||||
|
0.57735 -0.788675 0.211325 |
||||||
|
0.437364 -0.874728 -0.208721 |
||||||
|
0.447214 -0.894427 -1.63234e-08 |
||||||
|
0.517007 -0.849313 -0.106637 |
||||||
|
0.517007 -0.849313 -0.106637 |
||||||
|
0.517007 -0.849313 -0.106637 |
||||||
|
0.497052 -0.809511 0.31246 |
||||||
|
0.437364 -0.874728 0.208721 |
||||||
|
0.517007 -0.849313 0.106637 |
||||||
|
0.517007 -0.849313 0.106637 |
||||||
|
0.517007 -0.849313 0.106637 |
||||||
|
0 -0.83147 -0.55557 |
||||||
|
0 -0.92388 -0.382683 |
||||||
|
0.10702 -0.867278 -0.486184 |
||||||
|
0.108374 -0.988185 -0.108374 |
||||||
|
0 -0.980785 -0.19509 |
||||||
|
0.214187 -0.953021 -0.214187 |
||||||
|
0.108113 -0.947388 -0.301277 |
||||||
|
0.314938 -0.895337 -0.314938 |
||||||
|
0.217112 -0.888679 -0.403872 |
||||||
|
0.335068 -0.935925 0.108508 |
||||||
|
0.335068 -0.935925 -0.108508 |
||||||
|
0.219275 -0.975663 -2.28828e-08 |
||||||
|
-0.707107 -0.707107 0 |
||||||
|
-0.64777 -0.754344 0.106574 |
||||||
|
-0.57735 -0.788675 0.211325 |
||||||
|
-0.408248 -0.816497 0.408248 |
||||||
|
-0.497052 -0.809511 0.31246 |
||||||
|
-0.106574 -0.754344 0.64777 |
||||||
|
-0.211325 -0.788675 0.57735 |
||||||
|
-0.31246 -0.809511 0.497052 |
||||||
|
-0.64777 -0.106574 0.754344 |
||||||
|
-0.57735 -0.211325 0.788675 |
||||||
|
-0.408248 -0.408248 0.816497 |
||||||
|
-0.497052 -0.31246 0.809511 |
||||||
|
-0.497052 -0.31246 0.809511 |
||||||
|
-0.57735 -0.211325 0.788675 |
||||||
|
-0.64777 -0.106574 0.754344 |
||||||
|
-0.106574 -0.64777 0.754344 |
||||||
|
-0.211325 -0.57735 0.788675 |
||||||
|
-0.211325 -0.57735 0.788675 |
||||||
|
-0.31246 -0.497052 0.809511 |
||||||
|
0.64777 -0.106574 0.754344 |
||||||
|
0.57735 -0.211325 0.788675 |
||||||
|
0.57735 -0.211325 0.788675 |
||||||
|
0.408248 -0.408248 0.816497 |
||||||
|
0.497052 -0.31246 0.809511 |
||||||
|
0.106574 -0.64777 0.754344 |
||||||
|
0.211325 -0.57735 0.788675 |
||||||
|
0.31246 -0.497052 0.809511 |
||||||
|
0.211325 -0.57735 0.788675 |
||||||
|
0.106574 -0.64777 0.754344 |
||||||
|
0.31246 -0.497052 0.809511 |
||||||
|
0.754344 -0.106574 0.64777 |
||||||
|
0.57735 0.211325 0.788675 |
||||||
|
0.788675 -0.211325 0.57735 |
||||||
|
0.816497 -0.408248 0.408248 |
||||||
|
0.754344 -0.106574 0.64777 |
||||||
|
0.809511 -0.31246 0.497052 |
||||||
|
0.57735 0.211325 0.788675 |
||||||
|
0.211325 0.57735 0.788675 |
||||||
|
0.31246 0.497052 0.809511 |
||||||
|
0.497052 0.31246 0.809511 |
@ -0,0 +1,108 @@ |
|||||||
|
/*
|
||||||
|
* Software License Agreement (BSD License) |
||||||
|
* |
||||||
|
* Copyright (c) 2009, Willow Garage, Inc. |
||||||
|
* All rights reserved. |
||||||
|
* |
||||||
|
* Redistribution and use in source and binary forms, with or without |
||||||
|
* modification, are permitted provided that the following conditions |
||||||
|
* are met: |
||||||
|
* |
||||||
|
* * Redistributions of source code must retain the above copyright |
||||||
|
* notice, this list of conditions and the following disclaimer. |
||||||
|
* * Redistributions 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. |
||||||
|
* * Neither the name of Willow Garage, Inc. nor the names of its |
||||||
|
* contributors may 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 |
||||||
|
* COPYRIGHT OWNER 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. |
||||||
|
* |
||||||
|
*/ |
||||||
|
#include <opencv2/cnn_3dobj.hpp> |
||||||
|
#include <opencv2/viz/vizcore.hpp> |
||||||
|
#include <iostream> |
||||||
|
#include <string> |
||||||
|
#include <stdio.h> |
||||||
|
#include <stdlib.h> |
||||||
|
using namespace cv; |
||||||
|
using namespace std; |
||||||
|
using namespace cv::cnn_3dobj; |
||||||
|
int main(int argc, char *argv[]){ |
||||||
|
float radius = atof(argv[1]); |
||||||
|
int ite_depth = argv[2][0] - '0'; |
||||||
|
cv::cnn_3dobj::IcoSphere ViewSphere(10,ite_depth); |
||||||
|
std::vector<cv::Point3d> campos = ViewSphere.CameraPos; |
||||||
|
std::fstream imglabel; |
||||||
|
std::string plymodel = argv[3]; |
||||||
|
imglabel.open("../data/label_ape.txt"); |
||||||
|
//IcoSphere ViewSphere(16,0);
|
||||||
|
//std::vector<cv::Point3d>* campos = ViewSphere.CameraPos;
|
||||||
|
bool camera_pov = (true); |
||||||
|
/// Create a window
|
||||||
|
viz::Viz3d myWindow("Coordinate Frame"); |
||||||
|
/// Add coordinate axes
|
||||||
|
myWindow.showWidget("Coordinate Widget", viz::WCoordinateSystem()); |
||||||
|
myWindow.setBackgroundColor(viz::Color::gray()); |
||||||
|
|
||||||
|
myWindow.spin(); |
||||||
|
/// Set background color
|
||||||
|
/// Let's assume camera has the following properties
|
||||||
|
Point3d cam_focal_point(0.0f,0.0f,0.0f), cam_y_dir(-0.0f,-0.0f,-1.0f); |
||||||
|
for(int pose = 0; pose < (int)campos.size(); pose++){ |
||||||
|
imglabel << campos.at(pose).x << ' ' << campos.at(pose).y << ' ' << campos.at(pose).z << endl; |
||||||
|
/// We can get the pose of the cam using makeCameraPoses
|
||||||
|
Affine3f cam_pose = viz::makeCameraPose(campos.at(pose)*radius, cam_focal_point, cam_y_dir); |
||||||
|
//Affine3f cam_pose = viz::makeCameraPose(cam_pos, cam_focal_point, cam_y_dir);
|
||||||
|
/// We can get the transformation matrix from camera coordinate system to global using
|
||||||
|
/// - makeTransformToGlobal. We need the axes of the camera
|
||||||
|
Affine3f transform = viz::makeTransformToGlobal(Vec3f(0.0f,-1.0f,0.0f), Vec3f(-1.0f,0.0f,0.0f), Vec3f(0.0f,0.0f,-1.0f), campos.at(pose)); |
||||||
|
/// Create a cloud widget.
|
||||||
|
viz::Mesh objmesh = viz::Mesh::load(plymodel); |
||||||
|
viz::WMesh mesh_widget(objmesh); |
||||||
|
/// Pose of the widget in camera frame
|
||||||
|
Affine3f cloud_pose = Affine3f().translate(Vec3f(3.0f,3.0f,3.0f)); |
||||||
|
/// Pose of the widget in global frame
|
||||||
|
Affine3f cloud_pose_global = transform * cloud_pose; |
||||||
|
/// Visualize camera frame
|
||||||
|
if (!camera_pov) |
||||||
|
{ |
||||||
|
viz::WCameraPosition cpw(1); // Coordinate axes
|
||||||
|
viz::WCameraPosition cpw_frustum(Vec2f(0.889484, 0.523599)); // Camera frustum
|
||||||
|
myWindow.showWidget("CPW", cpw, cam_pose); |
||||||
|
myWindow.showWidget("CPW_FRUSTUM", cpw_frustum, cam_pose); |
||||||
|
} |
||||||
|
|
||||||
|
/// Visualize widget
|
||||||
|
mesh_widget.setRenderingProperty(viz::LINE_WIDTH, 4.0); |
||||||
|
myWindow.showWidget("ape", mesh_widget, cloud_pose_global); |
||||||
|
|
||||||
|
/*viz::WLine axis(cam_focal_point, campos->at(pose)*23);
|
||||||
|
axis.setRenderingProperty(viz::LINE_WIDTH, 4.0); |
||||||
|
myWindow.showWidget("Line Widget", axis);*/ |
||||||
|
|
||||||
|
/// Set the viewer pose to that of camera
|
||||||
|
if (camera_pov) |
||||||
|
myWindow.setViewerPose(cam_pose); |
||||||
|
char* temp = new char; |
||||||
|
sprintf (temp,"%d",pose); |
||||||
|
string filename = temp; |
||||||
|
filename = "../data/images_ape/" + filename; |
||||||
|
filename += ".png"; |
||||||
|
myWindow.saveScreenshot(filename); |
||||||
|
} |
||||||
|
return 1; |
||||||
|
}; |
@ -0,0 +1,119 @@ |
|||||||
|
#include "precomp.hpp" |
||||||
|
using namespace cv; |
||||||
|
using namespace std; |
||||||
|
|
||||||
|
namespace cv{ namespace cnn_3dobj{ |
||||||
|
|
||||||
|
IcoSphere::IcoSphere(float radius_in, int depth_in) |
||||||
|
{ |
||||||
|
|
||||||
|
X = 0.5f; |
||||||
|
Z = 0.5f; |
||||||
|
int radius = radius_in; |
||||||
|
int depth = depth_in; |
||||||
|
X *= radius; |
||||||
|
Z *= radius; |
||||||
|
|
||||||
|
float vdata[12][3] = { { -X, 0.0f, Z }, { X, 0.0f, Z }, |
||||||
|
{ -X, 0.0f, -Z }, { X, 0.0f, -Z }, { 0.0f, Z, X }, { 0.0f, Z, -X }, |
||||||
|
{ 0.0f, -Z, X }, { 0.0f, -Z, -X }, { Z, X, 0.0f }, { -Z, X, 0.0f }, |
||||||
|
{ Z, -X, 0.0f }, { -Z, -X, 0.0f } }; |
||||||
|
|
||||||
|
|
||||||
|
int tindices[20][3] = { { 0, 4, 1 }, { 0, 9, 4 }, { 9, 5, 4 }, |
||||||
|
{ 4, 5, 8 }, { 4, 8, 1 }, { 8, 10, 1 }, { 8, 3, 10 }, { 5, 3, 8 }, |
||||||
|
{ 5, 2, 3 }, { 2, 7, 3 }, { 7, 10, 3 }, { 7, 6, 10 }, { 7, 11, 6 }, |
||||||
|
{ 11, 0, 6 }, { 0, 1, 6 }, { 6, 1, 10 }, { 9, 0, 11 }, |
||||||
|
{ 9, 11, 2 }, { 9, 2, 5 }, { 7, 2, 11 } }; |
||||||
|
|
||||||
|
std::vector<float>* texCoordsList = new std::vector<float>; |
||||||
|
std::vector<int>* indicesList = new std::vector<int>; |
||||||
|
|
||||||
|
// Iterate over points
|
||||||
|
for (int i = 0; i < 20; ++i) { |
||||||
|
|
||||||
|
subdivide(vdata[tindices[i][1]], vdata[tindices[i][2]], |
||||||
|
vdata[tindices[i][3]], depth); |
||||||
|
} |
||||||
|
CameraPos_temp.push_back(CameraPos[0]); |
||||||
|
for (int j = 1; j<int(CameraPos.size()); j++) |
||||||
|
{ |
||||||
|
for (int k = 0; k<j; k++) |
||||||
|
{ |
||||||
|
if (CameraPos.at(k).x==CameraPos.at(j).x && CameraPos.at(k).y==CameraPos.at(j).y && CameraPos.at(k).z==CameraPos.at(j).z) |
||||||
|
break; |
||||||
|
if(k == j-1) |
||||||
|
CameraPos_temp.push_back(CameraPos[j]); |
||||||
|
} |
||||||
|
} |
||||||
|
CameraPos = CameraPos_temp; |
||||||
|
cout << "View points in total: " << CameraPos.size() << endl; |
||||||
|
cout << "The coordinate of view point: " << endl; |
||||||
|
for(int i=0; i < (int)CameraPos.size(); i++) { |
||||||
|
cout << CameraPos.at(i).x <<' '<< CameraPos.at(i).y << ' ' << CameraPos.at(i).z << endl; |
||||||
|
} |
||||||
|
} |
||||||
|
void IcoSphere::norm(float v[]) |
||||||
|
{ |
||||||
|
|
||||||
|
float len = 0; |
||||||
|
|
||||||
|
for (int i = 0; i < 3; ++i) { |
||||||
|
len += v[i] * v[i]; |
||||||
|
} |
||||||
|
|
||||||
|
len = sqrt(len); |
||||||
|
|
||||||
|
for (int i = 0; i < 3; ++i) { |
||||||
|
v[i] /= ((float)len); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
void IcoSphere::add(float v[]) |
||||||
|
{ |
||||||
|
Point3f temp_Campos; |
||||||
|
std::vector<float>* temp = new std::vector<float>; |
||||||
|
for (int k = 0; k < 3; ++k) { |
||||||
|
vertexList.push_back(v[k]); |
||||||
|
vertexNormalsList.push_back(v[k]); |
||||||
|
temp->push_back(v[k]); |
||||||
|
} |
||||||
|
temp_Campos.x = temp->at(0);temp_Campos.y = temp->at(1);temp_Campos.z = temp->at(2); |
||||||
|
CameraPos.push_back(temp_Campos); |
||||||
|
} |
||||||
|
|
||||||
|
void IcoSphere::subdivide(float v1[], float v2[], float v3[], int depth) |
||||||
|
{ |
||||||
|
|
||||||
|
norm(v1); |
||||||
|
norm(v2); |
||||||
|
norm(v3); |
||||||
|
if (depth == 0) { |
||||||
|
add(v1); |
||||||
|
add(v2); |
||||||
|
add(v3); |
||||||
|
return; |
||||||
|
} |
||||||
|
|
||||||
|
float* v12 = new float[3]; |
||||||
|
float* v23 = new float[3]; |
||||||
|
float* v31 = new float[3]; |
||||||
|
|
||||||
|
for (int i = 0; i < 3; ++i) { |
||||||
|
v12[i] = (v1[i] + v2[i]) / 2; |
||||||
|
v23[i] = (v2[i] + v3[i]) / 2; |
||||||
|
v31[i] = (v3[i] + v1[i]) / 2; |
||||||
|
} |
||||||
|
|
||||||
|
norm(v12); |
||||||
|
norm(v23); |
||||||
|
norm(v31); |
||||||
|
|
||||||
|
subdivide(v1, v12, v31, depth - 1); |
||||||
|
subdivide(v2, v23, v12, depth - 1); |
||||||
|
subdivide(v3, v31, v23, depth - 1); |
||||||
|
subdivide(v12, v23, v31, depth - 1); |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
}} |
@ -0,0 +1,53 @@ |
|||||||
|
/*
|
||||||
|
|
||||||
|
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 |
||||||
|
(3-clause BSD License) |
||||||
|
|
||||||
|
Copyright (C) 2013, OpenCV Foundation, 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: |
||||||
|
|
||||||
|
* Redistributions of source code must retain the above copyright notice, |
||||||
|
this list of conditions and the following disclaimer. |
||||||
|
|
||||||
|
* Redistributions 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. |
||||||
|
|
||||||
|
* Neither the names of the copyright holders nor the names of the contributors |
||||||
|
may 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 copyright holders 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. |
||||||
|
|
||||||
|
*/ |
||||||
|
|
||||||
|
#ifndef __OPENCV_CNN_3DOBJ_PRECOMP_HPP__ |
||||||
|
#define __OPENCV_CNN_3DOBJ_PRECOMP_HPP__ |
||||||
|
|
||||||
|
#include <opencv2/cnn_3dobj.hpp> |
||||||
|
#include <opencv2/calib3d.hpp> |
||||||
|
#include <opencv2/viz/vizcore.hpp> |
||||||
|
#include <opencv2/highgui.hpp> |
||||||
|
#include <iostream> |
||||||
|
#include <vector> |
||||||
|
#include <iostream> |
||||||
|
|
||||||
|
#endif |
@ -0,0 +1,110 @@ |
|||||||
|
#include "../include/cnn_3dobj.hpp" |
||||||
|
using namespace cv; |
||||||
|
using namespace std; |
||||||
|
|
||||||
|
namespace cv{ namespace cnn_3dobj{ |
||||||
|
|
||||||
|
IcoSphere::IcoSphere(float radius_in, int depth_in) |
||||||
|
{ |
||||||
|
|
||||||
|
X = 0.525731112119133606f; |
||||||
|
Z = 0.850650808352039932f; |
||||||
|
int radius = radius_in; |
||||||
|
int depth = depth_in; |
||||||
|
X *= radius; |
||||||
|
Z *= radius; |
||||||
|
|
||||||
|
float vdata[12][3] = { { -X, 0.0f, Z }, { X, 0.0f, Z }, |
||||||
|
{ -X, 0.0f, -Z }, { X, 0.0f, -Z }, { 0.0f, Z, X }, { 0.0f, Z, -X }, |
||||||
|
{ 0.0f, -Z, X }, { 0.0f, -Z, -X }, { Z, X, 0.0f }, { -Z, X, 0.0f }, |
||||||
|
{ Z, -X, 0.0f }, { -Z, -X, 0.0f } }; |
||||||
|
|
||||||
|
|
||||||
|
int tindices[20][3] = { { 0, 4, 1 }, { 0, 9, 4 }, { 9, 5, 4 }, |
||||||
|
{ 4, 5, 8 }, { 4, 8, 1 }, { 8, 10, 1 }, { 8, 3, 10 }, { 5, 3, 8 }, |
||||||
|
{ 5, 2, 3 }, { 2, 7, 3 }, { 7, 10, 3 }, { 7, 6, 10 }, { 7, 11, 6 }, |
||||||
|
{ 11, 0, 6 }, { 0, 1, 6 }, { 6, 1, 10 }, { 9, 0, 11 }, |
||||||
|
{ 9, 11, 2 }, { 9, 2, 5 }, { 7, 2, 11 } }; |
||||||
|
|
||||||
|
std::vector<float>* texCoordsList = new std::vector<float>; |
||||||
|
std::vector<int>* indicesList = new std::vector<int>; |
||||||
|
|
||||||
|
// Iterate over points
|
||||||
|
for (int i = 0; i < 20; ++i) { |
||||||
|
|
||||||
|
subdivide(vdata[tindices[i][1]], vdata[tindices[i][2]], |
||||||
|
vdata[tindices[i][3]], depth); |
||||||
|
} |
||||||
|
cout << "View points in total: " << CameraPos->size() << endl; |
||||||
|
cout << "The coordinate of view point: " << endl; |
||||||
|
for(int i=0; i < CameraPos->size(); i++) |
||||||
|
{ |
||||||
|
cout << CameraPos->at(i).x << endl; |
||||||
|
} |
||||||
|
|
||||||
|
} |
||||||
|
void IcoSphere::norm(float v[]) |
||||||
|
{ |
||||||
|
|
||||||
|
float len = 0; |
||||||
|
|
||||||
|
for (int i = 0; i < 3; ++i) { |
||||||
|
len += v[i] * v[i]; |
||||||
|
} |
||||||
|
|
||||||
|
len = sqrt(len); |
||||||
|
|
||||||
|
for (int i = 0; i < 3; ++i) { |
||||||
|
v[i] /= ((float)len/(float)IcoSphere::radius); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
void IcoSphere::add(float v[]) |
||||||
|
{ |
||||||
|
Point3f temp_Campos; |
||||||
|
std::vector<float>* temp = new std::vector<float>; |
||||||
|
for (int k = 0; k < 3; ++k) { |
||||||
|
vertexList->push_back(v[k]); |
||||||
|
vertexNormalsList->push_back(v[k]); |
||||||
|
temp->push_back(v[k]); |
||||||
|
} |
||||||
|
temp_Campos.x = temp->at(0);temp_Campos.y = temp->at(1);temp_Campos.z = temp->at(2); |
||||||
|
CameraPos->push_back(temp_Campos); |
||||||
|
} |
||||||
|
|
||||||
|
void IcoSphere::subdivide(float v1[], float v2[], float v3[], int depth) |
||||||
|
{ |
||||||
|
|
||||||
|
if (depth == 0) { |
||||||
|
add(v1); |
||||||
|
add(v2); |
||||||
|
add(v3); |
||||||
|
return; |
||||||
|
} |
||||||
|
|
||||||
|
float* v12 = new float[3]; |
||||||
|
float* v23 = new float[3]; |
||||||
|
float* v31 = new float[3]; |
||||||
|
|
||||||
|
for (int i = 0; i < 3; ++i) { |
||||||
|
v12[i] = (v1[i] + v2[i]) / 2; |
||||||
|
v23[i] = (v2[i] + v3[i]) / 2; |
||||||
|
v31[i] = (v3[i] + v1[i]) / 2; |
||||||
|
} |
||||||
|
|
||||||
|
norm(v12); |
||||||
|
norm(v23); |
||||||
|
norm(v31); |
||||||
|
|
||||||
|
subdivide(v1, v12, v31, depth - 1); |
||||||
|
subdivide(v2, v23, v12, depth - 1); |
||||||
|
subdivide(v3, v31, v23, depth - 1); |
||||||
|
subdivide(v12, v23, v31, depth - 1); |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
}} |
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -1,5 +0,0 @@ |
|||||||
cmake_minimum_required(VERSION 2.8) |
|
||||||
project( IcoSphere ) |
|
||||||
find_package( OpenCV REQUIRED ) |
|
||||||
add_executable( IcoSphere icosphere.cpp ) |
|
||||||
target_link_libraries( IcoSphere ${OpenCV_LIBS} ) |
|
@ -1,2 +0,0 @@ |
|||||||
Sphere view of 3D objects from .ply files, the windows shows the last view point and press 'q' to exit. |
|
||||||
============================================== |
|
File diff suppressed because it is too large
Load Diff
@ -1,173 +0,0 @@ |
|||||||
#include <opencv2/calib3d/calib3d.hpp> |
|
||||||
#include <opencv2/viz/vizcore.hpp> |
|
||||||
#include <opencv2/highgui/highgui.hpp> |
|
||||||
#include <iostream> |
|
||||||
#include <vector> |
|
||||||
#include <iostream> |
|
||||||
using namespace cv; |
|
||||||
using namespace std; |
|
||||||
|
|
||||||
class IcoSphere { |
|
||||||
|
|
||||||
|
|
||||||
private: |
|
||||||
std::vector<float>* vertexNormalsList = new std::vector<float>; |
|
||||||
std::vector<float>* vertexList = new std::vector<float>; |
|
||||||
float radius; |
|
||||||
float X = 0.525731112119133606f; |
|
||||||
float Z = 0.850650808352039932f; |
|
||||||
void norm(float v[]) |
|
||||||
{ |
|
||||||
|
|
||||||
float len = 0; |
|
||||||
|
|
||||||
for (int i = 0; i < 3; ++i) { |
|
||||||
len += v[i] * v[i]; |
|
||||||
} |
|
||||||
|
|
||||||
len = sqrt(len); |
|
||||||
|
|
||||||
for (int i = 0; i < 3; ++i) { |
|
||||||
v[i] /= ((float)len/(float)radius); |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
void add(float v[]) |
|
||||||
{ |
|
||||||
Point3f temp_Campos; |
|
||||||
std::vector<float>* temp = new std::vector<float>; |
|
||||||
for (int k = 0; k < 3; ++k) { |
|
||||||
vertexList->push_back(v[k]); |
|
||||||
vertexNormalsList->push_back(v[k]); |
|
||||||
temp->push_back(v[k]); |
|
||||||
} |
|
||||||
temp_Campos.x = temp->at(0);temp_Campos.y = temp->at(1);temp_Campos.z = temp->at(2); |
|
||||||
CameraPos->push_back(temp_Campos); |
|
||||||
} |
|
||||||
|
|
||||||
void subdivide(float v1[], float v2[], float v3[], int depth) |
|
||||||
{ |
|
||||||
|
|
||||||
if (depth == 0) { |
|
||||||
add(v1); |
|
||||||
add(v2); |
|
||||||
add(v3); |
|
||||||
return; |
|
||||||
} |
|
||||||
|
|
||||||
float* v12 = new float[3]; |
|
||||||
float* v23 = new float[3]; |
|
||||||
float* v31 = new float[3]; |
|
||||||
|
|
||||||
for (int i = 0; i < 3; ++i) { |
|
||||||
v12[i] = (v1[i] + v2[i]) / 2; |
|
||||||
v23[i] = (v2[i] + v3[i]) / 2; |
|
||||||
v31[i] = (v3[i] + v1[i]) / 2; |
|
||||||
} |
|
||||||
|
|
||||||
norm(v12); |
|
||||||
norm(v23); |
|
||||||
norm(v31); |
|
||||||
|
|
||||||
subdivide(v1, v12, v31, depth - 1); |
|
||||||
subdivide(v2, v23, v12, depth - 1); |
|
||||||
subdivide(v3, v31, v23, depth - 1); |
|
||||||
subdivide(v12, v23, v31, depth - 1); |
|
||||||
} |
|
||||||
|
|
||||||
|
|
||||||
public: |
|
||||||
|
|
||||||
std::vector<cv::Point3d>* CameraPos = new std::vector<cv::Point3d>; |
|
||||||
IcoSphere(float radius_in, int depth_in) |
|
||||||
{ |
|
||||||
|
|
||||||
int radius = radius_in; |
|
||||||
int depth = depth_in; |
|
||||||
X *= radius; |
|
||||||
Z *= radius; |
|
||||||
|
|
||||||
float vdata[12][3] = { { -X, 0.0f, Z }, { X, 0.0f, Z }, |
|
||||||
{ -X, 0.0f, -Z }, { X, 0.0f, -Z }, { 0.0f, Z, X }, { 0.0f, Z, -X }, |
|
||||||
{ 0.0f, -Z, X }, { 0.0f, -Z, -X }, { Z, X, 0.0f }, { -Z, X, 0.0f }, |
|
||||||
{ Z, -X, 0.0f }, { -Z, -X, 0.0f } }; |
|
||||||
|
|
||||||
|
|
||||||
int tindices[20][3] = { { 0, 4, 1 }, { 0, 9, 4 }, { 9, 5, 4 }, |
|
||||||
{ 4, 5, 8 }, { 4, 8, 1 }, { 8, 10, 1 }, { 8, 3, 10 }, { 5, 3, 8 }, |
|
||||||
{ 5, 2, 3 }, { 2, 7, 3 }, { 7, 10, 3 }, { 7, 6, 10 }, { 7, 11, 6 }, |
|
||||||
{ 11, 0, 6 }, { 0, 1, 6 }, { 6, 1, 10 }, { 9, 0, 11 }, |
|
||||||
{ 9, 11, 2 }, { 9, 2, 5 }, { 7, 2, 11 } }; |
|
||||||
|
|
||||||
std::vector<float>* texCoordsList = new std::vector<float>; |
|
||||||
std::vector<int>* indicesList = new std::vector<int>; |
|
||||||
|
|
||||||
// Iterate over points
|
|
||||||
for (int i = 0; i < 20; ++i) { |
|
||||||
|
|
||||||
subdivide(vdata[tindices[i][1]], vdata[tindices[i][2]], |
|
||||||
vdata[tindices[i][3]], depth); |
|
||||||
} |
|
||||||
cout << "View points in total: " << CameraPos->size() << endl; |
|
||||||
cout << "The coordinate of view point: " << endl; |
|
||||||
for(int i=0; i < CameraPos->size(); i++) |
|
||||||
{ |
|
||||||
cout << CameraPos->at(i).x << endl; |
|
||||||
} |
|
||||||
|
|
||||||
} |
|
||||||
}; |
|
||||||
|
|
||||||
int main(){ |
|
||||||
IcoSphere ViewSphere(16,0); |
|
||||||
std::vector<cv::Point3d>* campos = ViewSphere.CameraPos; |
|
||||||
bool camera_pov = (true); |
|
||||||
/// Create a window
|
|
||||||
viz::Viz3d myWindow("Coordinate Frame"); |
|
||||||
|
|
||||||
/// Add coordinate axes
|
|
||||||
myWindow.showWidget("Coordinate Widget", viz::WCoordinateSystem()); |
|
||||||
|
|
||||||
/// Let's assume camera has the following properties
|
|
||||||
Point3d cam_pos(3.0f,0.0f,0.0f), cam_focal_point(0.0f,0.0f,0.0f), cam_y_dir(-0.0f,-0.0f,-1.0f); |
|
||||||
for(int pose = 0; pose < campos->size(); pose++){ |
|
||||||
/// We can get the pose of the cam using makeCameraPose
|
|
||||||
Affine3f cam_pose = viz::makeCameraPose(campos->at(pose), cam_focal_point, cam_y_dir); |
|
||||||
|
|
||||||
/// We can get the transformation matrix from camera coordinate system to global using
|
|
||||||
/// - makeTransformToGlobal. We need the axes of the camera
|
|
||||||
Affine3f transform = viz::makeTransformToGlobal(Vec3f(0.0f,-1.0f,0.0f), Vec3f(-1.0f,0.0f,0.0f), Vec3f(0.0f,0.0f,-1.0f), campos->at(pose)); |
|
||||||
|
|
||||||
/// Create a cloud widget.
|
|
||||||
|
|
||||||
viz::Mesh objmesh = viz::Mesh::load("../ape.ply"); |
|
||||||
viz::WMesh mesh_widget(objmesh); |
|
||||||
|
|
||||||
/// Pose of the widget in camera frame
|
|
||||||
Affine3f cloud_pose = Affine3f().translate(Vec3f(3.0f,3.0f,3.0f)); |
|
||||||
/// Pose of the widget in global frame
|
|
||||||
Affine3f cloud_pose_global = transform * cloud_pose; |
|
||||||
|
|
||||||
/// Visualize camera frame
|
|
||||||
if (!camera_pov) |
|
||||||
{ |
|
||||||
viz::WCameraPosition cpw(0.5); // Coordinate axes
|
|
||||||
viz::WCameraPosition cpw_frustum(Vec2f(0.889484, 0.523599)); // Camera frustum
|
|
||||||
myWindow.showWidget("CPW", cpw, cam_pose); |
|
||||||
myWindow.showWidget("CPW_FRUSTUM", cpw_frustum, cam_pose); |
|
||||||
} |
|
||||||
|
|
||||||
/// Visualize widget
|
|
||||||
mesh_widget.setRenderingProperty(viz::LINE_WIDTH, 4.0); |
|
||||||
myWindow.showWidget("bunny", mesh_widget, transform); |
|
||||||
|
|
||||||
/// Set the viewer pose to that of camera
|
|
||||||
if (camera_pov) |
|
||||||
myWindow.setViewerPose(cam_pose); |
|
||||||
} |
|
||||||
|
|
||||||
/// Start event loop.
|
|
||||||
myWindow.spin(); |
|
||||||
return 1; |
|
||||||
} |
|
||||||
|
|
Loading…
Reference in new issue