Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
A
AI Chess Robot
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package 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
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
jhur22
AI Chess Robot
Commits
137dc2e9
Commit
137dc2e9
authored
10 months ago
by
zalonzo2
Browse files
Options
Downloads
Patches
Plain Diff
Some final comments and added some sources that can be found in my notebook as well
parent
4dd5c21c
Branches
main
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
board_detector.py
+9
-2
9 additions, 2 deletions
board_detector.py
with
9 additions
and
2 deletions
board_detector.py
+
9
−
2
View file @
137dc2e9
...
...
@@ -95,6 +95,8 @@ def find_lines(img):
return
sorted_vertical
,
sorted_horizontal
def
convert_to_cartesian
(
lines
):
# used for HoughLines
# www.geeksforgeeks.org/line-detection-python-opencv-houghline-method/
line_points
=
[]
if
lines
is
not
None
:
for
line
in
lines
:
...
...
@@ -145,6 +147,10 @@ def filter_lines(lines, min_distance):
return
filtered_lines
def
find_board
(
img
):
# https://opencvpython.blogspot.com/2012/06/sudoku-solver-part-2.html
# https://stackoverflow.com/questions/10196198/how-to-remove-convexity-defects-in-a-sudoku-square/11366549#11366549
# ^ two sources that were very useful for the board detection code
vertical_lines
,
horizontal_lines
=
find_lines
(
img
)
# create bitmasks for vert and horiz so we can get lines and intersections
...
...
@@ -280,7 +286,7 @@ def warp_board(img, corners_sorted, intersection):
return
warped_img
,
sorted_warped_points
prev_filled_contour_mask
=
None
prev_filled_contour_mask
=
None
# probably should have stored this in game.py instead
def
find_pieces
(
warped_img
,
prev_warped_img
,
sorted_warped_points
,
reader
,
img_idx
):
global
prev_filled_contour_mask
...
...
@@ -485,6 +491,7 @@ def find_pieces(warped_img, prev_warped_img, sorted_warped_points, reader, img_i
if
len
(
box_contours_sorted
)
!=
0
:
# straighten the letter based on its contours' bounding box
# https://stackoverflow.com/questions/11627362/how-to-straighten-a-rotated-rectangle-area-of-an-image-using-opencv-in-python <- this helped a lot
box_contour
=
box_contours_sorted
[
0
]
drawn_box_img
=
cv2
.
cvtColor
(
box_img
,
cv2
.
COLOR_GRAY2BGR
)
cv2
.
drawContours
(
drawn_box_img
,
[
box_contour
],
-
1
,
(
255
,
255
,
0
),
1
)
...
...
@@ -547,7 +554,7 @@ def find_pieces(warped_img, prev_warped_img, sorted_warped_points, reader, img_i
img_to_read_bigger
=
np
.
zeros
((
cols
+
40
,
rows
+
40
))
img_to_read_bigger
=
img_to_read_bigger
.
astype
(
np
.
uint8
)
# put img_to_read in center of img_to_read_bigger
# put img_to_read in center of img_to_read_bigger
(probably should have made this section a separate function)
start_row
=
int
((
img_to_read_bigger
.
shape
[
0
]
-
img_to_read
.
shape
[
0
])
//
2
)
start_col
=
int
((
img_to_read_bigger
.
shape
[
1
]
-
img_to_read
.
shape
[
1
])
//
2
)
end_row
=
start_row
+
img_to_read
.
shape
[
0
]
...
...
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