1
/*M///////////////////////////////////////////////////////////////////////////////////////
3
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
5
// By downloading, copying, installing or using the software you agree to this license.
6
// If you do not agree to this license, do not download, install,
7
// copy or use the software.
11
// For Open Source Computer Vision Library
13
// Copyright (C) 2000-2008, Intel Corporation, all rights reserved.
14
// Copyright (C) 2009-2011, Willow Garage Inc., all rights reserved.
15
// Third party copyrights are property of their respective owners.
17
// Redistribution and use in source and binary forms, with or without modification,
18
// are permitted provided that the following conditions are met:
20
// * Redistribution's of source code must retain the above copyright notice,
21
// this list of conditions and the following disclaimer.
23
// * Redistribution's in binary form must reproduce the above copyright notice,
24
// this list of conditions and the following disclaimer in the documentation
25
// and/or other materials provided with the distribution.
27
// * The name of the copyright holders may not be used to endorse or promote products
28
// derived from this software without specific prior written permission.
30
// This software is provided by the copyright holders and contributors "as is" and
31
// any express or implied warranties, including, but not limited to, the implied
32
// warranties of merchantability and fitness for a particular purpose are disclaimed.
33
// In no event shall the Intel Corporation or contributors be liable for any direct,
34
// indirect, incidental, special, exemplary, or consequential damages
35
// (including, but not limited to, procurement of substitute goods or services;
36
// loss of use, data, or profits; or business interruption) however caused
37
// and on any theory of liability, whether in contract, strict liability,
38
// or tort (including negligence or otherwise) arising in any way out of
39
// the use of this software, even if advised of the possibility of such damage.
43
#include "precomp.hpp"
44
#include "opencv2/videostab/fast_marching.hpp"
45
#include "opencv2/videostab/ring_buffer.hpp"
52
float FastMarchingMethod::solve(int x1, int y1, int x2, int y2) const
55
if (y1 >=0 && y1 < flag_.rows && x1 >= 0 && x1 < flag_.cols && flag_(y1,x1) == KNOWN)
57
float t1 = dist_(y1,x1);
58
if (y2 >=0 && y2 < flag_.rows && x2 >= 0 && x2 < flag_.cols && flag_(y2,x2) == KNOWN)
60
float t2 = dist_(y2,x2);
61
float r = std::sqrt(2 - sqr(t1 - t2));
62
float s = (t1 + t2 - r) / 2;
64
if (s >= t1 && s >= t2)
69
if (s >= t1 && s >= t2)
76
else if (y2 >=0 && y2 < flag_.rows && x2 >= 0 && x2 < flag_.cols && flag_(y2,x2) == KNOWN)
77
sol = 1 + dist_(y2,x1);
82
void FastMarchingMethod::heapUp(int idx)
85
while (idx > 0 && narrowBand_[idx] < narrowBand_[p])
87
std::swap(indexOf(narrowBand_[p]), indexOf(narrowBand_[idx]));
88
std::swap(narrowBand_[p], narrowBand_[idx]);
95
void FastMarchingMethod::heapDown(int idx)
104
if (l < size_ && narrowBand_[l] < narrowBand_[smallest]) smallest = l;
105
if (r < size_ && narrowBand_[r] < narrowBand_[smallest]) smallest = r;
111
std::swap(indexOf(narrowBand_[idx]), indexOf(narrowBand_[smallest]));
112
std::swap(narrowBand_[idx], narrowBand_[smallest]);
119
void FastMarchingMethod::heapAdd(const DXY &dxy)
121
if (static_cast<int>(narrowBand_.size()) < size_ + 1)
122
narrowBand_.resize(size_*2 + 1);
123
narrowBand_[size_] = dxy;
124
indexOf(dxy) = size_++;
129
void FastMarchingMethod::heapRemoveMin()
134
std::swap(indexOf(narrowBand_[0]), indexOf(narrowBand_[size_]));
135
std::swap(narrowBand_[0], narrowBand_[size_]);
140
} // namespace videostab