Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
Toggle navigation
O
opencv
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Packages
Packages
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
submodule
opencv
Commits
0876f69d
Commit
0876f69d
authored
Jun 15, 2011
by
Vadim Pisarevsky
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
added variational stereo correspondence (by Sergey Kosov) and polynomial fitting (by Onkar Raut)
parent
0d09352f
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
140 additions
and
5 deletions
+140
-5
contrib.hpp
modules/contrib/include/opencv2/contrib/contrib.hpp
+42
-0
polyfit.cpp
modules/contrib/src/polyfit.cpp
+72
-0
stereovar.cpp
modules/contrib/src/stereovar.cpp
+0
-0
stereo_match.cpp
samples/cpp/stereo_match.cpp
+26
-5
No files found.
modules/contrib/include/opencv2/contrib/contrib.hpp
View file @
0876f69d
...
@@ -562,6 +562,48 @@ namespace cv
...
@@ -562,6 +562,48 @@ namespace cv
double
minMatchDistance
=
1.0
,
int
padX
=
3
,
double
minMatchDistance
=
1.0
,
int
padX
=
3
,
int
padY
=
3
,
int
scales
=
5
,
double
minScale
=
0.6
,
double
maxScale
=
1.6
,
int
padY
=
3
,
int
scales
=
5
,
double
minScale
=
0.6
,
double
maxScale
=
1.6
,
double
orientationWeight
=
0.5
,
double
truncate
=
20
);
double
orientationWeight
=
0.5
,
double
truncate
=
20
);
class
CV_EXPORTS
StereoVar
{
public
:
// Flags
enum
{
USE_INITIAL_DISPARITY
=
1
,
USE_EQUALIZE_HIST
=
2
,
USE_SMART_ID
=
4
,
USE_MEDIAN_FILTERING
=
8
};
enum
{
CYCLE_O
,
CYCLE_V
};
enum
{
PENALIZATION_TICHONOV
,
PENALIZATION_CHARBONNIER
,
PENALIZATION_PERONA_MALIK
};
//! the default constructor
CV_WRAP
StereoVar
();
//! the full constructor taking all the necessary algorithm parameters
CV_WRAP
StereoVar
(
int
levels
,
double
pyrScale
,
int
nIt
,
int
minDisp
,
int
maxDisp
,
int
poly_n
,
double
poly_sigma
,
float
fi
,
float
lambda
,
int
penalization
,
int
cycle
,
int
flags
);
//! the destructor
virtual
~
StereoVar
();
//! the stereo correspondence operator that computes disparity map for the specified rectified stereo pair
CV_WRAP_AS
(
compute
)
virtual
void
operator
()(
const
Mat
&
left
,
const
Mat
&
right
,
Mat
&
disp
);
CV_PROP_RW
int
levels
;
CV_PROP_RW
double
pyrScale
;
CV_PROP_RW
int
nIt
;
CV_PROP_RW
int
minDisp
;
CV_PROP_RW
int
maxDisp
;
CV_PROP_RW
int
poly_n
;
CV_PROP_RW
double
poly_sigma
;
CV_PROP_RW
float
fi
;
CV_PROP_RW
float
lambda
;
CV_PROP_RW
int
penalization
;
CV_PROP_RW
int
cycle
;
CV_PROP_RW
int
flags
;
private
:
void
FMG
(
Mat
&
I1
,
Mat
&
I2
,
Mat
&
I2x
,
Mat
&
u
,
int
level
);
void
VCycle_MyFAS
(
Mat
&
I1_h
,
Mat
&
I2_h
,
Mat
&
I2x_h
,
Mat
&
u_h
,
int
level
);
void
VariationalSolver
(
Mat
&
I1_h
,
Mat
&
I2_h
,
Mat
&
I2x_h
,
Mat
&
u_h
,
int
level
);
};
CV_EXPORTS
void
polyfit
(
const
Mat
&
srcx
,
const
Mat
&
srcy
,
Mat
&
dst
,
int
order
);
}
}
...
...
modules/contrib/src/polyfit.cpp
0 → 100644
View file @
0876f69d
/*M///////////////////////////////////////////////////////////////////////////////////////
//
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
//
// By downloading, copying, installing or using the software you agree to this license.
// If you do not agree to this license, do not download, install,
// copy or use the software.
//
//
// License Agreement
// For Open Source Computer Vision Library
//
// Copyright (C) 2000-2008, Intel Corporation, all rights reserved.
// Copyright (C) 2009, Willow Garage Inc., all rights reserved.
// Third party copyrights are property of their respective owners.
//
// Redistribution and use in source and binary forms, with or without modification,
// are permitted provided that the following conditions are met:
//
// * Redistribution's of source code must retain the above copyright notice,
// this list of conditions and the following disclaimer.
//
// * Redistribution's in binary form must reproduce the above copyright notice,
// this list of conditions and the following disclaimer in the documentation
// and/or other materials provided with the distribution.
//
// * The name of the copyright holders may not be used to endorse or promote products
// derived from this software without specific prior written permission.
//
// This software is provided by the copyright holders and contributors "as is" and
// any express or implied warranties, including, but not limited to, the implied
// warranties of merchantability and fitness for a particular purpose are disclaimed.
// In no event shall the Intel Corporation or contributors be liable for any direct,
// indirect, incidental, special, exemplary, or consequential damages
// (including, but not limited to, procurement of substitute goods or services;
// loss of use, data, or profits; or business interruption) however caused
// and on any theory of liability, whether in contract, strict liability,
// or tort (including negligence or otherwise) arising in any way out of
// the use of this software, even if advised of the possibility of such damage.
//
//M*/
// This original code was written by
// Onkar Raut
// Graduate Student,
// University of North Carolina at Charlotte
#include "precomp.hpp"
void
cv
::
polyfit
(
const
Mat
&
src_x
,
const
Mat
&
src_y
,
Mat
&
dst
,
int
order
)
{
CV_Assert
((
src_x
.
rows
>
0
)
&&
(
src_y
.
rows
>
0
)
&&
(
src_x
.
cols
==
1
)
&&
(
src_y
.
cols
==
1
)
&&
(
dst
.
cols
==
1
)
&&
(
dst
.
rows
==
(
order
+
1
))
&&
(
order
>=
1
));
Mat
X
;
X
=
Mat
::
zeros
(
src_x
.
rows
,
order
+
1
,
CV_32FC1
);
Mat
copy
;
for
(
int
i
=
0
;
i
<=
order
;
i
++
)
{
copy
=
src_x
.
clone
();
pow
(
copy
,
i
,
copy
);
Mat
M1
=
X
.
col
(
i
);
copy
.
col
(
0
).
copyTo
(
M1
);
}
Mat
X_t
,
X_inv
;
transpose
(
X
,
X_t
);
Mat
temp
=
X_t
*
X
;
Mat
temp2
;
invert
(
temp
,
temp2
);
Mat
temp3
=
temp2
*
X_t
;
Mat
W
=
temp3
*
src_y
;
W
.
copyTo
(
dst
);
}
modules/contrib/src/stereovar.cpp
0 → 100755
View file @
0876f69d
This diff is collapsed.
Click to expand it.
samples/cpp/stereo_match.cpp
View file @
0876f69d
...
@@ -10,6 +10,7 @@
...
@@ -10,6 +10,7 @@
#include "opencv2/calib3d/calib3d.hpp"
#include "opencv2/calib3d/calib3d.hpp"
#include "opencv2/imgproc/imgproc.hpp"
#include "opencv2/imgproc/imgproc.hpp"
#include "opencv2/highgui/highgui.hpp"
#include "opencv2/highgui/highgui.hpp"
#include "opencv2/contrib/contrib.hpp"
#include <stdio.h>
#include <stdio.h>
...
@@ -18,7 +19,7 @@ using namespace cv;
...
@@ -18,7 +19,7 @@ using namespace cv;
void
print_help
()
void
print_help
()
{
{
printf
(
"
\n
Demo stereo matching converting L and R images into disparity and point clouds
\n
"
);
printf
(
"
\n
Demo stereo matching converting L and R images into disparity and point clouds
\n
"
);
printf
(
"
\n
Usage: stereo_match <left_image> <right_image> [--algorithm=bm|sgbm|hh] [--blocksize=<block_size>]
\n
"
printf
(
"
\n
Usage: stereo_match <left_image> <right_image> [--algorithm=bm|sgbm|hh
|var
] [--blocksize=<block_size>]
\n
"
"[--max-disparity=<max_disparity>] [-i <intrinsic_filename>] [-e <extrinsic_filename>]
\n
"
"[--max-disparity=<max_disparity>] [-i <intrinsic_filename>] [-e <extrinsic_filename>]
\n
"
"[--no-display] [-o <disparity_image>] [-p <point_cloud_file>]
\n
"
);
"[--no-display] [-o <disparity_image>] [-p <point_cloud_file>]
\n
"
);
}
}
...
@@ -59,13 +60,14 @@ int main(int argc, char** argv)
...
@@ -59,13 +60,14 @@ int main(int argc, char** argv)
const
char
*
disparity_filename
=
0
;
const
char
*
disparity_filename
=
0
;
const
char
*
point_cloud_filename
=
0
;
const
char
*
point_cloud_filename
=
0
;
enum
{
STEREO_BM
=
0
,
STEREO_SGBM
=
1
,
STEREO_HH
=
2
};
enum
{
STEREO_BM
=
0
,
STEREO_SGBM
=
1
,
STEREO_HH
=
2
,
STEREO_VAR
=
3
};
int
alg
=
STEREO_SGBM
;
int
alg
=
STEREO_SGBM
;
int
SADWindowSize
=
0
,
numberOfDisparities
=
0
;
int
SADWindowSize
=
0
,
numberOfDisparities
=
0
;
bool
no_display
=
false
;
bool
no_display
=
false
;
StereoBM
bm
;
StereoBM
bm
;
StereoSGBM
sgbm
;
StereoSGBM
sgbm
;
StereoVar
var
;
for
(
int
i
=
1
;
i
<
argc
;
i
++
)
for
(
int
i
=
1
;
i
<
argc
;
i
++
)
{
{
...
@@ -81,7 +83,8 @@ int main(int argc, char** argv)
...
@@ -81,7 +83,8 @@ int main(int argc, char** argv)
char
*
_alg
=
argv
[
i
]
+
strlen
(
algorithm_opt
);
char
*
_alg
=
argv
[
i
]
+
strlen
(
algorithm_opt
);
alg
=
strcmp
(
_alg
,
"bm"
)
==
0
?
STEREO_BM
:
alg
=
strcmp
(
_alg
,
"bm"
)
==
0
?
STEREO_BM
:
strcmp
(
_alg
,
"sgbm"
)
==
0
?
STEREO_SGBM
:
strcmp
(
_alg
,
"sgbm"
)
==
0
?
STEREO_SGBM
:
strcmp
(
_alg
,
"hh"
)
==
0
?
STEREO_HH
:
-
1
;
strcmp
(
_alg
,
"hh"
)
==
0
?
STEREO_HH
:
strcmp
(
_alg
,
"var"
)
==
0
?
STEREO_VAR
:
-
1
;
if
(
alg
<
0
)
if
(
alg
<
0
)
{
{
printf
(
"Command-line parameter error: Unknown stereo algorithm
\n\n
"
);
printf
(
"Command-line parameter error: Unknown stereo algorithm
\n\n
"
);
...
@@ -192,7 +195,7 @@ int main(int argc, char** argv)
...
@@ -192,7 +195,7 @@ int main(int argc, char** argv)
img2
=
img2r
;
img2
=
img2r
;
}
}
numberOfDisparities
=
numberOfDisparities
>
0
?
numberOfDisparities
:
img_size
.
width
/
8
;
numberOfDisparities
=
numberOfDisparities
>
0
?
numberOfDisparities
:
((
img_size
.
width
/
8
)
+
15
)
&
-
16
;
bm
.
state
->
roi1
=
roi1
;
bm
.
state
->
roi1
=
roi1
;
bm
.
state
->
roi2
=
roi2
;
bm
.
state
->
roi2
=
roi2
;
...
@@ -221,6 +224,19 @@ int main(int argc, char** argv)
...
@@ -221,6 +224,19 @@ int main(int argc, char** argv)
sgbm
.
disp12MaxDiff
=
1
;
sgbm
.
disp12MaxDiff
=
1
;
sgbm
.
fullDP
=
alg
==
STEREO_HH
;
sgbm
.
fullDP
=
alg
==
STEREO_HH
;
var
.
levels
=
6
;
var
.
pyrScale
=
0.6
;
var
.
nIt
=
3
;
var
.
minDisp
=
-
numberOfDisparities
;
var
.
maxDisp
=
0
;
var
.
poly_n
=
3
;
var
.
poly_sigma
=
0.0
;
var
.
fi
=
5.0
f
;
var
.
lambda
=
0.1
;
var
.
penalization
=
var
.
PENALIZATION_TICHONOV
;
var
.
cycle
=
var
.
CYCLE_V
;
var
.
flags
=
var
.
USE_SMART_ID
|
var
.
USE_INITIAL_DISPARITY
|
1
*
var
.
USE_MEDIAN_FILTERING
;
Mat
disp
,
disp8
;
Mat
disp
,
disp8
;
//Mat img1p, img2p, dispp;
//Mat img1p, img2p, dispp;
//copyMakeBorder(img1, img1p, 0, 0, numberOfDisparities, 0, IPL_BORDER_REPLICATE);
//copyMakeBorder(img1, img1p, 0, 0, numberOfDisparities, 0, IPL_BORDER_REPLICATE);
...
@@ -229,13 +245,18 @@ int main(int argc, char** argv)
...
@@ -229,13 +245,18 @@ int main(int argc, char** argv)
int64
t
=
getTickCount
();
int64
t
=
getTickCount
();
if
(
alg
==
STEREO_BM
)
if
(
alg
==
STEREO_BM
)
bm
(
img1
,
img2
,
disp
);
bm
(
img1
,
img2
,
disp
);
else
else
if
(
alg
==
STEREO_VAR
)
var
(
img1
,
img2
,
disp
);
else
if
(
alg
==
STEREO_SGBM
||
alg
==
STEREO_HH
)
sgbm
(
img1
,
img2
,
disp
);
sgbm
(
img1
,
img2
,
disp
);
t
=
getTickCount
()
-
t
;
t
=
getTickCount
()
-
t
;
printf
(
"Time elapsed: %fms
\n
"
,
t
*
1000
/
getTickFrequency
());
printf
(
"Time elapsed: %fms
\n
"
,
t
*
1000
/
getTickFrequency
());
//disp = dispp.colRange(numberOfDisparities, img1p.cols);
//disp = dispp.colRange(numberOfDisparities, img1p.cols);
if
(
alg
!=
STEREO_VAR
)
disp
.
convertTo
(
disp8
,
CV_8U
,
255
/
(
numberOfDisparities
*
16.
));
disp
.
convertTo
(
disp8
,
CV_8U
,
255
/
(
numberOfDisparities
*
16.
));
else
disp
.
convertTo
(
disp8
,
CV_8U
);
if
(
!
no_display
)
if
(
!
no_display
)
{
{
namedWindow
(
"left"
,
1
);
namedWindow
(
"left"
,
1
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment