forked from YinlinHu/CPM
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CPM.h
124 lines (82 loc) · 2.78 KB
/
CPM.h
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
/*
Code of the Coarse-to-Fine PatchMatch, published at CVPR 2016 in
"Efficient Coarse-to-Fine PatchMatch for Large Displacement Optical Flow"
by Yinlin.Hu, Rui Song and Yunsong Li.
Email: huyinlin@gmail.com
Version 1.2
Copyright (C) 2016 Yinlin.Hu
Usages:
The program "cpm.exe" has been built and tested on Windows 7.
USAGE: cpm.exe img1Name img2Name outMatchName
Explanations:
The output of the program is a text file, which is in the format of "x1,y1,x2,y2"
corresponding to one match per line.
*/
#ifndef _CPM_H_
#define _CPM_H_
#include "ImagePyramid.h"
#include "Image.h"
namespace cpm
{
struct sCPMParameters
{
int m_Step_i;
bool m_IsStereo_b;
int m_maxIters_i;
float m_StopIterRatio_f;
float m_pydRatio_f;
int m_maxDisplacement_i;
int m_checkThreshold_i;
int m_borderWidth_i;
// default parameters
sCPMParameters()
: m_Step_i( 3 )
, m_IsStereo_b(false)
, m_maxIters_i( 8 )
, m_StopIterRatio_f( 0.05 )
, m_pydRatio_f( 0.5 )
, m_maxDisplacement_i( 400 )
, m_checkThreshold_i( 3 )
, m_borderWidth_i( 5 )
{}
};
class CPM
{
public:
CPM();
explicit CPM( const sCPMParameters &f_Param );
~CPM();
int Matching(FImage& img1, FImage& img2, FImage& outMatches);
private:
void CrossCheck(IntImage& seeds, FImage& seedsFlow, FImage& seedsFlow2, IntImage& kLabel2, int* valid, float th);
float MatchCost(FImage& img1, FImage& img2, UCImage* im1f, UCImage* im2f, int x1, int y1, int x2, int y2);
// a good initialization is already stored in bestU & bestV
int Propogate(FImagePyramid& pyd1, FImagePyramid& pyd2, UCImage* pyd1f, UCImage* pyd2f, int level, float* radius, int iterCnt, IntImage* pydSeeds, IntImage& neighbors, FImage* pydSeedsFlow, float* bestCosts);
void PyramidRandomSearch(FImagePyramid& pyd1, FImagePyramid& pyd2, UCImage* im1f, UCImage* im2f, IntImage* pydSeeds, IntImage& neighbors, FImage* pydSeedsFlow);
void OnePass(FImagePyramid& pyd1, FImagePyramid& pyd2, UCImage* im1f, UCImage* im2f, IntImage& seeds, IntImage& neighbors, FImage* pydSeedsFlow);
void UpdateSearchRadius(IntImage& neighbors, FImage* pydSeedsFlow, int level, float* outRadius);
// minimum circle
struct Point{
double x, y;
};
double dist(Point a, Point b);
Point intersection(Point u1, Point u2, Point v1, Point v2);
Point circumcenter(Point a, Point b, Point c);
// return the radius of the minimal circle
float MinimalCircle(float* x, float*y, int n, float* centerX = NULL, float* centerY = NULL);
//
const sCPMParameters m_Param;
IntImage _kLabels, _kLabels2;
FImagePyramid _pyd1;
FImagePyramid _pyd2;
UCImage* _im1f;
UCImage* _im2f;
FImage* _pydSeedsFlow;
FImage* _pydSeedsFlow2;
IntImage _seeds;
IntImage _seeds2;
IntImage _neighbors;
IntImage _neighbors2;
};
} //namespace cpm
#endif // _CPM_H_