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
efe74da5
Commit
efe74da5
authored
11 months ago
by
Sebastian Böttger
Browse files
Options
Downloads
Patches
Plain Diff
Insert comments
parent
f63782ca
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
+287
-92
287 additions, 92 deletions
src/image_analysis/ImageAnalyser.py
with
287 additions
and
92 deletions
src/image_analysis/ImageAnalyser.py
+
287
−
92
View file @
efe74da5
# -*- coding: utf-8 -*-
"""
Created on Fri Apr 26 15:10:15 2024
@author: Sebastian Böttger
"""
#%% imports
import
sys
sys
.
path
.
append
(
"
../general/
"
)
import
cv2
as
cv
import
numpy
as
np
import
imutils
as
im
from
Side
import
Side
,
SideType
from
PuzzlePiece
import
PuzzlePiece
,
Category
from
scipy.spatial
import
distance
import
matplotlib.pyplot
as
plt
#%% clases
class
ImageAnalyser
():
def
__init__
(
self
,
image_path
,
corner_value
=
0.04
):
self
.
image_path
=
image_path
"""
This class analyze a picture of one puzzle piece and convert it into a the object
'
PuzzlePiece
'
.
The PuzzlePiece object contains a Side object for each side of the puzzle piece.
To create a side object the corner of the piece must be found to split the outline into four parts.
With the outline of each side the type of side can be determined.
To get the outline of the puzzle piece every change from black to white or white to black
in horizontal and vertical direction, will be mark as outline.
This image of the outline is transformed in an array of cartesian coordinates of the outline.
To find the corner of the outline the cartesian coordinates will be transform into polar coordinates.
In the graph of these coordinates (phi as x-axis and r as y-axis) the corners are shown as relative sharp spices.
To find these spices the path of polar coordinates will be searched for points how have the maximum value in a given range.
The range is defined by the property
"
high_spot_search_size
"
.
Sides with a head are also shown as a high spot in the graph, but less sharp.
To define the sharpness of a high spot the angel between a point before the high spot, the high spot itself and a point after that will be measured.
The range for the points before and after the high spot is defined by the property
"
angle_base_size
"
.
The angel will be calculated with the low of cosines.
The threshold when a point is a corner, or a head is defined by
"
corner_value
"
.
With the correct coordinates of the corners the outline is split into four parts.
Each side will be rotated so that the start and end point is on the same height.
If the maximum height of a side is lower than the threshold
"
max_hight_flat_side
"
, it will be classified as flat.
If the start point coordinates are lower than the half of the height of a side, this side will be classified as hole.
Otherwise as a head.
Paramteres:
-----------
image:
Binary image of the puzzle piece.
If the image is a BGR image (unint8 Array with y,x,3 dimensions),
it will be converted to an grayscale image (unint8 Array with y,x dimensions).
piece_id:
The id of the puzzle piece
high_spot_search_size:
The range of points of the polar coordinates, in which the method find_high_spots_index check for a max value.
The given value defines the whole range around the checked point.
The half of the range is on the left side and the other on the right side.
angle_base_size:
The range of points to create the triangle to define the angel at the high spot.
The given value defines the whole range around the high spot.
The half of the range is on the left side and the other on the right side.
corner_value:
The max angle in rad which defines if a high spot in the polar coordinates plot
of the outline of the puzzle piece is a corner or not.
To classify a high spot as a corner, the angle of the high spot must be
lower than the given angle.
max_hight_flat_side:
The max height of a side to classify it as a flat side.
To classify a side as flat, the height of the side must be
lower than the given value.
"""
def
__init__
(
self
,
image
,
piece_id
=
0
,
high_spot_search_size
=
20
,
angle_base_size
=
20
,
corner_value
=
0.04
,
max_hight_flat_side
=
20
):
"""
The init method of the class initialized all thresholds and ranges, as well as empty properties of the object.
"""
if
(
len
(
image
.
shape
)
==
3
):
self
.
image
=
cv
.
cvtColor
(
image
,
cv
.
COLOR_BGR2GRAY
)
else
:
self
.
image
=
image
self
.
piece_id
=
piece_id
self
.
high_spot_search_size
=
high_spot_search_size
self
.
angle_base_size
=
angle_base_size
self
.
corner_value
=
corner_value
self
.
load_image
(
image_path
)
self
.
max_hight_flat_side
=
max_hight_flat_side
self
.
outline_image
=
None
self
.
cart_path
=
None
self
.
pol_path
=
None
...
...
@@ -18,28 +94,55 @@ class ImageAnalyser():
self
.
index_corners
=
None
self
.
angles
=
None
self
.
corners
=
None
self
.
sides_cart_path
=
None
self
.
puzzle_piece
=
None
def
load_image
(
self
,
path
):
self
.
image
=
cv
.
imread
(
path
)
def
analyse
(
self
):
"""
This method analysed the image and returnd a
"
PuzzlePiece
"
object.
"""
# create outline image
self
.
create_outline_image
(
self
.
image
)
def
show_image
(
self
,
path
):
cv
.
show
(
"
puzzle piece
"
,
self
.
image
)
cv
.
waitKey
(
0
)
cv
.
destroyAllWindows
()
# convert to cartesian coordinates
self
.
convert_to_cart_path
(
self
.
outline_image
)
# convert to polar coordinates
self
.
convert_to_pol_path
(
self
.
cart_path
)
# find high spots
self
.
find_high_spots_index
(
self
.
pol_path
,
self
.
high_spot_search_size
)
# calculate angles
self
.
calculate_angle
(
self
.
index_high_spots
,
self
.
angle_base_size
)
# extract corners
self
.
extract_corners
(
self
.
angles
,
self
.
index_high_spots
,
self
.
corner_value
)
# split sides
self
.
split_sites
(
self
.
cart_path
,
self
.
index_corners
)
# normalize sides
self
.
normalize_sides
()
# polish side paths
self
.
polish_side_paths
()
def
get_outline_image
(
self
):
if
self
.
outline_image
is
not
None
:
self
.
find_outline_image
()
return
self
.
outline_image
# create puzzle piece
return
self
.
create_puzzle_piece
(
self
.
sides_cart_path
)
def
find_outline_image
(
self
):
gray
=
cv
.
cvtColor
(
self
.
image
,
cv
.
COLOR_BGR2GRAY
)
outline_detection
=
np
.
zeros_like
(
gray
)
def
create_outline_image
(
self
,
image
):
"""
This method crate a image with only the outline of the piece.
To get the outline of the puzzle piece every change from black to white or white to black
in horizontal and vertical direction, will be mark as outline.
"""
outline_detection
=
np
.
zeros_like
(
image
)
found_white
=
False
for
line
in
range
(
gray
.
shape
[
0
]):
for
col
in
range
(
gray
.
shape
[
1
]):
if
gray
[
line
,
col
]
>
30
:
for
line
in
range
(
image
.
shape
[
0
]):
for
col
in
range
(
image
.
shape
[
1
]):
if
image
[
line
,
col
]
>
30
:
if
not
found_white
:
outline_detection
[
line
,
col
]
=
255
found_white
=
True
...
...
@@ -48,9 +151,9 @@ class ImageAnalyser():
outline_detection
[
line
,
col
-
1
]
=
255
found_white
=
False
for
col
in
range
(
gray
.
shape
[
1
]):
for
line
in
range
(
gray
.
shape
[
0
]):
if
gray
[
line
,
col
]
>
30
:
for
col
in
range
(
image
.
shape
[
1
]):
for
line
in
range
(
image
.
shape
[
0
]):
if
image
[
line
,
col
]
>
30
:
if
not
found_white
:
outline_detection
[
line
,
col
]
=
255
found_white
=
True
...
...
@@ -61,12 +164,21 @@ class ImageAnalyser():
self
.
outline_image
=
outline_detection
.
copy
()
def
convert_to_cart_path
(
self
,
outline_image
):
"""
This methid converts the image of the outline into an array of outline coordinates.
The highest left white pixel will be selected for the start point.
From there the nearst white pixel will be selected as the next point in the path.
If two pixels are equidistant from the last one, the first one of the pixel array will be choosen.
"""
cart_path
=
np
.
where
(
outline_image
>
10
)
cart_path
=
np
.
stack
(
cart_path
,
1
)
cart_path
=
self
.
sort_by_diff
(
cart_path
)
self
.
cart_path
=
cart_path
.
copy
()
def
sort_by_diff
(
self
,
cart_path
):
"""
This method sorts the path of coordinates by distance from on to the next one.
"""
sorted_cart_path
=
np
.
zeros_like
(
cart_path
)
unsorted_cart_path
=
cart_path
.
copy
()
...
...
@@ -82,10 +194,10 @@ class ImageAnalyser():
return
sorted_cart_path
def
get_center_point
(
self
,
cart_path
):
return
np
.
array
(
cart_path
.
mean
(
axis
=
0
),
dtype
=
int
)
def
convert_to_pol_path
(
self
,
cart_path
):
"""
This method converts the cartesian coordinates into polar coordinates.
"""
center_point
=
self
.
get_center_point
(
cart_path
)
center_point
[
0
]
*=
(
-
1
)
shifted_cart_path
=
cart_path
.
copy
()
...
...
@@ -100,12 +212,18 @@ class ImageAnalyser():
self
.
pol_path
=
pol_path
.
copy
()
def
get_high_spots_index
(
self
):
if
self
.
index_high_spots
is
not
None
:
self
.
find_high_spots_index
(
self
.
pol_path
)
return
self
.
index_high_spots
def
get_center_point
(
self
,
cart_path
):
"""
This method returns the center point of the puzzle piece, by averaging all values of the coordinate path.
"""
return
np
.
array
(
cart_path
.
mean
(
axis
=
0
),
dtype
=
int
)
def
find_high_spots_index
(
self
,
pol_path
,
size
=
20
):
"""
This method finds high spots in the polar coordinates.
To find these high spots the path of polar coordinates will be searched for points how have the maximum value in a given range.
The range is defined by the property
"
high_spot_search_size
"
.
"""
size
//=
2
index_high_spots
=
np
.
array
([],
dtype
=
int
)
...
...
@@ -116,6 +234,14 @@ class ImageAnalyser():
self
.
index_high_spots
=
index_high_spots
.
copy
()
def
calculate_angle
(
self
,
index_high_spots
,
size
=
20
):
"""
This method calculates tha angle of the high spots.
To calcilat the angle of a high spot the angle gamma of a triangle between a point before the high spot,
the high spot itself and a point after that will be measured.
The high spot is always point C of the triangle.
The range for the points before and after the high spot is defined by the property
"
angle_base_size
"
.
The angel will be calculated with the low of cosines.
"""
size
//=
2
angles
=
np
.
zeros_like
(
index_high_spots
,
dtype
=
float
)
points
=
np
.
zeros
((
index_high_spots
.
shape
[
0
],
3
,
2
))
...
...
@@ -128,6 +254,11 @@ class ImageAnalyser():
self
.
angles
=
angles
.
copy
()
def
calculate_gamma
(
self
,
points
):
"""
This method calculates the angle gamma of an triangle.
The points array are in the ordner A,C,B.
To calculate the angle the low of cosines is be used.
"""
sides
=
np
.
zeros
((
points
.
shape
[
0
],
3
))
sides
[:,
0
]
=
np
.
sqrt
(((
points
[:,
2
]
-
points
[:,
1
])
**
2
).
sum
(
axis
=
1
))
sides
[:,
1
]
=
np
.
sqrt
(((
points
[:,
0
]
-
points
[:,
1
])
**
2
).
sum
(
axis
=
1
))
...
...
@@ -138,11 +269,15 @@ class ImageAnalyser():
angles
=
np
.
arccos
(
numerators
/
denominators
)
return
angles
def
extracted_corners
(
self
):
if
self
.
angles
is
None
:
def
extract_corners
(
self
,
angles
,
index_high_spots
,
corner_value
=
0.04
):
"""
This method extrect the corners from the high spots.
It filters the angles of the high spots to the threshold corner_value.
"""
if
angles
is
None
:
raise
Exception
(
'
No angles was found!
'
)
self
.
index_corners
=
self
.
index_high_spots
[
self
.
angles
<
self
.
corner_value
]
self
.
index_corners
=
index_high_spots
[
angles
<
corner_value
]
if
self
.
index_corners
.
size
>
4
:
raise
Exception
(
'
More than four corners are possible!
'
)
...
...
@@ -153,77 +288,130 @@ class ImageAnalyser():
self
.
corners
=
np
.
zeros
((
4
,
2
),
dtype
=
int
)
self
.
corners
=
self
.
cart_path
[
self
.
index_corners
]
shift
=
self
.
cart_path
.
shape
[
0
]
-
self
.
index_
high_spot
s
[
self
.
corners
.
sum
(
axis
=
1
).
argmin
()]
shift
=
self
.
cart_path
.
shape
[
0
]
-
self
.
index_
corner
s
[
self
.
corners
.
sum
(
axis
=
1
).
argmin
()]
self
.
index_corners
=
np
.
roll
(
self
.
index_corners
,
self
.
index_corners
.
size
-
self
.
corners
.
sum
(
axis
=
1
).
argmin
(),
axis
=
0
)
self
.
corners
=
np
.
roll
(
self
.
corners
,
self
.
corners
.
size
-
self
.
corners
.
sum
(
axis
=
1
).
argmin
(),
axis
=
0
)
self
.
cart_path
=
np
.
roll
(
self
.
cart_path
,
shift
,
axis
=
0
)
self
.
pol_path
=
np
.
roll
(
self
.
pol_path
,
shift
,
axis
=
0
)
self
.
index_corners
=
(
self
.
index_corners
+
shift
)
%
self
.
cart_path
.
shape
[
0
]
def
split_sites
(
self
):
def
split_sites
(
self
,
cart_path
,
index_corners
):
"""
This method splits the outline into the four sides of the piece.
"""
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
]:]
self
.
sides_cart_path
[
i
]
=
cart_path
[
index_corners
[
i
]:
index_corners
[
i
+
1
]]
self
.
sides_cart_path
[
3
]
=
cart_path
[
index_corners
[
3
]:]
def
normalize_sides
(
self
):
"""
This method rotates the sides and trims it.
"""
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
]:
def
calculate_straight_angle
(
self
,
side_path
):
"""
This method calculates the angle to rotates the side horizontaly.
"""
if
side_path
[
0
,
0
]
==
side_path
[
-
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
]
points
[
0
,
0
]
=
np
.
array
((
side
_path
[
0
,
0
],
side
_path
[
-
1
,
1
]))
points
[
0
,
1
]
=
side
_path
[
0
]
points
[
0
,
2
]
=
side
_path
[
-
1
]
if
side
[
0
,
0
]
>
side
[
-
1
,
0
]:
if
side
_path
[
0
,
0
]
>
side
_path
[
-
1
,
0
]:
return
self
.
calculate_gamma
(
points
)
else
:
return
-
self
.
calculate_gamma
(
points
)
def
rotate_side
(
self
,
side
,
angle
):
center
=
side
[
0
]
def
rotate_side
(
self
,
side_path
,
angle
):
"""
This method rotates the side coordinates by a given angle.
It use a rotaion matrix.
"""
center
=
side_path
[
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
shifted_side
_path
=
side
_path
-
center
rotated_side
_path
=
np
.
dot
(
shifted_side
_path
,
rotation_matrix
)
rotated_side
_path
+=
center
rotated_side
[:,
0
]
-=
rotated_side
[:,
0
].
min
()
rotated_side
[:,
1
]
-=
rotated_side
[:,
1
].
min
()
rotated_side
_path
[:,
0
]
-=
rotated_side
_path
[:,
0
].
min
()
rotated_side
_path
[:,
1
]
-=
rotated_side
_path
[:,
1
].
min
()
return
rotated_side
.
copy
().
astype
(
int
)
return
rotated_side
_path
.
copy
().
astype
(
int
)
def
polish_side_paths
(
self
):
"""
This method fills gaps in the outline of a side, which are produced by the rotaion.
"""
for
side_index
in
range
(
len
(
self
.
sides_cart_path
)):
side
=
self
.
sides_cart_path
[
side_index
]
side
_path
=
self
.
sides_cart_path
[
side_index
]
index
=
0
while
index
<
side
.
shape
[
0
]
-
1
:
while
index
<
side
_path
.
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
)
if
(
np
.
abs
(
side
_path
[
index
]
-
side
_path
[
index
+
1
]).
max
())
>
1
:
side
_path
=
np
.
insert
(
side
_path
,
index
+
1
,
side
_path
[
index
]
-
((
side
_path
[
index
]
-
side
_path
[
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
self
.
sides_cart_path
[
side_index
]
=
side_path
def
convert_to_binary_array
(
self
,
side_path
):
"""
This method converts a array with coordinates into a binary image.
"""
bin_array
=
np
.
zeros
(
side_path
.
max
(
axis
=
0
)
+
1
,
dtype
=
np
.
uint8
)
bin_array
[
side_path
[:,
0
],
side_path
[:,
1
]]
=
1
return
bin_array
def
create_puzzle_piece
(
self
,
sides_paths
):
"""
This method creats the PuzzlePiece object from the four side outlines.
"""
sides
=
np
.
array
([
None
,
None
,
None
,
None
])
for
i
in
range
(
sides
.
shape
[
0
]):
side_type
=
self
.
determine_side_type
(
sides_paths
[
i
])
outline
=
self
.
convert_to_binary_array
(
sides_paths
[
i
])
height
=
sides_paths
[
i
][:,
0
].
max
()
width
=
sides_paths
[
i
][:,
1
].
max
()
sides
[
i
]
=
Side
(
i
,
side_type
,
outline
,
width
,
height
)
number_of_flats
=
len
([
s
for
s
in
sides
if
s
.
side_type
==
SideType
.
FLAT
])
number_of_holes
=
len
([
s
for
s
in
sides
if
s
.
side_type
==
SideType
.
HOLE
])
number_of_heads
=
len
([
s
for
s
in
sides
if
s
.
side_type
==
SideType
.
HEAD
])
category
=
Category
.
INNER
if
number_of_flats
==
0
else
(
Category
.
EDGE
if
number_of_flats
==
1
else
Category
.
CORNER
)
puzzle_piece
=
PuzzlePiece
(
self
.
piece_id
,
category
,
number_of_holes
,
number_of_heads
,
""
,
sides
=
sides
)
self
.
puzzle_piece
=
puzzle_piece
return
self
.
puzzle_piece
def
determine_side_type
(
self
,
side_path
):
"""
This method determ the type of a side.
If the maximum height of a side is lower than the threshold
"
max_hight_flat_side
"
, it will be classified as flat.
If the start point coordinates are lower than the half of the height of a side, this side will be classified as hole.
Otherwise as a head.
"""
if
side_path
[:,
0
].
max
()
<
self
.
max_hight_flat_side
:
return
SideType
.
FLAT
elif
side_path
[
0
,
0
]
<
(
side_path
[:,
0
].
max
()
//
2
):
return
SideType
.
HOLE
else
:
return
SideType
.
HEAD
#%% test functions
if
__name__
==
"
__main__
"
:
def
print_outline
(
cart_path
,
image_shape
):
image
=
np
.
zeros
(
image_shape
)
...
...
@@ -240,20 +428,22 @@ def print_outline(cart_path, image_shape):
def
show_pol_path
(
pol_path
):
pol_path_edit
=
pol_path
.
copy
()
#(pol_path_edit[pol_path_edit[:,1]<0])[:,1] = (pol_path_edit[pol_path_edit[:,1]<0][:,1]*(-1))+np.pi
plt
.
plot
(
pol_path_edit
[:,
1
],
pol_path_edit
[:,
0
])
return
plt
.
plot
(
pol_path_edit
[:,
1
],
pol_path_edit
[:,
0
])[
0
]
#%% test script
if
__name__
==
"
__main__
"
:
image_path
=
"
..
\\
..
\\
resources
\\
binary_pic
\\
binary_puzzle.png
"
print
(
"
load test image
"
)
image_path
=
"
..
\\
..
\\
resources
\\
binary_pic
\\
binary_puzzle_2.png
"
image
=
cv
.
imread
(
image_path
,
cv
.
IMREAD_GRAYSCALE
)
print
(
"
create image analyser
"
)
ia
=
ImageAnalyser
(
image
_path
)
ia
=
ImageAnalyser
(
image
)
cv
.
imshow
(
"
binary image
"
,
ia
.
image
)
cv
.
waitKey
(
0
)
#cv.destroyAllWindows()
print
(
"
find
outline image
"
)
ia
.
find
_outline_image
()
print
(
"
create
outline image
"
)
ia
.
create
_outline_image
(
ia
.
image
)
cv
.
imshow
(
"
outline image
"
,
ia
.
outline_image
)
cv
.
waitKey
(
0
)
#cv.destroyAllWindows()
...
...
@@ -264,23 +454,23 @@ if __name__ == "__main__":
print
(
"
convert to polar coordianates
"
)
ia
.
convert_to_pol_path
(
ia
.
cart_path
)
show_pol_path
(
ia
.
pol_path
)
line
=
show_pol_path
(
ia
.
pol_path
)
cv
.
waitKey
(
0
)
print
(
"
find high spots
"
)
ia
.
find_high_spots_index
(
ia
.
pol_path
)
print
(
ia
.
get
_high_spots
_index
()
)
print
(
ia
.
index
_high_spots
)
print
(
"
calculate angles
"
)
ia
.
calculate_angle
(
ia
.
index_high_spots
)
print
(
ia
.
angles
)
print
(
"
extract
ed
corners
"
)
ia
.
extract
ed
_corners
()
print
(
"
extract corners
"
)
ia
.
extract_corners
(
ia
.
angles
,
ia
.
index_high_spots
)
print
(
ia
.
corners
)
print
(
"
split sides
"
)
ia
.
split_sites
()
ia
.
split_sites
(
ia
.
cart_path
,
ia
.
index_corners
)
print
(
"
normalize sides
"
)
ia
.
normalize_sides
()
...
...
@@ -288,10 +478,15 @@ if __name__ == "__main__":
print
(
"
polish side paths
"
)
ia
.
polish_side_paths
()
for
i
in
range
(
5
):
for
i
in
range
(
4
):
temp
=
ia
.
convert_to_binary_array
(
ia
.
sides_cart_path
[
i
])
cv
.
imshow
(
f
"
Side
{
i
}
"
,
temp
*
255
)
cv
.
waitKey
(
0
)
print
(
"
create puzzle piece
"
)
piece
=
ia
.
create_puzzle_piece
(
ia
.
sides_cart_path
)
print
(
piece
.
category
)
cv
.
waitKey
(
0
)
#%% playground
\ No newline at end of file
cv
.
destroyAllWindows
()
plt
.
close
(
line
.
figure
)
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