Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
7
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
Thiago Santini
EyeRecToo
Commits
5a749b27
Commit
5a749b27
authored
Jun 10, 2019
by
Thiago Santini
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Small canny readability improvements
parent
b9d13078
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
41 additions
and
45 deletions
+41
-45
EyeRecToo/src/pupil-detection/PuRe.cpp
EyeRecToo/src/pupil-detection/PuRe.cpp
+41
-45
No files found.
EyeRecToo/src/pupil-detection/PuRe.cpp
View file @
5a749b27
...
@@ -38,10 +38,10 @@
...
@@ -38,10 +38,10 @@
#include "PuRe.h"
#include "PuRe.h"
#include <QDebug>
#include <QElapsedTimer>
#include <climits>
#include <climits>
#include <iostream>
#include <iostream>
#include <xmemory>
#include <opencv2/highgui.hpp>
#include <opencv2/highgui.hpp>
//#define SAVE_ILLUSTRATION
//#define SAVE_ILLUSTRATION
...
@@ -146,8 +146,6 @@ Mat PuRe::canny(const Mat& in, const bool blurImage, const bool useL2, const int
...
@@ -146,8 +146,6 @@ Mat PuRe::canny(const Mat& in, const bool blurImage, const bool useL2, const int
*/
*/
double
minMag
=
0
;
double
minMag
=
0
;
double
maxMag
=
0
;
double
maxMag
=
0
;
float
*
p_res
;
float
*
p_x
,
*
p_y
;
// result, x, y
cv
::
magnitude
(
dx
,
dy
,
magnitude
);
cv
::
magnitude
(
dx
,
dy
,
magnitude
);
cv
::
minMaxLoc
(
magnitude
,
&
minMag
,
&
maxMag
);
cv
::
minMaxLoc
(
magnitude
,
&
minMag
,
&
maxMag
);
...
@@ -162,10 +160,10 @@ Mat PuRe::canny(const Mat& in, const bool blurImage, const bool useL2, const int
...
@@ -162,10 +160,10 @@ Mat PuRe::canny(const Mat& in, const bool blurImage, const bool useL2, const int
magnitude
=
magnitude
/
maxMag
;
magnitude
=
magnitude
/
maxMag
;
// Histogram
// Histogram
int
*
histogram
=
new
int
[
bins
](
);
auto
histogram
=
std
::
make_unique
<
int
[
]
>
(
bins
);
Mat
res_idx
=
(
bins
-
1
)
*
magnitude
;
Mat
res_idx
=
(
bins
-
1
)
*
magnitude
;
res_idx
.
convertTo
(
res_idx
,
CV_16U
);
res_idx
.
convertTo
(
res_idx
,
CV_16U
);
short
*
p_res_idx
=
0
;
short
*
p_res_idx
=
nullptr
;
for
(
int
i
=
0
;
i
<
res_idx
.
rows
;
i
++
)
{
for
(
int
i
=
0
;
i
<
res_idx
.
rows
;
i
++
)
{
p_res_idx
=
res_idx
.
ptr
<
short
>
(
i
);
p_res_idx
=
res_idx
.
ptr
<
short
>
(
i
);
for
(
int
j
=
0
;
j
<
res_idx
.
cols
;
j
++
)
for
(
int
j
=
0
;
j
<
res_idx
.
cols
;
j
++
)
...
@@ -174,65 +172,65 @@ Mat PuRe::canny(const Mat& in, const bool blurImage, const bool useL2, const int
...
@@ -174,65 +172,65 @@ Mat PuRe::canny(const Mat& in, const bool blurImage, const bool useL2, const int
// Ratio
// Ratio
int
sum
=
0
;
int
sum
=
0
;
int
nonEdgePixels
=
static_cast
<
int
>
(
nonEdgePixelsRatio
*
in
.
rows
*
in
.
cols
);
const
int
nonEdgePixels
=
static_cast
<
int
>
(
nonEdgePixelsRatio
*
in
.
rows
*
in
.
cols
);
for
(
int
i
=
0
;
i
<
bins
;
i
++
)
{
for
(
int
i
=
0
;
i
<
bins
;
i
++
)
{
sum
+=
histogram
[
i
];
sum
+=
histogram
[
i
];
if
(
sum
>
nonEdgePixels
)
{
if
(
sum
>
nonEdgePixels
)
{
high_th
=
float
(
i
+
1
)
/
bins
;
high_th
=
static_cast
<
float
>
(
i
+
1
)
/
bins
;
break
;
break
;
}
}
}
}
low_th
=
lowHighThresholdRatio
*
high_th
;
low_th
=
lowHighThresholdRatio
*
high_th
;
delete
[]
histogram
;
/*
/*
* Non maximum supression
* Non maximum supression
*/
*/
enum
{
NON_EDGE
=
0
,
POSSIBLE_EDGE
=
128
,
EDGE
=
255
};
const
float
tg22_5
=
0.4142135623730950488016887242097
f
;
const
float
tg22_5
=
0.4142135623730950488016887242097
f
;
const
float
tg67_5
=
2.4142135623730950488016887242097
f
;
const
float
tg67_5
=
2.4142135623730950488016887242097
f
;
uchar
*
_edgeType
;
edgeType
.
setTo
(
NON_EDGE
);
float
*
p_res_b
,
*
p_res_t
;
edgeType
.
setTo
(
0
);
for
(
int
i
=
1
;
i
<
magnitude
.
rows
-
1
;
i
++
)
{
for
(
int
i
=
1
;
i
<
magnitude
.
rows
-
1
;
i
++
)
{
_edgeType
=
edgeType
.
ptr
<
uchar
>
(
i
);
auto
edgeTypePtr
=
edgeType
.
ptr
<
uchar
>
(
i
);
p_res
=
magnitude
.
ptr
<
float
>
(
i
);
p_res_t
=
magnitude
.
ptr
<
float
>
(
i
-
1
);
p_res_b
=
magnitude
.
ptr
<
float
>
(
i
+
1
);
p_x
=
dx
.
ptr
<
float
>
(
i
);
const
auto
&
p_res
=
magnitude
.
ptr
<
float
>
(
i
);
p_y
=
dy
.
ptr
<
float
>
(
i
);
const
auto
&
p_res_t
=
magnitude
.
ptr
<
float
>
(
i
-
1
);
const
auto
&
p_res_b
=
magnitude
.
ptr
<
float
>
(
i
+
1
);
const
auto
&
p_x
=
dx
.
ptr
<
float
>
(
i
);
const
auto
&
p_y
=
dy
.
ptr
<
float
>
(
i
);
for
(
int
j
=
1
;
j
<
magnitude
.
cols
-
1
;
j
++
)
{
for
(
int
j
=
1
;
j
<
magnitude
.
cols
-
1
;
j
++
)
{
float
m
=
p_res
[
j
];
const
auto
&
m
=
p_res
[
j
];
if
(
m
<
low_th
)
if
(
m
<
low_th
)
continue
;
continue
;
float
iy
=
p_y
[
j
];
const
auto
&
iy
=
p_y
[
j
];
float
ix
=
p_x
[
j
];
const
auto
&
ix
=
p_x
[
j
];
float
y
=
abs
(
iy
);
float
x
=
abs
(
ix
);
uchar
val
=
p_res
[
j
]
>
high_th
?
255
:
128
;
const
auto
y
=
abs
(
iy
);
const
auto
x
=
abs
(
ix
);
const
auto
val
=
p_res
[
j
]
>
high_th
?
EDGE
:
POSSIBLE_EDGE
;
const
auto
tg22_5x
=
tg22_5
*
x
;
float
tg22_5x
=
tg22_5
*
x
;
if
(
y
<
tg22_5x
)
{
if
(
y
<
tg22_5x
)
{
if
(
m
>
p_res
[
j
-
1
]
&&
m
>=
p_res
[
j
+
1
])
if
(
m
>
p_res
[
j
-
1
]
&&
m
>=
p_res
[
j
+
1
])
_
edgeType
[
j
]
=
val
;
edgeType
Ptr
[
j
]
=
val
;
}
else
{
}
else
{
float
tg67_5x
=
tg67_5
*
x
;
float
tg67_5x
=
tg67_5
*
x
;
if
(
y
>
tg67_5x
)
{
if
(
y
>
tg67_5x
)
{
if
(
m
>
p_res_b
[
j
]
&&
m
>=
p_res_t
[
j
])
if
(
m
>
p_res_b
[
j
]
&&
m
>=
p_res_t
[
j
])
_
edgeType
[
j
]
=
val
;
edgeType
Ptr
[
j
]
=
val
;
}
else
{
}
else
{
if
((
iy
<=
0
)
==
(
ix
<=
0
))
{
if
((
iy
<=
0
)
==
(
ix
<=
0
))
{
if
(
m
>
p_res_t
[
j
-
1
]
&&
m
>=
p_res_b
[
j
+
1
])
if
(
m
>
p_res_t
[
j
-
1
]
&&
m
>=
p_res_b
[
j
+
1
])
_
edgeType
[
j
]
=
val
;
edgeType
Ptr
[
j
]
=
val
;
}
else
{
}
else
{
if
(
m
>
p_res_b
[
j
-
1
]
&&
m
>=
p_res_t
[
j
+
1
])
if
(
m
>
p_res_b
[
j
-
1
]
&&
m
>=
p_res_t
[
j
+
1
])
_
edgeType
[
j
]
=
val
;
edgeType
Ptr
[
j
]
=
val
;
}
}
}
}
}
}
...
@@ -242,21 +240,19 @@ Mat PuRe::canny(const Mat& in, const bool blurImage, const bool useL2, const int
...
@@ -242,21 +240,19 @@ Mat PuRe::canny(const Mat& in, const bool blurImage, const bool useL2, const int
/*
/*
* Hystheresis
* Hystheresis
*/
*/
int
pic_x
=
edgeType
.
cols
;
const
int
area
=
edgeType
.
cols
*
edgeType
.
rows
;
int
pic_y
=
edgeType
.
rows
;
int
area
=
pic_x
*
pic_y
;
unsigned
int
lines_idx
=
0
;
unsigned
int
lines_idx
=
0
;
int
idx
=
0
;
int
idx
=
0
;
vector
<
int
>
lines
;
vector
<
int
>
lines
;
edge
.
setTo
(
0
);
edge
.
setTo
(
NON_EDGE
);
for
(
int
i
=
1
;
i
<
pic_y
-
1
;
i
++
)
{
for
(
int
i
=
1
;
i
<
edgeType
.
rows
-
1
;
i
++
)
{
for
(
int
j
=
1
;
j
<
pic_x
-
1
;
j
++
)
{
for
(
int
j
=
1
;
j
<
edgeType
.
cols
-
1
;
j
++
)
{
if
(
edgeType
.
data
[
idx
+
j
]
!=
255
||
edge
.
data
[
idx
+
j
]
!=
0
)
if
(
edgeType
.
data
[
idx
+
j
]
!=
EDGE
||
edge
.
data
[
idx
+
j
]
!=
NON_EDGE
)
continue
;
continue
;
edge
.
data
[
idx
+
j
]
=
255
;
edge
.
data
[
idx
+
j
]
=
EDGE
;
lines_idx
=
1
;
lines_idx
=
1
;
lines
.
clear
();
lines
.
clear
();
lines
.
push_back
(
idx
+
j
);
lines
.
push_back
(
idx
+
j
);
...
@@ -266,20 +262,20 @@ Mat PuRe::canny(const Mat& in, const bool blurImage, const bool useL2, const int
...
@@ -266,20 +262,20 @@ Mat PuRe::canny(const Mat& in, const bool blurImage, const bool useL2, const int
int
akt_pos
=
lines
[
akt_idx
];
int
akt_pos
=
lines
[
akt_idx
];
akt_idx
++
;
akt_idx
++
;
if
(
akt_pos
-
pic_x
-
1
<
0
||
akt_pos
+
pic_x
+
1
>=
area
)
if
(
akt_pos
-
edgeType
.
cols
-
1
<
0
||
akt_pos
+
edgeType
.
cols
+
1
>=
area
)
continue
;
continue
;
for
(
int
k1
=
-
1
;
k1
<
2
;
k1
++
)
for
(
int
k1
=
-
1
;
k1
<
2
;
k1
++
)
for
(
int
k2
=
-
1
;
k2
<
2
;
k2
++
)
{
for
(
int
k2
=
-
1
;
k2
<
2
;
k2
++
)
{
if
(
edge
.
data
[(
akt_pos
+
(
k1
*
pic_x
))
+
k2
]
!=
0
||
edgeType
.
data
[(
akt_pos
+
(
k1
*
pic_x
))
+
k2
]
==
0
)
if
(
edge
.
data
[(
akt_pos
+
(
k1
*
edgeType
.
cols
))
+
k2
]
!=
NON_EDGE
||
edgeType
.
data
[(
akt_pos
+
(
k1
*
edgeType
.
cols
))
+
k2
]
==
NON_EDGE
)
continue
;
continue
;
edge
.
data
[(
akt_pos
+
(
k1
*
pic_x
))
+
k2
]
=
255
;
edge
.
data
[(
akt_pos
+
(
k1
*
edgeType
.
cols
))
+
k2
]
=
EDGE
;
lines
.
push_back
((
akt_pos
+
(
k1
*
pic_x
))
+
k2
);
lines
.
push_back
((
akt_pos
+
(
k1
*
edgeType
.
cols
))
+
k2
);
lines_idx
++
;
lines_idx
++
;
}
}
}
}
}
}
idx
+=
pic_x
;
idx
+=
edgeType
.
cols
;
}
}
return
edge
;
return
edge
;
...
...
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