PlayChessWithAWebCam
OsProject | |
---|---|
edit | |
id | PlayChessWithAWebCam |
state | |
owner | Wolfgang Fahl |
title | Play Chess With A WebCam |
url | https://github.com/WolfgangFahl/play-chess-with-a-webcam |
version | 0.0.1 |
description | |
date | 2019/10/21 |
since | |
until |
Motivation
See MagneticSensorChessBoard1987 for the initial project of 1987. Time has moved on and the goals of the 1987 project can be achieved with less hardware and software in a more convenient manner these days.
State of Project
As of 2019-10-21 version 0.0.1 has not been release yet. The state of the project is development/alpha.
There is already a lof of stuff to try out and to participate in this open source project.
The scripts:
- still
- record
are already useful for taking pictures and movie recordings of your chess match. The detection of the board and moves is not fully operational yet.
If you'd like to experiment a bit you can run the tests which will show some debug output.
opencv tutorial stuff
Also in the opencvtutoral directory you'll find:
- colorcluster.py
- histogramm.py
- hough_lines.py
hough lines
python3 opencvtutorial/hough_lines.py testMedia/chessBoard002.jpg
histogramm / colorcluster
python3 opencvtutorial/histogramm.py testMedia/chessBoard006.jpg
python3 opencvtutorial/colorcluster.py testMedia/chessBoard006.jpg
Clusterization took 2.8 s for 1 channels
Clusterization took 4.5 s for 2 channels
Clusterization took 6.7 s for 3 channels
Installation
Prerequisites: python3.7 (install script will check and try automatic installation in Ubuntu/MacOS)
1git clone https://github.com/WolfgangFahl/play-chess-with-a-webcam
2Cloning into 'play-chess-with-a-webcam'...
3remote: Enumerating objects: 57, done.
4remote: Counting objects: 100% (57/57), done.
5remote: Compressing objects: 100% (40/40), done.
6remote: Total 385 (delta 29), reused 34 (delta 17), pack-reused 328
7Receiving objects: 100% (385/385), 1.79 MiB | 3.17 MiB/s, done.
8Resolving deltas: 100% (244/244), done
9cd play-chess-with-a-webcam
10scripts/install
11scripts/install
12checking that python3 is installed on os Linux ...
13/usr/bin/python3
14checking that pip3 is installed on os Linux ...
15installing pip3 from apt-package python3-pip
16Reading package lists... Done
17Building dependency tree
18Reading state information... Done
19The following package was automatically installed and is no longer required:
20 libevent-core-2.1-6
21Use 'sudo apt autoremove' to remove it.
22The following additional packages will be installed:
23 libexpat1-dev libpython3-dev libpython3.6-dev python-pip-whl python3-dev
24 python3-setuptools python3-wheel python3.6-dev
25Suggested packages:
26 python-setuptools-doc
27The following NEW packages will be installed:
28 libexpat1-dev libpython3-dev libpython3.6-dev python-pip-whl python3-dev
29 python3-pip python3-setuptools python3-wheel python3.6-dev
300 upgraded, 9 newly installed, 0 to remove and 40 not upgraded.
31Need to get 47,5 MB of archives.
32After this operation, 81,7 MB of additional disk space will be used.
33Do you want to continue? [Y/n] y
Usage
Command line usage
scripts/run -h
usage: ChessCam.py [-h] [--nouci] [--input INPUT] [--debug]
[--cornermarker CORNERMARKER] [--fullScreen]
ChessCam Argument Parser
optional arguments:
-h, --help show this help message and exit
--nouci Don't use the UCI interface.
--input INPUT Manually set the input device.
--debug show debug output
--cornermarker CORNERMARKER
filepath for an image of the cornermarker being used
--fullScreen Display output in fullScreen mode
Recording
Still images
scripts/still
Video of match
scripts/record
Testing
scripts/test
============================= test session starts =============================
platform darwin -- Python 3.7.4, pytest-5.2.1, py-1.8.0, pluggy-0.12.0
rootdir: /Users/wf/source/python/play-chess-with-a-webcam
plugins: cov-2.8.1
collected 11 items
src/test_Board.py . [ 9%]
src/test_ChessCam.py . [ 18%]
src/test_OpenCV_version.py . [ 27%]
src/test_Video.py ... [ 54%]
src/test_findBoard.py ..... [100%]
---------- coverage: platform darwin, python 3.7.4-final-0 -----------
Name Stmts Miss Cover
------------------------------------------------
src/Args.py 10 7 30%
src/Board.py 33 3 91%
src/BoardFinder.py 186 12 94%
src/Cell.py 10 4 60%
src/ChessCam.py 86 59 31%
src/InputManager.py 57 37 35%
src/MovementDetector.py 55 40 27%
src/StateDetector.py 92 75 18%
src/Video.py 133 48 64%
src/mathUtils.py 49 25 49%
src/test_Board.py 23 3 87%
src/test_ChessCam.py 4 0 100%
src/test_OpenCV_version.py 6 0 100%
src/test_Video.py 28 0 100%
src/test_findBoard.py 49 0 100%
------------------------------------------------
TOTAL 821 313 62%
============================= 11 passed in 25.18s =============================
Hardware
see e.g Raspberry_PI_Chessboard_Camera
Source Code
play-chess-with-a-webcam
see github fork at
Written in python2 migrated to python3.7. see https://unix.stackexchange.com/a/410851/38701 for selection your python version on Ubuntu
Code Structure
OS-Support
Ubuntu 18.04.3 LTS bionic beaver
1scripts/install
2checking that python3 is installed on os Linux ...
3/usr/bin/python3
4checking that pip3 is installed on os Linux ...
5installing pip3 from apt-package python3-pip
6Reading package lists... Done
7Building dependency tree
8Reading state information... Done
9The following package was automatically installed and is no longer required:
10 libevent-core-2.1-6
11Use 'sudo apt autoremove' to remove it.
12The following additional packages will be installed:
13 libexpat1-dev libpython3-dev libpython3.6-dev python-pip-whl python3-dev
14 python3-setuptools python3-wheel python3.6-dev
15Suggested packages:
16 python-setuptools-doc
17The following NEW packages will be installed:
18 libexpat1-dev libpython3-dev libpython3.6-dev python-pip-whl python3-dev
19 python3-pip python3-setuptools python3-wheel python3.6-dev
200 upgraded, 9 newly installed, 0 to remove and 40 not upgraded.
21Need to get 47,5 MB of archives.
22After this operation, 81,7 MB of additional disk space will be used.
23Do you want to continue? [Y/n] y
24Get:1 http://de.archive.ubuntu.com/ubuntu bionic-updates/main amd64 libexpat1-dev amd64 2.2.5-3ubuntu0.2 [122 kB]
25Get:2 http://de.archive.ubuntu.com/ubuntu bionic-updates/main amd64 libpython3.6-dev amd64 3.6.8-1~18.04.3 [44,8 MB]
26Get:3 http://de.archive.ubuntu.com/ubuntu bionic-updates/main amd64 libpython3-dev amd64 3.6.7-1~18.04 [7.328 B]
27Get:4 http://de.archive.ubuntu.com/ubuntu bionic-updates/universe amd64 python-pip-whl all 9.0.1-2.3~ubuntu1.18.04.1 [1.653 kB]
28Get:5 http://de.archive.ubuntu.com/ubuntu bionic-updates/main amd64 python3.6-dev amd64 3.6.8-1~18.04.3 [508 kB]
29Get:6 http://de.archive.ubuntu.com/ubuntu bionic-updates/main amd64 python3-dev amd64 3.6.7-1~18.04 [1.288 B]
30Get:7 http://de.archive.ubuntu.com/ubuntu bionic-updates/universe amd64 python3-pip all 9.0.1-2.3~ubuntu1.18.04.1 [114 kB]
31Get:8 http://de.archive.ubuntu.com/ubuntu bionic/main amd64 python3-setuptools all 39.0.1-2 [248 kB]
32Get:9 http://de.archive.ubuntu.com/ubuntu bionic/universe amd64 python3-wheel all 0.30.0-0.2 [36,5 kB]
33Fetched 47,5 MB in 7s (7.072 kB/s)
34Selecting previously unselected package libexpat1-dev:amd64.
35(Reading database ... 198536 files and directories currently installed.)
36Preparing to unpack .../0-libexpat1-dev_2.2.5-3ubuntu0.2_amd64.deb ...
37Unpacking libexpat1-dev:amd64 (2.2.5-3ubuntu0.2) ...
38Selecting previously unselected package libpython3.6-dev:amd64.
39Preparing to unpack .../1-libpython3.6-dev_3.6.8-1~18.04.3_amd64.deb ...
40Unpacking libpython3.6-dev:amd64 (3.6.8-1~18.04.3) ...
41Selecting previously unselected package libpython3-dev:amd64.
42Preparing to unpack .../2-libpython3-dev_3.6.7-1~18.04_amd64.deb ...
43Unpacking libpython3-dev:amd64 (3.6.7-1~18.04) ...
44Selecting previously unselected package python-pip-whl.
45Preparing to unpack .../3-python-pip-whl_9.0.1-2.3~ubuntu1.18.04.1_all.deb ...
46Unpacking python-pip-whl (9.0.1-2.3~ubuntu1.18.04.1) ...
47Selecting previously unselected package python3.6-dev.
48Preparing to unpack .../4-python3.6-dev_3.6.8-1~18.04.3_amd64.deb ...
49Unpacking python3.6-dev (3.6.8-1~18.04.3) ...
50Selecting previously unselected package python3-dev.
51Preparing to unpack .../5-python3-dev_3.6.7-1~18.04_amd64.deb ...
52Unpacking python3-dev (3.6.7-1~18.04) ...
53Selecting previously unselected package python3-pip.
54Preparing to unpack .../6-python3-pip_9.0.1-2.3~ubuntu1.18.04.1_all.deb ...
55Unpacking python3-pip (9.0.1-2.3~ubuntu1.18.04.1) ...
56Selecting previously unselected package python3-setuptools.
57Preparing to unpack .../7-python3-setuptools_39.0.1-2_all.deb ...
58Unpacking python3-setuptools (39.0.1-2) ...
59Selecting previously unselected package python3-wheel.
60Preparing to unpack .../8-python3-wheel_0.30.0-0.2_all.deb ...
61Unpacking python3-wheel (0.30.0-0.2) ...
62Setting up python-pip-whl (9.0.1-2.3~ubuntu1.18.04.1) ...
63Setting up python3-wheel (0.30.0-0.2) ...
64Setting up python3-pip (9.0.1-2.3~ubuntu1.18.04.1) ...
65Setting up libexpat1-dev:amd64 (2.2.5-3ubuntu0.2) ...
66Setting up python3-setuptools (39.0.1-2) ...
67Setting up libpython3.6-dev:amd64 (3.6.8-1~18.04.3) ...
68Setting up python3.6-dev (3.6.8-1~18.04.3) ...
69Setting up libpython3-dev:amd64 (3.6.7-1~18.04) ...
70Setting up python3-dev (3.6.7-1~18.04) ...
71Processing triggers for man-db (2.8.3-2ubuntu0.1) ...
72Processing triggers for doc-base (0.10.8) ...
73Processing 1 added doc-base file...
74Collecting opencv-python (from -r requirements.txt (line 2))
75 Downloading https://files.pythonhosted.org/packages/5e/7e/bd5425f4dacb73367fddc71388a47c1ea570839197c2bcad86478e565186/opencv_python-4.1.1.26-cp36-cp36m-manylinux1_x86_64.whl (28.7MB)
76 100% |████████████████████████████████| 28.7MB 30kB/s
77Collecting pytest (from -r requirements.txt (line 4))
78 Downloading https://files.pythonhosted.org/packages/0c/91/d68f68ce54cd3e8afa1ef73ea1ad44df2438521b64c0820e5fd9b9f13b7d/pytest-5.2.1-py3-none-any.whl (226kB)
79 100% |████████████████████████████████| 235kB 2.5MB/s
80Collecting matplotlib (from -r requirements.txt (line 6))
81 Downloading https://files.pythonhosted.org/packages/57/4f/dd381ecf6c6ab9bcdaa8ea912e866dedc6e696756156d8ecc087e20817e2/matplotlib-3.1.1-cp36-cp36m-manylinux1_x86_64.whl (13.1MB)
82 100% |████████████████████████████████| 13.1MB 69kB/s
83Collecting scipy (from -r requirements.txt (line 8))
84 Downloading https://files.pythonhosted.org/packages/29/50/a552a5aff252ae915f522e44642bb49a7b7b31677f9580cfd11bcc869976/scipy-1.3.1-cp36-cp36m-manylinux1_x86_64.whl (25.2MB)
85 100% |████████████████████████████████| 25.2MB 34kB/s
86Collecting pytest-cov (from -r requirements.txt (line 10))
87 Downloading https://files.pythonhosted.org/packages/b9/54/3673ee8be482f81527678ac894276223b9814bb7262e4f730469bb7bf70e/pytest_cov-2.8.1-py2.py3-none-any.whl
88Collecting python-chess (from -r requirements.txt (line 12))
89 Downloading https://files.pythonhosted.org/packages/58/70/72dc875a30ac7f26e0bec45714d67b19e0f498de920323b906995a741a88/python_chess-0.28.3-py3-none-any.whl (127kB)
90 100% |████████████████████████████████| 133kB 3.5MB/s
91Collecting numpy>=1.11.3 (from opencv-python->-r requirements.txt (line 2))
92 Downloading https://files.pythonhosted.org/packages/0e/46/ae6773894f7eacf53308086287897ec568eac9768918d913d5b9d366c5db/numpy-1.17.3-cp36-cp36m-manylinux1_x86_64.whl (20.0MB)
93 100% |████████████████████████████████| 20.0MB 45kB/s
94Collecting pluggy<1.0,>=0.12 (from pytest->-r requirements.txt (line 4))
95 Downloading https://files.pythonhosted.org/packages/92/c7/48439f7d5fd6bddb4c04b850bb862b42e3e2b98570040dfaf68aedd8114b/pluggy-0.13.0-py2.py3-none-any.whl
96Collecting atomicwrites>=1.0 (from pytest->-r requirements.txt (line 4))
97 Downloading https://files.pythonhosted.org/packages/52/90/6155aa926f43f2b2a22b01be7241be3bfd1ceaf7d0b3267213e8127d41f4/atomicwrites-1.3.0-py2.py3-none-any.whl
98Collecting packaging (from pytest->-r requirements.txt (line 4))
99 Downloading https://files.pythonhosted.org/packages/cf/94/9672c2d4b126e74c4496c6b3c58a8b51d6419267be9e70660ba23374c875/packaging-19.2-py2.py3-none-any.whl
100Collecting wcwidth (from pytest->-r requirements.txt (line 4))
101 Downloading https://files.pythonhosted.org/packages/7e/9f/526a6947247599b084ee5232e4f9190a38f398d7300d866af3ab571a5bfe/wcwidth-0.1.7-py2.py3-none-any.whl
102Collecting importlib-metadata>=0.12; python_version < "3.8" (from pytest->-r requirements.txt (line 4))
103 Downloading https://files.pythonhosted.org/packages/f6/d2/40b3fa882147719744e6aa50ac39cf7a22a913cbcba86a0371176c425a3b/importlib_metadata-0.23-py2.py3-none-any.whl
104Collecting attrs>=17.4.0 (from pytest->-r requirements.txt (line 4))
105 Downloading https://files.pythonhosted.org/packages/a2/db/4313ab3be961f7a763066401fb77f7748373b6094076ae2bda2806988af6/attrs-19.3.0-py2.py3-none-any.whl
106Collecting py>=1.5.0 (from pytest->-r requirements.txt (line 4))
107 Downloading https://files.pythonhosted.org/packages/76/bc/394ad449851729244a97857ee14d7cba61ddb268dce3db538ba2f2ba1f0f/py-1.8.0-py2.py3-none-any.whl (83kB)
108 100% |████████████████████████████████| 92kB 4.4MB/s
109Collecting more-itertools>=4.0.0 (from pytest->-r requirements.txt (line 4))
110 Downloading https://files.pythonhosted.org/packages/45/dc/3241eef99eb45f1def35cf93af35d1cf9ef4c0991792583b8f33ea41b092/more_itertools-7.2.0-py3-none-any.whl (57kB)
111 100% |████████████████████████████████| 61kB 4.8MB/s
112Requirement already satisfied: pyparsing!=2.0.4,!=2.1.2,!=2.1.6,>=2.0.1 in /usr/lib/python3/dist-packages (from matplotlib->-r requirements.txt (line 6))
113Requirement already satisfied: python-dateutil>=2.1 in /usr/lib/python3/dist-packages (from matplotlib->-r requirements.txt (line 6))
114Collecting kiwisolver>=1.0.1 (from matplotlib->-r requirements.txt (line 6))
115 Downloading https://files.pythonhosted.org/packages/f8/a1/5742b56282449b1c0968197f63eae486eca2c35dcd334bab75ad524e0de1/kiwisolver-1.1.0-cp36-cp36m-manylinux1_x86_64.whl (90kB)
116 100% |████████████████████████████████| 92kB 5.2MB/s
117Collecting cycler>=0.10 (from matplotlib->-r requirements.txt (line 6))
118 Downloading https://files.pythonhosted.org/packages/f7/d2/e07d3ebb2bd7af696440ce7e754c59dd546ffe1bbe732c8ab68b9c834e61/cycler-0.10.0-py2.py3-none-any.whl
119Collecting coverage>=4.4 (from pytest-cov->-r requirements.txt (line 10))
120 Downloading https://files.pythonhosted.org/packages/51/b1/13609068fff1c8c056f0c4601ad6985cf5c1bbfc529196ab08bd2a57dc39/coverage-4.5.4-cp36-cp36m-manylinux1_x86_64.whl (205kB)
121 100% |████████████████████████████████| 215kB 2.8MB/s
122Requirement already satisfied: six in /usr/lib/python3/dist-packages (from packaging->pytest->-r requirements.txt (line 4))
123Collecting zipp>=0.5 (from importlib-metadata>=0.12; python_version < "3.8"->pytest->-r requirements.txt (line 4))
124 Downloading https://files.pythonhosted.org/packages/74/3d/1ee25a26411ba0401b43c6376d2316a71addcc72ef8690b101b4ea56d76a/zipp-0.6.0-py2.py3-none-any.whl
125Requirement already satisfied: setuptools in /usr/lib/python3/dist-packages (from kiwisolver>=1.0.1->matplotlib->-r requirements.txt (line 6))
126Installing collected packages: numpy, opencv-python, more-itertools, zipp, importlib-metadata, pluggy, atomicwrites, packaging, wcwidth, attrs, py, pytest, kiwisolver, cycler, matplotlib, scipy, coverage, pytest-cov, python-chess
127Successfully installed atomicwrites-1.3.0 attrs-19.3.0 coverage-4.5.4 cycler-0.10.0 importlib-metadata-0.23 kiwisolver-1.1.0 matplotlib-3.1.1 more-itertools-7.2.0 numpy-1.17.3 opencv-python-4.1.1.26 packaging-19.2 pluggy-0.13.0 py-1.8.0 pytest-5.2.1 pytest-cov-2.8.1 python-chess-0.28.3 scipy-1.3.1 wcwidth-0.1.7 zipp-0.6.0