├── .gitignore ├── .travis.yml ├── README ├── ar_track_alvar.rosinstall ├── ar_track_alvar ├── CHANGELOG.rst ├── CMakeLists.txt ├── bundles │ ├── table_8_9_10.xml │ ├── tags8and9.xml │ └── truthTableLeg.xml ├── cfg │ └── Params.cfg ├── include │ └── ar_track_alvar │ │ ├── Alvar.h │ │ ├── AlvarException.h │ │ ├── Bitset.h │ │ ├── Camera.h │ │ ├── Capture.h │ │ ├── CaptureDevice.h │ │ ├── CaptureFactory.h │ │ ├── CaptureFactory_private.h │ │ ├── CapturePlugin.h │ │ ├── ConnectedComponents.h │ │ ├── Container3d.h │ │ ├── CvTestbed.h │ │ ├── DirectoryIterator.h │ │ ├── DirectoryIterator_private.h │ │ ├── Draw.h │ │ ├── EC.h │ │ ├── FernImageDetector.h │ │ ├── FernPoseEstimator.h │ │ ├── FileFormat.h │ │ ├── FileFormatUtils.h │ │ ├── Filter.h │ │ ├── GlutViewer.h │ │ ├── IntegralImage.h │ │ ├── Kalman.h │ │ ├── Line.h │ │ ├── Lock.h │ │ ├── Marker.h │ │ ├── MarkerDetector.h │ │ ├── MultiMarker.h │ │ ├── MultiMarkerBundle.h │ │ ├── MultiMarkerFiltered.h │ │ ├── MultiMarkerInitializer.h │ │ ├── Mutex.h │ │ ├── Mutex_private.h │ │ ├── Optimization.h │ │ ├── Platform.h │ │ ├── Plugin.h │ │ ├── Plugin_private.h │ │ ├── Pose.h │ │ ├── Ransac.h │ │ ├── Rotation.h │ │ ├── SfM.h │ │ ├── Shared.h │ │ ├── Threads.h │ │ ├── Threads_private.h │ │ ├── Timer.h │ │ ├── Timer_private.h │ │ ├── Tracker.h │ │ ├── TrackerFeatures.h │ │ ├── TrackerOrientation.h │ │ ├── TrackerPsa.h │ │ ├── TrackerStat.h │ │ ├── TrifocalTensor.h │ │ ├── Uncopyable.h │ │ ├── UnscentedKalman.h │ │ ├── Util.h │ │ └── filter │ │ ├── kinect_filtering.h │ │ └── medianFilter.h ├── launch │ ├── pr2_bundle.launch │ ├── pr2_bundle_no_kinect.launch │ ├── pr2_indiv.launch │ ├── pr2_indiv_no_kinect.launch │ └── pr2_train.launch ├── markers │ ├── Markers_0_to_8.png │ ├── Markers_9_to_17.png │ └── table_8_9_10.png ├── nodes │ ├── FindMarkerBundles.cpp │ ├── FindMarkerBundlesNoKinect.cpp │ ├── IndividualMarkers.cpp │ ├── IndividualMarkersNoKinect.cpp │ └── TrainMarkerBundle.cpp ├── package.xml ├── src │ ├── Alvar.cpp │ ├── Alvar.h.cmake │ ├── Bitset.cpp │ ├── CMakeLists.txt │ ├── Camera.cpp │ ├── CaptureDevice.cpp │ ├── CaptureFactory.cpp │ ├── CaptureFactory_unix.cpp │ ├── CaptureFactory_win.cpp │ ├── ConnectedComponents.cpp │ ├── CvTestbed.cpp │ ├── DirectoryIterator.cpp │ ├── DirectoryIterator_unix.cpp │ ├── DirectoryIterator_win.cpp │ ├── Draw.cpp │ ├── EC.cpp │ ├── FernImageDetector.cpp │ ├── FernPoseEstimator.cpp │ ├── FileFormatUtils.cpp │ ├── Filter.cpp │ ├── GlutViewer.cpp │ ├── IntegralImage.cpp │ ├── Kalman.cpp │ ├── Line.cpp │ ├── Marker.cpp │ ├── MarkerDetector.cpp │ ├── MultiMarker.cpp │ ├── MultiMarkerBundle.cpp │ ├── MultiMarkerFiltered.cpp │ ├── MultiMarkerInitializer.cpp │ ├── Mutex.cpp │ ├── Mutex_unix.cpp │ ├── Mutex_win.cpp │ ├── Optimization.cpp │ ├── Platform.cpp │ ├── Plugin.cpp │ ├── Plugin_unix.cpp │ ├── Plugin_win.cpp │ ├── Pose.cpp │ ├── Ransac.cpp │ ├── Rotation.cpp │ ├── SampleCamCalib.cpp │ ├── SampleCvTestbed.cpp │ ├── SampleFilter.cpp │ ├── SampleIntegralImage.cpp │ ├── SampleLabeling.cpp │ ├── SampleMarkerCreator.cpp │ ├── SampleMarkerDetector.cpp │ ├── SampleMarkerHide.cpp │ ├── SampleMarkerlessCreator.cpp │ ├── SampleMarkerlessDetector.cpp │ ├── SampleMultiMarker.cpp │ ├── SampleMultiMarkerBundle.cpp │ ├── SampleOptimization.cpp │ ├── SamplePointcloud.cpp │ ├── SampleTrack.cpp │ ├── SfM.cpp │ ├── Threads.cpp │ ├── Threads_unix.cpp │ ├── Threads_win.cpp │ ├── Timer.cpp │ ├── Timer_unix.cpp │ ├── Timer_win.cpp │ ├── TrackerFeatures.cpp │ ├── TrackerOrientation.cpp │ ├── TrackerPsa.cpp │ ├── TrackerStat.cpp │ ├── TrifocalTensor.cpp │ ├── UnscentedKalman.cpp │ ├── Util.cpp │ ├── kinect_filtering.cpp │ ├── medianFilter.cpp │ └── platform │ │ ├── CMakeLists.txt │ │ ├── capture_plugin_cmu │ │ ├── CMakeLists.txt │ │ ├── CapturePluginCmu.cpp │ │ └── CapturePluginCmu.h │ │ ├── capture_plugin_dscapture │ │ ├── CMakeLists.txt │ │ ├── CapturePluginDSCapture.cpp │ │ └── CapturePluginDSCapture.h │ │ ├── capture_plugin_file │ │ ├── CMakeLists.txt │ │ ├── CapturePluginFile.cpp │ │ └── CapturePluginFile.h │ │ ├── capture_plugin_highgui │ │ ├── CMakeLists.txt │ │ ├── CapturePluginHighgui.cpp │ │ └── CapturePluginHighgui.h │ │ └── capture_plugin_ptgrey │ │ ├── CMakeLists.txt │ │ ├── CapturePluginPtgrey.cpp │ │ └── CapturePluginPtgrey.h └── test │ ├── marker_abstract.launch.xml │ ├── marker_arg_config-basic.test │ ├── marker_arg_config-full.test │ ├── marker_param_config-basic.test │ ├── marker_param_config-full.test │ ├── points │ ├── test_ar.py │ ├── test_kinect_filtering.cpp │ ├── test_markerdetect.launch.xml │ └── test_points.cpp └── ar_track_alvar_msgs ├── CHANGELOG.rst ├── CMakeLists.txt ├── README ├── msg ├── .gitignore ├── AlvarMarker.msg └── AlvarMarkers.msg └── package.xml /.gitignore: -------------------------------------------------------------------------------- 1 | *.pyc 2 | *.o 3 | *.so 4 | *build 5 | *lib 6 | *msg_gen 7 | *srv_gen 8 | *bin 9 | *~ 10 | src/ar_track_alvar 11 | *.user -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | sudo: required 2 | dist: trusty 3 | language: generic 4 | 5 | compiler: 6 | - gcc 7 | 8 | notifications: 9 | email: 10 | on_failure: always 11 | recipients: 12 | - 130s@2000.jukuin.keio.ac.jp 13 | env: 14 | global: 15 | - ROS_PARALLEL_JOBS=-j4 16 | matrix: 17 | - ROS_DISTRO="kinetic" ROS_REPOSITORY_PATH=http://packages.ros.org/ros/ubuntu USE_DEB=true NOT_TEST_INSTALL=true ABICHECK_URL='github:ros-perception/ar_track_alvar/#kinetic-devel' 18 | - ROS_DISTRO="kinetic" ROS_REPOSITORY_PATH=http://packages.ros.org/ros-shadow-fixed/ubuntu USE_DEB=true NOT_TEST_INSTALL=true VERBOSE_OUTPUT='true' 19 | - ROS_DISTRO="kinetic" PRERELEASE=true 20 | - ROS_DISTRO="lunar" ROS_REPOSITORY_PATH=http://packages.ros.org/ros/ubuntu USE_DEB=true NOT_TEST_INSTALL=true 21 | - ROS_DISTRO="lunar" ROS_REPOSITORY_PATH=http://packages.ros.org/ros-shadow-fixed/ubuntu USE_DEB=true NOT_TEST_INSTALL=true VERBOSE_OUTPUT='true' 22 | - ROS_DISTRO="lunar" PRERELEASE=true 23 | - ROS_DISTRO="melodic" ROS_REPOSITORY_PATH=http://packages.ros.org/ros/ubuntu USE_DEB=true NOT_TEST_INSTALL=true ABICHECK_URL='github:ros-perception/ar_track_alvar/#kinetic-devel' 24 | - ROS_DISTRO="melodic" ROS_REPOSITORY_PATH=http://packages.ros.org/ros-shadow-fixed/ubuntu USE_DEB=true NOT_TEST_INSTALL=true VERBOSE_OUTPUT='true' 25 | - ROS_DISTRO="melodic" PRERELEASE=true 26 | matrix: 27 | allow_failures: 28 | - env: ROS_DISTRO="kinetic" PRERELEASE=true 29 | - env: ROS_DISTRO="lunar" ROS_REPOSITORY_PATH=http://packages.ros.org/ros/ubuntu USE_DEB=true NOT_TEST_INSTALL=true 30 | - env: ROS_DISTRO="lunar" ROS_REPOSITORY_PATH=http://packages.ros.org/ros-shadow-fixed/ubuntu USE_DEB=true NOT_TEST_INSTALL=true VERBOSE_OUTPUT='true' 31 | - env: ROS_DISTRO="lunar" PRERELEASE=true 32 | - env: ROS_DISTRO="melodic" PRERELEASE=true 33 | install: 34 | - git clone https://github.com/ros-industrial/industrial_ci.git .ci_config 35 | 36 | script: 37 | - .ci_config/travis.sh 38 | -------------------------------------------------------------------------------- /README: -------------------------------------------------------------------------------- 1 | See [ROS wiki](http://wiki.ros.org/ar_track_alvar) for the users document. 2 | 3 | 4 | -------------------------------------------------------------------------------- /ar_track_alvar.rosinstall: -------------------------------------------------------------------------------- 1 | - git: {local-name: ar_track_alvar_metapkg, uri: 'https://github.com/sniekum/ar_track_alvar.git', version: indigo-devel} 2 | 3 | -------------------------------------------------------------------------------- /ar_track_alvar/bundles/table_8_9_10.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | -------------------------------------------------------------------------------- /ar_track_alvar/bundles/tags8and9.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /ar_track_alvar/bundles/truthTableLeg.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | -------------------------------------------------------------------------------- /ar_track_alvar/cfg/Params.cfg: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | PACKAGE = "ar_track_alvar" 4 | 5 | from dynamic_reconfigure.parameter_generator_catkin import * 6 | 7 | gen = ParameterGenerator() 8 | 9 | gen.add("enabled", bool_t, 0, "Enable/disable tracking, unsubscribing from camera topic to stop openni processing", True) 10 | gen.add("max_frequency", double_t, 0, "Maximum processing rate; frames coming at a higher rate are discarded", 10.0, 1.0, 30.0) 11 | gen.add("marker_size", double_t, 0, "The width in centimeters of one side of the black square marker border", 10.0, 1.0, 100.0) 12 | gen.add("max_new_marker_error", double_t, 0, "A threshold determining when new markers can be detected under uncertainty", 0.08, 0.0, 2.0) 13 | gen.add("max_track_error", double_t, 0, "A threshold determining how much tracking error can be observed before an tag is considered to have disappeared", 0.2, 0.0, 4.0) 14 | 15 | # Second arg is node name it will run in (doc purposes only), third is generated filename prefix 16 | exit(gen.generate(PACKAGE, "ar_track_alvar_configure", "Params")) 17 | -------------------------------------------------------------------------------- /ar_track_alvar/include/ar_track_alvar/AlvarException.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of ALVAR, A Library for Virtual and Augmented Reality. 3 | * 4 | * Copyright 2007-2012 VTT Technical Research Centre of Finland 5 | * 6 | * Contact: VTT Augmented Reality Team 7 | * 8 | * 9 | * ALVAR is free software; you can redistribute it and/or modify it under the 10 | * terms of the GNU Lesser General Public License as published by the Free 11 | * Software Foundation; either version 2.1 of the License, or (at your option) 12 | * any later version. 13 | * 14 | * This library is distributed in the hope that it will be useful, but WITHOUT 15 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 16 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License 17 | * for more details. 18 | * 19 | * You should have received a copy of the GNU Lesser General Public License 20 | * along with ALVAR; if not, see 21 | * . 22 | */ 23 | 24 | #ifndef ALVAR_EXCEPTION_H 25 | #define ALVAR_EXCEPTION_H 26 | 27 | /** 28 | * \file AlvarException.h 29 | * 30 | * \brief This file implements the ALVAR exception class. 31 | */ 32 | 33 | #include 34 | 35 | namespace alvar { 36 | 37 | /** 38 | * \brief ALVAR exception class. 39 | */ 40 | class AlvarException : public std::runtime_error 41 | { 42 | public: 43 | AlvarException(const char *s) : std::runtime_error(s) { } 44 | }; 45 | 46 | } 47 | 48 | #endif 49 | -------------------------------------------------------------------------------- /ar_track_alvar/include/ar_track_alvar/CaptureDevice.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of ALVAR, A Library for Virtual and Augmented Reality. 3 | * 4 | * Copyright 2007-2012 VTT Technical Research Centre of Finland 5 | * 6 | * Contact: VTT Augmented Reality Team 7 | * 8 | * 9 | * ALVAR is free software; you can redistribute it and/or modify it under the 10 | * terms of the GNU Lesser General Public License as published by the Free 11 | * Software Foundation; either version 2.1 of the License, or (at your option) 12 | * any later version. 13 | * 14 | * This library is distributed in the hope that it will be useful, but WITHOUT 15 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 16 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License 17 | * for more details. 18 | * 19 | * You should have received a copy of the GNU Lesser General Public License 20 | * along with ALVAR; if not, see 21 | * . 22 | */ 23 | 24 | #ifndef CAPTUREDEVICE_H 25 | #define CAPTUREDEVICE_H 26 | 27 | /** 28 | * \file CaptureDevice.h 29 | * 30 | * \brief This file implements a capture device to hold camera information. 31 | */ 32 | 33 | #include "Alvar.h" 34 | 35 | #include 36 | 37 | namespace alvar { 38 | 39 | /** 40 | * \brief CaptureDevice holder for camera information. 41 | * 42 | * CaptureDevice contains the desired backend, the id and description of the camera. 43 | */ 44 | class ALVAR_EXPORT CaptureDevice 45 | { 46 | public: 47 | /** 48 | * \brief Constructor. 49 | * 50 | * \param captureType The type of capture backend. 51 | * \param id The id of the camera. 52 | * \param description A human readable description of the camera. 53 | */ 54 | CaptureDevice(const std::string captureType, const std::string id, const std::string description = ""); 55 | 56 | /** 57 | * \brief Destructor. 58 | */ 59 | ~CaptureDevice(); 60 | 61 | /** 62 | * \brief The type of capture backend. 63 | */ 64 | std::string captureType() const; 65 | 66 | /** 67 | * \brief The id of the camera. 68 | */ 69 | std::string id() const; 70 | 71 | /** 72 | * \brief The description of the camera. 73 | */ 74 | std::string description() const; 75 | 76 | /** 77 | * \brief A unique name consisting of the capture type and the id. 78 | */ 79 | std::string uniqueName() const; 80 | 81 | private: 82 | std::string mCaptureType; 83 | std::string mId; 84 | std::string mDescription; 85 | }; 86 | 87 | } // namespace alvar 88 | 89 | #endif 90 | -------------------------------------------------------------------------------- /ar_track_alvar/include/ar_track_alvar/CaptureFactory_private.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of ALVAR, A Library for Virtual and Augmented Reality. 3 | * 4 | * Copyright 2007-2012 VTT Technical Research Centre of Finland 5 | * 6 | * Contact: VTT Augmented Reality Team 7 | * 8 | * 9 | * ALVAR is free software; you can redistribute it and/or modify it under the 10 | * terms of the GNU Lesser General Public License as published by the Free 11 | * Software Foundation; either version 2.1 of the License, or (at your option) 12 | * any later version. 13 | * 14 | * This library is distributed in the hope that it will be useful, but WITHOUT 15 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 16 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License 17 | * for more details. 18 | * 19 | * You should have received a copy of the GNU Lesser General Public License 20 | * along with ALVAR; if not, see 21 | * . 22 | */ 23 | 24 | #ifndef CAPTUREFACTORY_PRIVATE_H 25 | #define CAPTUREFACTORY_PRIVATE_H 26 | 27 | #include 28 | #include 29 | #include 30 | 31 | #include "Plugin.h" 32 | 33 | namespace alvar { 34 | 35 | class CapturePlugin; 36 | 37 | class CaptureFactoryPrivate 38 | { 39 | public: 40 | CaptureFactoryPrivate(); 41 | ~CaptureFactoryPrivate(); 42 | 43 | void setupPluginPaths(); 44 | void parseEnvironmentVariable(const std::string &variable); 45 | std::string pluginPrefix(); 46 | std::string pluginExtension(); 47 | 48 | void loadPlugins(); 49 | void loadPlugin(const std::string &captureType); 50 | void loadPlugin(const std::string &captureType, const std::string &filename); 51 | CapturePlugin *getPlugin(const std::string &captureType); 52 | 53 | typedef std::vector PluginPathsVector; 54 | PluginPathsVector mPluginPaths; 55 | std::string mPluginPrefix; 56 | std::string mPluginPostfix; 57 | 58 | bool mLoadedAllPlugins; 59 | typedef std::map PluginMap; 60 | PluginMap mPluginMap; 61 | typedef std::map CapturePluginMap; 62 | CapturePluginMap mCapturePluginMap; 63 | }; 64 | 65 | } // namespace alvar 66 | 67 | #endif 68 | -------------------------------------------------------------------------------- /ar_track_alvar/include/ar_track_alvar/CapturePlugin.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of ALVAR, A Library for Virtual and Augmented Reality. 3 | * 4 | * Copyright 2007-2012 VTT Technical Research Centre of Finland 5 | * 6 | * Contact: VTT Augmented Reality Team 7 | * 8 | * 9 | * ALVAR is free software; you can redistribute it and/or modify it under the 10 | * terms of the GNU Lesser General Public License as published by the Free 11 | * Software Foundation; either version 2.1 of the License, or (at your option) 12 | * any later version. 13 | * 14 | * This library is distributed in the hope that it will be useful, but WITHOUT 15 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 16 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License 17 | * for more details. 18 | * 19 | * You should have received a copy of the GNU Lesser General Public License 20 | * along with ALVAR; if not, see 21 | * . 22 | */ 23 | 24 | #ifndef CAPTUREPLUGIN_H 25 | #define CAPTUREPLUGIN_H 26 | 27 | /** 28 | * \file CapturePlugin.h 29 | * 30 | * \brief This file implements a capture plugin interface. 31 | */ 32 | 33 | #include "Alvar.h" 34 | #include "CaptureDevice.h" 35 | 36 | namespace alvar { 37 | 38 | /** 39 | * \brief CapturePlugin interface that plugins must implement. 40 | * 41 | * All plugins must implement the CapturePlugin interface. When the plugin is loaded, 42 | * the CapturePlugin implementation will register itself with the CaptureFactory. 43 | */ 44 | class ALVAR_EXPORT CapturePlugin 45 | { 46 | public: 47 | /** 48 | * \brief Constructor. 49 | * 50 | * \param captureType A unique identifier for the capture plugin. 51 | */ 52 | CapturePlugin(const std::string &captureType) 53 | : mCaptureType(captureType) 54 | { 55 | } 56 | 57 | /** 58 | * \brief Destructor. 59 | */ 60 | virtual ~CapturePlugin() {}; 61 | 62 | /** 63 | * \brief Vector of CaptureDevices. 64 | */ 65 | typedef std::vector CaptureDeviceVector; 66 | 67 | /** 68 | * \brief Enumerate capture devices currently available. 69 | * 70 | * \return A vector of CaptureDevice objects that are currently available. 71 | */ 72 | virtual CaptureDeviceVector enumerateDevices() = 0; 73 | 74 | /** 75 | * \brief Create Capture class. Transfers onwership to the caller. 76 | * 77 | * \param captureDevice Information of which camera to create. 78 | * \return A new Capture class for which the caller takes ownership. 79 | */ 80 | virtual Capture *createCapture(const CaptureDevice captureDevice) = 0; 81 | 82 | protected: 83 | std::string mCaptureType; 84 | }; 85 | 86 | } // namespace alvar 87 | 88 | #endif 89 | -------------------------------------------------------------------------------- /ar_track_alvar/include/ar_track_alvar/ConnectedComponents.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of ALVAR, A Library for Virtual and Augmented Reality. 3 | * 4 | * Copyright 2007-2012 VTT Technical Research Centre of Finland 5 | * 6 | * Contact: VTT Augmented Reality Team 7 | * 8 | * 9 | * ALVAR is free software; you can redistribute it and/or modify it under the 10 | * terms of the GNU Lesser General Public License as published by the Free 11 | * Software Foundation; either version 2.1 of the License, or (at your option) 12 | * any later version. 13 | * 14 | * This library is distributed in the hope that it will be useful, but WITHOUT 15 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 16 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License 17 | * for more details. 18 | * 19 | * You should have received a copy of the GNU Lesser General Public License 20 | * along with ALVAR; if not, see 21 | * . 22 | */ 23 | 24 | #ifndef CONNECTEDCOMPONENTS_H 25 | #define CONNECTEDCOMPONENTS_H 26 | 27 | /** 28 | * \file ConnectedComponents.h 29 | * 30 | * \brief This file implements connected component labeling. 31 | */ 32 | 33 | #include "Alvar.h" 34 | #include "Util.h" 35 | #include "Line.h" 36 | #include "Camera.h" 37 | 38 | namespace alvar { 39 | 40 | /** 41 | * \brief Connected components labeling methods. 42 | */ 43 | enum ALVAR_EXPORT LabelingMethod 44 | { 45 | CVSEQ 46 | }; 47 | 48 | /** 49 | * \brief Base class for labeling connected components from binary image. 50 | */ 51 | class ALVAR_EXPORT Labeling 52 | { 53 | 54 | protected : 55 | 56 | Camera *cam; 57 | int thresh_param1, thresh_param2; 58 | 59 | public : 60 | 61 | /** 62 | * \brief Pointer to grayscale image that is thresholded for labeling. 63 | */ 64 | IplImage *gray; 65 | /** 66 | * \brief Pointer to binary image that is then labeled. 67 | */ 68 | IplImage *bw; 69 | 70 | /** 71 | * \brief Vector of 4-length vectors where the corners of detected blobs are stored. 72 | */ 73 | std::vector > blob_corners; 74 | 75 | /** 76 | * \brief Two alternatives for thresholding the gray image. ADAPT (adaptive threshold) is only supported currently. 77 | */ 78 | enum ThresholdMethod 79 | { 80 | THRESH, 81 | ADAPT 82 | }; 83 | 84 | /** Constructor */ 85 | Labeling(); 86 | 87 | /** Destructor*/ 88 | virtual ~Labeling(); 89 | 90 | /** 91 | * \brief Sets the camera object that is used to correct lens distortions. 92 | */ 93 | void SetCamera(Camera* camera) {cam = camera;} 94 | 95 | /** 96 | * \brief Labels image and filters blobs to obtain square-shaped objects from the scene. 97 | */ 98 | virtual void LabelSquares(IplImage* image, bool visualize=false) = 0; 99 | 100 | bool CheckBorder(CvSeq* contour, int width, int height); 101 | 102 | void SetThreshParams(int param1, int param2) 103 | { 104 | thresh_param1 = param1; 105 | thresh_param2 = param2; 106 | } 107 | }; 108 | 109 | /** 110 | * \brief Labeling class that uses OpenCV routines to find connected components. 111 | */ 112 | class ALVAR_EXPORT LabelingCvSeq : public Labeling 113 | { 114 | 115 | protected : 116 | 117 | int _n_blobs; 118 | int _min_edge; 119 | int _min_area; 120 | bool detect_pose_grayscale; 121 | 122 | CvMemStorage* storage; 123 | 124 | public: 125 | 126 | LabelingCvSeq(); 127 | ~LabelingCvSeq(); 128 | 129 | void SetOptions(bool _detect_pose_grayscale=false); 130 | 131 | void LabelSquares(IplImage* image, bool visualize=false); 132 | 133 | // TODO: Releases memory inside, cannot return CvSeq* 134 | CvSeq* LabelImage(IplImage* image, int min_size, bool approx=false); 135 | }; 136 | 137 | } // namespace alvar 138 | 139 | #endif 140 | -------------------------------------------------------------------------------- /ar_track_alvar/include/ar_track_alvar/DirectoryIterator.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of ALVAR, A Library for Virtual and Augmented Reality. 3 | * 4 | * Copyright 2007-2012 VTT Technical Research Centre of Finland 5 | * 6 | * Contact: VTT Augmented Reality Team 7 | * 8 | * 9 | * ALVAR is free software; you can redistribute it and/or modify it under the 10 | * terms of the GNU Lesser General Public License as published by the Free 11 | * Software Foundation; either version 2.1 of the License, or (at your option) 12 | * any later version. 13 | * 14 | * This library is distributed in the hope that it will be useful, but WITHOUT 15 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 16 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License 17 | * for more details. 18 | * 19 | * You should have received a copy of the GNU Lesser General Public License 20 | * along with ALVAR; if not, see 21 | * . 22 | */ 23 | 24 | #ifndef DIRECTORYITERATOR_H 25 | #define DIRECTORYITERATOR_H 26 | 27 | /** 28 | * \file DirectoryIterator.h 29 | * 30 | * \brief This file implements a directory iterator. 31 | */ 32 | 33 | #include "Alvar.h" 34 | 35 | #include 36 | 37 | namespace alvar { 38 | 39 | class DirectoryIteratorPrivate; 40 | 41 | /** 42 | * \brief DirectoryIterator for iterating over files and directories. 43 | * 44 | * DirectoryIterator class for iterating over files and directories on the filesystem. 45 | */ 46 | class ALVAR_EXPORT DirectoryIterator 47 | { 48 | public: 49 | /** 50 | * \brief Constructor. 51 | * 52 | * \param path The path on the filesystem to iterate. 53 | */ 54 | DirectoryIterator(const std::string &path); 55 | 56 | /** 57 | * \brief Destructor. 58 | */ 59 | ~DirectoryIterator(); 60 | 61 | /** 62 | * \brief Verifies if another entry exist in the directory. 63 | */ 64 | bool hasNext(); 65 | 66 | /** 67 | * \brief Advances the iterator and returns the name of the next entry. 68 | */ 69 | std::string next(); 70 | 71 | /** 72 | * \brief Returns the name of the current entry. 73 | */ 74 | std::string currentEntry(); 75 | 76 | /** 77 | * \brief Returns the path of the current entry. 78 | * 79 | * This appends the name of the current entry to the path of the directory that 80 | * is being iterated. 81 | */ 82 | std::string currentPath(); 83 | 84 | private: 85 | DirectoryIteratorPrivate *d; 86 | }; 87 | 88 | } // namespace alvar 89 | 90 | #endif 91 | -------------------------------------------------------------------------------- /ar_track_alvar/include/ar_track_alvar/DirectoryIterator_private.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of ALVAR, A Library for Virtual and Augmented Reality. 3 | * 4 | * Copyright 2007-2012 VTT Technical Research Centre of Finland 5 | * 6 | * Contact: VTT Augmented Reality Team 7 | * 8 | * 9 | * ALVAR is free software; you can redistribute it and/or modify it under the 10 | * terms of the GNU Lesser General Public License as published by the Free 11 | * Software Foundation; either version 2.1 of the License, or (at your option) 12 | * any later version. 13 | * 14 | * This library is distributed in the hope that it will be useful, but WITHOUT 15 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 16 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License 17 | * for more details. 18 | * 19 | * You should have received a copy of the GNU Lesser General Public License 20 | * along with ALVAR; if not, see 21 | * . 22 | */ 23 | 24 | #ifndef PLUGIN_PRIVATE_H 25 | #define PLUGIN_PRIVATE_H 26 | 27 | #include 28 | 29 | namespace alvar { 30 | 31 | class DirectoryIteratorPrivateData; 32 | 33 | class DirectoryIteratorPrivate 34 | { 35 | public: 36 | DirectoryIteratorPrivate(const std::string &path); 37 | ~DirectoryIteratorPrivate(); 38 | bool hasNext(); 39 | std::string next(); 40 | void skip(); 41 | 42 | DirectoryIteratorPrivateData *d; 43 | std::string mDirectory; 44 | std::string mEntry; 45 | bool mValid; 46 | }; 47 | 48 | } // namespace alvar 49 | 50 | #endif 51 | -------------------------------------------------------------------------------- /ar_track_alvar/include/ar_track_alvar/FernImageDetector.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of ALVAR, A Library for Virtual and Augmented Reality. 3 | * 4 | * Copyright 2007-2012 VTT Technical Research Centre of Finland 5 | * 6 | * Contact: VTT Augmented Reality Team 7 | * 8 | * 9 | * ALVAR is free software; you can redistribute it and/or modify it under the 10 | * terms of the GNU Lesser General Public License as published by the Free 11 | * Software Foundation; either version 2.1 of the License, or (at your option) 12 | * any later version. 13 | * 14 | * This library is distributed in the hope that it will be useful, but WITHOUT 15 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 16 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License 17 | * for more details. 18 | * 19 | * You should have received a copy of the GNU Lesser General Public License 20 | * along with ALVAR; if not, see 21 | * . 22 | */ 23 | 24 | #ifndef FERNIMAGEDETECTOR_H 25 | #define FERNIMAGEDETECTOR_H 26 | 27 | /** 28 | * \file FernImageDetector.h 29 | * 30 | * \brief This file implements a Fern-based image detector. 31 | */ 32 | 33 | #include 34 | #include 35 | #include 36 | #include 37 | 38 | #include "cv.h" 39 | #include "highgui.h" 40 | #include "cvaux.h" 41 | 42 | #include "Camera.h" 43 | #include "EC.h" 44 | 45 | using namespace cv; 46 | 47 | namespace alvar{ 48 | 49 | /** 50 | * \brief FernClassifier subclass that implements binary reading and writting. 51 | */ 52 | class FernClassifierWrapper : public FernClassifier 53 | { 54 | public: 55 | FernClassifierWrapper(); 56 | FernClassifierWrapper(const FileNode &fileNode); 57 | FernClassifierWrapper(const vector > &points, 58 | const vector &referenceImages, 59 | const vector > &labels = vector >(), 60 | int _nclasses = 0, 61 | int _patchSize = PATCH_SIZE, 62 | int _signatureSize = DEFAULT_SIGNATURE_SIZE, 63 | int _nstructs = DEFAULT_STRUCTS, 64 | int _structSize = DEFAULT_STRUCT_SIZE, 65 | int _nviews = DEFAULT_VIEWS, 66 | int _compressionMethod = COMPRESSION_NONE, 67 | const PatchGenerator &patchGenerator = PatchGenerator()); 68 | virtual ~FernClassifierWrapper(); 69 | 70 | virtual void readBinary(std::fstream &stream); 71 | virtual void writeBinary(std::fstream &stream) const; 72 | }; 73 | 74 | /** 75 | * \brief Image detector based on a Fern classifier. 76 | */ 77 | class ALVAR_EXPORT FernImageDetector 78 | { 79 | public: 80 | FernImageDetector(const bool visualize = false); 81 | ~FernImageDetector(); 82 | 83 | void imagePoints(vector &points); 84 | void modelPoints(vector &points, bool normalize = true); 85 | 86 | cv::Size size(); 87 | cv::Mat homography(); 88 | double inlierRatio(); 89 | 90 | void train(const std::string &filename); 91 | void train(Mat &image); 92 | void findFeatures(Mat &image, bool planeAssumption = true); 93 | 94 | bool read(const std::string &filename, const bool binary = true); 95 | bool write(const std::string &filename, const bool binary = true); 96 | 97 | private: 98 | PatchGenerator mPatchGenerator; 99 | LDetector mLDetector; 100 | std::vector mClassifier; 101 | 102 | vector mKeyPoints; 103 | vector mImagePoints; 104 | vector mModelPoints; 105 | 106 | bool mVisualize; 107 | std::vector mObjects; 108 | cv::Size mSize; 109 | cv::Mat mCorrespondences; 110 | cv::Mat mHomography; 111 | double mInlierRatio; 112 | }; 113 | 114 | } // namespace alvar 115 | 116 | #endif 117 | -------------------------------------------------------------------------------- /ar_track_alvar/include/ar_track_alvar/FernPoseEstimator.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of ALVAR, A Library for Virtual and Augmented Reality. 3 | * 4 | * Copyright 2007-2012 VTT Technical Research Centre of Finland 5 | * 6 | * Contact: VTT Augmented Reality Team 7 | * 8 | * 9 | * ALVAR is free software; you can redistribute it and/or modify it under the 10 | * terms of the GNU Lesser General Public License as published by the Free 11 | * Software Foundation; either version 2.1 of the License, or (at your option) 12 | * any later version. 13 | * 14 | * This library is distributed in the hope that it will be useful, but WITHOUT 15 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 16 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License 17 | * for more details. 18 | * 19 | * You should have received a copy of the GNU Lesser General Public License 20 | * along with ALVAR; if not, see 21 | * . 22 | */ 23 | 24 | #ifndef FERNPOSEESTIMATOR_H 25 | #define FERNPOSEESTIMATOR_H 26 | 27 | /** 28 | * \file FernPoseEstimator.h 29 | * 30 | * \brief This file implements a pose estimator for the Fern-based image 31 | * detector. 32 | */ 33 | 34 | #include 35 | #include 36 | 37 | #include "cv.h" 38 | 39 | #include "Pose.h" 40 | #include "Camera.h" 41 | #include "EC.h" 42 | 43 | namespace alvar 44 | { 45 | 46 | /** 47 | * \brief Pose estimation class for FernImageDetector. 48 | */ 49 | class ALVAR_EXPORT FernPoseEstimator 50 | { 51 | 52 | public: 53 | FernPoseEstimator(); 54 | ~FernPoseEstimator(); 55 | 56 | Pose pose() const; 57 | Camera camera() const; 58 | 59 | bool setCalibration(const std::string &filename, int width, int height); 60 | void setResolution(int width, int height); 61 | 62 | typedef std::vector ImagePointVector; 63 | typedef std::vector ModelPointVector; 64 | typedef std::map ExternalContainerMap; 65 | void calculateFromPointCorrespondences(ModelPointVector &mpts, ImagePointVector &ipts); 66 | void updateFromTrackedPoints(ExternalContainerMap &container); 67 | void extractPlaneCoordinates(ExternalContainerMap &container); 68 | 69 | private: 70 | Pose mPose; 71 | Camera mCamera; 72 | CameraEC mCameraEC; 73 | }; 74 | 75 | } // namespace alvar 76 | 77 | #endif 78 | -------------------------------------------------------------------------------- /ar_track_alvar/include/ar_track_alvar/FileFormat.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of ALVAR, A Library for Virtual and Augmented Reality. 3 | * 4 | * Copyright 2007-2012 VTT Technical Research Centre of Finland 5 | * 6 | * Contact: VTT Augmented Reality Team 7 | * 8 | * 9 | * ALVAR is free software; you can redistribute it and/or modify it under the 10 | * terms of the GNU Lesser General Public License as published by the Free 11 | * Software Foundation; either version 2.1 of the License, or (at your option) 12 | * any later version. 13 | * 14 | * This library is distributed in the hope that it will be useful, but WITHOUT 15 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 16 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License 17 | * for more details. 18 | * 19 | * You should have received a copy of the GNU Lesser General Public License 20 | * along with ALVAR; if not, see 21 | * . 22 | */ 23 | 24 | #ifndef FILEFORMAT_H 25 | #define FILEFORMAT_H 26 | 27 | /** 28 | * \file FileFormat.h 29 | * 30 | * \brief This file defines various file formats. 31 | */ 32 | 33 | namespace alvar { 34 | 35 | /** 36 | * File format enumeration used when reading / writing configuration 37 | * files. 38 | */ 39 | typedef enum { 40 | /** 41 | * \brief Default file format. 42 | * 43 | * Format is either OPENCV, TEXT or XML depending on load/store function used. 44 | */ 45 | FILE_FORMAT_DEFAULT, 46 | 47 | /** 48 | * \brief File format written with cvWrite. 49 | * 50 | * File contents depend on the specific load/store function used. 51 | */ 52 | FILE_FORMAT_OPENCV, 53 | 54 | /** 55 | * \brief Plain ASCII text file format. 56 | * 57 | * File contents depend on the specific load/store function used. 58 | */ 59 | FILE_FORMAT_TEXT, 60 | 61 | /** 62 | * \brief XML file format. 63 | * 64 | * XML schema depends on the specific load/store function used. 65 | */ 66 | FILE_FORMAT_XML 67 | 68 | } FILE_FORMAT; 69 | } 70 | 71 | #endif //FILEFORMAT_H 72 | -------------------------------------------------------------------------------- /ar_track_alvar/include/ar_track_alvar/FileFormatUtils.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of ALVAR, A Library for Virtual and Augmented Reality. 3 | * 4 | * Copyright 2007-2012 VTT Technical Research Centre of Finland 5 | * 6 | * Contact: VTT Augmented Reality Team 7 | * 8 | * 9 | * ALVAR is free software; you can redistribute it and/or modify it under the 10 | * terms of the GNU Lesser General Public License as published by the Free 11 | * Software Foundation; either version 2.1 of the License, or (at your option) 12 | * any later version. 13 | * 14 | * This library is distributed in the hope that it will be useful, but WITHOUT 15 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 16 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License 17 | * for more details. 18 | * 19 | * You should have received a copy of the GNU Lesser General Public License 20 | * along with ALVAR; if not, see 21 | * . 22 | */ 23 | 24 | #ifndef FILEFORMATUTILS_H 25 | #define FILEFORMATUTILS_H 26 | 27 | /** 28 | * \file FileFormatUtils.h 29 | * 30 | * \brief This file implements utilities that assist in reading and writing 31 | * files. 32 | */ 33 | 34 | #include "Alvar.h" 35 | #include "cv.h" 36 | #include "tinyxml.h" 37 | 38 | namespace alvar { 39 | 40 | /** \brief Utility functions for file reading / writing. 41 | */ 42 | class ALVAR_EXPORT FileFormatUtils { 43 | private: 44 | /** 45 | * \brief Reads matrix type, rows and cols from XML element. 46 | * \return true if XML element appears to be valid; otherwise false. 47 | */ 48 | static bool decodeXMLMatrix(const TiXmlElement *xml_matrix, int &type, int &rows, int &cols); 49 | 50 | public: 51 | 52 | /** \brief Allocates CvMat of a correct type and size. 53 | * \param xml_matrix alvar:matrix element. 54 | * \return CvMat that has the correct size for \e parseXMLMatrix. 55 | */ 56 | static CvMat* allocateXMLMatrix(const TiXmlElement *xml_matrix); 57 | 58 | /** \brief Reads contents of alvar:matrix into CvMat. 59 | * 60 | * Parsing fails if the matrix is not the same type or does not have 61 | * the same number of rows and columns as the XML element. 62 | * 63 | * \param xml_matrix alvar:matrix element. If NULL no parsing is done and 64 | * false is returned. 65 | * \param matrix CvMat that has the correct size, populated with data in 66 | * the xml_matrix. 67 | * \return true if matrix was successfully parsed; otherwise false. 68 | */ 69 | static bool parseXMLMatrix(const TiXmlElement *xml_matrix, CvMat *matrix); 70 | 71 | /** \brief Allocates new XML element and populates it with a CvMat data. 72 | * 73 | * The returned element needs to be deallocated by the caller. 74 | * 75 | * \param element_name Name of the allocated tiXmlElement. 76 | * \param matrix Data that is written into the returned XML element. 77 | * \return Newly allocated TiXmlElement. 78 | */ 79 | static TiXmlElement* createXMLMatrix(const char* element_name, const CvMat *matrix); 80 | }; 81 | } 82 | 83 | #endif //FILEFORMATUTILS_H 84 | -------------------------------------------------------------------------------- /ar_track_alvar/include/ar_track_alvar/GlutViewer.h: -------------------------------------------------------------------------------- 1 | #ifndef _GLUTVIEWER_H_ 2 | #define _GLUTVIEWER_H_ 3 | 4 | #include 5 | 6 | #ifdef WIN32 7 | #include 8 | #include 9 | #include 10 | #include 11 | #else 12 | #include 13 | #include 14 | #include 15 | #endif 16 | 17 | class Drawable 18 | { 19 | public: 20 | Drawable(double _scale=1, double _r=1, double _g=1, double _b=1); 21 | 22 | void SetScale(double _scale); 23 | void SetColor(double _r=1, double _g=1, double _b=1); 24 | 25 | virtual void Draw(); 26 | virtual void DrawAxis(double scale, double color[3]); 27 | 28 | void SetGLMatTraQuat(double *tra, double *quat, bool flip=false); 29 | void SetGLMatTraRod(double *tra, double *rod); 30 | 31 | double scale; 32 | double color[3]; 33 | double gl_mat[16]; 34 | 35 | protected: 36 | double ax_len; 37 | }; 38 | 39 | namespace GlutViewer 40 | { 41 | void Draw(); 42 | void Exit(); 43 | void Start(int argc, char** argv, int w, int h, float r=300.0); 44 | void Reshape(int w, int h); 45 | 46 | void DrawableClear(); 47 | void DrawableAdd(Drawable* item); 48 | 49 | void DrawVr(); 50 | void DrawAr(); 51 | void DrawFloor(); 52 | void DrawContent(); 53 | void DrawAxis(float scale); 54 | void Mouse(int button, int state, int x, int y); 55 | void Motion(int x, int y); 56 | void SetGlProjectionMatrix(double p[16]); 57 | void SetGlModelviewMatrix(double p[16]); 58 | void KeyCallback(int key, int x, int y); 59 | 60 | void SetVideo(const IplImage* _image); 61 | void DrawVideo(); 62 | 63 | double GetXOffset(); 64 | double GetYOffset(); 65 | } 66 | 67 | #endif 68 | -------------------------------------------------------------------------------- /ar_track_alvar/include/ar_track_alvar/Line.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of ALVAR, A Library for Virtual and Augmented Reality. 3 | * 4 | * Copyright 2007-2012 VTT Technical Research Centre of Finland 5 | * 6 | * Contact: VTT Augmented Reality Team 7 | * 8 | * 9 | * ALVAR is free software; you can redistribute it and/or modify it under the 10 | * terms of the GNU Lesser General Public License as published by the Free 11 | * Software Foundation; either version 2.1 of the License, or (at your option) 12 | * any later version. 13 | * 14 | * This library is distributed in the hope that it will be useful, but WITHOUT 15 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 16 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License 17 | * for more details. 18 | * 19 | * You should have received a copy of the GNU Lesser General Public License 20 | * along with ALVAR; if not, see 21 | * . 22 | */ 23 | 24 | #ifndef _LINE_H 25 | #define _LINE_H 26 | 27 | /** 28 | * \file Line.h 29 | * 30 | * \brief This file implements a parametrized line. 31 | */ 32 | 33 | #include "Alvar.h" 34 | #include "Util.h" 35 | 36 | namespace alvar { 37 | 38 | /** 39 | * \brief Struct representing a line. The line is parametrized by its center and direction vector. 40 | */ 41 | struct ALVAR_EXPORT Line 42 | { 43 | /** 44 | * \brief Constructor. 45 | * \param params params[0] and params[1] are the x and y components of the direction vector, params[2] and params[3] are the x and y coordinates of the line center. 46 | */ 47 | Line(float params[4]); 48 | Line() 49 | {} 50 | 51 | /** 52 | * \brief Line center. 53 | */ 54 | PointDouble c; // center 55 | /** 56 | * \brief Direction vector. 57 | */ 58 | PointDouble s; // direction vector 59 | }; 60 | 61 | /** 62 | * \brief Fit lines to vector of points. 63 | * \param lines Resulting set of lines. 64 | * \param corners Index list of line breaks. 65 | * \param edge Vector of points (pixels) where the line is fitted. 66 | * \param grey In the future, we may want to fit lines directly to grayscale image instead of thresholded edge. 67 | */ 68 | int ALVAR_EXPORT FitLines(std::vector &lines, 69 | const std::vector& corners, 70 | const std::vector& edge, 71 | IplImage *grey=0); 72 | 73 | /** 74 | * \brief Calculates an intersection point of two lines. 75 | * \param l1 First line. 76 | * \param l2 Second line. 77 | * \return Intersection point. 78 | */ 79 | PointDouble ALVAR_EXPORT Intersection(const Line& l1, const Line& l2); 80 | 81 | } // namespace alvar 82 | 83 | #endif 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | -------------------------------------------------------------------------------- /ar_track_alvar/include/ar_track_alvar/Lock.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of ALVAR, A Library for Virtual and Augmented Reality. 3 | * 4 | * Copyright 2007-2012 VTT Technical Research Centre of Finland 5 | * 6 | * Contact: VTT Augmented Reality Team 7 | * 8 | * 9 | * ALVAR is free software; you can redistribute it and/or modify it under the 10 | * terms of the GNU Lesser General Public License as published by the Free 11 | * Software Foundation; either version 2.1 of the License, or (at your option) 12 | * any later version. 13 | * 14 | * This library is distributed in the hope that it will be useful, but WITHOUT 15 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 16 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License 17 | * for more details. 18 | * 19 | * You should have received a copy of the GNU Lesser General Public License 20 | * along with ALVAR; if not, see 21 | * . 22 | */ 23 | 24 | #ifndef LOCK_H 25 | #define LOCK_H 26 | 27 | /** 28 | * \file Lock.h 29 | * 30 | * \brief This file implements a lock to simplify mutex handling. 31 | */ 32 | 33 | #include "Alvar.h" 34 | #include "Mutex.h" 35 | #include "Uncopyable.h" 36 | 37 | namespace alvar { 38 | 39 | /** 40 | * \brief Lock for simplifying mutex handling. 41 | * 42 | * Lock class for simplifying mutex handling. Simply pass a mutex to the 43 | * constructor and the mutex will be locked. When the lock is destroyed, the 44 | * mutex will be unlocked. 45 | */ 46 | class ALVAR_EXPORT Lock : private Uncopyable 47 | { 48 | public: 49 | /** 50 | * \brief Constructor. 51 | * 52 | * \param mutex The mutex to lock. 53 | */ 54 | Lock(Mutex *mutex) 55 | : mMutex(mutex) 56 | { 57 | mMutex->lock(); 58 | } 59 | 60 | /** 61 | * \brief Destructor. 62 | */ 63 | ~Lock() 64 | { 65 | mMutex->unlock(); 66 | } 67 | 68 | private: 69 | Mutex *mMutex; 70 | }; 71 | 72 | } // namespace alvar 73 | 74 | #endif 75 | -------------------------------------------------------------------------------- /ar_track_alvar/include/ar_track_alvar/MultiMarkerBundle.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of ALVAR, A Library for Virtual and Augmented Reality. 3 | * 4 | * Copyright 2007-2012 VTT Technical Research Centre of Finland 5 | * 6 | * Contact: VTT Augmented Reality Team 7 | * 8 | * 9 | * ALVAR is free software; you can redistribute it and/or modify it under the 10 | * terms of the GNU Lesser General Public License as published by the Free 11 | * Software Foundation; either version 2.1 of the License, or (at your option) 12 | * any later version. 13 | * 14 | * This library is distributed in the hope that it will be useful, but WITHOUT 15 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 16 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License 17 | * for more details. 18 | * 19 | * You should have received a copy of the GNU Lesser General Public License 20 | * along with ALVAR; if not, see 21 | * . 22 | */ 23 | 24 | #ifndef MULTIMARKERBUNDLE_H 25 | #define MULTIMARKERBUNDLE_H 26 | 27 | /** 28 | * \file MultiMarkerBundle.h 29 | * 30 | * \brief This file implements an algorithm to create a multi-marker 31 | * field configuration. 32 | */ 33 | 34 | #include "MultiMarker.h" 35 | #include "Optimization.h" 36 | #include 37 | 38 | namespace alvar { 39 | 40 | /** 41 | * \brief Multi marker that uses bundle adjustment to refine the 3D positions of the markers (point cloud). 42 | * 43 | * This can be initialized by using e.g. MultiMarkerAverage class. 44 | */ 45 | class ALVAR_EXPORT MultiMarkerBundle : public MultiMarker 46 | { 47 | protected: 48 | int optimization_keyframes; 49 | int optimization_markers; 50 | double optimization_error; 51 | bool optimizing; 52 | std::vector camera_poses; // Estimated camera pose for every frame 53 | std::map measurements; // 54 | int measurements_index(int frame, int marker_id, int marker_corner) { 55 | // hop return (int) (frame*marker_indices.size()*4)+(marker_id*4)+marker_corner; 56 | return (int) (frame*marker_indices.size()*4)+(get_id_index(marker_id)*4)+marker_corner; 57 | } 58 | 59 | void _MeasurementsAdd(MarkerIterator &begin, MarkerIterator &end, const Pose& camera_pose); 60 | 61 | public: 62 | 63 | /** \brief Constructor. 64 | \param indices Vector of marker codes that are included into multi marker. The first element defines origin. 65 | */ 66 | MultiMarkerBundle(std::vector& indices); 67 | 68 | ~MultiMarkerBundle(); 69 | 70 | /** \brief Resets the measurements and camera poses that are stored for bundle adjustment. If something goes from in 71 | optimization one will call this and acquire new measurements. 72 | */ 73 | void MeasurementsReset(); 74 | 75 | double GetOptimizationError() { return optimization_error; } 76 | int GetOptimizationKeyframes() { return optimization_keyframes; } 77 | int GetOptimizationMarkers() { return optimization_markers; } 78 | bool GetOptimizing() { return optimizing; } 79 | 80 | /** \brief Adds new measurements that are used in bundle adjustment. 81 | \param markers Vector of markers detected by MarkerDetector. 82 | \param camera_pose Current camera pose. 83 | */ 84 | template 85 | void MeasurementsAdd(const std::vector > *markers, const Pose& camera_pose) { 86 | MarkerIteratorImpl begin(markers->begin()); 87 | MarkerIteratorImpl end(markers->end()); 88 | _MeasurementsAdd(begin, end, 89 | camera_pose); 90 | } 91 | 92 | /** \brief Runs the bundle adjustment optimization. 93 | \param markers Vector of markers detected by MarkerDetector. 94 | \param camera_pose Current camera pose. 95 | \param max_iter Maximum number of iteration loops. 96 | \param method The method that is applied inside optimization. Try Optimization::LEVENBERGMARQUARDT or Optimization::GAUSSNEWTON or Optmization::TUKEY_LM 97 | */ //LEVENBERGMARQUARDT 98 | bool Optimize(Camera *_cam, double stop, int max_iter, Optimization::OptimizeMethod method = Optimization::TUKEY_LM); //TUKEY_LM 99 | }; 100 | 101 | } // namespace alvar 102 | 103 | #endif 104 | -------------------------------------------------------------------------------- /ar_track_alvar/include/ar_track_alvar/MultiMarkerFiltered.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of ALVAR, A Library for Virtual and Augmented Reality. 3 | * 4 | * Copyright 2007-2012 VTT Technical Research Centre of Finland 5 | * 6 | * Contact: VTT Augmented Reality Team 7 | * 8 | * 9 | * ALVAR is free software; you can redistribute it and/or modify it under the 10 | * terms of the GNU Lesser General Public License as published by the Free 11 | * Software Foundation; either version 2.1 of the License, or (at your option) 12 | * any later version. 13 | * 14 | * This library is distributed in the hope that it will be useful, but WITHOUT 15 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 16 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License 17 | * for more details. 18 | * 19 | * You should have received a copy of the GNU Lesser General Public License 20 | * along with ALVAR; if not, see 21 | * . 22 | */ 23 | 24 | #ifndef MULTIMARKERFILTERED_H 25 | #define MULTIMARKERFILTERED_H 26 | 27 | /** 28 | * \file MultiMarkerFiltered.h 29 | * 30 | * \brief This file implements an approximation algorithm to create a 31 | * multi-marker field configuration. 32 | */ 33 | 34 | #include "MultiMarker.h" 35 | 36 | namespace alvar { 37 | 38 | /** 39 | * \brief Multi marker that is constructed by first calculating the marker 40 | * poses directly relative to base marker and then filtering the results 41 | * using e.g. median filter. 42 | * 43 | * This can be used to initialize the marker field for MultiMarkerBundle class. 44 | */ 45 | class ALVAR_EXPORT MultiMarkerFiltered : public MultiMarker 46 | { 47 | protected: 48 | static const int filter_buffer_max=15; 49 | FilterMedian *pointcloud_filtered; 50 | 51 | double _Update(MarkerIterator &begin, MarkerIterator &end, 52 | Camera* cam, Pose& pose, IplImage* image); 53 | 54 | public: 55 | /** \brief Constructor. 56 | \param indices Vector of marker codes that are included into multi marker. The first element defines origin. 57 | */ 58 | MultiMarkerFiltered(std::vector& indices); 59 | 60 | /** \brief Destructor. */ 61 | ~MultiMarkerFiltered(); 62 | 63 | /** \brief Updates the 3D point cloud by averaging the calculated results. 64 | \param marker_id The id of the marker whose corner positions are updated. 65 | \param edge_length The edge length of the marker. 66 | \param pose Current camera pose that is used to estimate the marker position. 67 | */ 68 | void PointCloudAverage(int marker_id, double edge_length, Pose &pose); 69 | 70 | /** \brief Updates the marker field and camera pose. 71 | \param markers Markers seen by the camera. 72 | \param camera Camera object used to detect markers. 73 | \param pose Current camera pose. This is also updated. 74 | \param image If != 0 some visualization will be drawn. 75 | */ 76 | template 77 | double Update(const std::vector* markers, Camera* cam, Pose& pose, IplImage* image = 0) 78 | { 79 | if(markers->size() < 1) return false; 80 | MarkerIteratorImpl begin(markers->begin()); 81 | MarkerIteratorImpl end(markers->end()); 82 | return _Update(begin, end, 83 | cam, pose, image); 84 | } 85 | 86 | /** 87 | * \brief Reset the measurements 88 | */ 89 | void MeasurementsReset() { 90 | pointcloud_filtered->reset(); 91 | } 92 | }; 93 | 94 | } // namespace alvar 95 | 96 | #endif 97 | -------------------------------------------------------------------------------- /ar_track_alvar/include/ar_track_alvar/Mutex.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of ALVAR, A Library for Virtual and Augmented Reality. 3 | * 4 | * Copyright 2007-2012 VTT Technical Research Centre of Finland 5 | * 6 | * Contact: VTT Augmented Reality Team 7 | * 8 | * 9 | * ALVAR is free software; you can redistribute it and/or modify it under the 10 | * terms of the GNU Lesser General Public License as published by the Free 11 | * Software Foundation; either version 2.1 of the License, or (at your option) 12 | * any later version. 13 | * 14 | * This library is distributed in the hope that it will be useful, but WITHOUT 15 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 16 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License 17 | * for more details. 18 | * 19 | * You should have received a copy of the GNU Lesser General Public License 20 | * along with ALVAR; if not, see 21 | * . 22 | */ 23 | 24 | #ifndef MUTEX_H 25 | #define MUTEX_H 26 | 27 | /** 28 | * \file Mutex.h 29 | * 30 | * \brief This file implements a mutex. 31 | */ 32 | 33 | #include "Alvar.h" 34 | 35 | namespace alvar { 36 | 37 | class MutexPrivate; 38 | 39 | /** 40 | * \brief Mutex for synchronizing multiple threads. 41 | * 42 | * Mutex class for synchronizing multiple threads. 43 | */ 44 | class ALVAR_EXPORT Mutex 45 | { 46 | public: 47 | /** 48 | * \brief Constructor. 49 | */ 50 | Mutex(); 51 | 52 | /** 53 | * \brief Destructor. 54 | */ 55 | ~Mutex(); 56 | 57 | /** 58 | * \brief Locks the mutex. 59 | * 60 | * If the mutex is already locked by another thread, this method will 61 | * block until the other thread unlocks the mutex. 62 | */ 63 | void lock(); 64 | 65 | /** 66 | * \brief Unlocks the mutex. 67 | */ 68 | void unlock(); 69 | 70 | private: 71 | MutexPrivate *d; 72 | }; 73 | 74 | } // namespace alvar 75 | 76 | #endif 77 | -------------------------------------------------------------------------------- /ar_track_alvar/include/ar_track_alvar/Mutex_private.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of ALVAR, A Library for Virtual and Augmented Reality. 3 | * 4 | * Copyright 2007-2012 VTT Technical Research Centre of Finland 5 | * 6 | * Contact: VTT Augmented Reality Team 7 | * 8 | * 9 | * ALVAR is free software; you can redistribute it and/or modify it under the 10 | * terms of the GNU Lesser General Public License as published by the Free 11 | * Software Foundation; either version 2.1 of the License, or (at your option) 12 | * any later version. 13 | * 14 | * This library is distributed in the hope that it will be useful, but WITHOUT 15 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 16 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License 17 | * for more details. 18 | * 19 | * You should have received a copy of the GNU Lesser General Public License 20 | * along with ALVAR; if not, see 21 | * . 22 | */ 23 | 24 | #ifndef MUTEX_PRIVATE_H 25 | #define MUTEX_PRIVATE_H 26 | 27 | namespace alvar { 28 | 29 | class MutexPrivateData; 30 | 31 | class MutexPrivate 32 | { 33 | public: 34 | MutexPrivate(); 35 | ~MutexPrivate(); 36 | void lock(); 37 | void unlock(); 38 | 39 | MutexPrivateData *d; 40 | }; 41 | 42 | } // namespace alvar 43 | 44 | #endif 45 | -------------------------------------------------------------------------------- /ar_track_alvar/include/ar_track_alvar/Platform.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of ALVAR, A Library for Virtual and Augmented Reality. 3 | * 4 | * Copyright 2007-2012 VTT Technical Research Centre of Finland 5 | * 6 | * Contact: VTT Augmented Reality Team 7 | * 8 | * 9 | * ALVAR is free software; you can redistribute it and/or modify it under the 10 | * terms of the GNU Lesser General Public License as published by the Free 11 | * Software Foundation; either version 2.1 of the License, or (at your option) 12 | * any later version. 13 | * 14 | * This library is distributed in the hope that it will be useful, but WITHOUT 15 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 16 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License 17 | * for more details. 18 | * 19 | * You should have received a copy of the GNU Lesser General Public License 20 | * along with ALVAR; if not, see 21 | * . 22 | */ 23 | 24 | #ifndef PLATFORM_H 25 | #define PLATFORM_H 26 | 27 | /** 28 | * \file Platform.h 29 | * 30 | * \brief This file implements generic platform specific methods. 31 | */ 32 | 33 | #include "Alvar.h" 34 | #include "Lock.h" 35 | #include "Mutex.h" 36 | #include "Threads.h" 37 | #include "Timer.h" 38 | #include "Uncopyable.h" 39 | 40 | namespace alvar { 41 | 42 | /** 43 | * \brief Error reporting function inspired by error_at_line() on Linux. 44 | * 45 | * It flushes stdout and prints the filename, line number and printf 46 | * compatible error message to stderr. If error is specified, it also prints 47 | * the corresponding error message from strerror(). If status is not zero, it 48 | * exits the process. 49 | */ 50 | void ALVAR_EXPORT errorAtLine(int status, int error, const char *filename, 51 | unsigned int line, const char *format, ...); 52 | 53 | /** 54 | * \brief Sleep for a specified amount of milliseconds. 55 | */ 56 | void ALVAR_EXPORT sleep(unsigned long milliseconds); 57 | 58 | } // namespace alvar 59 | 60 | #ifdef min 61 | #undef min 62 | #endif 63 | 64 | #ifdef max 65 | #undef max 66 | #endif 67 | 68 | #endif 69 | -------------------------------------------------------------------------------- /ar_track_alvar/include/ar_track_alvar/Plugin.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of ALVAR, A Library for Virtual and Augmented Reality. 3 | * 4 | * Copyright 2007-2012 VTT Technical Research Centre of Finland 5 | * 6 | * Contact: VTT Augmented Reality Team 7 | * 8 | * 9 | * ALVAR is free software; you can redistribute it and/or modify it under the 10 | * terms of the GNU Lesser General Public License as published by the Free 11 | * Software Foundation; either version 2.1 of the License, or (at your option) 12 | * any later version. 13 | * 14 | * This library is distributed in the hope that it will be useful, but WITHOUT 15 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 16 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License 17 | * for more details. 18 | * 19 | * You should have received a copy of the GNU Lesser General Public License 20 | * along with ALVAR; if not, see 21 | * . 22 | */ 23 | 24 | #ifndef PLUGIN_H 25 | #define PLUGIN_H 26 | 27 | /** 28 | * \file Plugin.h 29 | * 30 | * \brief This file implements a loader for plugins as dynamic libraries. 31 | */ 32 | 33 | #include "Alvar.h" 34 | 35 | #include 36 | 37 | namespace alvar { 38 | 39 | class PluginPrivate; 40 | 41 | /** 42 | * \brief Plugin for loading dynamic libraries. 43 | * 44 | * Plugin class for loading dynamic libraires. The library is loaded during construction and 45 | * unloaded during destruction. 46 | */ 47 | class Plugin 48 | { 49 | public: 50 | /** 51 | * \brief Constructor. 52 | * 53 | * Constructing a Plugin object will attempt to load the plugin dynamic library. 54 | * 55 | * \param filename The filename of the dynamic library to load. 56 | * \exception AlvarException An exeption is thrown if the library can't be loaded. 57 | */ 58 | Plugin(const std::string filename); 59 | 60 | /** 61 | * \brief Copy constructor. 62 | * 63 | * \param plugin The Plugin to copy. 64 | */ 65 | Plugin(const Plugin &plugin); 66 | 67 | /** 68 | * \brief Assignment operator. 69 | * 70 | * \param plugin The Plugin to copy. 71 | */ 72 | Plugin &operator=(const Plugin &plugin); 73 | 74 | /** 75 | * \brief Destructor. 76 | */ 77 | ~Plugin(); 78 | 79 | /** 80 | * \brief Resolves the address of a symbol. 81 | * 82 | * The symbol must be exported from the library as a C function. 83 | * 84 | * \param symbol The signature of the symbol. 85 | * \return The address of the symbol. 86 | * \exception AlvarException An exception is thrown if the symbol is not found. 87 | */ 88 | void *resolve(const char *symbol); 89 | 90 | private: 91 | PluginPrivate *d; 92 | int *mReferenceCount; 93 | }; 94 | 95 | } // namespace alvar 96 | 97 | #endif 98 | -------------------------------------------------------------------------------- /ar_track_alvar/include/ar_track_alvar/Plugin_private.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of ALVAR, A Library for Virtual and Augmented Reality. 3 | * 4 | * Copyright 2007-2012 VTT Technical Research Centre of Finland 5 | * 6 | * Contact: VTT Augmented Reality Team 7 | * 8 | * 9 | * ALVAR is free software; you can redistribute it and/or modify it under the 10 | * terms of the GNU Lesser General Public License as published by the Free 11 | * Software Foundation; either version 2.1 of the License, or (at your option) 12 | * any later version. 13 | * 14 | * This library is distributed in the hope that it will be useful, but WITHOUT 15 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 16 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License 17 | * for more details. 18 | * 19 | * You should have received a copy of the GNU Lesser General Public License 20 | * along with ALVAR; if not, see 21 | * . 22 | */ 23 | 24 | #ifndef PLUGIN_PRIVATE_H 25 | #define PLUGIN_PRIVATE_H 26 | 27 | #include 28 | 29 | namespace alvar { 30 | 31 | class PluginPrivateData; 32 | 33 | class PluginPrivate 34 | { 35 | public: 36 | PluginPrivate(); 37 | ~PluginPrivate(); 38 | void load(const std::string filename); 39 | void unload(); 40 | void *resolve(const char *symbol); 41 | 42 | PluginPrivateData *d; 43 | }; 44 | 45 | } // namespace alvar 46 | 47 | #endif 48 | -------------------------------------------------------------------------------- /ar_track_alvar/include/ar_track_alvar/Shared.h: -------------------------------------------------------------------------------- 1 | #ifndef SHARED_H 2 | #define SHARED_H 3 | 4 | #include "CaptureFactory.h" 5 | 6 | using namespace alvar; 7 | 8 | void outputEnumeratedPlugins(CaptureFactory::CapturePluginVector &plugins) 9 | { 10 | for (int i = 0; i < (int)plugins.size(); ++i) { 11 | if (i != 0) { 12 | std::cout << ", "; 13 | } 14 | std::cout << plugins.at(i); 15 | } 16 | 17 | std::cout << std::endl; 18 | } 19 | 20 | void outputEnumeratedDevices(CaptureFactory::CaptureDeviceVector &devices, int selectedDevice) 21 | { 22 | for (int i = 0; i < (int)devices.size(); ++i) { 23 | if (selectedDevice == i) { 24 | std::cout << "* "; 25 | } 26 | else { 27 | std::cout << " "; 28 | } 29 | 30 | std::cout << i << ": " << devices.at(i).uniqueName(); 31 | 32 | if (devices[i].description().length() > 0) { 33 | std::cout << ", " << devices.at(i).description(); 34 | } 35 | 36 | std::cout << std::endl; 37 | } 38 | } 39 | 40 | int defaultDevice(CaptureFactory::CaptureDeviceVector &devices) 41 | { 42 | for (int i = 0; i < (int)devices.size(); ++i) { 43 | if (devices.at(i).captureType() == "highgui") { 44 | return i; 45 | } 46 | } 47 | 48 | return 0; 49 | } 50 | 51 | #endif 52 | -------------------------------------------------------------------------------- /ar_track_alvar/include/ar_track_alvar/Threads.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of ALVAR, A Library for Virtual and Augmented Reality. 3 | * 4 | * Copyright 2007-2012 VTT Technical Research Centre of Finland 5 | * 6 | * Contact: VTT Augmented Reality Team 7 | * 8 | * 9 | * ALVAR is free software; you can redistribute it and/or modify it under the 10 | * terms of the GNU Lesser General Public License as published by the Free 11 | * Software Foundation; either version 2.1 of the License, or (at your option) 12 | * any later version. 13 | * 14 | * This library is distributed in the hope that it will be useful, but WITHOUT 15 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 16 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License 17 | * for more details. 18 | * 19 | * You should have received a copy of the GNU Lesser General Public License 20 | * along with ALVAR; if not, see 21 | * . 22 | */ 23 | 24 | #ifndef THREADS_H 25 | #define THREADS_H 26 | 27 | /** 28 | * \file Threads.h 29 | * 30 | * \brief This file implements a threads vector. 31 | */ 32 | 33 | #include "Alvar.h" 34 | 35 | namespace alvar { 36 | 37 | class ThreadsPrivate; 38 | 39 | /** 40 | * \brief Threads vector for handling multiple threads. 41 | * 42 | * Threads class for handling multiple threads. 43 | */ 44 | class ALVAR_EXPORT Threads 45 | { 46 | public: 47 | /** 48 | * \brief Constructor. 49 | */ 50 | Threads(); 51 | 52 | /** 53 | * \brief Destructor. 54 | */ 55 | ~Threads(); 56 | 57 | /** 58 | * \brief Creates a new thread and returns true on success. 59 | * 60 | * \param method The method that the thread will execute. 61 | * \param parameters The parameters sent to the method. 62 | */ 63 | bool create(void *(*method)(void *), void *parameters); 64 | 65 | private: 66 | ThreadsPrivate *d; 67 | }; 68 | 69 | } // namespace alvar 70 | 71 | #endif 72 | -------------------------------------------------------------------------------- /ar_track_alvar/include/ar_track_alvar/Threads_private.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of ALVAR, A Library for Virtual and Augmented Reality. 3 | * 4 | * Copyright 2007-2012 VTT Technical Research Centre of Finland 5 | * 6 | * Contact: VTT Augmented Reality Team 7 | * 8 | * 9 | * ALVAR is free software; you can redistribute it and/or modify it under the 10 | * terms of the GNU Lesser General Public License as published by the Free 11 | * Software Foundation; either version 2.1 of the License, or (at your option) 12 | * any later version. 13 | * 14 | * This library is distributed in the hope that it will be useful, but WITHOUT 15 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 16 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License 17 | * for more details. 18 | * 19 | * You should have received a copy of the GNU Lesser General Public License 20 | * along with ALVAR; if not, see 21 | * . 22 | */ 23 | 24 | #ifndef THREADS_PRIVATE_H 25 | #define THREADS_PRIVATE_H 26 | 27 | namespace alvar { 28 | 29 | class ThreadsPrivateData; 30 | 31 | class ThreadsPrivate 32 | { 33 | public: 34 | ThreadsPrivate(); 35 | ~ThreadsPrivate(); 36 | bool create(void *(*method)(void *), void *parameters); 37 | 38 | ThreadsPrivateData *d; 39 | }; 40 | 41 | } // namespace alvar 42 | 43 | #endif 44 | -------------------------------------------------------------------------------- /ar_track_alvar/include/ar_track_alvar/Timer.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of ALVAR, A Library for Virtual and Augmented Reality. 3 | * 4 | * Copyright 2007-2012 VTT Technical Research Centre of Finland 5 | * 6 | * Contact: VTT Augmented Reality Team 7 | * 8 | * 9 | * ALVAR is free software; you can redistribute it and/or modify it under the 10 | * terms of the GNU Lesser General Public License as published by the Free 11 | * Software Foundation; either version 2.1 of the License, or (at your option) 12 | * any later version. 13 | * 14 | * This library is distributed in the hope that it will be useful, but WITHOUT 15 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 16 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License 17 | * for more details. 18 | * 19 | * You should have received a copy of the GNU Lesser General Public License 20 | * along with ALVAR; if not, see 21 | * . 22 | */ 23 | 24 | #ifndef TIMER_H 25 | #define TIMER_H 26 | 27 | /** 28 | * \file Timer.h 29 | * 30 | * \brief This file implements a timer. 31 | */ 32 | 33 | #include "Alvar.h" 34 | 35 | namespace alvar { 36 | 37 | class TimerPrivate; 38 | 39 | /** 40 | * \brief Timer for measuring execution time. 41 | * 42 | * Timer class for measuring execution time. 43 | */ 44 | class ALVAR_EXPORT Timer 45 | { 46 | public: 47 | /** 48 | * \brief Constructor. 49 | */ 50 | Timer(); 51 | 52 | /** 53 | * \brief Destructor. 54 | */ 55 | ~Timer(); 56 | 57 | /** 58 | * \brief Starts the timer. 59 | */ 60 | void start(); 61 | 62 | /** 63 | * \brief Stops the timer and returns the elapsed time in seconds. 64 | */ 65 | double stop(); 66 | 67 | private: 68 | TimerPrivate *d; 69 | }; 70 | 71 | } // namespace alvar 72 | 73 | #endif 74 | -------------------------------------------------------------------------------- /ar_track_alvar/include/ar_track_alvar/Timer_private.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of ALVAR, A Library for Virtual and Augmented Reality. 3 | * 4 | * Copyright 2007-2012 VTT Technical Research Centre of Finland 5 | * 6 | * Contact: VTT Augmented Reality Team 7 | * 8 | * 9 | * ALVAR is free software; you can redistribute it and/or modify it under the 10 | * terms of the GNU Lesser General Public License as published by the Free 11 | * Software Foundation; either version 2.1 of the License, or (at your option) 12 | * any later version. 13 | * 14 | * This library is distributed in the hope that it will be useful, but WITHOUT 15 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 16 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License 17 | * for more details. 18 | * 19 | * You should have received a copy of the GNU Lesser General Public License 20 | * along with ALVAR; if not, see 21 | * . 22 | */ 23 | 24 | #ifndef TIMER_PRIVATE_H 25 | #define TIMER_PRIVATE_H 26 | 27 | namespace alvar { 28 | 29 | class TimerPrivateData; 30 | 31 | class TimerPrivate 32 | { 33 | public: 34 | TimerPrivate(); 35 | ~TimerPrivate(); 36 | void start(); 37 | double stop(); 38 | 39 | TimerPrivateData *d; 40 | }; 41 | 42 | } // namespace alvar 43 | 44 | #endif 45 | -------------------------------------------------------------------------------- /ar_track_alvar/include/ar_track_alvar/Tracker.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of ALVAR, A Library for Virtual and Augmented Reality. 3 | * 4 | * Copyright 2007-2012 VTT Technical Research Centre of Finland 5 | * 6 | * Contact: VTT Augmented Reality Team 7 | * 8 | * 9 | * ALVAR is free software; you can redistribute it and/or modify it under the 10 | * terms of the GNU Lesser General Public License as published by the Free 11 | * Software Foundation; either version 2.1 of the License, or (at your option) 12 | * any later version. 13 | * 14 | * This library is distributed in the hope that it will be useful, but WITHOUT 15 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 16 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License 17 | * for more details. 18 | * 19 | * You should have received a copy of the GNU Lesser General Public License 20 | * along with ALVAR; if not, see 21 | * . 22 | */ 23 | 24 | #ifndef TRACKER_H 25 | #define TRACKER_H 26 | 27 | /** 28 | * \file Tracker.h 29 | * 30 | * \brief This file implements a tracking interface. 31 | */ 32 | 33 | #include 34 | #include "Alvar.h" 35 | 36 | namespace alvar { 37 | 38 | /** 39 | * \brief Pure virtual base class for tracking optical flow 40 | * 41 | * The idea is to make own versions of \e Track method which updates the class member variables accordingly 42 | */ 43 | class ALVAR_EXPORT Tracker { 44 | public: 45 | Tracker() {} 46 | /** \brief Pure virtual function for making the next track step. This analyses the image and updates class member variables accordingly */ 47 | virtual double Track(IplImage *img) = 0; 48 | 49 | virtual void Compensate(double *x, double *y) {} 50 | }; 51 | 52 | } // namespace alvar 53 | 54 | #endif 55 | -------------------------------------------------------------------------------- /ar_track_alvar/include/ar_track_alvar/TrackerOrientation.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of ALVAR, A Library for Virtual and Augmented Reality. 3 | * 4 | * Copyright 2007-2012 VTT Technical Research Centre of Finland 5 | * 6 | * Contact: VTT Augmented Reality Team 7 | * 8 | * 9 | * ALVAR is free software; you can redistribute it and/or modify it under the 10 | * terms of the GNU Lesser General Public License as published by the Free 11 | * Software Foundation; either version 2.1 of the License, or (at your option) 12 | * any later version. 13 | * 14 | * This library is distributed in the hope that it will be useful, but WITHOUT 15 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 16 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License 17 | * for more details. 18 | * 19 | * You should have received a copy of the GNU Lesser General Public License 20 | * along with ALVAR; if not, see 21 | * . 22 | */ 23 | 24 | #ifndef TRACKERORIENTATION_H 25 | #define TRACKERORIENTATION_H 26 | 27 | #include "Tracker.h" 28 | #include "TrackerFeatures.h" 29 | #include "Pose.h" 30 | #include "Camera.h" 31 | 32 | /** 33 | * \file TrackerOrientation.h 34 | * 35 | * \brief This file implements an orientation tracker. 36 | */ 37 | 38 | namespace alvar { 39 | 40 | /** 41 | * \brief Track orientation based only on features in the image plane. 42 | */ 43 | class ALVAR_EXPORT TrackerOrientation : public Tracker { 44 | 45 | public: 46 | TrackerOrientation(int width, int height, int image_scale=1, int outlier_limit=20) 47 | : _image_scale(image_scale) 48 | , _outlier_limit(outlier_limit) 49 | , _xres(width) 50 | , _yres(height) 51 | { 52 | _camera = 0; 53 | _grsc = 0; 54 | _object_model = 0; 55 | } 56 | 57 | private: 58 | 59 | struct Feature 60 | { 61 | enum {NOT_TRACKED=0, IS_TRACKED} status2D; 62 | enum {NONE=0, USE_FOR_POSE, IS_OUTLIER, IS_INITIAL} status3D; 63 | 64 | Feature() 65 | { 66 | status3D = NONE; 67 | status2D = NOT_TRACKED; 68 | } 69 | 70 | Feature(double vx, double vy) 71 | { 72 | point.x = float(vx); 73 | point.y = float(vy); 74 | status3D = NONE; 75 | status2D = NOT_TRACKED; 76 | } 77 | 78 | ~Feature() {} 79 | 80 | CvPoint2D32f point; 81 | CvPoint3D64f point3d; 82 | }; 83 | 84 | TrackerFeatures _ft; 85 | std::map _F_v; 86 | 87 | int _xres; 88 | int _yres; 89 | int _image_scale; 90 | int _outlier_limit; 91 | 92 | Pose _pose; 93 | IplImage *_grsc; 94 | Camera *_camera; 95 | CvMat *_object_model; 96 | 97 | public: 98 | void SetCamera(Camera *camera) { 99 | _camera = camera; 100 | } 101 | void GetPose(Pose &pose); 102 | void GetPose(double gl_mat[16]) { 103 | _pose.GetMatrixGL(gl_mat); 104 | } 105 | void Reset(); 106 | double Track(IplImage *image); 107 | 108 | private: 109 | static void Project(CvMat* state, CvMat* projection, void *param); 110 | bool UpdatePose(IplImage* image=0); 111 | bool UpdateRotationOnly(IplImage *gray, IplImage *image=0); 112 | 113 | }; 114 | 115 | } // namespace alvar 116 | 117 | #endif 118 | 119 | 120 | -------------------------------------------------------------------------------- /ar_track_alvar/include/ar_track_alvar/TrackerPsa.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of ALVAR, A Library for Virtual and Augmented Reality. 3 | * 4 | * Copyright 2007-2012 VTT Technical Research Centre of Finland 5 | * 6 | * Contact: VTT Augmented Reality Team 7 | * 8 | * 9 | * ALVAR is free software; you can redistribute it and/or modify it under the 10 | * terms of the GNU Lesser General Public License as published by the Free 11 | * Software Foundation; either version 2.1 of the License, or (at your option) 12 | * any later version. 13 | * 14 | * This library is distributed in the hope that it will be useful, but WITHOUT 15 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 16 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License 17 | * for more details. 18 | * 19 | * You should have received a copy of the GNU Lesser General Public License 20 | * along with ALVAR; if not, see 21 | * . 22 | */ 23 | 24 | #ifndef TRACKERPSA_H 25 | #define TRACKERPSA_H 26 | 27 | #include "Tracker.h" 28 | 29 | /** 30 | * \file TrackerPsa.h 31 | * 32 | * \brief This file implements a PSA tracker. 33 | */ 34 | 35 | namespace alvar { 36 | 37 | /** 38 | * \brief \e TrackerPsa implements a very simple PSA tracker 39 | * 40 | * (See Drab, Stephan A. & Artner, Nicole M. "Motion Detection as Interaction Technique for Games & Applications on Mobile Devices" PERMID 2005) 41 | */ 42 | class ALVAR_EXPORT TrackerPsa : public Tracker { 43 | protected: 44 | int max_shift; 45 | int x_res, y_res; 46 | long *hor, *horprev; 47 | long *ver, *verprev; 48 | long framecount; 49 | 50 | public: 51 | /** \brief \e Track result x-translation in pixels */ 52 | double xd; 53 | /** \brief \e Track result y-translation in pixels */ 54 | double yd; 55 | /** \brief Constructor */ 56 | TrackerPsa(int _max_shift = 50); 57 | /** \brief Destructor */ 58 | ~TrackerPsa(); 59 | /** \brief Track using PSA */ 60 | double Track(IplImage *img); 61 | 62 | virtual void Compensate(double *x, double *y); 63 | }; 64 | 65 | /** 66 | * \brief \e TrackerPsaRot implements a slightly extended version of a \e TrackerPsa which can also detect sideways rotation 67 | */ 68 | class ALVAR_EXPORT TrackerPsaRot : public TrackerPsa { 69 | protected: 70 | double *rot, *rotprev; 71 | int *rot_count; 72 | 73 | public: 74 | /** \brief \e Track result rotation in degrees */ 75 | double rotd; 76 | /** \brief Constructor */ 77 | TrackerPsaRot(int _max_shift = 50); 78 | /** \brief Destructor */ 79 | ~TrackerPsaRot(); 80 | /** \brief Track using PSA with rotation*/ 81 | double Track(IplImage *img); 82 | 83 | virtual void Compensate(double *x, double *y); 84 | }; 85 | 86 | } // namespace alvar 87 | 88 | #endif 89 | 90 | 91 | -------------------------------------------------------------------------------- /ar_track_alvar/include/ar_track_alvar/TrackerStat.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of ALVAR, A Library for Virtual and Augmented Reality. 3 | * 4 | * Copyright 2007-2012 VTT Technical Research Centre of Finland 5 | * 6 | * Contact: VTT Augmented Reality Team 7 | * 8 | * 9 | * ALVAR is free software; you can redistribute it and/or modify it under the 10 | * terms of the GNU Lesser General Public License as published by the Free 11 | * Software Foundation; either version 2.1 of the License, or (at your option) 12 | * any later version. 13 | * 14 | * This library is distributed in the hope that it will be useful, but WITHOUT 15 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 16 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License 17 | * for more details. 18 | * 19 | * You should have received a copy of the GNU Lesser General Public License 20 | * along with ALVAR; if not, see 21 | * . 22 | */ 23 | 24 | #ifndef TRACKERSTAT_H 25 | #define TRACKERSTAT_H 26 | 27 | #include "Tracker.h" 28 | #include "TrackerFeatures.h" 29 | #include "Util.h" 30 | 31 | /** 32 | * \file TrackerStat.h 33 | * 34 | * \brief This file implements a statistical tracker. 35 | */ 36 | 37 | namespace alvar { 38 | 39 | /** 40 | * \brief \e TrackerStat deduces the optical flow based on tracked features using Seppo Valli's statistical tracking. 41 | */ 42 | class ALVAR_EXPORT TrackerStat : public Tracker { 43 | protected: 44 | TrackerFeatures f; 45 | HistogramSubpixel hist; 46 | public: 47 | /** \brief \e Track result x-translation in pixels */ 48 | double xd; 49 | /** \brief \e Track result y-translation in pixels */ 50 | double yd; 51 | /** \brief Constructor */ 52 | TrackerStat(int binsize=8); 53 | /** \brief Reset */ 54 | void Reset(); 55 | /** 56 | * \brief Translation tracker (the simplest possible) 57 | */ 58 | double Track(IplImage *img); 59 | virtual void Compensate(double *x, double *y); 60 | }; 61 | 62 | /** 63 | * \brief TrackerStatRot implements a slightly extended version of TrackerStat which can also detect sideways rotation. 64 | */ 65 | class ALVAR_EXPORT TrackerStatRot : public TrackerStat { 66 | int x_res, y_res; 67 | HistogramSubpixel hist_rot; 68 | public: 69 | /** \brief \e Track result rotation in degrees */ 70 | double rotd; 71 | /** \brief Constructor */ 72 | TrackerStatRot(int binsize=8, int binsize_rot=3); 73 | /** 74 | * \brief Translation + rotation tracker 75 | */ 76 | double Track(IplImage *img); 77 | virtual void Compensate(double *x, double *y); 78 | }; 79 | 80 | } // namespace alvar 81 | 82 | #endif 83 | 84 | 85 | -------------------------------------------------------------------------------- /ar_track_alvar/include/ar_track_alvar/Uncopyable.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of ALVAR, A Library for Virtual and Augmented Reality. 3 | * 4 | * Copyright 2007-2012 VTT Technical Research Centre of Finland 5 | * 6 | * Contact: VTT Augmented Reality Team 7 | * 8 | * 9 | * ALVAR is free software; you can redistribute it and/or modify it under the 10 | * terms of the GNU Lesser General Public License as published by the Free 11 | * Software Foundation; either version 2.1 of the License, or (at your option) 12 | * any later version. 13 | * 14 | * This library is distributed in the hope that it will be useful, but WITHOUT 15 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 16 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License 17 | * for more details. 18 | * 19 | * You should have received a copy of the GNU Lesser General Public License 20 | * along with ALVAR; if not, see 21 | * . 22 | */ 23 | 24 | #ifndef UNCOPYABLE_H 25 | #define UNCOPYABLE_H 26 | 27 | /** 28 | * \file Uncopyable.h 29 | * 30 | * \brief This file implements an uncopyable interface. 31 | */ 32 | 33 | #include "Alvar.h" 34 | 35 | namespace alvar { 36 | 37 | /** 38 | * \brief Uncopyable for preventing object copies. 39 | * 40 | * Uncopyable class for preventing the inheriting class to be copied. The 41 | * inheriting class must use private inheritance. 42 | */ 43 | class ALVAR_EXPORT Uncopyable 44 | { 45 | protected: 46 | /** 47 | * \brief Constructor. 48 | */ 49 | Uncopyable() 50 | { 51 | } 52 | 53 | /** 54 | * \brief Destructor. 55 | */ 56 | ~Uncopyable() 57 | { 58 | } 59 | 60 | private: 61 | /** 62 | * \brief Copy constructor. 63 | */ 64 | Uncopyable(const Uncopyable &uncopyable); 65 | 66 | /** 67 | * \brief Assignment operator. 68 | */ 69 | Uncopyable &operator=(const Uncopyable &uncopyable); 70 | }; 71 | 72 | } // namespace alvar 73 | 74 | #endif 75 | -------------------------------------------------------------------------------- /ar_track_alvar/include/ar_track_alvar/filter/kinect_filtering.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2008, Willow Garage, Inc. 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions are met: 7 | * 8 | * * Redistributions of source code must retain the above copyright 9 | * notice, this list of conditions and the following disclaimer. 10 | * * Redistributions in binary form must reproduce the above copyright 11 | * notice, this list of conditions and the following disclaimer in the 12 | * documentation and/or other materials provided with the distribution. 13 | * * Neither the name of the Willow Garage, Inc. nor the names of its 14 | * contributors may be used to endorse or promote products derived from 15 | * this software without specific prior written permission. 16 | * 17 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 18 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 21 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 22 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 23 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 24 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 25 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 26 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 27 | * POSSIBILITY OF SUCH DAMAGE. 28 | * 29 | */ 30 | 31 | /** 32 | * \file 33 | * 34 | * Library for depth based filtering 35 | * 36 | * \author Bhaskara Marthi 37 | */ 38 | 39 | #ifndef AR_TRACK_ALVAR_KINECT_FILTERING_H 40 | #define AR_TRACK_ALVAR_KINECT_FILTERING_H 41 | 42 | #include 43 | #include 44 | #include 45 | #include 46 | 47 | #include 48 | #include 49 | #include 50 | #include 51 | #include 52 | #include 53 | #include 54 | #include 55 | #include 56 | #include 57 | #include 58 | 59 | #include 60 | 61 | #include 62 | 63 | namespace ar_track_alvar 64 | { 65 | 66 | typedef pcl::PointXYZRGB ARPoint; 67 | typedef pcl::PointCloud ARCloud; 68 | 69 | // Result of plane fit: inliers and the plane equation 70 | struct PlaneFitResult 71 | { 72 | EIGEN_MAKE_ALIGNED_OPERATOR_NEW 73 | PlaneFitResult () : inliers(ARCloud::Ptr(new ARCloud)) {} 74 | ARCloud::Ptr inliers; 75 | pcl::ModelCoefficients coeffs; 76 | }; 77 | 78 | // Select out a subset of a cloud corresponding to a set of pixel coordinates 79 | ARCloud::Ptr filterCloud (const ARCloud& cloud, 80 | const std::vector >& pixels); 81 | 82 | // Wrapper for PCL plane fitting 83 | PlaneFitResult fitPlane (ARCloud::ConstPtr cloud); 84 | 85 | // Given the coefficients of a plane, and two points p1 and p2, we produce a 86 | // quaternion q that sends p2'-p1' to (1,0,0) and n to (0,0,1), where p1' and 87 | // p2' are the projections of p1 and p2 onto the plane and n is the normal. 88 | // There's a sign ambiguity here, which is resolved by requiring that the 89 | // difference p4'-p3' ends up with a positive y coordinate 90 | int 91 | extractOrientation (const pcl::ModelCoefficients& coeffs, 92 | const ARPoint& p1, const ARPoint& p2, 93 | const ARPoint& p3, const ARPoint& p4, 94 | geometry_msgs::Quaternion &retQ); 95 | 96 | // Like extractOrientation except return value is a btMatrix3x3 97 | int 98 | extractFrame (const pcl::ModelCoefficients& coeffs, 99 | const ARPoint& p1, const ARPoint& p2, 100 | const ARPoint& p3, const ARPoint& p4, 101 | tf::Matrix3x3 &retmat); 102 | 103 | 104 | // Return the centroid (mean) of a point cloud 105 | geometry_msgs::Point centroid (const ARCloud& points); 106 | } // namespace 107 | 108 | #endif // include guard 109 | -------------------------------------------------------------------------------- /ar_track_alvar/include/ar_track_alvar/filter/medianFilter.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2008, Willow Garage, Inc. 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions are met: 7 | * 8 | * * Redistributions of source code must retain the above copyright 9 | * notice, this list of conditions and the following disclaimer. 10 | * * Redistributions in binary form must reproduce the above copyright 11 | * notice, this list of conditions and the following disclaimer in the 12 | * documentation and/or other materials provided with the distribution. 13 | * * Neither the name of the Willow Garage, Inc. nor the names of its 14 | * contributors may be used to endorse or promote products derived from 15 | * this software without specific prior written permission. 16 | * 17 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 18 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 21 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 22 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 23 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 24 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 25 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 26 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 27 | * POSSIBILITY OF SUCH DAMAGE. 28 | * 29 | */ 30 | 31 | /** 32 | * \file 33 | * 34 | * N-dimensional median filter for marker poses 35 | * 36 | * \author Scott Niekum 37 | */ 38 | 39 | #ifndef AR_TRACK_ALVAR_MEDIAN_FILTER_H 40 | #define AR_TRACK_ALVAR_MEDIAN_FILTER_H 41 | 42 | #include "ar_track_alvar/Pose.h" 43 | 44 | namespace ar_track_alvar 45 | { 46 | 47 | class MedianFilter 48 | { 49 | public: 50 | MedianFilter(int n); 51 | void addPose(const alvar::Pose &new_pose); 52 | void getMedian(alvar::Pose &ret_pose); 53 | 54 | private: 55 | int median_n; 56 | alvar::Pose *median_poses; 57 | int median_ind; 58 | bool median_init; 59 | }; 60 | 61 | 62 | } // namespace 63 | 64 | #endif // include guard 65 | -------------------------------------------------------------------------------- /ar_track_alvar/launch/pr2_bundle.launch: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /ar_track_alvar/launch/pr2_bundle_no_kinect.launch: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /ar_track_alvar/launch/pr2_indiv.launch: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /ar_track_alvar/launch/pr2_indiv_no_kinect.launch: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | -------------------------------------------------------------------------------- /ar_track_alvar/launch/pr2_train.launch: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /ar_track_alvar/markers/Markers_0_to_8.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/machinekoder/ar_track_alvar/a870d5f00a548acb346bfcc89d42b997771d71a3/ar_track_alvar/markers/Markers_0_to_8.png -------------------------------------------------------------------------------- /ar_track_alvar/markers/Markers_9_to_17.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/machinekoder/ar_track_alvar/a870d5f00a548acb346bfcc89d42b997771d71a3/ar_track_alvar/markers/Markers_9_to_17.png -------------------------------------------------------------------------------- /ar_track_alvar/markers/table_8_9_10.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/machinekoder/ar_track_alvar/a870d5f00a548acb346bfcc89d42b997771d71a3/ar_track_alvar/markers/table_8_9_10.png -------------------------------------------------------------------------------- /ar_track_alvar/package.xml: -------------------------------------------------------------------------------- 1 | 2 | ar_track_alvar 3 | 0.7.1 4 | 5 | This package is a ROS wrapper for Alvar, an open source AR tag tracking library. 6 | 7 | Scott Niekum 8 | Scott Niekum 9 | Isaac I.Y. Saito 10 | LGPL-2.1 11 | http://ros.org/wiki/ar_track_alvar 12 | 13 | catkin 14 | 15 | ar_track_alvar_msgs 16 | cmake_modules 17 | cv_bridge 18 | geometry_msgs 19 | image_transport 20 | message_generation 21 | pcl_ros 22 | pcl_conversions 23 | resource_retriever 24 | rospy 25 | roscpp 26 | sensor_msgs 27 | std_msgs 28 | tf 29 | tf2 30 | tinyxml 31 | visualization_msgs 32 | dynamic_reconfigure 33 | 34 | ar_track_alvar_msgs 35 | cv_bridge 36 | geometry_msgs 37 | image_transport 38 | message_runtime 39 | pcl_ros 40 | pcl_conversions 41 | resource_retriever 42 | rospy 43 | roscpp 44 | sensor_msgs 45 | std_msgs 46 | tf 47 | tf2 48 | tinyxml 49 | visualization_msgs 50 | dynamic_reconfigure 51 | 52 | rosbag 53 | rostest 54 | 55 | 56 | 57 | 58 | -------------------------------------------------------------------------------- /ar_track_alvar/src/Alvar.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of ALVAR, A Library for Virtual and Augmented Reality. 3 | * 4 | * Copyright 2007-2012 VTT Technical Research Centre of Finland 5 | * 6 | * Contact: VTT Augmented Reality Team 7 | * 8 | * 9 | * ALVAR is free software; you can redistribute it and/or modify it under the 10 | * terms of the GNU Lesser General Public License as published by the Free 11 | * Software Foundation; either version 2.1 of the License, or (at your option) 12 | * any later version. 13 | * 14 | * This library is distributed in the hope that it will be useful, but WITHOUT 15 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 16 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License 17 | * for more details. 18 | * 19 | * You should have received a copy of the GNU Lesser General Public License 20 | * along with ALVAR; if not, see 21 | * . 22 | */ 23 | 24 | #include "Alvar.h" 25 | 26 | #include 27 | 28 | namespace alvar { 29 | 30 | void alvarInfo() 31 | { 32 | std::cerr << "ALVAR " << ALVAR_VERSION << " - A Library for Virtual and Augmented Reality" << std::endl; 33 | std::cerr << "Copyright 2007-2012 VTT Technical Research Centre of Finland" << std::endl; 34 | std::cerr << "Licensed under the GNU Lesser General Public License" << std::endl; 35 | std::cerr << "Built on " << ALVAR_DATE << " for " << ALVAR_SYSTEM << std::endl; 36 | std::cerr << std::endl; 37 | } 38 | 39 | struct AlvarLoader { 40 | AlvarLoader() { 41 | alvarInfo(); 42 | } 43 | } alvarBasicLoader; 44 | 45 | } // namespace alvar 46 | -------------------------------------------------------------------------------- /ar_track_alvar/src/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # include opencv library 2 | include_directories(${OpenCV_INCLUDE_DIRS}) 3 | 4 | # include opengl and glut library if found 5 | if(GLUT_FOUND) 6 | include_directories(${OPENGL_INCLUDE_DIR}) 7 | include_directories(${GLUT_INCLUDE_DIR}) 8 | endif(GLUT_FOUND) 9 | 10 | # include alvar library 11 | include_directories(${ALVAR_INCLUDE_DIRS}) 12 | 13 | # define samples in alphabetical order 14 | set(ALVAR_SAMPLES 15 | SampleCamCalib 16 | SampleCvTestbed 17 | SampleFilter 18 | SampleIntegralImage 19 | SampleLabeling 20 | SampleMarkerCreator 21 | SampleMarkerlessCreator 22 | SampleMultiMarker 23 | SampleMultiMarkerBundle 24 | SampleOptimization 25 | SampleTrack 26 | ) 27 | 28 | # define samples that require GlutViewer in alphabetical order 29 | set(ALVAR_SAMPLES_GLUTVIEWER 30 | SampleMarkerDetector 31 | SampleMarkerHide 32 | SampleMarkerlessDetector 33 | SamplePointcloud 34 | ) 35 | 36 | # add shared samples library 37 | add_library(SharedSamples STATIC 38 | CvTestbed.h 39 | CvTestbed.cpp 40 | Shared.h 41 | ) 42 | 43 | # add GlutViewer library and samples if glut library is found 44 | if(GLUT_FOUND) 45 | add_library(SharedGlutViewer STATIC 46 | GlutViewer.h 47 | GlutViewer.cpp 48 | ) 49 | target_link_libraries(SharedGlutViewer 50 | ${OPENGL_LIBRARIES} 51 | ${GLUT_glut_LIBRARY} 52 | ) 53 | list(APPEND ALVAR_SAMPLES ${ALVAR_SAMPLES_GLUTVIEWER}) 54 | endif(GLUT_FOUND) 55 | 56 | # add each sample as a seperate executable 57 | foreach(_sample ${ALVAR_SAMPLES}) 58 | # determine if glut common sources need to be included 59 | list(FIND ALVAR_SAMPLES_GLUTVIEWER ${_sample} _glutviewer) 60 | 61 | # add source files to executable and set name and properties 62 | add_executable(${_sample} ${_sample}.cpp) 63 | string(TOLOWER ${_sample} _filename) 64 | set_target_properties(${_sample} PROPERTIES OUTPUT_NAME ${_filename}) 65 | set_target_properties(${_sample} PROPERTIES DEBUG_POSTFIX d) 66 | 67 | # link executable target to required libraries 68 | target_link_libraries(${_sample} 69 | ${OpenCV_LIBRARIES} 70 | ${ALVAR_LIBRARIES} 71 | SharedSamples 72 | ) 73 | if(NOT _glutviewer EQUAL -1) 74 | target_link_libraries(${_sample} SharedGlutViewer) 75 | endif(NOT _glutviewer EQUAL -1) 76 | 77 | # install executable 78 | if(NOT ALVAR_PACKAGE OR ALVAR_PACKAGE MATCHES bin) 79 | install(TARGETS ${_sample} DESTINATION bin) 80 | endif(NOT ALVAR_PACKAGE OR ALVAR_PACKAGE MATCHES bin) 81 | endforeach(_sample ${ALVAR_SAMPLES}) 82 | 83 | # install files for exported build environment 84 | if(ALVAR_PACKAGE MATCHES sdk) 85 | install(FILES CMakeLists.txt DESTINATION sample) 86 | file(GLOB ALVAR_SAMPLE_HEADERS "*.h") 87 | install(FILES ${ALVAR_SAMPLE_HEADERS} DESTINATION sample) 88 | file(GLOB ALVAR_SAMPLE_SOURCES "*.cpp") 89 | install(FILES ${ALVAR_SAMPLE_SOURCES} DESTINATION sample) 90 | endif(ALVAR_PACKAGE MATCHES sdk) 91 | -------------------------------------------------------------------------------- /ar_track_alvar/src/CaptureDevice.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of ALVAR, A Library for Virtual and Augmented Reality. 3 | * 4 | * Copyright 2007-2012 VTT Technical Research Centre of Finland 5 | * 6 | * Contact: VTT Augmented Reality Team 7 | * 8 | * 9 | * ALVAR is free software; you can redistribute it and/or modify it under the 10 | * terms of the GNU Lesser General Public License as published by the Free 11 | * Software Foundation; either version 2.1 of the License, or (at your option) 12 | * any later version. 13 | * 14 | * This library is distributed in the hope that it will be useful, but WITHOUT 15 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 16 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License 17 | * for more details. 18 | * 19 | * You should have received a copy of the GNU Lesser General Public License 20 | * along with ALVAR; if not, see 21 | * . 22 | */ 23 | 24 | #include "ar_track_alvar/CaptureDevice.h" 25 | 26 | #include 27 | 28 | namespace alvar { 29 | 30 | CaptureDevice::CaptureDevice(const std::string captureType, const std::string id, const std::string description) 31 | : mCaptureType(captureType) 32 | , mId(id) 33 | , mDescription(description) 34 | { 35 | } 36 | 37 | CaptureDevice::~CaptureDevice() 38 | { 39 | } 40 | 41 | std::string CaptureDevice::captureType() const 42 | { 43 | return mCaptureType; 44 | } 45 | 46 | std::string CaptureDevice::id() const 47 | { 48 | return mId; 49 | } 50 | 51 | std::string CaptureDevice::description() const 52 | { 53 | return mDescription; 54 | } 55 | 56 | std::string CaptureDevice::uniqueName() const 57 | { 58 | std::stringstream name; 59 | name << captureType() << "_" << id(); 60 | return name.str(); 61 | } 62 | 63 | } // namespace alvar 64 | -------------------------------------------------------------------------------- /ar_track_alvar/src/CaptureFactory_unix.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of ALVAR, A Library for Virtual and Augmented Reality. 3 | * 4 | * Copyright 2007-2012 VTT Technical Research Centre of Finland 5 | * 6 | * Contact: VTT Augmented Reality Team 7 | * 8 | * 9 | * ALVAR is free software; you can redistribute it and/or modify it under the 10 | * terms of the GNU Lesser General Public License as published by the Free 11 | * Software Foundation; either version 2.1 of the License, or (at your option) 12 | * any later version. 13 | * 14 | * This library is distributed in the hope that it will be useful, but WITHOUT 15 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 16 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License 17 | * for more details. 18 | * 19 | * You should have received a copy of the GNU Lesser General Public License 20 | * along with ALVAR; if not, see 21 | * . 22 | */ 23 | 24 | #include "ar_track_alvar/CaptureFactory_private.h" 25 | 26 | #include 27 | #include // for readlink() 28 | 29 | namespace alvar { 30 | 31 | void CaptureFactoryPrivate::setupPluginPaths() 32 | { 33 | // application path and default plugin path 34 | const int bufferSize = 4096; 35 | char applicationBuffer[bufferSize]; 36 | int count = readlink("/proc/self/exe", applicationBuffer, bufferSize); 37 | if (count != 0 && count < bufferSize) { 38 | std::string applicationPath(applicationBuffer, count); 39 | applicationPath = std::string(applicationPath, 0, applicationPath.find_last_of("/")); 40 | mPluginPaths.push_back(applicationPath); 41 | mPluginPaths.push_back(applicationPath + "/alvarplugins"); 42 | } 43 | 44 | // ALVAR library path 45 | parseEnvironmentVariable(std::string("ALVAR_LIBRARY_PATH")); 46 | 47 | // ALVAR plugin path 48 | parseEnvironmentVariable(std::string("ALVAR_PLUGIN_PATH")); 49 | } 50 | 51 | void CaptureFactoryPrivate::parseEnvironmentVariable(const std::string &variable) 52 | { 53 | // acquire environment variable 54 | char *buffer; 55 | std::string path(""); 56 | buffer = getenv(variable.data()); 57 | if (buffer) { 58 | path = std::string(buffer); 59 | } 60 | 61 | // tokenize paths 62 | char delimitor = ':'; 63 | if (!path.empty()) { 64 | std::string::size_type start = 0; 65 | std::string::size_type end = 0; 66 | while ((end = path.find_first_of(delimitor, start)) != std::string::npos) { 67 | std::string tmp(path, start, end - start); 68 | if (!tmp.empty()) { 69 | mPluginPaths.push_back(tmp); 70 | } 71 | start = end + 1; 72 | } 73 | if (start != path.size()) { 74 | std::string tmp(path, start, std::string::npos); 75 | if (!tmp.empty()) { 76 | mPluginPaths.push_back(tmp); 77 | } 78 | } 79 | } 80 | } 81 | 82 | std::string CaptureFactoryPrivate::pluginPrefix() 83 | { 84 | return std::string("lib"); 85 | } 86 | 87 | std::string CaptureFactoryPrivate::pluginExtension() 88 | { 89 | return std::string("so"); 90 | } 91 | 92 | } // namespace alvar 93 | -------------------------------------------------------------------------------- /ar_track_alvar/src/CaptureFactory_win.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of ALVAR, A Library for Virtual and Augmented Reality. 3 | * 4 | * Copyright 2007-2012 VTT Technical Research Centre of Finland 5 | * 6 | * Contact: VTT Augmented Reality Team 7 | * 8 | * 9 | * ALVAR is free software; you can redistribute it and/or modify it under the 10 | * terms of the GNU Lesser General Public License as published by the Free 11 | * Software Foundation; either version 2.1 of the License, or (at your option) 12 | * any later version. 13 | * 14 | * This library is distributed in the hope that it will be useful, but WITHOUT 15 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 16 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License 17 | * for more details. 18 | * 19 | * You should have received a copy of the GNU Lesser General Public License 20 | * along with ALVAR; if not, see 21 | * . 22 | */ 23 | 24 | #include "CaptureFactory_private.h" 25 | 26 | #include 27 | 28 | namespace alvar { 29 | 30 | void CaptureFactoryPrivate::setupPluginPaths() 31 | { 32 | // application path and default plugin path 33 | const DWORD bufferSize = 4096; 34 | char applicationBuffer[bufferSize]; 35 | DWORD count = GetModuleFileName(NULL, applicationBuffer, bufferSize); 36 | if (count != 0 && count < bufferSize) { 37 | std::string applicationPath(applicationBuffer, count); 38 | applicationPath = std::string(applicationPath, 0, applicationPath.find_last_of("\\")); 39 | mPluginPaths.push_back(applicationPath); 40 | mPluginPaths.push_back(applicationPath + "\\alvarplugins"); 41 | } 42 | 43 | // ALVAR library path 44 | parseEnvironmentVariable(std::string("ALVAR_LIBRARY_PATH")); 45 | 46 | // ALVAR plugin path 47 | parseEnvironmentVariable(std::string("ALVAR_PLUGIN_PATH")); 48 | } 49 | 50 | void CaptureFactoryPrivate::parseEnvironmentVariable(const std::string &variable) 51 | { 52 | // acquire environment variable 53 | char *buffer; 54 | std::string path(""); 55 | #if defined(_MSC_VER) && (_MSC_VER < 1400) 56 | buffer = getenv(variable.data()); 57 | if (buffer) { 58 | path = std::string(buffer); 59 | } 60 | #else 61 | size_t requiredSize; 62 | getenv_s(&requiredSize, NULL, 0, variable.data()); 63 | if (requiredSize > 0) { 64 | buffer = (char *)malloc(requiredSize * sizeof(char)); 65 | getenv_s(&requiredSize, buffer, requiredSize, variable.data()); 66 | path = std::string(buffer, requiredSize - 1); 67 | free(buffer); 68 | } 69 | #endif 70 | 71 | // tokenize paths 72 | char delimitor = ';'; 73 | if (!path.empty()) { 74 | std::string::size_type start = 0; 75 | std::string::size_type end = 0; 76 | while ((end = path.find_first_of(delimitor, start)) != std::string::npos) { 77 | std::string tmp(path, start, end - start); 78 | if (!tmp.empty()) { 79 | mPluginPaths.push_back(tmp); 80 | } 81 | start = end + 1; 82 | } 83 | if (start != path.size()) { 84 | std::string tmp(path, start, std::string::npos); 85 | if (!tmp.empty()) { 86 | mPluginPaths.push_back(tmp); 87 | } 88 | } 89 | } 90 | } 91 | 92 | std::string CaptureFactoryPrivate::pluginPrefix() 93 | { 94 | return std::string(""); 95 | } 96 | 97 | std::string CaptureFactoryPrivate::pluginExtension() 98 | { 99 | return std::string("dll"); 100 | } 101 | 102 | } // namespace alvar 103 | -------------------------------------------------------------------------------- /ar_track_alvar/src/DirectoryIterator.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of ALVAR, A Library for Virtual and Augmented Reality. 3 | * 4 | * Copyright 2007-2012 VTT Technical Research Centre of Finland 5 | * 6 | * Contact: VTT Augmented Reality Team 7 | * 8 | * 9 | * ALVAR is free software; you can redistribute it and/or modify it under the 10 | * terms of the GNU Lesser General Public License as published by the Free 11 | * Software Foundation; either version 2.1 of the License, or (at your option) 12 | * any later version. 13 | * 14 | * This library is distributed in the hope that it will be useful, but WITHOUT 15 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 16 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License 17 | * for more details. 18 | * 19 | * You should have received a copy of the GNU Lesser General Public License 20 | * along with ALVAR; if not, see 21 | * . 22 | */ 23 | 24 | #include "ar_track_alvar/DirectoryIterator.h" 25 | 26 | #include "ar_track_alvar/DirectoryIterator_private.h" 27 | 28 | namespace alvar { 29 | 30 | DirectoryIterator::DirectoryIterator(const std::string &path) 31 | : d(new DirectoryIteratorPrivate(path)) 32 | { 33 | } 34 | 35 | DirectoryIterator::~DirectoryIterator() 36 | { 37 | delete d; 38 | } 39 | 40 | bool DirectoryIterator::hasNext() 41 | { 42 | return d->hasNext(); 43 | } 44 | 45 | std::string DirectoryIterator::next() 46 | { 47 | return d->next(); 48 | } 49 | 50 | std::string DirectoryIterator::currentEntry() 51 | { 52 | return d->mEntry; 53 | } 54 | 55 | std::string DirectoryIterator::currentPath() 56 | { 57 | return d->mDirectory + d->mEntry; 58 | } 59 | 60 | } // namespace alvar 61 | -------------------------------------------------------------------------------- /ar_track_alvar/src/DirectoryIterator_unix.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of ALVAR, A Library for Virtual and Augmented Reality. 3 | * 4 | * Copyright 2007-2012 VTT Technical Research Centre of Finland 5 | * 6 | * Contact: VTT Augmented Reality Team 7 | * 8 | * 9 | * ALVAR is free software; you can redistribute it and/or modify it under the 10 | * terms of the GNU Lesser General Public License as published by the Free 11 | * Software Foundation; either version 2.1 of the License, or (at your option) 12 | * any later version. 13 | * 14 | * This library is distributed in the hope that it will be useful, but WITHOUT 15 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 16 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License 17 | * for more details. 18 | * 19 | * You should have received a copy of the GNU Lesser General Public License 20 | * along with ALVAR; if not, see 21 | * . 22 | */ 23 | 24 | #include "ar_track_alvar/DirectoryIterator_private.h" 25 | 26 | #include 27 | 28 | namespace alvar { 29 | 30 | class DirectoryIteratorPrivateData 31 | { 32 | public: 33 | DirectoryIteratorPrivateData() 34 | : mHandle(NULL) 35 | , mData(NULL) 36 | { 37 | } 38 | 39 | DIR *mHandle; 40 | dirent *mData; 41 | }; 42 | 43 | DirectoryIteratorPrivate::DirectoryIteratorPrivate(const std::string &path) 44 | : d(new DirectoryIteratorPrivateData()) 45 | , mDirectory(path) 46 | , mEntry() 47 | , mValid(false) 48 | { 49 | if (mDirectory.at(mDirectory.length() - 1) != '/') { 50 | mDirectory.append("/"); 51 | } 52 | } 53 | 54 | DirectoryIteratorPrivate::~DirectoryIteratorPrivate() 55 | { 56 | closedir(d->mHandle); 57 | delete d; 58 | } 59 | 60 | bool DirectoryIteratorPrivate::hasNext() 61 | { 62 | if (d->mHandle == NULL) { 63 | d->mHandle = opendir(mDirectory.data()); 64 | 65 | if (d->mHandle != NULL) { 66 | d->mData = readdir(d->mHandle); 67 | 68 | if (d->mData != NULL) { 69 | mValid = true; 70 | skip(); 71 | } 72 | } 73 | } 74 | 75 | return mValid; 76 | } 77 | 78 | std::string DirectoryIteratorPrivate::next() 79 | { 80 | if (!hasNext()) { 81 | return ""; 82 | } 83 | 84 | mEntry = std::string(d->mData->d_name); 85 | 86 | d->mData = readdir(d->mHandle); 87 | if (d->mData == NULL) { 88 | mValid = false; 89 | } 90 | else { 91 | skip(); 92 | } 93 | 94 | return mEntry; 95 | } 96 | 97 | void DirectoryIteratorPrivate::skip() 98 | { 99 | while (true) { 100 | if (std::string(d->mData->d_name) != "." && std::string(d->mData->d_name) != "..") { 101 | return; 102 | } 103 | 104 | d->mData = readdir(d->mHandle); 105 | if (d->mData == NULL) { 106 | mValid = false; 107 | return; 108 | } 109 | } 110 | } 111 | 112 | } // namespace alvar 113 | -------------------------------------------------------------------------------- /ar_track_alvar/src/DirectoryIterator_win.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of ALVAR, A Library for Virtual and Augmented Reality. 3 | * 4 | * Copyright 2007-2012 VTT Technical Research Centre of Finland 5 | * 6 | * Contact: VTT Augmented Reality Team 7 | * 8 | * 9 | * ALVAR is free software; you can redistribute it and/or modify it under the 10 | * terms of the GNU Lesser General Public License as published by the Free 11 | * Software Foundation; either version 2.1 of the License, or (at your option) 12 | * any later version. 13 | * 14 | * This library is distributed in the hope that it will be useful, but WITHOUT 15 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 16 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License 17 | * for more details. 18 | * 19 | * You should have received a copy of the GNU Lesser General Public License 20 | * along with ALVAR; if not, see 21 | * . 22 | */ 23 | 24 | #include "DirectoryIterator_private.h" 25 | 26 | #include 27 | 28 | namespace alvar { 29 | 30 | class DirectoryIteratorPrivateData 31 | { 32 | public: 33 | DirectoryIteratorPrivateData() 34 | : mHandle(INVALID_HANDLE_VALUE) 35 | , mData() 36 | { 37 | } 38 | 39 | HANDLE mHandle; 40 | WIN32_FIND_DATA mData; 41 | }; 42 | 43 | DirectoryIteratorPrivate::DirectoryIteratorPrivate(const std::string &path) 44 | : d(new DirectoryIteratorPrivateData()) 45 | , mDirectory(path) 46 | , mEntry() 47 | , mValid(false) 48 | { 49 | if (mDirectory.at(mDirectory.length() - 1) != '\\') { 50 | mDirectory.append("\\"); 51 | } 52 | } 53 | 54 | DirectoryIteratorPrivate::~DirectoryIteratorPrivate() 55 | { 56 | FindClose(d->mHandle); 57 | delete d; 58 | } 59 | 60 | bool DirectoryIteratorPrivate::hasNext() 61 | { 62 | if (d->mHandle == INVALID_HANDLE_VALUE) { 63 | std::string search = mDirectory + "*"; 64 | d->mHandle = FindFirstFile(search.data(), &d->mData); 65 | 66 | if (d->mHandle != INVALID_HANDLE_VALUE) { 67 | mValid = true; 68 | skip(); 69 | } 70 | } 71 | 72 | return mValid; 73 | } 74 | 75 | std::string DirectoryIteratorPrivate::next() 76 | { 77 | if (!hasNext()) { 78 | return ""; 79 | } 80 | 81 | mEntry = std::string(d->mData.cFileName); 82 | 83 | if (!FindNextFile(d->mHandle, &d->mData)) { 84 | mValid = false; 85 | } 86 | else { 87 | skip(); 88 | } 89 | 90 | return mEntry; 91 | } 92 | 93 | void DirectoryIteratorPrivate::skip() 94 | { 95 | while (true) { 96 | if (std::string(d->mData.cFileName) != "." && std::string(d->mData.cFileName) != "..") { 97 | return; 98 | } 99 | 100 | if (!FindNextFile(d->mHandle, &d->mData)) { 101 | mValid = false; 102 | return; 103 | } 104 | } 105 | } 106 | 107 | } // namespace alvar 108 | -------------------------------------------------------------------------------- /ar_track_alvar/src/FernPoseEstimator.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of ALVAR, A Library for Virtual and Augmented Reality. 3 | * 4 | * Copyright 2007-2012 VTT Technical Research Centre of Finland 5 | * 6 | * Contact: VTT Augmented Reality Team 7 | * 8 | * 9 | * ALVAR is free software; you can redistribute it and/or modify it under the 10 | * terms of the GNU Lesser General Public License as published by the Free 11 | * Software Foundation; either version 2.1 of the License, or (at your option) 12 | * any later version. 13 | * 14 | * This library is distributed in the hope that it will be useful, but WITHOUT 15 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 16 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License 17 | * for more details. 18 | * 19 | * You should have received a copy of the GNU Lesser General Public License 20 | * along with ALVAR; if not, see 21 | * . 22 | */ 23 | 24 | #include "FernPoseEstimator.h" 25 | 26 | namespace alvar { 27 | 28 | FernPoseEstimator::FernPoseEstimator() 29 | : mPose() 30 | , mCamera() 31 | , mCameraEC() 32 | { 33 | } 34 | 35 | FernPoseEstimator::~FernPoseEstimator() 36 | { 37 | } 38 | 39 | Pose FernPoseEstimator::pose() const 40 | { 41 | return mPose; 42 | } 43 | 44 | Camera FernPoseEstimator::camera() const 45 | { 46 | return mCamera; 47 | } 48 | 49 | bool FernPoseEstimator::setCalibration(const std::string &filename, int width, int height) 50 | { 51 | bool r1 = mCamera.SetCalib(filename.c_str(), width, height); 52 | bool r2 = mCameraEC.SetCalib(filename.c_str(), width, height); 53 | return r1 && r2; 54 | } 55 | 56 | void FernPoseEstimator::setResolution(int width, int height) 57 | { 58 | mCamera.SetRes(width, height); 59 | mCameraEC.SetRes(width, height); 60 | } 61 | 62 | void FernPoseEstimator::calculateFromPointCorrespondences(FernPoseEstimator::ModelPointVector &mpts, FernPoseEstimator::ImagePointVector &ipts) 63 | { 64 | mCamera.CalcExteriorOrientation(mpts, ipts, &mPose); // TODO replace camera->cameraec 65 | } 66 | 67 | void FernPoseEstimator::updateFromTrackedPoints(FernPoseEstimator::ExternalContainerMap &container) 68 | { 69 | mCameraEC.UpdatePose(container, &mPose); 70 | } 71 | 72 | void FernPoseEstimator::extractPlaneCoordinates(FernPoseEstimator::ExternalContainerMap &container) 73 | { 74 | ExternalContainerMap::iterator iter = container.begin(); 75 | ExternalContainerMap::iterator iter_end = container.end(); 76 | for(; iter != iter_end; ++iter) { 77 | alvar::ExternalContainer &f = iter->second; 78 | mCameraEC.Get3dOnPlane(&mPose, f.p2d, f.p3d); 79 | f.has_p3d = true; 80 | } 81 | } 82 | 83 | } // namespace alvar 84 | -------------------------------------------------------------------------------- /ar_track_alvar/src/FileFormatUtils.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of ALVAR, A Library for Virtual and Augmented Reality. 3 | * 4 | * Copyright 2007-2012 VTT Technical Research Centre of Finland 5 | * 6 | * Contact: VTT Augmented Reality Team 7 | * 8 | * 9 | * ALVAR is free software; you can redistribute it and/or modify it under the 10 | * terms of the GNU Lesser General Public License as published by the Free 11 | * Software Foundation; either version 2.1 of the License, or (at your option) 12 | * any later version. 13 | * 14 | * This library is distributed in the hope that it will be useful, but WITHOUT 15 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 16 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License 17 | * for more details. 18 | * 19 | * You should have received a copy of the GNU Lesser General Public License 20 | * along with ALVAR; if not, see 21 | * . 22 | */ 23 | 24 | #include "ar_track_alvar/FileFormatUtils.h" 25 | #include 26 | #include 27 | #include 28 | 29 | namespace alvar { 30 | 31 | bool FileFormatUtils::decodeXMLMatrix(const TiXmlElement *xml_matrix, int &type, int &rows, int &cols) { 32 | const char * xml_type = xml_matrix->Attribute("type"); 33 | if (strcmp("CV_32F", xml_type) == 0) type = CV_32F; 34 | else if (strcmp("CV_64F", xml_type) == 0) type = CV_64F; 35 | else return false; 36 | 37 | if (xml_matrix->QueryIntAttribute("rows", &rows) != TIXML_SUCCESS) return false; 38 | if (xml_matrix->QueryIntAttribute("cols", &cols) != TIXML_SUCCESS) return false; 39 | 40 | return true; 41 | } 42 | 43 | CvMat* FileFormatUtils::allocateXMLMatrix(const TiXmlElement *xml_matrix) { 44 | if (!xml_matrix) return NULL; 45 | 46 | int type, rows, cols; 47 | if (!decodeXMLMatrix(xml_matrix, type, rows, cols)) return NULL; 48 | 49 | return cvCreateMat(rows, cols, type); 50 | } 51 | 52 | bool FileFormatUtils::parseXMLMatrix(const TiXmlElement *xml_matrix, CvMat *matrix) { 53 | if (!xml_matrix || !matrix) return false; 54 | 55 | int type, rows, cols; 56 | if (!decodeXMLMatrix(xml_matrix, type, rows, cols)) return false; 57 | 58 | if (type != cvGetElemType(matrix)) return false; 59 | if (rows != matrix->rows) return false; 60 | if (cols != matrix->cols) return false; 61 | 62 | const TiXmlElement *xml_data = xml_matrix->FirstChildElement("data"); 63 | for (int r = 0; r < matrix->rows; ++r) { 64 | for (int c = 0; c < matrix->cols; ++c) { 65 | if (!xml_data) return false; 66 | double value = atof(xml_data->GetText()); 67 | cvSetReal2D(matrix, r, c, value); 68 | xml_data = (const TiXmlElement *) xml_data->NextSibling("data"); 69 | } 70 | } 71 | 72 | return true; 73 | } 74 | 75 | TiXmlElement* FileFormatUtils::createXMLMatrix(const char* element_name, const CvMat *matrix) { 76 | if (!matrix) return NULL; 77 | 78 | TiXmlElement* xml_matrix = new TiXmlElement(element_name); 79 | int precision; 80 | if (cvGetElemType(matrix) == CV_32F) { 81 | xml_matrix->SetAttribute("type", "CV_32F"); 82 | precision = std::numeric_limits::digits10 + 2; 83 | } 84 | else if (cvGetElemType(matrix) == CV_64F) { 85 | xml_matrix->SetAttribute("type", "CV_64F"); 86 | precision = std::numeric_limits::digits10 + 2; 87 | } 88 | else { 89 | delete xml_matrix; 90 | return NULL; 91 | } 92 | 93 | xml_matrix->SetAttribute("rows", matrix->rows); 94 | xml_matrix->SetAttribute("cols", matrix->cols); 95 | 96 | for (int r = 0; r < matrix->rows; ++r) { 97 | for (int c = 0; c < matrix->cols; ++c) { 98 | TiXmlElement *xml_data = new TiXmlElement("data"); 99 | xml_matrix->LinkEndChild(xml_data); 100 | std::stringstream ss; 101 | ss.precision(precision); 102 | ss<LinkEndChild(new TiXmlText(ss.str().c_str())); 104 | } 105 | } 106 | return xml_matrix; 107 | } 108 | } 109 | -------------------------------------------------------------------------------- /ar_track_alvar/src/Filter.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of ALVAR, A Library for Virtual and Augmented Reality. 3 | * 4 | * Copyright 2007-2012 VTT Technical Research Centre of Finland 5 | * 6 | * Contact: VTT Augmented Reality Team 7 | * 8 | * 9 | * ALVAR is free software; you can redistribute it and/or modify it under the 10 | * terms of the GNU Lesser General Public License as published by the Free 11 | * Software Foundation; either version 2.1 of the License, or (at your option) 12 | * any later version. 13 | * 14 | * This library is distributed in the hope that it will be useful, but WITHOUT 15 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 16 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License 17 | * for more details. 18 | * 19 | * You should have received a copy of the GNU Lesser General Public License 20 | * along with ALVAR; if not, see 21 | * . 22 | */ 23 | 24 | #include "ar_track_alvar/Alvar.h" 25 | #include "ar_track_alvar/Filter.h" 26 | 27 | template class ALVAR_EXPORT alvar::FilterArray; 28 | template class ALVAR_EXPORT alvar::FilterArray; 29 | template class ALVAR_EXPORT alvar::FilterArray; 30 | template class ALVAR_EXPORT alvar::FilterArray; 31 | 32 | using namespace std; 33 | 34 | namespace alvar { 35 | using namespace std; 36 | 37 | Filter::Filter() { 38 | value=0; 39 | } 40 | 41 | void FilterAverage::push_to_buffer(double y) { 42 | buffer.push_back(y); 43 | while (buffer.size() > window_size) { 44 | buffer.pop_front(); 45 | } 46 | } 47 | 48 | double FilterAverage::next(double y) { 49 | if (window_size <= 0) { 50 | count++; 51 | double alpha = 1.0/count; 52 | return (value=((1.0-alpha)*value)+(alpha*y)); 53 | } else { 54 | push_to_buffer(y); 55 | double sum = 0; 56 | for (deque::iterator iter = buffer.begin(); iter != buffer.end(); iter++) { 57 | sum += (double)*iter; 58 | } 59 | return (value=sum/buffer.size()); 60 | } 61 | } 62 | 63 | void FilterAverage::reset() { 64 | buffer.clear(); 65 | } 66 | 67 | double FilterAverage::deviation() const { 68 | double sum = 0; 69 | if (buffer.size() == 0) return 0; 70 | for (deque::const_iterator iter = buffer.begin(); iter != buffer.end(); iter++) { 71 | double val = ((double)*iter)-value; 72 | sum += (val*val); 73 | } 74 | sum /= buffer.size(); 75 | return sqrt(sum); 76 | } 77 | 78 | double FilterMedian::next(double y) { 79 | if (window_size <= 1) return y; 80 | push_to_buffer(y); 81 | copy(buffer.begin(), buffer.end(), sort_buffer.begin()); 82 | int nth = buffer.size()/2; 83 | nth_element(sort_buffer.begin(), sort_buffer.begin() + nth, sort_buffer.begin()+buffer.size()); 84 | return value = sort_buffer[nth]; 85 | } 86 | 87 | double FilterRunningAverage::next(double y) { 88 | if (breset) { 89 | breset=false; 90 | value=(double)y; 91 | } else { 92 | value = ((1.0-alpha) * value) + (alpha * (double)y); 93 | } 94 | return value; 95 | } 96 | 97 | void FilterRunningAverage::reset() { breset=true; } 98 | 99 | double FilterDoubleExponentialSmoothing::next(double y) { 100 | if (breset) { 101 | breset=false; 102 | value=(double)y; 103 | slope=0.0; 104 | } 105 | else { 106 | double value_prev = value; 107 | value = ((1.0-alpha) * (value + slope)) + (alpha * (double)y); 108 | slope = ((1.0-gamma) * (slope)) + (gamma * (value - value_prev)); 109 | } 110 | return value; 111 | } 112 | 113 | } // namespace alvar 114 | -------------------------------------------------------------------------------- /ar_track_alvar/src/Line.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of ALVAR, A Library for Virtual and Augmented Reality. 3 | * 4 | * Copyright 2007-2012 VTT Technical Research Centre of Finland 5 | * 6 | * Contact: VTT Augmented Reality Team 7 | * 8 | * 9 | * ALVAR is free software; you can redistribute it and/or modify it under the 10 | * terms of the GNU Lesser General Public License as published by the Free 11 | * Software Foundation; either version 2.1 of the License, or (at your option) 12 | * any later version. 13 | * 14 | * This library is distributed in the hope that it will be useful, but WITHOUT 15 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 16 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License 17 | * for more details. 18 | * 19 | * You should have received a copy of the GNU Lesser General Public License 20 | * along with ALVAR; if not, see 21 | * . 22 | */ 23 | 24 | #include "ar_track_alvar/Line.h" 25 | 26 | using namespace std; 27 | 28 | namespace alvar { 29 | using namespace std; 30 | 31 | Line::Line(float params[4]) 32 | { 33 | c.x = params[2]; 34 | c.y = params[3]; 35 | s.x = params[0]; 36 | s.y = params[1]; 37 | } 38 | 39 | void FitLines(vector& lines) 40 | { 41 | 42 | } 43 | 44 | int FitLines(vector &lines, 45 | const vector& corners, 46 | const vector& edge, 47 | IplImage *grey /*=0*/) // grey image for future sub pixel accuracy 48 | { 49 | lines.clear(); 50 | for(unsigned j = 0; j < corners.size(); ++j) 51 | { 52 | int start, end, first; 53 | int size = (int)edge.size(); 54 | 55 | first = corners[0]; 56 | start = corners[j]; 57 | 58 | if(j < corners.size()-1) 59 | end = corners[j+1]; 60 | else 61 | end = first; 62 | 63 | int len = 0; 64 | 65 | if(start < end) 66 | len = end-start+1; 67 | else 68 | len = size-start+end+1; 69 | 70 | int ind; 71 | double* data = new double[2*len]; 72 | 73 | // OpenCV routine... 74 | CvMat* line_data = cvCreateMat(1, len, CV_32FC2); 75 | for(int i = 0; i < len; ++i) 76 | { 77 | ind = i + start; 78 | if(ind >= size) 79 | ind = ind-size; 80 | 81 | double px = double(edge[ind].x); 82 | double py = double(edge[ind].y); 83 | CV_MAT_ELEM(*line_data, CvPoint2D32f, 0, i) = cvPoint2D32f(px, py); 84 | } 85 | 86 | float params[4] = {0}; 87 | cvFitLine(line_data, CV_DIST_L2, 0, 0.01, 0.01, params); 88 | lines.push_back(Line(params)); 89 | 90 | delete [] data; 91 | cvReleaseMat(&line_data); 92 | 93 | } 94 | 95 | return lines.size(); 96 | } 97 | 98 | PointDouble Intersection(const Line& l1, const Line& l2) 99 | { 100 | 101 | double vx = l1.s.x; 102 | double vy = l1.s.y; 103 | double ux = l2.s.x; 104 | double uy = l2.s.y; 105 | double wx = l2.c.x-l1.c.x; 106 | double wy = l2.c.y-l1.c.y; 107 | 108 | double s, px, py; 109 | double tmp = vx*uy-vy*ux; 110 | if(tmp==0) tmp = 1; 111 | 112 | //if(/*tmp <= 1.f && tmp >= -1.f && */tmp != 0.f && ang > 0.1) 113 | { 114 | s = (vy*wx-vx*wy) / (tmp); 115 | px = l2.c.x+s*ux; 116 | py = l2.c.y+s*uy; 117 | } 118 | 119 | return PointDouble(px, py); 120 | } 121 | 122 | } // namespace alvar 123 | -------------------------------------------------------------------------------- /ar_track_alvar/src/MultiMarkerFiltered.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of ALVAR, A Library for Virtual and Augmented Reality. 3 | * 4 | * Copyright 2007-2012 VTT Technical Research Centre of Finland 5 | * 6 | * Contact: VTT Augmented Reality Team 7 | * 8 | * 9 | * ALVAR is free software; you can redistribute it and/or modify it under the 10 | * terms of the GNU Lesser General Public License as published by the Free 11 | * Software Foundation; either version 2.1 of the License, or (at your option) 12 | * any later version. 13 | * 14 | * This library is distributed in the hope that it will be useful, but WITHOUT 15 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 16 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License 17 | * for more details. 18 | * 19 | * You should have received a copy of the GNU Lesser General Public License 20 | * along with ALVAR; if not, see 21 | * . 22 | */ 23 | 24 | #include "MultiMarkerFiltered.h" 25 | 26 | using namespace std; 27 | 28 | namespace alvar { 29 | using namespace std; 30 | 31 | MultiMarkerFiltered::MultiMarkerFiltered(std::vector& indices) 32 | : MultiMarker(indices) 33 | { 34 | pointcloud_filtered = new FilterMedian[indices.size()*4*3]; 35 | for (size_t i=0; i= filter_buffer_max) { 62 | marker_status[get_id_index(marker_id)]=1; 63 | } 64 | } 65 | } 66 | } 67 | 68 | double MultiMarkerFiltered::_Update(MarkerIterator &begin, MarkerIterator &end, 69 | Camera* cam, Pose& pose, IplImage* image) 70 | { 71 | if (_GetPose(begin, end, cam, pose, NULL) == -1) return -1; 72 | 73 | // For every detected marker 74 | for (MarkerIterator &i = begin.reset(); i != end; ++i) 75 | { 76 | const Marker* marker = *i; 77 | int id = marker->GetId(); 78 | int index = get_id_index(id); 79 | if (index < 0) continue; 80 | 81 | // Initialize marker pose 82 | if (marker_status[index] == 0) 83 | { 84 | double cam_posed[16]; 85 | double mar_posed[16]; 86 | 87 | CvMat cam_mat = cvMat(4, 4, CV_64F, cam_posed); 88 | CvMat mar_mat = cvMat(4, 4, CV_64F, mar_posed); 89 | 90 | pose.GetMatrix(&cam_mat); 91 | marker->pose.GetMatrix(&mar_mat); 92 | 93 | cvInvert(&cam_mat, &cam_mat); 94 | cvMatMul(&cam_mat, &mar_mat, &mar_mat); 95 | 96 | Pose p; 97 | p.SetMatrix(&mar_mat); 98 | PointCloudAverage(id, marker->GetMarkerEdgeLength(), p); 99 | } 100 | } 101 | 102 | // When the pointcloud is updated we will get the new "better" pose... 103 | return _GetPose(begin, end, cam, pose, image); 104 | } 105 | 106 | } // namespace alvar 107 | -------------------------------------------------------------------------------- /ar_track_alvar/src/Mutex.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of ALVAR, A Library for Virtual and Augmented Reality. 3 | * 4 | * Copyright 2007-2012 VTT Technical Research Centre of Finland 5 | * 6 | * Contact: VTT Augmented Reality Team 7 | * 8 | * 9 | * ALVAR is free software; you can redistribute it and/or modify it under the 10 | * terms of the GNU Lesser General Public License as published by the Free 11 | * Software Foundation; either version 2.1 of the License, or (at your option) 12 | * any later version. 13 | * 14 | * This library is distributed in the hope that it will be useful, but WITHOUT 15 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 16 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License 17 | * for more details. 18 | * 19 | * You should have received a copy of the GNU Lesser General Public License 20 | * along with ALVAR; if not, see 21 | * . 22 | */ 23 | 24 | #include "ar_track_alvar/Mutex.h" 25 | 26 | #include "ar_track_alvar/Mutex_private.h" 27 | 28 | namespace alvar { 29 | 30 | Mutex::Mutex() 31 | : d(new MutexPrivate()) 32 | { 33 | } 34 | 35 | Mutex::~Mutex() 36 | { 37 | delete d; 38 | } 39 | 40 | void Mutex::lock() 41 | { 42 | return d->lock(); 43 | } 44 | 45 | void Mutex::unlock() 46 | { 47 | return d->unlock(); 48 | } 49 | 50 | } // namespace alvar 51 | -------------------------------------------------------------------------------- /ar_track_alvar/src/Mutex_unix.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of ALVAR, A Library for Virtual and Augmented Reality. 3 | * 4 | * Copyright 2007-2012 VTT Technical Research Centre of Finland 5 | * 6 | * Contact: VTT Augmented Reality Team 7 | * 8 | * 9 | * ALVAR is free software; you can redistribute it and/or modify it under the 10 | * terms of the GNU Lesser General Public License as published by the Free 11 | * Software Foundation; either version 2.1 of the License, or (at your option) 12 | * any later version. 13 | * 14 | * This library is distributed in the hope that it will be useful, but WITHOUT 15 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 16 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License 17 | * for more details. 18 | * 19 | * You should have received a copy of the GNU Lesser General Public License 20 | * along with ALVAR; if not, see 21 | * . 22 | */ 23 | 24 | #include "ar_track_alvar/Mutex_private.h" 25 | 26 | #include 27 | 28 | namespace alvar { 29 | 30 | class MutexPrivateData 31 | { 32 | public: 33 | MutexPrivateData() 34 | : mMutex() 35 | { 36 | } 37 | 38 | pthread_mutex_t mMutex; 39 | }; 40 | 41 | MutexPrivate::MutexPrivate() 42 | : d(new MutexPrivateData()) 43 | { 44 | pthread_mutex_init(&d->mMutex, NULL); 45 | } 46 | 47 | MutexPrivate::~MutexPrivate() 48 | { 49 | pthread_mutex_destroy(&d->mMutex); 50 | delete d; 51 | } 52 | 53 | void MutexPrivate::lock() 54 | { 55 | pthread_mutex_lock(&d->mMutex); 56 | } 57 | 58 | void MutexPrivate::unlock() 59 | { 60 | pthread_mutex_unlock(&d->mMutex); 61 | } 62 | 63 | } // namespace alvar 64 | -------------------------------------------------------------------------------- /ar_track_alvar/src/Mutex_win.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of ALVAR, A Library for Virtual and Augmented Reality. 3 | * 4 | * Copyright 2007-2012 VTT Technical Research Centre of Finland 5 | * 6 | * Contact: VTT Augmented Reality Team 7 | * 8 | * 9 | * ALVAR is free software; you can redistribute it and/or modify it under the 10 | * terms of the GNU Lesser General Public License as published by the Free 11 | * Software Foundation; either version 2.1 of the License, or (at your option) 12 | * any later version. 13 | * 14 | * This library is distributed in the hope that it will be useful, but WITHOUT 15 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 16 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License 17 | * for more details. 18 | * 19 | * You should have received a copy of the GNU Lesser General Public License 20 | * along with ALVAR; if not, see 21 | * . 22 | */ 23 | 24 | #include "Mutex_private.h" 25 | 26 | #include 27 | 28 | namespace alvar { 29 | 30 | class MutexPrivateData 31 | { 32 | public: 33 | MutexPrivateData() 34 | : mCriticalSection() 35 | { 36 | } 37 | 38 | CRITICAL_SECTION mCriticalSection; 39 | }; 40 | 41 | MutexPrivate::MutexPrivate() 42 | : d(new MutexPrivateData()) 43 | { 44 | InitializeCriticalSection(&d->mCriticalSection); 45 | } 46 | 47 | MutexPrivate::~MutexPrivate() 48 | { 49 | DeleteCriticalSection(&d->mCriticalSection); 50 | delete d; 51 | } 52 | 53 | void MutexPrivate::lock() 54 | { 55 | EnterCriticalSection(&d->mCriticalSection); 56 | } 57 | 58 | void MutexPrivate::unlock() 59 | { 60 | LeaveCriticalSection(&d->mCriticalSection); 61 | } 62 | 63 | } // namespace alvar 64 | -------------------------------------------------------------------------------- /ar_track_alvar/src/Platform.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of ALVAR, A Library for Virtual and Augmented Reality. 3 | * 4 | * Copyright 2007-2012 VTT Technical Research Centre of Finland 5 | * 6 | * Contact: VTT Augmented Reality Team 7 | * 8 | * 9 | * ALVAR is free software; you can redistribute it and/or modify it under the 10 | * terms of the GNU Lesser General Public License as published by the Free 11 | * Software Foundation; either version 2.1 of the License, or (at your option) 12 | * any later version. 13 | * 14 | * This library is distributed in the hope that it will be useful, but WITHOUT 15 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 16 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License 17 | * for more details. 18 | * 19 | * You should have received a copy of the GNU Lesser General Public License 20 | * along with ALVAR; if not, see 21 | * . 22 | */ 23 | 24 | #include "Platform.h" 25 | 26 | #include 27 | #include 28 | #include 29 | #include 30 | #ifdef WIN32 31 | #include 32 | #else 33 | #include 34 | #endif 35 | 36 | namespace alvar { 37 | 38 | void errorAtLine(int status, int error, const char *filename, 39 | unsigned int line, const char *format, ...) 40 | { 41 | fflush(stdout); 42 | if (filename) { 43 | fprintf(stderr, "%s:%d: ", filename, line); 44 | } 45 | if (format) { 46 | va_list args; 47 | va_start(args, format); 48 | vfprintf(stderr, format, args); 49 | va_end(args); 50 | } 51 | if (error) { 52 | fprintf(stderr, ": %s", strerror(error)); 53 | } 54 | fprintf(stderr, "\n"); 55 | fflush(stderr); 56 | if (status) { 57 | exit(status); 58 | } 59 | } 60 | 61 | void sleep(unsigned long milliseconds) 62 | { 63 | #ifdef WIN32 64 | Sleep(milliseconds); 65 | #else 66 | struct timespec t; 67 | t.tv_sec = 0; 68 | t.tv_nsec = 1000 * 1000 * milliseconds; 69 | nanosleep(&t, NULL); 70 | #endif 71 | } 72 | 73 | } // namespace alvar 74 | -------------------------------------------------------------------------------- /ar_track_alvar/src/Plugin.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of ALVAR, A Library for Virtual and Augmented Reality. 3 | * 4 | * Copyright 2007-2012 VTT Technical Research Centre of Finland 5 | * 6 | * Contact: VTT Augmented Reality Team 7 | * 8 | * 9 | * ALVAR is free software; you can redistribute it and/or modify it under the 10 | * terms of the GNU Lesser General Public License as published by the Free 11 | * Software Foundation; either version 2.1 of the License, or (at your option) 12 | * any later version. 13 | * 14 | * This library is distributed in the hope that it will be useful, but WITHOUT 15 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 16 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License 17 | * for more details. 18 | * 19 | * You should have received a copy of the GNU Lesser General Public License 20 | * along with ALVAR; if not, see 21 | * . 22 | */ 23 | 24 | #include "ar_track_alvar/Plugin.h" 25 | 26 | #include "ar_track_alvar/Plugin_private.h" 27 | 28 | namespace alvar { 29 | 30 | Plugin::Plugin(const std::string filename) 31 | : d(new PluginPrivate()) 32 | , mReferenceCount(new int(1)) 33 | { 34 | d->load(filename); 35 | } 36 | 37 | Plugin::Plugin(const Plugin &plugin) 38 | : d(plugin.d) 39 | , mReferenceCount(plugin.mReferenceCount) 40 | { 41 | ++*mReferenceCount; 42 | } 43 | 44 | Plugin &Plugin::operator=(const Plugin &plugin) 45 | { 46 | d = plugin.d; 47 | mReferenceCount = plugin.mReferenceCount; 48 | ++*mReferenceCount; 49 | return *this; 50 | } 51 | 52 | Plugin::~Plugin() 53 | { 54 | if (!--*mReferenceCount) { 55 | d->unload(); 56 | delete d; 57 | delete mReferenceCount; 58 | } 59 | } 60 | 61 | void *Plugin::resolve(const char *symbol) 62 | { 63 | return d->resolve(symbol); 64 | } 65 | 66 | } // namespace alvar 67 | -------------------------------------------------------------------------------- /ar_track_alvar/src/Plugin_unix.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of ALVAR, A Library for Virtual and Augmented Reality. 3 | * 4 | * Copyright 2007-2012 VTT Technical Research Centre of Finland 5 | * 6 | * Contact: VTT Augmented Reality Team 7 | * 8 | * 9 | * ALVAR is free software; you can redistribute it and/or modify it under the 10 | * terms of the GNU Lesser General Public License as published by the Free 11 | * Software Foundation; either version 2.1 of the License, or (at your option) 12 | * any later version. 13 | * 14 | * This library is distributed in the hope that it will be useful, but WITHOUT 15 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 16 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License 17 | * for more details. 18 | * 19 | * You should have received a copy of the GNU Lesser General Public License 20 | * along with ALVAR; if not, see 21 | * . 22 | */ 23 | 24 | #include "ar_track_alvar/Plugin_private.h" 25 | 26 | #include "ar_track_alvar/AlvarException.h" 27 | 28 | #include 29 | #include 30 | #include 31 | 32 | namespace alvar { 33 | 34 | class PluginPrivateData 35 | { 36 | public: 37 | PluginPrivateData() 38 | : mHandle(NULL) 39 | { 40 | } 41 | 42 | void *mHandle; 43 | }; 44 | 45 | PluginPrivate::PluginPrivate() 46 | : d(new PluginPrivateData()) 47 | { 48 | } 49 | 50 | PluginPrivate::~PluginPrivate() 51 | { 52 | delete d; 53 | } 54 | 55 | void PluginPrivate::load(const std::string filename) 56 | { 57 | d->mHandle = dlopen(filename.data(), RTLD_LAZY); 58 | if (!d->mHandle) { 59 | std::stringstream message; 60 | message << "could not load " << filename 61 | << ", error code " << errno; 62 | throw AlvarException(message.str().data()); 63 | } 64 | } 65 | 66 | void PluginPrivate::unload() 67 | { 68 | dlclose(d->mHandle); 69 | } 70 | 71 | void *PluginPrivate::resolve(const char *symbol) 72 | { 73 | void *address = (void *)dlsym(d->mHandle, symbol); 74 | if (!address) { 75 | std::stringstream message; 76 | message << "could not resolve " << symbol; 77 | throw AlvarException(message.str().data()); 78 | } 79 | return address; 80 | } 81 | 82 | } // namespace alvar 83 | -------------------------------------------------------------------------------- /ar_track_alvar/src/Plugin_win.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of ALVAR, A Library for Virtual and Augmented Reality. 3 | * 4 | * Copyright 2007-2012 VTT Technical Research Centre of Finland 5 | * 6 | * Contact: VTT Augmented Reality Team 7 | * 8 | * 9 | * ALVAR is free software; you can redistribute it and/or modify it under the 10 | * terms of the GNU Lesser General Public License as published by the Free 11 | * Software Foundation; either version 2.1 of the License, or (at your option) 12 | * any later version. 13 | * 14 | * This library is distributed in the hope that it will be useful, but WITHOUT 15 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 16 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License 17 | * for more details. 18 | * 19 | * You should have received a copy of the GNU Lesser General Public License 20 | * along with ALVAR; if not, see 21 | * . 22 | */ 23 | 24 | #include "Plugin_private.h" 25 | 26 | #include "AlvarException.h" 27 | 28 | #include 29 | #include 30 | 31 | namespace alvar { 32 | 33 | class PluginPrivateData 34 | { 35 | public: 36 | PluginPrivateData() 37 | : mHandle(NULL) 38 | { 39 | } 40 | 41 | HINSTANCE mHandle; 42 | }; 43 | 44 | PluginPrivate::PluginPrivate() 45 | : d(new PluginPrivateData()) 46 | { 47 | } 48 | 49 | PluginPrivate::~PluginPrivate() 50 | { 51 | delete d; 52 | } 53 | 54 | void PluginPrivate::load(const std::string filename) 55 | { 56 | d->mHandle = LoadLibrary(filename.data()); 57 | if (!d->mHandle) { 58 | std::stringstream message; 59 | message << "could not load " << filename 60 | << ", error code " << GetLastError(); 61 | throw AlvarException(message.str().data()); 62 | } 63 | } 64 | 65 | void PluginPrivate::unload() 66 | { 67 | FreeLibrary(d->mHandle); 68 | } 69 | 70 | void *PluginPrivate::resolve(const char *symbol) 71 | { 72 | void *address = (void *)GetProcAddress(d->mHandle, symbol); 73 | if (!address) { 74 | std::stringstream message; 75 | message << "could not resolve " << symbol; 76 | throw AlvarException(message.str().data()); 77 | } 78 | return address; 79 | } 80 | 81 | } // namespace alvar 82 | -------------------------------------------------------------------------------- /ar_track_alvar/src/SampleMarkerlessCreator.cpp: -------------------------------------------------------------------------------- 1 | #include "FernImageDetector.h" 2 | using namespace std; 3 | using namespace alvar; 4 | 5 | int main(int argc, char *argv[]) 6 | { 7 | try { 8 | // Output usage message 9 | std::string filename(argv[0]); 10 | filename = filename.substr(filename.find_last_of('\\') + 1); 11 | std::cout << "SampleMarkerlessCreator" << std::endl; 12 | std::cout << "=======================" << std::endl; 13 | std::cout << std::endl; 14 | std::cout << "Description:" << std::endl; 15 | std::cout << " This is an example of how to use the 'FernImageDetector' class" << std::endl; 16 | std::cout << " to train a Fern classifier for markerless image-based tracking." << std::endl; 17 | std::cout << " The image should contain many unique features and be in the range" << std::endl; 18 | std::cout << " of 200x200 to 500x500 pixels. A '.dat' file will be saved in the" << std::endl; 19 | std::cout << " same directory as the image and can be used with the" << std::endl; 20 | std::cout << " SampleMarkerlessDetector sample." << std::endl; 21 | std::cout << std::endl; 22 | std::cout << "Usage:" << std::endl; 23 | std::cout << " " << filename << " filename" << std::endl; 24 | std::cout << std::endl; 25 | std::cout << " filename filename of image to train" << std::endl; 26 | std::cout << std::endl; 27 | 28 | if (argc < 2) { 29 | std::cout << "Filename not specified." << std::endl; 30 | return 0; 31 | } 32 | 33 | std::cout << "Training classifier." << std::endl; 34 | FernImageDetector fernDetector(true); 35 | std::string imageFilename(argv[1]); 36 | fernDetector.train(imageFilename); 37 | 38 | std::cout << "Writing classifier." << std::endl; 39 | std::string classifierFilename = imageFilename + ".dat"; 40 | if (!fernDetector.write(classifierFilename)) { 41 | std::cout << "Writing classifier failed." << std::endl; 42 | return 1; 43 | } 44 | 45 | return 0; 46 | } 47 | catch (const std::exception &e) { 48 | std::cout << "Exception: " << e.what() << endl; 49 | } 50 | catch (...) { 51 | std::cout << "Exception: unknown" << std::endl; 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /ar_track_alvar/src/Threads.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of ALVAR, A Library for Virtual and Augmented Reality. 3 | * 4 | * Copyright 2007-2012 VTT Technical Research Centre of Finland 5 | * 6 | * Contact: VTT Augmented Reality Team 7 | * 8 | * 9 | * ALVAR is free software; you can redistribute it and/or modify it under the 10 | * terms of the GNU Lesser General Public License as published by the Free 11 | * Software Foundation; either version 2.1 of the License, or (at your option) 12 | * any later version. 13 | * 14 | * This library is distributed in the hope that it will be useful, but WITHOUT 15 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 16 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License 17 | * for more details. 18 | * 19 | * You should have received a copy of the GNU Lesser General Public License 20 | * along with ALVAR; if not, see 21 | * . 22 | */ 23 | 24 | #include "ar_track_alvar/Threads.h" 25 | 26 | #include "ar_track_alvar/Threads_private.h" 27 | 28 | namespace alvar { 29 | 30 | Threads::Threads() 31 | : d(new ThreadsPrivate()) 32 | { 33 | } 34 | 35 | Threads::~Threads() 36 | { 37 | delete d; 38 | } 39 | 40 | bool Threads::create(void *(*method)(void *), void *parameters) 41 | { 42 | return d->create(method, parameters); 43 | } 44 | 45 | } // namespace alvar 46 | -------------------------------------------------------------------------------- /ar_track_alvar/src/Threads_unix.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of ALVAR, A Library for Virtual and Augmented Reality. 3 | * 4 | * Copyright 2007-2012 VTT Technical Research Centre of Finland 5 | * 6 | * Contact: VTT Augmented Reality Team 7 | * 8 | * 9 | * ALVAR is free software; you can redistribute it and/or modify it under the 10 | * terms of the GNU Lesser General Public License as published by the Free 11 | * Software Foundation; either version 2.1 of the License, or (at your option) 12 | * any later version. 13 | * 14 | * This library is distributed in the hope that it will be useful, but WITHOUT 15 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 16 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License 17 | * for more details. 18 | * 19 | * You should have received a copy of the GNU Lesser General Public License 20 | * along with ALVAR; if not, see 21 | * . 22 | */ 23 | 24 | #include "ar_track_alvar/Threads_private.h" 25 | 26 | #include 27 | #include 28 | 29 | namespace alvar { 30 | 31 | class ThreadsPrivateData 32 | { 33 | public: 34 | ThreadsPrivateData() 35 | : mHandles() 36 | { 37 | } 38 | 39 | std::vector mHandles; 40 | }; 41 | 42 | ThreadsPrivate::ThreadsPrivate() 43 | : d(new ThreadsPrivateData()) 44 | { 45 | } 46 | 47 | ThreadsPrivate::~ThreadsPrivate() 48 | { 49 | for (int i = 0; i < (int)d->mHandles.size(); ++i) { 50 | pthread_exit(&d->mHandles.at(i)); 51 | } 52 | d->mHandles.clear(); 53 | 54 | delete d; 55 | } 56 | 57 | bool ThreadsPrivate::create(void *(*method)(void *), void *parameters) 58 | { 59 | pthread_t thread; 60 | if (pthread_create(&thread, 0, method, parameters)) { 61 | d->mHandles.push_back(thread); 62 | return true; 63 | } 64 | return false; 65 | } 66 | 67 | } // namespace alvar 68 | -------------------------------------------------------------------------------- /ar_track_alvar/src/Threads_win.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of ALVAR, A Library for Virtual and Augmented Reality. 3 | * 4 | * Copyright 2007-2012 VTT Technical Research Centre of Finland 5 | * 6 | * Contact: VTT Augmented Reality Team 7 | * 8 | * 9 | * ALVAR is free software; you can redistribute it and/or modify it under the 10 | * terms of the GNU Lesser General Public License as published by the Free 11 | * Software Foundation; either version 2.1 of the License, or (at your option) 12 | * any later version. 13 | * 14 | * This library is distributed in the hope that it will be useful, but WITHOUT 15 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 16 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License 17 | * for more details. 18 | * 19 | * You should have received a copy of the GNU Lesser General Public License 20 | * along with ALVAR; if not, see 21 | * . 22 | */ 23 | 24 | #include "Threads_private.h" 25 | 26 | #include 27 | #include 28 | 29 | namespace alvar { 30 | 31 | struct StartThreadParameters 32 | { 33 | void *(*method)(void *); 34 | void *parameters; 35 | }; 36 | 37 | static DWORD WINAPI startThread(void *parameters) 38 | { 39 | DWORD value; 40 | struct StartThreadParameters *p = (struct StartThreadParameters *)parameters; 41 | value = (DWORD)p->method(p->parameters); 42 | delete p; 43 | return value; 44 | } 45 | 46 | class ThreadsPrivateData 47 | { 48 | public: 49 | ThreadsPrivateData() 50 | : mHandles() 51 | { 52 | } 53 | 54 | std::vector mHandles; 55 | }; 56 | 57 | ThreadsPrivate::ThreadsPrivate() 58 | : d(new ThreadsPrivateData()) 59 | { 60 | } 61 | 62 | ThreadsPrivate::~ThreadsPrivate() 63 | { 64 | for (int i = 0; i < (int)d->mHandles.size(); ++i) { 65 | CloseHandle(d->mHandles.at(i)); 66 | } 67 | d->mHandles.clear(); 68 | 69 | delete d; 70 | } 71 | 72 | bool ThreadsPrivate::create(void *(*method)(void *), void *parameters) 73 | { 74 | StartThreadParameters *p = new StartThreadParameters; 75 | p->method = method; 76 | p->parameters = parameters; 77 | 78 | HANDLE thread = CreateThread( 79 | NULL, 80 | 0, 81 | (LPTHREAD_START_ROUTINE)startThread, 82 | p, 83 | 0, 84 | NULL); 85 | 86 | if (thread != NULL) { 87 | d->mHandles.push_back(thread); 88 | return true; 89 | } 90 | return false; 91 | } 92 | 93 | } // namespace alvar 94 | -------------------------------------------------------------------------------- /ar_track_alvar/src/Timer.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of ALVAR, A Library for Virtual and Augmented Reality. 3 | * 4 | * Copyright 2007-2012 VTT Technical Research Centre of Finland 5 | * 6 | * Contact: VTT Augmented Reality Team 7 | * 8 | * 9 | * ALVAR is free software; you can redistribute it and/or modify it under the 10 | * terms of the GNU Lesser General Public License as published by the Free 11 | * Software Foundation; either version 2.1 of the License, or (at your option) 12 | * any later version. 13 | * 14 | * This library is distributed in the hope that it will be useful, but WITHOUT 15 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 16 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License 17 | * for more details. 18 | * 19 | * You should have received a copy of the GNU Lesser General Public License 20 | * along with ALVAR; if not, see 21 | * . 22 | */ 23 | 24 | #include "Timer.h" 25 | 26 | #include "Timer_private.h" 27 | 28 | namespace alvar { 29 | 30 | Timer::Timer() 31 | : d(new TimerPrivate()) 32 | { 33 | } 34 | 35 | Timer::~Timer() 36 | { 37 | delete d; 38 | } 39 | 40 | void Timer::start() 41 | { 42 | return d->start(); 43 | } 44 | 45 | double Timer::stop() 46 | { 47 | return d->stop(); 48 | } 49 | 50 | } // namespace alvar 51 | -------------------------------------------------------------------------------- /ar_track_alvar/src/Timer_unix.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of ALVAR, A Library for Virtual and Augmented Reality. 3 | * 4 | * Copyright 2007-2012 VTT Technical Research Centre of Finland 5 | * 6 | * Contact: VTT Augmented Reality Team 7 | * 8 | * 9 | * ALVAR is free software; you can redistribute it and/or modify it under the 10 | * terms of the GNU Lesser General Public License as published by the Free 11 | * Software Foundation; either version 2.1 of the License, or (at your option) 12 | * any later version. 13 | * 14 | * This library is distributed in the hope that it will be useful, but WITHOUT 15 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 16 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License 17 | * for more details. 18 | * 19 | * You should have received a copy of the GNU Lesser General Public License 20 | * along with ALVAR; if not, see 21 | * . 22 | */ 23 | 24 | #include "Timer_private.h" 25 | 26 | #include 27 | 28 | namespace alvar { 29 | 30 | class TimerPrivateData 31 | { 32 | public: 33 | TimerPrivateData() 34 | : mStart() 35 | { 36 | } 37 | 38 | timespec mStart; 39 | }; 40 | 41 | TimerPrivate::TimerPrivate() 42 | : d(new TimerPrivateData()) 43 | { 44 | } 45 | 46 | TimerPrivate::~TimerPrivate() 47 | { 48 | delete d; 49 | } 50 | 51 | void TimerPrivate::start() 52 | { 53 | clock_gettime(CLOCK_MONOTONIC, &d->mStart); 54 | } 55 | 56 | double TimerPrivate::stop() 57 | { 58 | timespec stop; 59 | clock_gettime(CLOCK_MONOTONIC, &stop); 60 | return (stop.tv_sec - d->mStart.tv_sec) + 61 | (stop.tv_nsec - d->mStart.tv_nsec) / 1000000000.0; 62 | } 63 | 64 | } // namespace alvar 65 | -------------------------------------------------------------------------------- /ar_track_alvar/src/Timer_win.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of ALVAR, A Library for Virtual and Augmented Reality. 3 | * 4 | * Copyright 2007-2012 VTT Technical Research Centre of Finland 5 | * 6 | * Contact: VTT Augmented Reality Team 7 | * 8 | * 9 | * ALVAR is free software; you can redistribute it and/or modify it under the 10 | * terms of the GNU Lesser General Public License as published by the Free 11 | * Software Foundation; either version 2.1 of the License, or (at your option) 12 | * any later version. 13 | * 14 | * This library is distributed in the hope that it will be useful, but WITHOUT 15 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 16 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License 17 | * for more details. 18 | * 19 | * You should have received a copy of the GNU Lesser General Public License 20 | * along with ALVAR; if not, see 21 | * . 22 | */ 23 | 24 | #include "Timer_private.h" 25 | 26 | #include 27 | 28 | namespace alvar { 29 | 30 | class TimerPrivateData 31 | { 32 | public: 33 | TimerPrivateData() 34 | : mPerformanceQuerySupported(false) 35 | , mPerformanceFrequency() 36 | , mPerformanceStart() 37 | , mStart() 38 | { 39 | } 40 | 41 | bool mPerformanceQuerySupported; 42 | LARGE_INTEGER mPerformanceFrequency; 43 | LARGE_INTEGER mPerformanceStart; 44 | DWORD mStart; 45 | }; 46 | 47 | TimerPrivate::TimerPrivate() 48 | : d(new TimerPrivateData()) 49 | { 50 | QueryPerformanceFrequency(&d->mPerformanceFrequency); 51 | if (d->mPerformanceFrequency.QuadPart) { 52 | d->mPerformanceQuerySupported = true; 53 | } 54 | } 55 | 56 | TimerPrivate::~TimerPrivate() 57 | { 58 | delete d; 59 | } 60 | 61 | void TimerPrivate::start() 62 | { 63 | if (d->mPerformanceQuerySupported) { 64 | QueryPerformanceCounter(&d->mPerformanceStart); 65 | } 66 | else { 67 | d->mStart = GetTickCount(); 68 | } 69 | } 70 | 71 | double TimerPrivate::stop() 72 | { 73 | if (d->mPerformanceQuerySupported) { 74 | LARGE_INTEGER stop; 75 | LARGE_INTEGER difference; 76 | QueryPerformanceCounter(&stop); 77 | difference.QuadPart = stop.QuadPart - d->mPerformanceStart.QuadPart; 78 | return double(difference.QuadPart) / d->mPerformanceFrequency.QuadPart; 79 | } 80 | else { 81 | return (GetTickCount() - d->mStart) / 1000.0; 82 | } 83 | } 84 | 85 | } // namespace alvar 86 | -------------------------------------------------------------------------------- /ar_track_alvar/src/TrackerStat.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of ALVAR, A Library for Virtual and Augmented Reality. 3 | * 4 | * Copyright 2007-2012 VTT Technical Research Centre of Finland 5 | * 6 | * Contact: VTT Augmented Reality Team 7 | * 8 | * 9 | * ALVAR is free software; you can redistribute it and/or modify it under the 10 | * terms of the GNU Lesser General Public License as published by the Free 11 | * Software Foundation; either version 2.1 of the License, or (at your option) 12 | * any later version. 13 | * 14 | * This library is distributed in the hope that it will be useful, but WITHOUT 15 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 16 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License 17 | * for more details. 18 | * 19 | * You should have received a copy of the GNU Lesser General Public License 20 | * along with ALVAR; if not, see 21 | * . 22 | */ 23 | 24 | #include "TrackerStat.h" 25 | 26 | using namespace std; 27 | 28 | namespace alvar { 29 | using namespace std; 30 | 31 | TrackerStat::TrackerStat(int binsize) : f(100,90) { 32 | hist.AddDimension(binsize); // x 33 | hist.AddDimension(binsize); // y 34 | } 35 | 36 | void TrackerStat::Reset() { 37 | f.Reset(); 38 | } 39 | 40 | double TrackerStat::Track(IplImage *img) 41 | { 42 | if (img == NULL) return -1; 43 | f.Track(img); 44 | hist.Clear(); 45 | for (int p=0; pwidth; 83 | y_res = img->height; 84 | hist_rot.Clear(); 85 | for (int p=0; p 40 | 41 | namespace ar_track_alvar 42 | { 43 | using namespace alvar; 44 | 45 | MedianFilter::MedianFilter(int n){ 46 | median_n = n; 47 | median_ind = 0; 48 | median_init = false; 49 | median_poses = new Pose[median_n]; 50 | } 51 | 52 | void MedianFilter::addPose(const Pose &new_pose){ 53 | median_poses[median_ind] = new_pose; 54 | median_ind = (median_ind+1) % median_n; 55 | } 56 | 57 | void MedianFilter::getMedian(Pose &ret_pose){ 58 | if(!median_init){ 59 | if(median_ind == median_n-1) 60 | median_init = true; 61 | ret_pose = median_poses[median_ind-1]; 62 | } 63 | 64 | else{ 65 | double min_dist = 0; 66 | int min_ind = 0; 67 | for(int i=0; i 7 | * 8 | * 9 | * ALVAR is free software; you can redistribute it and/or modify it under the 10 | * terms of the GNU Lesser General Public License as published by the Free 11 | * Software Foundation; either version 2.1 of the License, or (at your option) 12 | * any later version. 13 | * 14 | * This library is distributed in the hope that it will be useful, but WITHOUT 15 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 16 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License 17 | * for more details. 18 | * 19 | * You should have received a copy of the GNU Lesser General Public License 20 | * along with ALVAR; if not, see 21 | * . 22 | */ 23 | 24 | #ifndef CAPTUREPLUGINCMU_H 25 | #define CAPTUREPLUGINCMU_H 26 | 27 | /** 28 | * \file CapturePluginCmu.h 29 | * 30 | * \brief This file implements a capture plugin based on Cmu. 31 | */ 32 | 33 | #ifdef WIN32 34 | #ifdef ALVAR_Capture_Plugin_CMU_BUILD 35 | #define ALVAR_CAPTURE_PLUGIN_CMU_EXPORT __declspec(dllexport) 36 | #else 37 | #define ALVAR_CAPTURE_PLUGIN_CMU_EXPORT __declspec(dllimport) 38 | #endif 39 | #else 40 | #define ALVAR_CAPTURE_PLUGIN_CMU_EXPORT 41 | #endif 42 | 43 | #include "Capture.h" 44 | #include "CapturePlugin.h" 45 | 46 | #include "1394camera.h" 47 | 48 | namespace alvar { 49 | 50 | /** 51 | * \brief Dynamically loaded plugins namespace. 52 | */ 53 | namespace plugins { 54 | 55 | /** 56 | * \brief Implementation of Capture interface for Cmu plugin. 57 | */ 58 | class ALVAR_CAPTURE_PLUGIN_CMU_EXPORT CaptureCmu 59 | : public alvar::Capture 60 | { 61 | public: 62 | /** 63 | * \brief Constructor. 64 | * 65 | * \param captureDevice Information of which camera to create. 66 | */ 67 | CaptureCmu(const CaptureDevice captureDevice); 68 | /** 69 | * \brief Destructor. 70 | */ 71 | ~CaptureCmu(); 72 | bool start(); 73 | void stop(); 74 | IplImage *captureImage(); 75 | bool showSettingsDialog(); 76 | std::string SerializeId(); 77 | bool Serialize(Serialization *serialization); 78 | private: 79 | C1394Camera *mCamera; 80 | int mChannels; 81 | IplImage *mReturnFrame; 82 | }; 83 | 84 | /** 85 | * \brief Implementation of CapturePlugin interface for Cmu plugin. 86 | */ 87 | class ALVAR_CAPTURE_PLUGIN_CMU_EXPORT CapturePluginCmu 88 | : public alvar::CapturePlugin 89 | { 90 | public: 91 | /** 92 | * \brief Constructor. 93 | * 94 | * \param captureType A unique identifier for the capture plugin. 95 | */ 96 | CapturePluginCmu(const std::string &captureType); 97 | /** 98 | * \brief Destructor. 99 | */ 100 | ~CapturePluginCmu(); 101 | CaptureDeviceVector enumerateDevices(); 102 | Capture *createCapture(const CaptureDevice captureDevice); 103 | }; 104 | 105 | extern "C" ALVAR_CAPTURE_PLUGIN_CMU_EXPORT void registerPlugin(const std::string &captureType, alvar::CapturePlugin *&capturePlugin); 106 | 107 | } // namespace plugins 108 | } // namespace alvar 109 | 110 | #endif 111 | -------------------------------------------------------------------------------- /ar_track_alvar/src/platform/capture_plugin_dscapture/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # include opencv library 2 | include_directories(${OpenCV_INCLUDE_DIRS}) 3 | 4 | # include alvar library 5 | include_directories(${ALVAR_INCLUDE_DIRS}) 6 | 7 | # include DSCapture library 8 | include_directories(${DSCAPTURE_INCLUDE_DIRS}) 9 | 10 | # ensure plugin api is exported when building library 11 | add_definitions(-DALVAR_Capture_Plugin_DSCapture_BUILD) 12 | 13 | # define plugin library source files to compile 14 | set(ALVARCapturePluginDSCapture_HEADERS 15 | CapturePluginDSCapture.h 16 | ) 17 | set(ALVARCapturePluginDSCapture_SOURCES 18 | CapturePluginDSCapture.cpp 19 | ) 20 | 21 | # add source files to plugin library and set name and properties 22 | add_library(ALVARCapturePluginDSCapture MODULE 23 | ${ALVARCapturePluginDSCapture_HEADERS} 24 | ${ALVARCapturePluginDSCapture_SOURCES} 25 | ) 26 | set_target_properties(ALVARCapturePluginDSCapture PROPERTIES OUTPUT_NAME alvarcaptureplugindscapture${ALVAR_VERSION_NODOTS}) 27 | set_target_properties(ALVARCapturePluginDSCapture PROPERTIES DEBUG_POSTFIX d) 28 | 29 | # link plugin library target to required libraries 30 | target_link_libraries(ALVARCapturePluginDSCapture 31 | ALVAR 32 | ALVARPlatform 33 | ${OpenCV_LIBRARIES} 34 | optimized ${DSCAPTURE_LIBRARIES} 35 | debug ${DSCAPTURE_LIBRARIES_DEBUG} 36 | ) 37 | 38 | # install headers 39 | if(ALVAR_PACKAGE MATCHES sdk) 40 | install(FILES ${ALVARCapturePluginDSCapture_HEADERS} DESTINATION include/platform/capture_plugin_dscapture) 41 | endif(ALVAR_PACKAGE MATCHES sdk) 42 | 43 | # install target 44 | install(TARGETS ALVARCapturePluginDSCapture DESTINATION bin/alvarplugins) 45 | 46 | # hack to setup environment runtime path 47 | if(NOT ${MSVC_IDE}) 48 | list(APPEND ALVAR_RUNTIME 49 | ${CMAKE_CURRENT_BINARY_DIR}\; 50 | ) 51 | else(NOT ${MSVC_IDE}) 52 | list(APPEND ALVAR_RUNTIME 53 | ${CMAKE_CURRENT_BINARY_DIR}/Debug\; 54 | ${CMAKE_CURRENT_BINARY_DIR}/Release\; 55 | ) 56 | endif(NOT ${MSVC_IDE}) 57 | set(ALVAR_RUNTIME ${ALVAR_RUNTIME} PARENT_SCOPE) 58 | -------------------------------------------------------------------------------- /ar_track_alvar/src/platform/capture_plugin_file/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # include opencv library 2 | include_directories(${OpenCV_INCLUDE_DIRS}) 3 | 4 | # include alvar library 5 | include_directories(${ALVAR_INCLUDE_DIRS}) 6 | 7 | # ensure plugin api is exported when building library 8 | add_definitions(-DALVAR_Capture_Plugin_File_BUILD) 9 | 10 | # define plugin library source files to compile 11 | set(ALVARCapturePluginFile_HEADERS 12 | CapturePluginFile.h 13 | ) 14 | set(ALVARCapturePluginFile_SOURCES 15 | CapturePluginFile.cpp 16 | ) 17 | 18 | # add source files to plugin library and set name and properties 19 | add_library(ALVARCapturePluginFile MODULE 20 | ${ALVARCapturePluginFile_HEADERS} 21 | ${ALVARCapturePluginFile_SOURCES} 22 | ) 23 | set_target_properties(ALVARCapturePluginFile PROPERTIES OUTPUT_NAME alvarcapturepluginfile${ALVAR_VERSION_NODOTS}) 24 | set_target_properties(ALVARCapturePluginFile PROPERTIES DEBUG_POSTFIX d) 25 | 26 | # link plugin library target to required libraries 27 | target_link_libraries(ALVARCapturePluginFile 28 | ALVAR 29 | ALVARPlatform 30 | ${OpenCV_LIBRARIES} 31 | ) 32 | 33 | # install headers 34 | if(ALVAR_PACKAGE MATCHES sdk) 35 | install(FILES ${ALVARCapturePluginFile_HEADERS} DESTINATION include/platform/capture_plugin_file) 36 | endif(ALVAR_PACKAGE MATCHES sdk) 37 | 38 | # install target 39 | install(TARGETS ALVARCapturePluginFile DESTINATION bin/alvarplugins) 40 | 41 | # hack to setup environment runtime path 42 | if(NOT ${MSVC_IDE}) 43 | list(APPEND ALVAR_RUNTIME 44 | ${CMAKE_CURRENT_BINARY_DIR}\; 45 | ) 46 | else(NOT ${MSVC_IDE}) 47 | list(APPEND ALVAR_RUNTIME 48 | ${CMAKE_CURRENT_BINARY_DIR}/Debug\; 49 | ${CMAKE_CURRENT_BINARY_DIR}/Release\; 50 | ) 51 | endif(NOT ${MSVC_IDE}) 52 | set(ALVAR_RUNTIME ${ALVAR_RUNTIME} PARENT_SCOPE) 53 | -------------------------------------------------------------------------------- /ar_track_alvar/src/platform/capture_plugin_file/CapturePluginFile.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of ALVAR, A Library for Virtual and Augmented Reality. 3 | * 4 | * Copyright 2007-2012 VTT Technical Research Centre of Finland 5 | * 6 | * Contact: VTT Augmented Reality Team 7 | * 8 | * 9 | * ALVAR is free software; you can redistribute it and/or modify it under the 10 | * terms of the GNU Lesser General Public License as published by the Free 11 | * Software Foundation; either version 2.1 of the License, or (at your option) 12 | * any later version. 13 | * 14 | * This library is distributed in the hope that it will be useful, but WITHOUT 15 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 16 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License 17 | * for more details. 18 | * 19 | * You should have received a copy of the GNU Lesser General Public License 20 | * along with ALVAR; if not, see 21 | * . 22 | */ 23 | 24 | #include "CapturePluginFile.h" 25 | 26 | namespace alvar { 27 | namespace plugins { 28 | 29 | CaptureFile::CaptureFile(const CaptureDevice captureDevice) 30 | : Capture(captureDevice) 31 | , mVideoCapture() 32 | , mMatrix() 33 | , mImage() 34 | { 35 | } 36 | 37 | CaptureFile::~CaptureFile() 38 | { 39 | stop(); 40 | } 41 | 42 | bool CaptureFile::start() 43 | { 44 | if (isCapturing()) { 45 | return isCapturing(); 46 | } 47 | 48 | mVideoCapture.open(captureDevice().id().c_str()); 49 | if (mVideoCapture.isOpened()) { 50 | mXResolution = (int)mVideoCapture.get(CV_CAP_PROP_FRAME_WIDTH); 51 | mYResolution = (int)mVideoCapture.get(CV_CAP_PROP_FRAME_HEIGHT); 52 | mIsCapturing = true; 53 | } 54 | 55 | return isCapturing(); 56 | } 57 | 58 | void CaptureFile::stop() 59 | { 60 | if (isCapturing()) { 61 | mVideoCapture.release(); 62 | mIsCapturing = false; 63 | } 64 | } 65 | 66 | IplImage *CaptureFile::captureImage() 67 | { 68 | if (!isCapturing()) { 69 | return NULL; 70 | } 71 | 72 | if (!mVideoCapture.grab()) { 73 | // try to restart the capturing when end of file is reached 74 | mVideoCapture.release(); 75 | mVideoCapture.open(captureDevice().id().c_str()); 76 | if (!mVideoCapture.isOpened()) { 77 | mIsCapturing = false; 78 | return NULL; 79 | } 80 | if (!mVideoCapture.grab()) { 81 | return NULL; 82 | } 83 | } 84 | mVideoCapture.retrieve(mMatrix); 85 | mImage = mMatrix; 86 | return &mImage; 87 | } 88 | 89 | bool CaptureFile::showSettingsDialog() 90 | { 91 | // TODO: implement this method 92 | return false; 93 | } 94 | 95 | std::string CaptureFile::SerializeId() 96 | { 97 | return "CaptureFile"; 98 | } 99 | 100 | bool CaptureFile::Serialize(Serialization *serialization) 101 | { 102 | return false; 103 | } 104 | 105 | CapturePluginFile::CapturePluginFile(const std::string &captureType) 106 | : CapturePlugin(captureType) 107 | { 108 | } 109 | 110 | CapturePluginFile::~CapturePluginFile() 111 | { 112 | } 113 | 114 | CapturePlugin::CaptureDeviceVector CapturePluginFile::enumerateDevices() 115 | { 116 | CaptureDeviceVector devices; 117 | return devices; 118 | } 119 | 120 | Capture *CapturePluginFile::createCapture(const CaptureDevice captureDevice) 121 | { 122 | return new CaptureFile(captureDevice); 123 | } 124 | 125 | void registerPlugin(const std::string &captureType, alvar::CapturePlugin *&capturePlugin) 126 | { 127 | capturePlugin = new CapturePluginFile(captureType); 128 | } 129 | 130 | } // namespace plugins 131 | } // namespace alvar 132 | -------------------------------------------------------------------------------- /ar_track_alvar/src/platform/capture_plugin_file/CapturePluginFile.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of ALVAR, A Library for Virtual and Augmented Reality. 3 | * 4 | * Copyright 2007-2012 VTT Technical Research Centre of Finland 5 | * 6 | * Contact: VTT Augmented Reality Team 7 | * 8 | * 9 | * ALVAR is free software; you can redistribute it and/or modify it under the 10 | * terms of the GNU Lesser General Public License as published by the Free 11 | * Software Foundation; either version 2.1 of the License, or (at your option) 12 | * any later version. 13 | * 14 | * This library is distributed in the hope that it will be useful, but WITHOUT 15 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 16 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License 17 | * for more details. 18 | * 19 | * You should have received a copy of the GNU Lesser General Public License 20 | * along with ALVAR; if not, see 21 | * . 22 | */ 23 | 24 | #ifndef CAPTUREPLUGINFILE_H 25 | #define CAPTUREPLUGINFILE_H 26 | 27 | /** 28 | * \file CapturePluginFile.h 29 | * 30 | * \brief This file implements a capture plugin based on File. 31 | */ 32 | 33 | #ifdef WIN32 34 | #ifdef ALVAR_Capture_Plugin_File_BUILD 35 | #define ALVAR_CAPTURE_PLUGIN_FILE_EXPORT __declspec(dllexport) 36 | #else 37 | #define ALVAR_CAPTURE_PLUGIN_FILE_EXPORT __declspec(dllimport) 38 | #endif 39 | #else 40 | #define ALVAR_CAPTURE_PLUGIN_FILE_EXPORT 41 | #endif 42 | 43 | #include "Capture.h" 44 | #include "CapturePlugin.h" 45 | 46 | #include "highgui.h" 47 | 48 | namespace alvar { 49 | 50 | /** 51 | * \brief Dynamically loaded plugins namespace. 52 | */ 53 | namespace plugins { 54 | 55 | /** 56 | * \brief Implementation of Capture interface for File plugin. 57 | */ 58 | class ALVAR_CAPTURE_PLUGIN_FILE_EXPORT CaptureFile 59 | : public alvar::Capture 60 | { 61 | public: 62 | /** 63 | * \brief Constructor. 64 | * 65 | * \param captureDevice Information of which camera to create. 66 | */ 67 | CaptureFile(const CaptureDevice captureDevice); 68 | /** 69 | * \brief Destructor. 70 | */ 71 | ~CaptureFile(); 72 | bool start(); 73 | void stop(); 74 | IplImage *captureImage(); 75 | bool showSettingsDialog(); 76 | std::string SerializeId(); 77 | bool Serialize(Serialization *serialization); 78 | private: 79 | cv::VideoCapture mVideoCapture; 80 | cv::Mat mMatrix; 81 | IplImage mImage; 82 | }; 83 | 84 | /** 85 | * \brief Implementation of CapturePlugin interface for File plugin. 86 | */ 87 | class ALVAR_CAPTURE_PLUGIN_FILE_EXPORT CapturePluginFile 88 | : public alvar::CapturePlugin 89 | { 90 | public: 91 | /** 92 | * \brief Constructor. 93 | * 94 | * \param captureType A unique identifier for the capture plugin. 95 | */ 96 | CapturePluginFile(const std::string &captureType); 97 | /** 98 | * \brief Destructor. 99 | */ 100 | ~CapturePluginFile(); 101 | CaptureDeviceVector enumerateDevices(); 102 | Capture *createCapture(const CaptureDevice captureDevice); 103 | }; 104 | 105 | extern "C" ALVAR_CAPTURE_PLUGIN_FILE_EXPORT void registerPlugin(const std::string &captureType, alvar::CapturePlugin *&capturePlugin); 106 | 107 | } // namespace plugins 108 | } // namespace alvar 109 | 110 | #endif 111 | -------------------------------------------------------------------------------- /ar_track_alvar/src/platform/capture_plugin_highgui/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # include opencv library 2 | include_directories(${OpenCV_INCLUDE_DIRS}) 3 | 4 | # include alvar library 5 | include_directories(${ALVAR_INCLUDE_DIRS}) 6 | 7 | # ensure plugin api is exported when building library 8 | add_definitions(-DALVAR_Capture_Plugin_Highgui_BUILD) 9 | 10 | # define plugin library source files to compile 11 | set(ALVARCapturePluginHighgui_HEADERS 12 | CapturePluginHighgui.h 13 | ) 14 | set(ALVARCapturePluginHighgui_SOURCES 15 | CapturePluginHighgui.cpp 16 | ) 17 | 18 | # add source files to plugin library and set name and properties 19 | add_library(ALVARCapturePluginHighgui MODULE 20 | ${ALVARCapturePluginHighgui_HEADERS} 21 | ${ALVARCapturePluginHighgui_SOURCES} 22 | ) 23 | set_target_properties(ALVARCapturePluginHighgui PROPERTIES OUTPUT_NAME alvarcapturepluginhighgui${ALVAR_VERSION_NODOTS}) 24 | set_target_properties(ALVARCapturePluginHighgui PROPERTIES DEBUG_POSTFIX d) 25 | 26 | # link plugin library target to required libraries 27 | target_link_libraries(ALVARCapturePluginHighgui 28 | ALVAR 29 | ALVARPlatform 30 | ${OpenCV_LIBRARIES} 31 | ) 32 | 33 | # install headers 34 | if(ALVAR_PACKAGE MATCHES sdk) 35 | install(FILES ${ALVARCapturePluginHighgui_HEADERS} DESTINATION include/platform/capture_plugin_highgui) 36 | endif(ALVAR_PACKAGE MATCHES sdk) 37 | 38 | # install target 39 | install(TARGETS ALVARCapturePluginHighgui DESTINATION bin/alvarplugins) 40 | 41 | # hack to setup environment runtime path 42 | if(NOT ${MSVC_IDE}) 43 | list(APPEND ALVAR_RUNTIME 44 | ${CMAKE_CURRENT_BINARY_DIR}\; 45 | ) 46 | else(NOT ${MSVC_IDE}) 47 | list(APPEND ALVAR_RUNTIME 48 | ${CMAKE_CURRENT_BINARY_DIR}/Debug\; 49 | ${CMAKE_CURRENT_BINARY_DIR}/Release\; 50 | ) 51 | endif(NOT ${MSVC_IDE}) 52 | set(ALVAR_RUNTIME ${ALVAR_RUNTIME} PARENT_SCOPE) 53 | -------------------------------------------------------------------------------- /ar_track_alvar/src/platform/capture_plugin_highgui/CapturePluginHighgui.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of ALVAR, A Library for Virtual and Augmented Reality. 3 | * 4 | * Copyright 2007-2012 VTT Technical Research Centre of Finland 5 | * 6 | * Contact: VTT Augmented Reality Team 7 | * 8 | * 9 | * ALVAR is free software; you can redistribute it and/or modify it under the 10 | * terms of the GNU Lesser General Public License as published by the Free 11 | * Software Foundation; either version 2.1 of the License, or (at your option) 12 | * any later version. 13 | * 14 | * This library is distributed in the hope that it will be useful, but WITHOUT 15 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 16 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License 17 | * for more details. 18 | * 19 | * You should have received a copy of the GNU Lesser General Public License 20 | * along with ALVAR; if not, see 21 | * . 22 | */ 23 | 24 | #ifndef CAPTUREPLUGINHIGHGUI_H 25 | #define CAPTUREPLUGINHIGHGUI_H 26 | 27 | /** 28 | * \file CapturePluginHighgui.h 29 | * 30 | * \brief This file implements a capture plugin based on Highgui. 31 | */ 32 | 33 | #ifdef WIN32 34 | #ifdef ALVAR_Capture_Plugin_Highgui_BUILD 35 | #define ALVAR_CAPTURE_PLUGIN_HIGHGUI_EXPORT __declspec(dllexport) 36 | #else 37 | #define ALVAR_CAPTURE_PLUGIN_HIGHGUI_EXPORT __declspec(dllimport) 38 | #endif 39 | #else 40 | #define ALVAR_CAPTURE_PLUGIN_HIGHGUI_EXPORT 41 | #endif 42 | 43 | #include "Capture.h" 44 | #include "CapturePlugin.h" 45 | 46 | #include "highgui.h" 47 | 48 | namespace alvar { 49 | 50 | /** 51 | * \brief Dynamically loaded plugins namespace. 52 | */ 53 | namespace plugins { 54 | 55 | /** 56 | * \brief Implementation of Capture interface for Highgui plugin. 57 | */ 58 | class ALVAR_CAPTURE_PLUGIN_HIGHGUI_EXPORT CaptureHighgui 59 | : public alvar::Capture 60 | { 61 | public: 62 | /** 63 | * \brief Constructor. 64 | * 65 | * \param captureDevice Information of which camera to create. 66 | */ 67 | CaptureHighgui(const CaptureDevice captureDevice); 68 | /** 69 | * \brief Destructor. 70 | */ 71 | ~CaptureHighgui(); 72 | void setResolution(const unsigned long xResolution, const unsigned long yResolution); 73 | bool start(); 74 | void stop(); 75 | IplImage *captureImage(); 76 | bool showSettingsDialog(); 77 | std::string SerializeId(); 78 | bool Serialize(Serialization *serialization); 79 | private: 80 | cv::VideoCapture mVideoCapture; 81 | cv::Mat mMatrix; 82 | IplImage mImage; 83 | }; 84 | 85 | /** 86 | * \brief Implementation of CapturePlugin interface for Highgui plugin. 87 | */ 88 | class ALVAR_CAPTURE_PLUGIN_HIGHGUI_EXPORT CapturePluginHighgui 89 | : public alvar::CapturePlugin 90 | { 91 | public: 92 | /** 93 | * \brief Constructor. 94 | * 95 | * \param captureType A unique identifier for the capture plugin. 96 | */ 97 | CapturePluginHighgui(const std::string &captureType); 98 | /** 99 | * \brief Destructor. 100 | */ 101 | ~CapturePluginHighgui(); 102 | CaptureDeviceVector enumerateDevices(); 103 | Capture *createCapture(const CaptureDevice captureDevice); 104 | }; 105 | 106 | extern "C" ALVAR_CAPTURE_PLUGIN_HIGHGUI_EXPORT void registerPlugin(const std::string &captureType, alvar::CapturePlugin *&capturePlugin); 107 | 108 | } // namespace plugins 109 | } // namespace alvar 110 | 111 | #endif 112 | -------------------------------------------------------------------------------- /ar_track_alvar/src/platform/capture_plugin_ptgrey/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # include opencv library 2 | include_directories(${OpenCV_INCLUDE_DIRS}) 3 | 4 | # include alvar library 5 | include_directories(${ALVAR_INCLUDE_DIRS}) 6 | 7 | # include PTGrey FlyCapture2 library 8 | include_directories(${FLYCAPTURE2_INCLUDE_DIRS}) 9 | 10 | # ensure plugin api is exported when building library 11 | add_definitions(-DALVAR_Capture_Plugin_Ptgrey_BUILD) 12 | 13 | # define plugin library source files to compile 14 | set(ALVARCapturePluginPtgrey_HEADERS 15 | CapturePluginPtgrey.h 16 | ) 17 | set(ALVARCapturePluginPtgrey_SOURCES 18 | CapturePluginPtgrey.cpp 19 | ) 20 | 21 | # add source files to plugin library and set name and properties 22 | add_library(ALVARCapturePluginPtgrey MODULE 23 | ${ALVARCapturePluginPtgrey_HEADERS} 24 | ${ALVARCapturePluginPtgrey_SOURCES} 25 | ) 26 | set_target_properties(ALVARCapturePluginPtgrey PROPERTIES OUTPUT_NAME alvarcapturepluginptgrey${ALVAR_VERSION_NODOTS}) 27 | set_target_properties(ALVARCapturePluginPtgrey PROPERTIES DEBUG_POSTFIX d) 28 | 29 | # link plugin library target to required libraries 30 | target_link_libraries(ALVARCapturePluginPtgrey 31 | ALVAR 32 | ALVARPlatform 33 | ${OpenCV_LIBRARIES} 34 | optimized ${FLYCAPTURE2_LIBRARIES} 35 | debug ${FLYCAPTURE2_LIBRARIES_DEBUG} 36 | ) 37 | 38 | # install headers 39 | if(ALVAR_PACKAGE MATCHES sdk) 40 | install(FILES ${ALVARCapturePluginPtgrey_HEADERS} DESTINATION include/platform/capture_plugin_ptgrey) 41 | endif(ALVAR_PACKAGE MATCHES sdk) 42 | 43 | # install target 44 | install(TARGETS ALVARCapturePluginPtgrey DESTINATION bin/alvarplugins) 45 | 46 | # hack to setup environment runtime path 47 | if(NOT ${MSVC_IDE}) 48 | list(APPEND ALVAR_RUNTIME 49 | ${CMAKE_CURRENT_BINARY_DIR}\; 50 | ) 51 | else(NOT ${MSVC_IDE}) 52 | list(APPEND ALVAR_RUNTIME 53 | ${CMAKE_CURRENT_BINARY_DIR}/Debug\; 54 | ${CMAKE_CURRENT_BINARY_DIR}/Release\; 55 | ) 56 | endif(NOT ${MSVC_IDE}) 57 | set(ALVAR_RUNTIME ${ALVAR_RUNTIME} PARENT_SCOPE) 58 | -------------------------------------------------------------------------------- /ar_track_alvar/src/platform/capture_plugin_ptgrey/CapturePluginPtgrey.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of ALVAR, A Library for Virtual and Augmented Reality. 3 | * 4 | * Copyright 2007-2012 VTT Technical Research Centre of Finland 5 | * 6 | * Contact: VTT Augmented Reality Team 7 | * 8 | * 9 | * ALVAR is free software; you can redistribute it and/or modify it under the 10 | * terms of the GNU Lesser General Public License as published by the Free 11 | * Software Foundation; either version 2.1 of the License, or (at your option) 12 | * any later version. 13 | * 14 | * This library is distributed in the hope that it will be useful, but WITHOUT 15 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 16 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License 17 | * for more details. 18 | * 19 | * You should have received a copy of the GNU Lesser General Public License 20 | * along with ALVAR; if not, see 21 | * . 22 | */ 23 | 24 | #ifndef CAPTUREPLUGINPTGREY_H 25 | #define CAPTUREPLUGINPTGREY_H 26 | 27 | /** 28 | * \file CapturePluginPtgrey.h 29 | * 30 | * \brief This file implements a capture plugin based on Ptgrey. 31 | * 32 | * \note The PointGrey plugin is currently experimental and not included in 33 | * the build by default. 34 | */ 35 | 36 | #ifdef WIN32 37 | #ifdef ALVAR_Capture_Plugin_Ptgrey_BUILD 38 | #define ALVAR_CAPTURE_PLUGIN_PTGREY_EXPORT __declspec(dllexport) 39 | #else 40 | #define ALVAR_CAPTURE_PLUGIN_PTGREY_EXPORT __declspec(dllimport) 41 | #endif 42 | #else 43 | #define ALVAR_CAPTURE_PLUGIN_PTGREY_EXPORT 44 | #endif 45 | 46 | #include "Capture.h" 47 | #include "CapturePlugin.h" 48 | 49 | #include "FlyCapture2Defs.h" 50 | 51 | // Forward declaration for PTGrey specific classes. 52 | namespace FlyCapture2 { 53 | class Camera; 54 | class Image; 55 | } 56 | 57 | namespace alvar { 58 | 59 | /** 60 | * \brief Dynamically loaded plugins namespace. 61 | */ 62 | namespace plugins { 63 | 64 | /** 65 | * \brief Implementation of Capture interface for Ptgrey plugin. 66 | * 67 | * \note The PointGrey plugin is currently experimental and not included in 68 | * the build by default. 69 | */ 70 | class ALVAR_CAPTURE_PLUGIN_PTGREY_EXPORT CapturePtgrey 71 | : public alvar::Capture 72 | { 73 | public: 74 | /** 75 | * \brief Constructor. 76 | * 77 | * \param captureDevice Information of which camera to create. 78 | */ 79 | CapturePtgrey(const CaptureDevice captureDevice); 80 | /** 81 | * \brief Destructor. 82 | */ 83 | ~CapturePtgrey(); 84 | bool start(); 85 | void stop(); 86 | IplImage *captureImage(); 87 | bool showSettingsDialog(); 88 | std::string SerializeId(); 89 | bool Serialize(Serialization *serialization); 90 | private: 91 | FlyCapture2::Camera *mCamera; 92 | FlyCapture2::Image *mImage; 93 | FlyCapture2::PGRGuid mGUID; 94 | int mChannels; 95 | IplImage *mReturnFrame; 96 | }; 97 | 98 | /** 99 | * \brief Implementation of CapturePlugin interface for Ptgrey plugin. 100 | * 101 | * \note The PointGrey plugin is currently experimental and not included in 102 | * the build by default. 103 | */ 104 | class ALVAR_CAPTURE_PLUGIN_PTGREY_EXPORT CapturePluginPtgrey 105 | : public alvar::CapturePlugin 106 | { 107 | public: 108 | /** 109 | * \brief Constructor. 110 | * 111 | * \param captureType A unique identifier for the capture plugin. 112 | */ 113 | CapturePluginPtgrey(const std::string &captureType); 114 | /** 115 | * \brief Destructor. 116 | */ 117 | ~CapturePluginPtgrey(); 118 | CaptureDeviceVector enumerateDevices(); 119 | Capture *createCapture(const CaptureDevice captureDevice); 120 | }; 121 | 122 | extern "C" ALVAR_CAPTURE_PLUGIN_PTGREY_EXPORT void registerPlugin(const std::string &captureType, alvar::CapturePlugin *&capturePlugin); 123 | 124 | } // namespace plugins 125 | } // namespace alvar 126 | 127 | #endif 128 | -------------------------------------------------------------------------------- /ar_track_alvar/test/marker_abstract.launch.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | -------------------------------------------------------------------------------- /ar_track_alvar/test/marker_arg_config-basic.test: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /ar_track_alvar/test/marker_arg_config-full.test: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /ar_track_alvar/test/marker_param_config-basic.test: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /ar_track_alvar/test/marker_param_config-full.test: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /ar_track_alvar/test/points: -------------------------------------------------------------------------------- 1 | 0.033776 0.107919 0.865000 2 | 0.035506 0.113123 0.867000 3 | 0.037157 0.118077 0.867000 4 | 0.038719 0.122748 0.865000 5 | 0.040367 0.127690 0.865000 6 | 0.028900 0.109820 0.867000 7 | 0.030481 0.114510 0.865000 8 | 0.032129 0.119452 0.865000 9 | 0.033776 0.124395 0.865000 10 | 0.035424 0.129338 0.865000 11 | 0.025597 0.111471 0.867000 12 | 0.027186 0.116157 0.865000 13 | 0.028833 0.121100 0.865000 14 | 0.030481 0.126043 0.865000 15 | 0.032129 0.129338 0.865000 16 | 0.020643 0.113123 0.867000 17 | 0.022294 0.118077 0.867000 18 | 0.023890 0.122748 0.865000 19 | 0.025538 0.127690 0.865000 20 | 0.027091 0.130531 0.862000 21 | 0.015652 0.114510 0.865000 22 | 0.017300 0.119452 0.865000 23 | 0.018882 0.123964 0.862000 24 | 0.020595 0.127690 0.865000 25 | 0.022166 0.132173 0.862000 26 | 0.007414 0.117805 0.865000 27 | 0.043763 0.104866 0.867000 28 | 0.012386 0.104866 0.867000 29 | 0.025450 0.142025 0.862000 30 | 0.009062 0.122748 0.865000 31 | 0.045414 0.109820 0.867000 32 | 0.017380 0.103452 0.869000 33 | 0.030375 0.140383 0.862000 34 | 0.010710 0.126043 0.865000 35 | 0.047066 0.114774 0.867000 36 | 0.022346 0.103452 0.869000 37 | 0.035301 0.138741 0.862000 38 | 0.012314 0.130531 0.862000 39 | 0.048605 0.119452 0.865000 40 | 0.025656 0.101797 0.869000 41 | 0.038719 0.137576 0.865000 42 | 0.013956 0.135457 0.862000 43 | 0.050252 0.124395 0.865000 44 | 0.030622 0.100142 0.869000 45 | 0.043662 0.135929 0.865000 46 | 0.004119 0.107919 0.865000 47 | 0.040553 0.096831 0.869000 48 | 0.053362 0.132173 0.862000 49 | 0.017200 0.144971 0.860000 50 | 0.005767 0.112862 0.865000 51 | 0.042111 0.101563 0.867000 52 | 0.051720 0.128890 0.862000 53 | 0.015562 0.140057 0.860000 54 | 0.010710 0.116157 0.865000 55 | 0.038719 0.106271 0.865000 56 | 0.014005 0.109567 0.865000 57 | 0.023808 0.137099 0.862000 58 | 0.012357 0.121100 0.865000 59 | 0.040460 0.111471 0.867000 60 | 0.018991 0.108169 0.867000 61 | 0.028833 0.135929 0.865000 62 | 0.014005 0.126043 0.865000 63 | 0.042111 0.116426 0.867000 64 | 0.024001 0.106763 0.869000 65 | 0.033659 0.133815 0.862000 66 | 0.015598 0.128890 0.862000 67 | 0.043662 0.121100 0.865000 68 | 0.027249 0.104866 0.867000 69 | 0.036943 0.132173 0.862000 70 | 0.017240 0.133815 0.862000 71 | 0.045310 0.126043 0.865000 72 | 0.032203 0.103214 0.867000 73 | 0.042014 0.130986 0.865000 74 | 0.009083 0.106517 0.867000 75 | 0.035588 0.098487 0.869000 76 | 0.048436 0.133815 0.862000 77 | 0.020476 0.143333 0.860000 78 | 0.009083 0.111471 0.867000 79 | 0.037071 0.102976 0.865000 80 | 0.046957 0.130986 0.865000 81 | 0.018882 0.138741 0.862000 -------------------------------------------------------------------------------- /ar_track_alvar/test/test_markerdetect.launch.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | -------------------------------------------------------------------------------- /ar_track_alvar/test/test_points.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2008, Willow Garage, Inc. 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions are met: 7 | * 8 | * * Redistributions of source code must retain the above copyright 9 | * notice, this list of conditions and the following disclaimer. 10 | * * Redistributions in binary form must reproduce the above copyright 11 | * notice, this list of conditions and the following disclaimer in the 12 | * documentation and/or other materials provided with the distribution. 13 | * * Neither the name of the Willow Garage, Inc. nor the names of its 14 | * contributors may be used to endorse or promote products derived from 15 | * this software without specific prior written permission. 16 | * 17 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 18 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 21 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 22 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 23 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 24 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 25 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 26 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 27 | * POSSIBILITY OF SUCH DAMAGE. 28 | * 29 | */ 30 | 31 | /** 32 | * \file 33 | * 34 | * Test node for kinect filtering 35 | * 36 | * \author Bhaskara Marthi 37 | */ 38 | 39 | #include 40 | #include 41 | 42 | namespace a=ar_track_alvar; 43 | namespace gm=geometry_msgs; 44 | 45 | using std::cerr; 46 | using std::ifstream; 47 | 48 | // Random float between a and b 49 | float randFloat (float a, float b) 50 | { 51 | const float u = static_cast(rand())/RAND_MAX; 52 | return a + u*(b-a); 53 | } 54 | 55 | // Generate points in a square in space of form p+av+bw where 56 | // a and b range from 0 to 1 57 | a::ARCloud::Ptr generateCloud(const double px, const double py, const double pz, 58 | const double vx, const double vy, const double vz, 59 | const double wx, const double wy, const double wz) 60 | { 61 | const double INC=0.1; 62 | const double NOISE=0.01; 63 | 64 | a::ARCloud::Ptr cloud(boost::make_shared()); 65 | for (double u=0; u<1+INC/2; u+=INC) 66 | { 67 | for (double v=0; v<1+INC/2; v+=INC) 68 | { 69 | a::ARPoint p; 70 | p.x = px+u*vx+v*wx+randFloat(-NOISE, NOISE); 71 | p.y = py+u*vy+v*wy+randFloat(-NOISE, NOISE); 72 | p.z = pz+u*vz+v*wz+randFloat(-NOISE, NOISE); 73 | cloud->points.push_back(p); 74 | } 75 | } 76 | return cloud; 77 | } 78 | 79 | int main (int argc, char** argv) 80 | { 81 | ros::init(argc, argv, "test_points"); 82 | ifstream f("points"); 83 | a::ARCloud::Ptr cloud(new a::ARCloud()); 84 | while (!f.eof()) 85 | { 86 | a::ARPoint pt; 87 | f >> pt.x >> pt.y >> pt.z; 88 | cloud->points.push_back(pt); 89 | } 90 | ROS_INFO("Cloud has %zu points such as (%.2f, %.2f, %.2f)", 91 | cloud->points.size(), cloud->points[0].x, cloud->points[0].y, 92 | cloud->points[0].z); 93 | a::ARPoint p1, p2, p3; 94 | p1.x = 0.1888; 95 | p1.y = 0.1240; 96 | p1.z = 0.8620; 97 | p2.x = 0.0372; 98 | p2.y = 0.1181; 99 | p2.z = 0.8670; 100 | p3.x = 42; 101 | p3.y = 24; 102 | p3.z = 88; 103 | 104 | a::PlaneFitResult res = a::fitPlane(cloud); 105 | ROS_INFO("Plane equation is %.3fx + %.3fy + %.3fz + %.3f = 0", 106 | res.coeffs.values[0], res.coeffs.values[1], res.coeffs.values[2], 107 | res.coeffs.values[3]); 108 | 109 | gm::Quaternion q = a::extractOrientation(res.coeffs, p1, p2, p3, p1); 110 | ROS_INFO_STREAM("Orientation is " << q); 111 | return 0; 112 | } 113 | -------------------------------------------------------------------------------- /ar_track_alvar_msgs/CHANGELOG.rst: -------------------------------------------------------------------------------- 1 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 2 | Changelog for package ar_track_alvar_msgs 3 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 4 | 5 | 0.7.1 (2017-06-14) 6 | ------------------ 7 | * [maintenance] Remove unnecessary metapkg. 8 | 9 | 0.7.0 (2017-04-21) 10 | ------------------ 11 | * Consolidate ar_track_alvar* packages into a single repo (`#120 `_) 12 | * Contributors: Isaac I.Y. Saito 13 | 14 | 0.5.2 (2017-04-20) 15 | ------------------ 16 | * Add CI config. Update maintainer. `#2 `_ 17 | * Contributors: Scott Niekum, Isaac I.Y. Saito 18 | 19 | 0.5.1 (2015-04-12) 20 | ------------------ 21 | * Release into Jade ROS 22 | * Contributors: Isaac IY Saito 23 | 24 | 0.5.0 (2014-06-25) 25 | ------------------ 26 | * migrate from ar_track_alvar repository 27 | * Contributors: Jihoon Lee 28 | -------------------------------------------------------------------------------- /ar_track_alvar_msgs/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 2.8.3) 2 | project(ar_track_alvar_msgs) 3 | 4 | set(MSG_DEPS 5 | std_msgs 6 | geometry_msgs 7 | ) 8 | 9 | find_package(catkin REQUIRED COMPONENTS 10 | message_generation 11 | ${MSG_DEPS} 12 | ) 13 | 14 | set(MSG_FILES AlvarMarker.msg AlvarMarkers.msg) 15 | add_message_files(DIRECTORY msg FILES ${MSG_FILES}) 16 | generate_messages(DEPENDENCIES ${MSG_DEPS}) 17 | 18 | catkin_package(CATKIN_DEPENDS message_runtime ${MSG_DEPS}) 19 | -------------------------------------------------------------------------------- /ar_track_alvar_msgs/README: -------------------------------------------------------------------------------- 1 | ar_track_alvar_msgs 2 | Package maintained by Scott Niekum 3 | sniekum@willowgarage.com 4 | sniekum@cs.umass.edu 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /ar_track_alvar_msgs/msg/.gitignore: -------------------------------------------------------------------------------- 1 | cpp/ 2 | -------------------------------------------------------------------------------- /ar_track_alvar_msgs/msg/AlvarMarker.msg: -------------------------------------------------------------------------------- 1 | Header header 2 | uint32 id 3 | uint32 confidence 4 | geometry_msgs/PoseStamped pose 5 | 6 | -------------------------------------------------------------------------------- /ar_track_alvar_msgs/msg/AlvarMarkers.msg: -------------------------------------------------------------------------------- 1 | Header header 2 | AlvarMarker[] markers 3 | -------------------------------------------------------------------------------- /ar_track_alvar_msgs/package.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | ar_track_alvar_msgs 4 | 0.7.1 5 | 6 | This package is a ROS wrapper for Alvar, an open source AR tag tracking library. 7 | 8 | Scott Niekum 9 | Isaac I.Y. Saito 10 | BSD 11 | http://ros.org/wiki/ar_track_alvar 12 | 13 | catkin 14 | message_generation 15 | geometry_msgs 16 | std_msgs 17 | message_runtime 18 | geometry_msgs 19 | std_msgs 20 | 21 | --------------------------------------------------------------------------------