MultiMarkerFiltered.cpp
Go to the documentation of this file.
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 <alvar.info@vtt.fi>
7  * <http://www.vtt.fi/multimedia/alvar.html>
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  * <http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html>.
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<int>& indices)
32  : MultiMarker(indices)
33 {
34  pointcloud_filtered = new FilterMedian[indices.size()*4*3];
35  for (size_t i=0; i<indices.size()*4*3; i++) {
37  }
38 }
39 
41 {
42  delete [] pointcloud_filtered;
43 }
44 
45 void MultiMarkerFiltered::PointCloudAverage(int marker_id, double edge_length, Pose &pose) {
46  if (marker_id == 0) {
47  if (marker_status[get_id_index(marker_id)] == 0) PointCloudAdd(marker_id, edge_length, pose);
48  } else {
49  CvPoint3D64f corners[4];
50  PointCloudCorners3d(edge_length, pose, corners);
51  for(size_t j = 0; j < 4; ++j) {
52  int id_index = get_id_index(marker_id);
53  if (id_index < 0) continue;
54  int index = id_index*4*3 + j*3;
55  CvPoint3D64f p;
56  p.x = pointcloud_filtered[index+0].next(corners[j].x);
57  p.y = pointcloud_filtered[index+1].next(corners[j].y);
58  p.z = pointcloud_filtered[index+2].next(corners[j].z);
59  pointcloud[pointcloud_index(marker_id, j)] = p;
60  // The marker isn't used for pose calculation until we are quite sure about it ???
61  if (pointcloud_filtered[index+0].getCurrentSize() >= filter_buffer_max) {
62  marker_status[get_id_index(marker_id)]=1;
63  }
64  }
65  }
66 }
67 
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
Main ALVAR namespace.
Definition: Alvar.h:174
void PointCloudAverage(int marker_id, double edge_length, Pose &pose)
Updates the 3D point cloud by averaging the calculated results.
void PointCloudCorners3d(double edge_length, Pose &pose, CvPoint3D64f corners[4])
Calculates 3D coordinates of marker corners relative to given pose (camera).
void SetMatrix(const CvMat *mat)
Definition: Pose.cpp:75
void setWindowSize(int size)
Definition: Filter.h:137
virtual unsigned long GetId() const
Get id for this marker This is used e.g. in MarkerDetector to associate a marker id with an appropria...
Definition: Marker.h:118
This file implements an approximation algorithm to create a multi-marker field configuration.
std::vector< int > marker_status
Definition: MultiMarker.h:65
unsigned char * image
Definition: GlutViewer.cpp:155
double _Update(MarkerIterator &begin, MarkerIterator &end, Camera *cam, Pose &pose, IplImage *image)
Base class for using MultiMarker.
Definition: MultiMarker.h:47
TFSIMD_FORCE_INLINE const tfScalar & y() const
std::map< int, CvPoint3D64f > pointcloud
Definition: MultiMarker.h:63
int get_id_index(int id, bool add_if_missing=false)
Definition: MultiMarker.cpp:38
Simple Camera class for calculating distortions, orientation or projections with pre-calibrated camer...
Definition: Camera.h:82
virtual double next(double y)
Update the value. All inherited classes need to update value in next().
Definition: Filter.cpp:78
int pointcloud_index(int marker_id, int marker_corner, bool add_if_missing=false)
Definition: MultiMarker.cpp:34
Pose pose
The current marker Pose.
Definition: Marker.h:136
Pose representation derived from the Rotation class
Definition: Pose.h:50
static const int filter_buffer_max
TFSIMD_FORCE_INLINE const tfScalar & x() const
Basic 2D Marker functionality.
Definition: Marker.h:52
void PointCloudAdd(int marker_id, double edge_length, Pose &pose)
Adds marker corners to 3D point cloud of multi marker.
TFSIMD_FORCE_INLINE const tfScalar & z() const
Iterator type for traversing templated Marker vector without the template.
Definition: Marker.h:277
double GetMarkerEdgeLength() const
Get edge length (to support different size markers.
Definition: Marker.h:102
FilterMedian provides an median filter
Definition: Filter.h:133
void GetMatrix(CvMat *mat) const
Definition: Pose.cpp:91
double _GetPose(MarkerIterator &begin, MarkerIterator &end, Camera *cam, Pose &pose, IplImage *image)
Camera * cam
virtual MarkerIterator & reset()=0


ar_track_alvar
Author(s): Scott Niekum
autogenerated on Mon Jun 10 2019 12:47:04