[f9fc67]: src / hugin_base / algorithms / basic / CalculateOverlap.cpp  Maximize  Restore  History

Download this file

132 lines (121 with data), 4.3 kB

  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
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
// -*- c-basic-offset: 4 -*-
/** @file CalculateOverlap.cpp
*
* @brief declaration of class to calculate overlap between different images
*
* @author Thomas Modes
*
* $Id$
*
*/
/* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public
* License along with this software; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*/
#include "CalculateOverlap.h"
namespace HuginBase {
using namespace hugin_utils;
CalculateImageOverlap::CalculateImageOverlap(const HuginBase::PanoramaData *pano):m_pano(pano)
{
m_nrImg=pano->getNrOfImages();
if(m_nrImg>0)
{
m_overlap.resize(m_nrImg);
PanoramaOptions opts=pano->getOptions();
m_transform.resize(m_nrImg);
m_invTransform.resize(m_nrImg);
for(unsigned int i=0;i<m_nrImg;i++)
{
m_overlap[i].resize(m_nrImg,0);
m_transform[i]=new PTools::Transform;
m_transform[i]->createTransform(*pano,i,opts);
m_invTransform[i]=new PTools::Transform;
m_invTransform[i]->createInvTransform(*pano,i,opts);
};
};
};
CalculateImageOverlap::~CalculateImageOverlap()
{
for(unsigned int i=0;i<m_nrImg;i++)
{
delete m_transform[i];
delete m_invTransform[i];
};
};
void CalculateImageOverlap::calculate(unsigned int steps)
{
for(unsigned int i=0; i<m_nrImg;i++)
{
const SrcPanoImage& img=m_pano->getImage(i);
vigra::Rect2D c=img.getCropRect();
unsigned int frequency=std::min<unsigned int>(steps,std::min<unsigned int>(c.width(),c.height()));
if(frequency<2)
frequency=2;
std::vector<unsigned int> overlapCounter;
overlapCounter.resize(m_nrImg,0);
unsigned int pointCounter=0;
for (unsigned int x=0; x<frequency; x++)
{
for (unsigned int y=0; y<frequency; y++)
{
// scale (x, y) so it is always within the cropped region of the
// image.
double xc = double (x) / double (frequency) * double(c.width()) + c.left();
double yc = double (y) / double (frequency) * double(c.height()) + c.top();
vigra::Point2D p(xc,yc);
//check if inside crop, especially for circular crops
if(img.isInside(p,true))
{
pointCounter++;
//transform to panorama coordinates
double xi,yi;
m_invTransform[i]->transformImgCoord(xi,yi,xc,yc);
//now, check if point is inside an other image
for(unsigned int j=0;j<m_nrImg;j++)
{
if(i==j)
continue;
double xj,yj;
//transform to image coordinates
m_transform[j]->transformImgCoord(xj,yj,xi,yi);
p.x=xj;
p.y=yj;
if(m_pano->getImage(j).isInside(p,true))
{
overlapCounter[j]++;
};
};
};
};
};
//now calculate overlap and save
m_overlap[i][i]=1.0;
if(pointCounter>0)
{
for(unsigned int k=0;k<m_nrImg;k++)
{
if(i==k)
{
continue;
};
m_overlap[i][k]=(double)overlapCounter[k]/(double)pointCounter;
};
};
};
};
double CalculateImageOverlap::getOverlap(unsigned int i, unsigned int j)
{
return std::max<double>(m_overlap[i][j],m_overlap[j][i]);
};
} // namespace

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:

JavaScript is required for this form.





No, thanks