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
db23e0fc
Commit
db23e0fc
authored
1 year ago
by
zalonzo2
Browse files
Options
Downloads
Patches
Plain Diff
Added argument show_cam
parent
8737240e
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
game.py
+11
-4
11 additions, 4 deletions
game.py
with
11 additions
and
4 deletions
game.py
+
11
−
4
View file @
db23e0fc
...
@@ -14,10 +14,11 @@ import time
...
@@ -14,10 +14,11 @@ import time
from
picamera2
import
Picamera2
,
Preview
from
picamera2
import
Picamera2
,
Preview
class
ChessGame
:
class
ChessGame
:
def
__init__
(
self
,
difficulty
,
show_cv
,
test_img
=
None
):
def
__init__
(
self
,
difficulty
,
show_cv
,
show_cam
,
test_img
=
None
):
self
.
board
=
chess
.
Board
()
self
.
board
=
chess
.
Board
()
self
.
difficulty
=
difficulty
self
.
difficulty
=
difficulty
self
.
show_cv
=
show_cv
self
.
show_cv
=
show_cv
self
.
show_cam
=
show_cam
self
.
test_img
=
test_img
self
.
test_img
=
test_img
self
.
img_idx
=
0
self
.
img_idx
=
0
self
.
picam2
=
Picamera2
()
self
.
picam2
=
Picamera2
()
...
@@ -30,8 +31,15 @@ class ChessGame:
...
@@ -30,8 +31,15 @@ class ChessGame:
init_show_cv
(
self
.
show_cv
)
init_show_cv
(
self
.
show_cv
)
preview_config
=
self
.
picam2
.
create_preview_configuration
(
main
=
{
"
size
"
:
(
512
,
512
)})
preview_config
=
self
.
picam2
.
create_preview_configuration
(
main
=
{
"
size
"
:
(
512
,
512
)})
self
.
picam2
.
configure
(
preview_config
)
self
.
picam2
.
configure
(
preview_config
)
if
(
self
.
show_cam
):
self
.
picam2
.
start_preview
(
Preview
.
QTGL
)
self
.
picam2
.
start
()
input
(
"
Press enter to continue.
"
)
else
:
self
.
picam2
.
start
()
# self.get_img()
# self.get_img()
...
@@ -86,8 +94,6 @@ class ChessGame:
...
@@ -86,8 +94,6 @@ class ChessGame:
def
take_pic
(
self
):
def
take_pic
(
self
):
self
.
img_idx
+=
1
self
.
img_idx
+=
1
# self.picam2.start_preview(Preview.QTGL)
self
.
picam2
.
start
()
time
.
sleep
(
2
)
time
.
sleep
(
2
)
img_txt
=
'
board
'
+
str
(
self
.
img_idx
)
+
'
.jpg
'
img_txt
=
'
board
'
+
str
(
self
.
img_idx
)
+
'
.jpg
'
print
(
img_txt
)
print
(
img_txt
)
...
@@ -100,8 +106,9 @@ if __name__ == "__main__":
...
@@ -100,8 +106,9 @@ if __name__ == "__main__":
parser
.
add_argument
(
"
--difficulty
"
,
choices
=
[
"
easy
"
,
"
medium
"
,
"
hard
"
],
parser
.
add_argument
(
"
--difficulty
"
,
choices
=
[
"
easy
"
,
"
medium
"
,
"
hard
"
],
default
=
"
medium
"
,
help
=
"
Chess AI difficulty (how far it looks ahead)
"
)
default
=
"
medium
"
,
help
=
"
Chess AI difficulty (how far it looks ahead)
"
)
parser
.
add_argument
(
"
--show_cv
"
,
action
=
"
store_true
"
,
help
=
"
Show opencv images as processing occurs during game
"
)
parser
.
add_argument
(
"
--show_cv
"
,
action
=
"
store_true
"
,
help
=
"
Show opencv images as processing occurs during game
"
)
parser
.
add_argument
(
"
--show_cam
"
,
action
=
"
store_true
"
,
help
=
"
Show persistent camera view
"
)
parser
.
add_argument
(
"
--test_img
"
,
help
=
"
If specified, will use said image in test_images folder rather than camera input
"
)
parser
.
add_argument
(
"
--test_img
"
,
help
=
"
If specified, will use said image in test_images folder rather than camera input
"
)
args
=
parser
.
parse_args
()
args
=
parser
.
parse_args
()
game
=
ChessGame
(
args
.
difficulty
,
args
.
show_cv
,
args
.
test_img
)
game
=
ChessGame
(
args
.
difficulty
,
args
.
show_cv
,
args
.
show_cam
,
args
.
test_img
)
game
.
start_game
()
game
.
start_game
()
\ 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