Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
Mario Jigsaw Genius
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Sebastian Böttger
Mario Jigsaw Genius
Commits
c86e9580
Commit
c86e9580
authored
11 months ago
by
Sebastian Böttger
Browse files
Options
Downloads
Patches
Plain Diff
Further improve of the image analyser
parent
e25437b1
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/image_analysis/ImageAnalyser.py
+75
-5
75 additions, 5 deletions
src/image_analysis/ImageAnalyser.py
with
75 additions
and
5 deletions
src/image_analysis/ImageAnalyser.py
+
75
−
5
View file @
c86e9580
...
...
@@ -161,11 +161,68 @@ class ImageAnalyser():
self
.
index_corners
=
(
self
.
index_corners
+
shift
)
%
self
.
cart_path
.
shape
[
0
]
def
split_sites
(
self
):
self
.
sides_cart_path
=
np
.
array
([[],[],[],[]],
dtype
=
np
.
ndarray
)
self
.
sides_cart_path
=
[
None
,
None
,
None
,
None
]
for
i
in
range
(
3
):
self
.
sides_cart_path
[
i
]
=
self
.
cart_path
[
self
.
index_corners
[
i
]:
self
.
index_corners
[
i
+
1
]]
self
.
sides_cart_path
[
3
]
=
self
.
cart_path
[
self
.
index_corners
[
3
]:]
def
normalize_sides
(
self
):
for
i
in
range
(
4
):
self
.
sides_cart_path
[
i
]
=
self
.
rotate_side
(
self
.
sides_cart_path
[
i
],
(
-
(
np
.
pi
/
2
)
*
i
))
angle
=
self
.
calculate_straight_angle
(
self
.
sides_cart_path
[
i
])[
0
]
self
.
sides_cart_path
[
i
]
=
self
.
rotate_side
(
self
.
sides_cart_path
[
i
],
angle
)
#angle = self.calculate_straight_angle(self.sides_cart_path[i])
def
calculate_straight_angle
(
self
,
side
):
if
side
[
0
,
0
]
==
side
[
-
1
,
0
]:
return
0
points
=
np
.
zeros
((
1
,
3
,
2
))
points
[
0
,
0
]
=
np
.
array
((
side
[
0
,
0
],
side
[
-
1
,
1
]))
points
[
0
,
1
]
=
side
[
0
]
points
[
0
,
2
]
=
side
[
-
1
]
if
side
[
0
,
0
]
>
side
[
-
1
,
0
]:
return
self
.
calculate_gamma
(
points
)
else
:
return
-
self
.
calculate_gamma
(
points
)
def
rotate_side
(
self
,
side
,
angle
):
center
=
side
[
0
]
rotation_matrix
=
np
.
array
([
[
np
.
cos
(
angle
),
-
np
.
sin
(
angle
)],
[
np
.
sin
(
angle
),
np
.
cos
(
angle
)]
])
shifted_side
=
side
-
center
rotated_side
=
np
.
dot
(
shifted_side
,
rotation_matrix
)
rotated_side
+=
center
rotated_side
[:,
0
]
-=
rotated_side
[:,
0
].
min
()
rotated_side
[:,
1
]
-=
rotated_side
[:,
1
].
min
()
return
rotated_side
.
copy
().
astype
(
int
)
def
polish_side_paths
(
self
):
for
side_index
in
range
(
len
(
self
.
sides_cart_path
)):
side
=
self
.
sides_cart_path
[
side_index
]
index
=
0
while
index
<
side
.
shape
[
0
]
-
1
:
if
(
np
.
abs
(
side
[
index
]
-
side
[
index
+
1
]).
max
())
>
1
:
side
=
np
.
insert
(
side
,
index
+
1
,
side
[
index
]
-
((
side
[
index
]
-
side
[
index
+
1
])
//
2
),
axis
=
0
)
else
:
index
+=
1
self
.
sides_cart_path
[
side_index
]
=
side
def
convert_to_binary_array
(
self
,
side
):
bin_array
=
np
.
zeros
(
side
.
max
(
axis
=
0
)
+
1
,
dtype
=
np
.
uint8
)
bin_array
[
side
[:,
0
],
side
[:,
1
]]
=
1
return
bin_array
#%% test functions
def
print_outline
(
cart_path
,
image_shape
):
image
=
np
.
zeros
(
image_shape
)
...
...
@@ -179,7 +236,7 @@ def print_outline(cart_path, image_shape):
cv
.
destroyWindow
(
"
outline sorted
"
)
cv
.
imshow
(
"
outline sorted
"
,
image
)
cv
.
waitKey
(
0
)
cv
.
destroyWindow
(
"
outline sorted
"
)
#
cv.destroyWindow("outline sorted")
def
show_pol_path
(
pol_path
):
pol_path_edit
=
pol_path
.
copy
()
...
...
@@ -193,13 +250,13 @@ if __name__ == "__main__":
ia
=
ImageAnalyser
(
image_path
)
cv
.
imshow
(
"
binary image
"
,
ia
.
image
)
cv
.
waitKey
(
0
)
cv
.
destroyAllWindows
()
#
cv.destroyAllWindows()
print
(
"
find outline image
"
)
ia
.
find_outline_image
()
cv
.
imshow
(
"
outline image
"
,
ia
.
outline_image
)
cv
.
waitKey
(
0
)
cv
.
destroyAllWindows
()
#
cv.destroyAllWindows()
print
(
"
convert to cartesian coordinates
"
)
ia
.
convert_to_cart_path
(
ia
.
outline_image
)
...
...
@@ -208,6 +265,7 @@ if __name__ == "__main__":
print
(
"
convert to polar coordianates
"
)
ia
.
convert_to_pol_path
(
ia
.
cart_path
)
show_pol_path
(
ia
.
pol_path
)
cv
.
waitKey
(
0
)
print
(
"
find high spots
"
)
ia
.
find_high_spots_index
(
ia
.
pol_path
)
...
...
@@ -221,7 +279,19 @@ if __name__ == "__main__":
ia
.
extracted_corners
()
print
(
ia
.
corners
)
print
(
"
split sides
"
)
ia
.
split_sites
()
print
(
"
normalize sides
"
)
ia
.
normalize_sides
()
print
(
"
polish side paths
"
)
ia
.
polish_side_paths
()
for
i
in
range
(
5
):
temp
=
ia
.
convert_to_binary_array
(
ia
.
sides_cart_path
[
i
])
cv
.
imshow
(
f
"
Side
{
i
}
"
,
temp
*
255
)
cv
.
waitKey
(
0
)
#%% playground
\ No newline at end of file
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment