Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
Toggle navigation
O
opencv_contrib
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_contrib
Commits
1f33b20b
Commit
1f33b20b
authored
Aug 02, 2014
by
biagio montesano
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Removed some other warnings
parent
e0da9f93
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
109 additions
and
107 deletions
+109
-107
lines_extraction.cpp
modules/line_descriptor/samples/lines_extraction.cpp
+2
-2
binary_descriptor.cpp
modules/line_descriptor/src/binary_descriptor.cpp
+4
-4
binary_descriptor_matcher.cpp
modules/line_descriptor/src/binary_descriptor_matcher.cpp
+11
-11
draw.cpp
modules/line_descriptor/src/draw.cpp
+7
-7
ed_line_detector.cpp
modules/line_descriptor/src/ed_line_detector.cpp
+84
-83
precomp.hpp
modules/line_descriptor/src/precomp.hpp
+1
-0
No files found.
modules/line_descriptor/samples/lines_extraction.cpp
View file @
1f33b20b
...
...
@@ -107,8 +107,8 @@ int main( int argc, char** argv )
int
B
=
(
rand
()
%
(
int
)
(
255
+
1
)
);
/* get extremes of line */
Point
pt1
=
Point
(
kl
.
startPointX
,
kl
.
startPointY
);
Point
pt2
=
Point
(
kl
.
endPointX
,
kl
.
endPointY
);
Point
pt1
=
Point
2f
(
kl
.
startPointX
,
kl
.
startPointY
);
Point
pt2
=
Point
2f
(
kl
.
endPointX
,
kl
.
endPointY
);
/* draw line */
line
(
output
,
pt1
,
pt2
,
Scalar
(
B
,
G
,
R
),
3
);
...
...
modules/line_descriptor/src/binary_descriptor.cpp
View file @
1f33b20b
...
...
@@ -610,7 +610,7 @@ int BinaryDescriptor::OctaveKeyLines( cv::Mat& image, ScaleLines &keyLines )
scale
[
0
]
=
1
;
for
(
int
octaveCount
=
1
;
octaveCount
<
params
.
numOfOctave_
;
octaveCount
++
)
{
scale
[
octaveCount
]
=
factor
*
scale
[
octaveCount
-
1
]
;
scale
[
octaveCount
]
=
(
float
)
(
factor
*
scale
[
octaveCount
-
1
]
)
;
}
/* some variables' declarations */
...
...
@@ -1114,7 +1114,7 @@ int BinaryDescriptor::computeLBD( ScaleLines &keyLines )
desVec
=
pSingleLine
->
descriptor
.
data
();
int
base
=
0
;
for
(
short
i
=
0
;
i
<
(
short
)
(
NUM_OF_BANDS
*
8
);
++
base
,
i
=
base
*
8
)
for
(
short
i
=
0
;
i
<
(
short
)
(
NUM_OF_BANDS
*
8
);
++
base
,
i
=
(
short
)
(
base
*
8
)
)
{
tempM
+=
*
(
desVec
+
i
)
*
*
(
desVec
+
i
);
//desVec[8*i+0] * desVec[8*i+0];
tempM
+=
*
(
desVec
+
i
+
1
)
*
*
(
desVec
+
i
+
1
);
//desVec[8*i+1] * desVec[8*i+1];
...
...
@@ -1130,7 +1130,7 @@ int BinaryDescriptor::computeLBD( ScaleLines &keyLines )
tempS
=
1
/
sqrt
(
tempS
);
desVec
=
pSingleLine
->
descriptor
.
data
();
base
=
0
;
for
(
short
i
=
0
;
i
<
(
short
)
(
NUM_OF_BANDS
*
8
);
++
base
,
i
=
base
*
8
)
for
(
short
i
=
0
;
i
<
(
short
)
(
NUM_OF_BANDS
*
8
);
++
base
,
i
=
(
short
)
(
base
*
8
)
)
{
*
(
desVec
+
i
)
=
*
(
desVec
+
i
)
*
tempM
;
//desVec[8*i] = desVec[8*i] * tempM;
*
(
desVec
+
1
+
i
)
=
*
(
desVec
+
1
+
i
)
*
tempM
;
//desVec[8*i+1] = desVec[8*i+1] * tempM;
...
...
@@ -1151,7 +1151,7 @@ int BinaryDescriptor::computeLBD( ScaleLines &keyLines )
{
if
(
desVec
[
i
]
>
0.4
)
{
desVec
[
i
]
=
(
float
)
0.4
;
desVec
[
i
]
=
(
float
)
0.4
;
}
}
...
...
modules/line_descriptor/src/binary_descriptor_matcher.cpp
View file @
1f33b20b
...
...
@@ -105,7 +105,7 @@ void BinaryDescriptorMatcher::checkKDistances( UINT32 * numres, int k, std::vect
{
if
(
(
*
(
numres_tmp
+
j
)
)
>
0
)
{
for
(
int
i
=
0
;
i
<
(
int
)(
*
(
numres_tmp
+
j
)
)
&&
k_to_found
>
0
;
i
++
)
for
(
int
i
=
0
;
i
<
(
int
)
(
*
(
numres_tmp
+
j
)
)
&&
k_to_found
>
0
;
i
++
)
{
k_distances
.
push_back
(
j
);
k_to_found
--
;
...
...
@@ -153,10 +153,10 @@ void BinaryDescriptorMatcher::match( const Mat& queryDescriptors, std::vector<DM
/* data validity check */
if
(
!
masks
.
empty
()
&&
(
masks
[
itup
->
second
].
rows
!=
queryDescriptors
.
rows
||
masks
[
itup
->
second
].
cols
!=
1
)
)
{
std
::
cout
<<
"Error: mask "
<<
itup
->
second
<<
" in knnMatch function "
<<
"should have "
<<
queryDescriptors
.
rows
<<
" and "
<<
"1 column. Program will be terminated"
<<
std
::
endl
;
CV_Assert
(
false
);
std
::
stringstream
ss
;
ss
<<
"Error: mask "
<<
itup
->
second
<<
" in knnMatch function "
<<
"should have "
<<
queryDescriptors
.
rows
<<
" and "
<<
"1 column. Program will be terminated"
;
throw
std
::
runtime_error
(
ss
.
str
()
);
}
/* create a DMatch object if required by mask or if there is
...
...
@@ -170,7 +170,7 @@ void BinaryDescriptorMatcher::match( const Mat& queryDescriptors, std::vector<DM
dm
.
queryIdx
=
counter
;
dm
.
trainIdx
=
results
[
counter
]
-
1
;
dm
.
imgIdx
=
itup
->
second
;
dm
.
distance
=
k_distances
[
0
];
dm
.
distance
=
(
float
)
k_distances
[
0
];
matches
.
push_back
(
dm
);
}
...
...
@@ -223,7 +223,7 @@ void BinaryDescriptorMatcher::match( const Mat& queryDescriptors, const Mat& tra
dm
.
queryIdx
=
counter
;
dm
.
trainIdx
=
results
[
counter
]
-
1
;
dm
.
imgIdx
=
0
;
dm
.
distance
=
k_distances
[
0
];
dm
.
distance
=
(
float
)
k_distances
[
0
];
matches
.
push_back
(
dm
);
}
...
...
@@ -293,7 +293,7 @@ void BinaryDescriptorMatcher::knnMatch( const Mat& queryDescriptors, const Mat&
dm
.
queryIdx
=
counter
;
dm
.
trainIdx
=
results
[
j
]
-
1
;
dm
.
imgIdx
=
0
;
dm
.
distance
=
k_distances
[
j
-
index
];
dm
.
distance
=
(
float
)
k_distances
[
j
-
index
];
tempVec
.
push_back
(
dm
);
}
...
...
@@ -375,7 +375,7 @@ void BinaryDescriptorMatcher::knnMatch( const Mat& queryDescriptors, std::vector
dm
.
queryIdx
=
counter
;
dm
.
trainIdx
=
results
[
j
]
-
1
;
dm
.
imgIdx
=
itup
->
second
;
dm
.
distance
=
k_distances
[
j
-
index
];
dm
.
distance
=
(
float
)
k_distances
[
j
-
index
];
tempVector
.
push_back
(
dm
);
}
...
...
@@ -444,7 +444,7 @@ void BinaryDescriptorMatcher::radiusMatch( const Mat& queryDescriptors, const Ma
dm
.
queryIdx
=
i
;
dm
.
trainIdx
=
results
[
j
]
-
1
;
dm
.
imgIdx
=
0
;
dm
.
distance
=
k_distances
[
j
-
index
];
dm
.
distance
=
(
float
)
k_distances
[
j
-
index
];
tempVector
.
push_back
(
dm
);
}
...
...
@@ -528,7 +528,7 @@ void BinaryDescriptorMatcher::radiusMatch( const Mat& queryDescriptors, std::vec
dm
.
queryIdx
=
counter
;
dm
.
trainIdx
=
results
[
j
]
-
1
;
dm
.
imgIdx
=
itup
->
second
;
dm
.
distance
=
k_distances
[
j
-
index
];
dm
.
distance
=
(
float
)
k_distances
[
j
-
index
];
tempVector
.
push_back
(
dm
);
}
...
...
modules/line_descriptor/src/draw.cpp
View file @
1f33b20b
...
...
@@ -61,7 +61,7 @@ void drawLineMatches( const Mat& img1, const std::vector<KeyLine>& keylines1, co
}
/* initialize random seed: */
srand
(
time
(
NULL
)
);
srand
(
(
unsigned
int
)
time
(
NULL
)
);
Scalar
singleLineColorRGB
;
if
(
singleLineColor
==
Scalar
::
all
(
-
1
)
)
...
...
@@ -91,13 +91,13 @@ void drawLineMatches( const Mat& img1, const std::vector<KeyLine>& keylines1, co
for
(
size_t
i
=
0
;
i
<
keylines1
.
size
();
i
++
)
{
KeyLine
k1
=
keylines1
[
i
];
line
(
outImg
,
Point
(
k1
.
startPointX
,
k1
.
startPointY
),
Point
(
k1
.
endPointX
,
k1
.
endPointY
),
singleLineColorRGB
,
2
);
line
(
outImg
,
Point
2f
(
k1
.
startPointX
,
k1
.
startPointY
),
Point2f
(
k1
.
endPointX
,
k1
.
endPointY
),
singleLineColorRGB
,
2
);
}
for
(
size_t
j
=
0
;
j
<
keylines2
.
size
();
j
++
)
{
KeyLine
k2
=
keylines2
[
j
];
line
(
outImg
,
Point
(
k2
.
startPointX
+
offset
,
k2
.
startPointY
),
Point
(
k2
.
endPointX
+
offset
,
k2
.
endPointY
),
singleLineColorRGB
,
2
);
line
(
outImg
,
Point
2f
(
k2
.
startPointX
+
offset
,
k2
.
startPointY
),
Point2f
(
k2
.
endPointX
+
offset
,
k2
.
endPointY
),
singleLineColorRGB
,
2
);
}
}
...
...
@@ -127,13 +127,13 @@ void drawLineMatches( const Mat& img1, const std::vector<KeyLine>& keylines1, co
matchColorRGB
=
matchColor
;
/* draw lines if necessary */
line
(
outImg
,
Point
(
left
.
startPointX
,
left
.
startPointY
),
Point
(
left
.
endPointX
,
left
.
endPointY
),
singleLineColorRGB
,
2
);
line
(
outImg
,
Point
2f
(
left
.
startPointX
,
left
.
startPointY
),
Point2f
(
left
.
endPointX
,
left
.
endPointY
),
singleLineColorRGB
,
2
);
line
(
outImg
,
Point
(
right
.
startPointX
+
offset
,
right
.
startPointY
),
Point
(
right
.
endPointX
+
offset
,
right
.
endPointY
),
singleLineColorRGB
,
line
(
outImg
,
Point
2f
(
right
.
startPointX
+
offset
,
right
.
startPointY
),
Point2f
(
right
.
endPointX
+
offset
,
right
.
endPointY
),
singleLineColorRGB
,
2
);
/* link correspondent lines */
line
(
outImg
,
Point
(
left
.
startPointX
,
left
.
startPointY
),
Point
(
right
.
startPointX
+
offset
,
right
.
startPointY
),
matchColorRGB
,
1
);
line
(
outImg
,
Point
2f
(
left
.
startPointX
,
left
.
startPointY
),
Point2f
(
right
.
startPointX
+
offset
,
right
.
startPointY
),
matchColorRGB
,
1
);
}
}
}
...
...
@@ -164,7 +164,7 @@ void drawKeylines( const Mat& image, const std::vector<KeyLine>& keylines, Mat&
KeyLine
k
=
keylines
[
i
];
/* draw line */
line
(
outImage
,
Point
(
k
.
startPointX
,
k
.
startPointY
),
Point
(
k
.
endPointX
,
k
.
endPointY
),
lineColor
,
1
);
line
(
outImage
,
Point
2f
(
k
.
startPointX
,
k
.
startPointY
),
Point2f
(
k
.
endPointX
,
k
.
endPointY
),
lineColor
,
1
);
}
}
...
...
modules/line_descriptor/src/ed_line_detector.cpp
View file @
1f33b20b
...
...
@@ -66,8 +66,8 @@ EDLineDetector::EDLineDetector( EDLineParam param )
//set parameters for line segment detection
ksize_
=
param
.
ksize
;
sigma_
=
param
.
sigma
;
gradienThreshold_
=
param
.
gradientThreshold
;
anchorThreshold_
=
param
.
anchorThreshold
;
gradienThreshold_
=
(
short
)
param
.
gradientThreshold
;
anchorThreshold_
=
(
unsigned
char
)
param
.
anchorThreshold
;
scanIntervals_
=
param
.
scanIntervals
;
minLineLen_
=
param
.
minLineLen
;
lineFitErrThreshold_
=
param
.
lineFitErrThreshold
;
...
...
@@ -132,17 +132,18 @@ int EDLineDetector::EdgeDrawing( cv::Mat &image, EdgeChains &edgeChains, bool sm
unsigned
int
edgePixelArraySize
=
pixelNum
/
5
;
unsigned
int
maxNumOfEdge
=
edgePixelArraySize
/
20
;
//compute dx, dy images
if
(
gImg_
.
cols
!=
(
int
)
imageWidth
||
gImg_
.
rows
!=
(
int
)
imageHeight
)
if
(
gImg_
.
cols
!=
(
int
)
imageWidth
||
gImg_
.
rows
!=
(
int
)
imageHeight
)
{
if
(
pFirstPartEdgeX_
!=
NULL
){
delete
[]
pFirstPartEdgeX_
;
delete
[]
pFirstPartEdgeY_
;
delete
[]
pSecondPartEdgeX_
;
delete
[]
pSecondPartEdgeY_
;
delete
[]
pFirstPartEdgeS_
;
delete
[]
pSecondPartEdgeS_
;
delete
[]
pAnchorX_
;
delete
[]
pAnchorY_
;
if
(
pFirstPartEdgeX_
!=
NULL
)
{
delete
[]
pFirstPartEdgeX_
;
delete
[]
pFirstPartEdgeY_
;
delete
[]
pSecondPartEdgeX_
;
delete
[]
pSecondPartEdgeY_
;
delete
[]
pFirstPartEdgeS_
;
delete
[]
pSecondPartEdgeS_
;
delete
[]
pAnchorX_
;
delete
[]
pAnchorY_
;
}
dxImg_
.
create
(
imageHeight
,
imageWidth
,
CV_16SC1
);
...
...
@@ -285,9 +286,9 @@ int EDLineDetector::EdgeDrawing( cv::Mat &image, EdgeChains &edgeChains, bool sm
break
;
}
// Look at 3 neighbors to the right and pick the one with the max. gradient value
gValue1
=
pgImg
[
indexInArray
-
imageWidth
+
1
];
gValue2
=
pgImg
[
indexInArray
+
1
];
gValue3
=
pgImg
[
indexInArray
+
imageWidth
+
1
];
gValue1
=
(
unsigned
char
)
pgImg
[
indexInArray
-
imageWidth
+
1
];
gValue2
=
(
unsigned
char
)
pgImg
[
indexInArray
+
1
];
gValue3
=
(
unsigned
char
)
pgImg
[
indexInArray
+
imageWidth
+
1
];
if
(
gValue1
>=
gValue2
&&
gValue1
>=
gValue3
)
{
//up-right
x
=
x
+
1
;
...
...
@@ -311,9 +312,9 @@ int EDLineDetector::EdgeDrawing( cv::Mat &image, EdgeChains &edgeChains, bool sm
break
;
}
// Look at 3 neighbors to the left and pick the one with the max. gradient value
gValue1
=
pgImg
[
indexInArray
-
imageWidth
-
1
];
gValue2
=
pgImg
[
indexInArray
-
1
];
gValue3
=
pgImg
[
indexInArray
+
imageWidth
-
1
];
gValue1
=
(
unsigned
char
)
pgImg
[
indexInArray
-
imageWidth
-
1
];
gValue2
=
(
unsigned
char
)
pgImg
[
indexInArray
-
1
];
gValue3
=
(
unsigned
char
)
pgImg
[
indexInArray
+
imageWidth
-
1
];
if
(
gValue1
>=
gValue2
&&
gValue1
>=
gValue3
)
{
//up-left
x
=
x
-
1
;
...
...
@@ -353,9 +354,9 @@ int EDLineDetector::EdgeDrawing( cv::Mat &image, EdgeChains &edgeChains, bool sm
break
;
}
// Look at 3 neighbors to the down and pick the one with the max. gradient value
gValue1
=
pgImg
[
indexInArray
+
imageWidth
+
1
];
gValue2
=
pgImg
[
indexInArray
+
imageWidth
];
gValue3
=
pgImg
[
indexInArray
+
imageWidth
-
1
];
gValue1
=
(
unsigned
char
)
pgImg
[
indexInArray
+
imageWidth
+
1
];
gValue2
=
(
unsigned
char
)
pgImg
[
indexInArray
+
imageWidth
];
gValue3
=
(
unsigned
char
)
pgImg
[
indexInArray
+
imageWidth
-
1
];
if
(
gValue1
>=
gValue2
&&
gValue1
>=
gValue3
)
{
//down-right
x
=
x
+
1
;
...
...
@@ -379,9 +380,9 @@ int EDLineDetector::EdgeDrawing( cv::Mat &image, EdgeChains &edgeChains, bool sm
break
;
}
// Look at 3 neighbors to the up and pick the one with the max. gradient value
gValue1
=
pgImg
[
indexInArray
-
imageWidth
+
1
];
gValue2
=
pgImg
[
indexInArray
-
imageWidth
];
gValue3
=
pgImg
[
indexInArray
-
imageWidth
-
1
];
gValue1
=
(
unsigned
char
)
pgImg
[
indexInArray
-
imageWidth
+
1
];
gValue2
=
(
unsigned
char
)
pgImg
[
indexInArray
-
imageWidth
];
gValue3
=
(
unsigned
char
)
pgImg
[
indexInArray
-
imageWidth
-
1
];
if
(
gValue1
>=
gValue2
&&
gValue1
>=
gValue3
)
{
//up-right
x
=
x
+
1
;
...
...
@@ -436,9 +437,9 @@ int EDLineDetector::EdgeDrawing( cv::Mat &image, EdgeChains &edgeChains, bool sm
break
;
}
// Look at 3 neighbors to the right and pick the one with the max. gradient value
gValue1
=
pgImg
[
indexInArray
-
imageWidth
+
1
];
gValue2
=
pgImg
[
indexInArray
+
1
];
gValue3
=
pgImg
[
indexInArray
+
imageWidth
+
1
];
gValue1
=
(
unsigned
char
)
pgImg
[
indexInArray
-
imageWidth
+
1
];
gValue2
=
(
unsigned
char
)
pgImg
[
indexInArray
+
1
];
gValue3
=
(
unsigned
char
)
pgImg
[
indexInArray
+
imageWidth
+
1
];
if
(
gValue1
>=
gValue2
&&
gValue1
>=
gValue3
)
{
//up-right
x
=
x
+
1
;
...
...
@@ -462,9 +463,9 @@ int EDLineDetector::EdgeDrawing( cv::Mat &image, EdgeChains &edgeChains, bool sm
break
;
}
// Look at 3 neighbors to the left and pick the one with the max. gradient value
gValue1
=
pgImg
[
indexInArray
-
imageWidth
-
1
];
gValue2
=
pgImg
[
indexInArray
-
1
];
gValue3
=
pgImg
[
indexInArray
+
imageWidth
-
1
];
gValue1
=
(
unsigned
char
)
pgImg
[
indexInArray
-
imageWidth
-
1
];
gValue2
=
(
unsigned
char
)
pgImg
[
indexInArray
-
1
];
gValue3
=
(
unsigned
char
)
pgImg
[
indexInArray
+
imageWidth
-
1
];
if
(
gValue1
>=
gValue2
&&
gValue1
>=
gValue3
)
{
//up-left
x
=
x
-
1
;
...
...
@@ -504,9 +505,9 @@ int EDLineDetector::EdgeDrawing( cv::Mat &image, EdgeChains &edgeChains, bool sm
break
;
}
// Look at 3 neighbors to the down and pick the one with the max. gradient value
gValue1
=
pgImg
[
indexInArray
+
imageWidth
+
1
];
gValue2
=
pgImg
[
indexInArray
+
imageWidth
];
gValue3
=
pgImg
[
indexInArray
+
imageWidth
-
1
];
gValue1
=
(
unsigned
char
)
pgImg
[
indexInArray
+
imageWidth
+
1
];
gValue2
=
(
unsigned
char
)
pgImg
[
indexInArray
+
imageWidth
];
gValue3
=
(
unsigned
char
)
pgImg
[
indexInArray
+
imageWidth
-
1
];
if
(
gValue1
>=
gValue2
&&
gValue1
>=
gValue3
)
{
//down-right
x
=
x
+
1
;
...
...
@@ -530,9 +531,9 @@ int EDLineDetector::EdgeDrawing( cv::Mat &image, EdgeChains &edgeChains, bool sm
break
;
}
// Look at 3 neighbors to the up and pick the one with the max. gradient value
gValue1
=
pgImg
[
indexInArray
-
imageWidth
+
1
];
gValue2
=
pgImg
[
indexInArray
-
imageWidth
];
gValue3
=
pgImg
[
indexInArray
-
imageWidth
-
1
];
gValue1
=
(
unsigned
char
)
pgImg
[
indexInArray
-
imageWidth
+
1
];
gValue2
=
(
unsigned
char
)
pgImg
[
indexInArray
-
imageWidth
];
gValue3
=
(
unsigned
char
)
pgImg
[
indexInArray
-
imageWidth
-
1
];
if
(
gValue1
>=
gValue2
&&
gValue1
>=
gValue3
)
{
//up-right
x
=
x
+
1
;
...
...
@@ -586,9 +587,9 @@ int EDLineDetector::EdgeDrawing( cv::Mat &image, EdgeChains &edgeChains, bool sm
break
;
}
// Look at 3 neighbors to the right and pick the one with the max. gradient value
gValue1
=
pgImg
[
indexInArray
-
imageWidth
+
1
];
gValue2
=
pgImg
[
indexInArray
+
1
];
gValue3
=
pgImg
[
indexInArray
+
imageWidth
+
1
];
gValue1
=
(
unsigned
char
)
pgImg
[
indexInArray
-
imageWidth
+
1
];
gValue2
=
(
unsigned
char
)
pgImg
[
indexInArray
+
1
];
gValue3
=
(
unsigned
char
)
pgImg
[
indexInArray
+
imageWidth
+
1
];
if
(
gValue1
>=
gValue2
&&
gValue1
>=
gValue3
)
{
//up-right
x
=
x
+
1
;
...
...
@@ -612,9 +613,9 @@ int EDLineDetector::EdgeDrawing( cv::Mat &image, EdgeChains &edgeChains, bool sm
break
;
}
// Look at 3 neighbors to the left and pick the one with the max. gradient value
gValue1
=
pgImg
[
indexInArray
-
imageWidth
-
1
];
gValue2
=
pgImg
[
indexInArray
-
1
];
gValue3
=
pgImg
[
indexInArray
+
imageWidth
-
1
];
gValue1
=
(
unsigned
char
)
pgImg
[
indexInArray
-
imageWidth
-
1
];
gValue2
=
(
unsigned
char
)
pgImg
[
indexInArray
-
1
];
gValue3
=
(
unsigned
char
)
pgImg
[
indexInArray
+
imageWidth
-
1
];
if
(
gValue1
>=
gValue2
&&
gValue1
>=
gValue3
)
{
//up-left
x
=
x
-
1
;
...
...
@@ -654,9 +655,9 @@ int EDLineDetector::EdgeDrawing( cv::Mat &image, EdgeChains &edgeChains, bool sm
break
;
}
// Look at 3 neighbors to the down and pick the one with the max. gradient value
gValue1
=
pgImg
[
indexInArray
+
imageWidth
+
1
];
gValue2
=
pgImg
[
indexInArray
+
imageWidth
];
gValue3
=
pgImg
[
indexInArray
+
imageWidth
-
1
];
gValue1
=
(
unsigned
char
)
pgImg
[
indexInArray
+
imageWidth
+
1
];
gValue2
=
(
unsigned
char
)
pgImg
[
indexInArray
+
imageWidth
];
gValue3
=
(
unsigned
char
)
pgImg
[
indexInArray
+
imageWidth
-
1
];
if
(
gValue1
>=
gValue2
&&
gValue1
>=
gValue3
)
{
//down-right
x
=
x
+
1
;
...
...
@@ -680,9 +681,9 @@ int EDLineDetector::EdgeDrawing( cv::Mat &image, EdgeChains &edgeChains, bool sm
break
;
}
// Look at 3 neighbors to the up and pick the one with the max. gradient value
gValue1
=
pgImg
[
indexInArray
-
imageWidth
+
1
];
gValue2
=
pgImg
[
indexInArray
-
imageWidth
];
gValue3
=
pgImg
[
indexInArray
-
imageWidth
-
1
];
gValue1
=
(
unsigned
char
)
pgImg
[
indexInArray
-
imageWidth
+
1
];
gValue2
=
(
unsigned
char
)
pgImg
[
indexInArray
-
imageWidth
];
gValue3
=
(
unsigned
char
)
pgImg
[
indexInArray
-
imageWidth
-
1
];
if
(
gValue1
>=
gValue2
&&
gValue1
>=
gValue3
)
{
//up-right
x
=
x
+
1
;
...
...
@@ -737,9 +738,9 @@ int EDLineDetector::EdgeDrawing( cv::Mat &image, EdgeChains &edgeChains, bool sm
break
;
}
// Look at 3 neighbors to the right and pick the one with the max. gradient value
gValue1
=
pgImg
[
indexInArray
-
imageWidth
+
1
];
gValue2
=
pgImg
[
indexInArray
+
1
];
gValue3
=
pgImg
[
indexInArray
+
imageWidth
+
1
];
gValue1
=
(
unsigned
char
)
pgImg
[
indexInArray
-
imageWidth
+
1
];
gValue2
=
(
unsigned
char
)
pgImg
[
indexInArray
+
1
];
gValue3
=
(
unsigned
char
)
pgImg
[
indexInArray
+
imageWidth
+
1
];
if
(
gValue1
>=
gValue2
&&
gValue1
>=
gValue3
)
{
//up-right
x
=
x
+
1
;
...
...
@@ -763,9 +764,9 @@ int EDLineDetector::EdgeDrawing( cv::Mat &image, EdgeChains &edgeChains, bool sm
break
;
}
// Look at 3 neighbors to the left and pick the one with the max. gradient value
gValue1
=
pgImg
[
indexInArray
-
imageWidth
-
1
];
gValue2
=
pgImg
[
indexInArray
-
1
];
gValue3
=
pgImg
[
indexInArray
+
imageWidth
-
1
];
gValue1
=
(
unsigned
char
)
pgImg
[
indexInArray
-
imageWidth
-
1
];
gValue2
=
(
unsigned
char
)
pgImg
[
indexInArray
-
1
];
gValue3
=
(
unsigned
char
)
pgImg
[
indexInArray
+
imageWidth
-
1
];
if
(
gValue1
>=
gValue2
&&
gValue1
>=
gValue3
)
{
//up-left
x
=
x
-
1
;
...
...
@@ -805,9 +806,9 @@ int EDLineDetector::EdgeDrawing( cv::Mat &image, EdgeChains &edgeChains, bool sm
break
;
}
// Look at 3 neighbors to the down and pick the one with the max. gradient value
gValue1
=
pgImg
[
indexInArray
+
imageWidth
+
1
];
gValue2
=
pgImg
[
indexInArray
+
imageWidth
];
gValue3
=
pgImg
[
indexInArray
+
imageWidth
-
1
];
gValue1
=
(
unsigned
char
)
pgImg
[
indexInArray
+
imageWidth
+
1
];
gValue2
=
(
unsigned
char
)
pgImg
[
indexInArray
+
imageWidth
];
gValue3
=
(
unsigned
char
)
pgImg
[
indexInArray
+
imageWidth
-
1
];
if
(
gValue1
>=
gValue2
&&
gValue1
>=
gValue3
)
{
//down-right
x
=
x
+
1
;
...
...
@@ -831,9 +832,9 @@ int EDLineDetector::EdgeDrawing( cv::Mat &image, EdgeChains &edgeChains, bool sm
break
;
}
// Look at 3 neighbors to the up and pick the one with the max. gradient value
gValue1
=
pgImg
[
indexInArray
-
imageWidth
+
1
];
gValue2
=
pgImg
[
indexInArray
-
imageWidth
];
gValue3
=
pgImg
[
indexInArray
-
imageWidth
-
1
];
gValue1
=
(
unsigned
char
)
pgImg
[
indexInArray
-
imageWidth
+
1
];
gValue2
=
(
unsigned
char
)
pgImg
[
indexInArray
-
imageWidth
];
gValue3
=
(
unsigned
char
)
pgImg
[
indexInArray
-
imageWidth
-
1
];
if
(
gValue1
>=
gValue2
&&
gValue1
>=
gValue3
)
{
//up-right
x
=
x
+
1
;
...
...
@@ -912,7 +913,7 @@ int EDLineDetector::EdgeDrawing( cv::Mat &image, EdgeChains &edgeChains, bool sm
}
indexInArray
=
pSecondPartEdgeS_
[
edgeId
];
offsetPSecond
=
pSecondPartEdgeS_
[
edgeId
+
1
];
for
(
tempID
=
indexInArray
+
1
;
tempID
<
(
int
)
offsetPSecond
;
tempID
++
)
for
(
tempID
=
indexInArray
+
1
;
tempID
<
(
int
)
offsetPSecond
;
tempID
++
)
{
//add second part edge
pxCors
[
indexInCors
]
=
pSecondPartEdgeX_
[
tempID
];
pyCors
[
indexInCors
++
]
=
pSecondPartEdgeY_
[
tempID
];
...
...
@@ -929,7 +930,7 @@ int EDLineDetector::EDline( cv::Mat &image, LineChains &lines, bool smoothed )
//first, call EdgeDrawing function to extract edges
EdgeChains
edges
;
if
(
(
EdgeDrawing
(
image
,
edges
,
smoothed
)
)
!=
true
)
if
(
(
EdgeDrawing
(
image
,
edges
,
smoothed
)
)
!=
1
)
{
cout
<<
"Line Detection not finished"
<<
endl
;
return
-
1
;
...
...
@@ -1053,12 +1054,12 @@ int EDLineDetector::EDline( cv::Mat &image, LineChains &lines, bool smoothed )
double
a5
=
lineEqu
[
2
]
*
lineEqu
[
1
];
unsigned
int
Px
=
pLineXCors
[
pLineSID
[
numOfLines
]];
//first pixel
unsigned
int
Py
=
pLineYCors
[
pLineSID
[
numOfLines
]];
lineEndP
[
0
]
=
a1
*
Px
-
a3
*
Py
-
a4
;
//x
lineEndP
[
1
]
=
a2
*
Py
-
a3
*
Px
-
a5
;
//y
lineEndP
[
0
]
=
(
float
)
(
a1
*
Px
-
a3
*
Py
-
a4
)
;
//x
lineEndP
[
1
]
=
(
float
)
(
a2
*
Py
-
a3
*
Px
-
a5
)
;
//y
Px
=
pLineXCors
[
offsetInLineArray
-
1
];
//last pixel
Py
=
pLineYCors
[
offsetInLineArray
-
1
];
lineEndP
[
2
]
=
a1
*
Px
-
a3
*
Py
-
a4
;
//x
lineEndP
[
3
]
=
a2
*
Py
-
a3
*
Px
-
a5
;
//y
lineEndP
[
2
]
=
(
float
)
(
a1
*
Px
-
a3
*
Py
-
a4
)
;
//x
lineEndP
[
3
]
=
(
float
)
(
a2
*
Py
-
a3
*
Px
-
a5
)
;
//y
lineEndpoints_
.
push_back
(
lineEndP
);
lineDirection_
.
push_back
(
direction
);
numOfLines
++
;
...
...
@@ -1140,12 +1141,12 @@ int EDLineDetector::EDline( cv::Mat &image, LineChains &lines, bool smoothed )
double
a5
=
lineEqu
[
2
]
*
lineEqu
[
1
];
unsigned
int
Px
=
pLineXCors
[
pLineSID
[
numOfLines
]];
//first pixel
unsigned
int
Py
=
pLineYCors
[
pLineSID
[
numOfLines
]];
lineEndP
[
0
]
=
a1
*
Px
-
a3
*
Py
-
a4
;
//x
lineEndP
[
1
]
=
a2
*
Py
-
a3
*
Px
-
a5
;
//y
lineEndP
[
0
]
=
(
float
)
(
a1
*
Px
-
a3
*
Py
-
a4
)
;
//x
lineEndP
[
1
]
=
(
float
)
(
a2
*
Py
-
a3
*
Px
-
a5
)
;
//y
Px
=
pLineXCors
[
offsetInLineArray
-
1
];
//last pixel
Py
=
pLineYCors
[
offsetInLineArray
-
1
];
lineEndP
[
2
]
=
a1
*
Px
-
a3
*
Py
-
a4
;
//x
lineEndP
[
3
]
=
a2
*
Py
-
a3
*
Px
-
a5
;
//y
lineEndP
[
2
]
=
(
float
)
(
a1
*
Px
-
a3
*
Py
-
a4
)
;
//x
lineEndP
[
3
]
=
(
float
)
(
a2
*
Py
-
a3
*
Px
-
a5
)
;
//y
lineEndpoints_
.
push_back
(
lineEndP
);
lineDirection_
.
push_back
(
direction
);
numOfLines
++
;
...
...
@@ -1187,8 +1188,8 @@ double EDLineDetector::LeastSquaresLineFit_( unsigned int *xCors, unsigned int *
for
(
int
i
=
0
;
i
<
minLineLen_
;
i
++
)
{
//*(pMatT+minLineLen_) = 1; //the value are not changed;
*
(
pMatT
++
)
=
xCors
[
offsetS
];
fitVec
[
0
][
i
]
=
yCors
[
offsetS
++
];
*
(
pMatT
++
)
=
(
float
)
xCors
[
offsetS
];
fitVec
[
0
][
i
]
=
(
float
)
yCors
[
offsetS
++
];
}
ATA
=
fitMatT
*
fitMatT
.
t
();
ATV
=
fitMatT
*
fitVec
.
t
();
...
...
@@ -1221,8 +1222,8 @@ double EDLineDetector::LeastSquaresLineFit_( unsigned int *xCors, unsigned int *
for
(
int
i
=
0
;
i
<
minLineLen_
;
i
++
)
{
//*(pMatT+minLineLen_) = 1;//the value are not changed;
*
(
pMatT
++
)
=
yCors
[
offsetS
];
fitVec
[
0
][
i
]
=
xCors
[
offsetS
++
];
*
(
pMatT
++
)
=
(
float
)
yCors
[
offsetS
];
fitVec
[
0
][
i
]
=
(
float
)
xCors
[
offsetS
++
];
}
ATA
=
fitMatT
*
(
fitMatT
.
t
()
);
ATV
=
fitMatT
*
fitVec
.
t
();
...
...
@@ -1279,8 +1280,8 @@ double EDLineDetector::LeastSquaresLineFit_( unsigned int *xCors, unsigned int *
for
(
int
i
=
0
;
i
<
newLength
;
i
++
)
{
*
(
pMatT
+
newLength
)
=
1
;
*
(
pMatT
++
)
=
xCors
[
newOffsetS
];
vec
[
0
][
i
]
=
yCors
[
newOffsetS
++
];
*
(
pMatT
++
)
=
(
float
)
xCors
[
newOffsetS
];
vec
[
0
][
i
]
=
(
float
)
yCors
[
newOffsetS
++
];
}
/* [a,b]^T = Inv(ATA + mat^T * mat) * (ATV + mat^T * vec) */
tempMatLineFit
=
matT
*
matT
.
t
();
...
...
@@ -1307,8 +1308,8 @@ double EDLineDetector::LeastSquaresLineFit_( unsigned int *xCors, unsigned int *
for
(
int
i
=
0
;
i
<
newLength
;
i
++
)
{
*
(
pMatT
+
newLength
)
=
1
;
*
(
pMatT
++
)
=
yCors
[
newOffsetS
];
vec
[
0
][
i
]
=
xCors
[
newOffsetS
++
];
*
(
pMatT
++
)
=
(
float
)
yCors
[
newOffsetS
];
vec
[
0
][
i
]
=
(
float
)
xCors
[
newOffsetS
++
];
}
/* [a,b]^T = Inv(ATA + mat^T * mat) * (ATV + mat^T * vec) */
// matT.MultiplyWithTransposeOf(matT, tempMatLineFit);
...
...
@@ -1358,19 +1359,19 @@ bool EDLineDetector::LineValidation_( unsigned int *xCors, unsigned int *yCors,
}
if
(
meanGradientX
>
0
&&
meanGradientY
>=
0
)
{
//first quadrant, and positive direction of X axis.
direction
=
atan2
(
-
dy
,
dx
);
//line direction is in fourth quadrant
direction
=
(
float
)
atan2
(
-
dy
,
dx
);
//line direction is in fourth quadrant
}
if
(
meanGradientX
<=
0
&&
meanGradientY
>
0
)
{
//second quadrant, and positive direction of Y axis.
direction
=
atan2
(
dy
,
dx
);
//line direction is in first quadrant
direction
=
(
float
)
atan2
(
dy
,
dx
);
//line direction is in first quadrant
}
if
(
meanGradientX
<
0
&&
meanGradientY
<=
0
)
{
//third quadrant, and negative direction of X axis.
direction
=
atan2
(
dy
,
-
dx
);
//line direction is in second quadrant
direction
=
(
float
)
atan2
(
dy
,
-
dx
);
//line direction is in second quadrant
}
if
(
meanGradientX
>=
0
&&
meanGradientY
<
0
)
{
//fourth quadrant, and negative direction of Y axis.
direction
=
atan2
(
-
dy
,
-
dx
);
//line direction is in third quadrant
direction
=
(
float
)
atan2
(
-
dy
,
-
dx
);
//line direction is in third quadrant
}
/*then check whether the line is on the border of the image. We don't keep the border line.*/
if
(
fabs
(
direction
)
<
0.15
||
M_PI
-
fabs
(
direction
)
<
0.15
)
...
...
@@ -1411,7 +1412,7 @@ bool EDLineDetector::LineValidation_( unsigned int *xCors, unsigned int *yCors,
int
EDLineDetector
::
EDline
(
cv
::
Mat
&
image
,
bool
smoothed
)
{
if
(
(
EDline
(
image
,
lines_
,
smoothed
)
)
!=
true
)
if
(
(
EDline
(
image
,
lines_
,
smoothed
)
)
!=
1
)
{
return
-
1
;
}
...
...
modules/line_descriptor/src/precomp.hpp
View file @
1f33b20b
...
...
@@ -61,6 +61,7 @@
#include <bitset>
#include <time.h>
#include <stdexcept>
#include <sstream>
#include "opencv2/line_descriptor.hpp"
...
...
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