rondinellimorais / chess_recognition

This project uses computer vision techniques to detect objects on a chessboard. The data are converted into an 8x8 numpy matrix which is passed to the minimax algorithm to suggest a move.
MIT License
17 stars 0 forks source link

Could you help me? #4

Open Skir0 opened 1 year ago

Skir0 commented 1 year ago

Hello. Looking your videos in YouTube I have to say that your project is awesome!!! And it is exactly that I need for my own project (also connected with a chess).

However to be honest I am not really good at python and I didn't work with such projects before. I didn't have a practise with Conda and other environment things. That is why I am asking you to help me - explain in more details how to start up a project.

Some notes: I have tried to install an env using Conda. It is installed files: absl-py 0.12.0  
attrs 21.2.0  
ca-certificates 2023.5.7  
cairocffi 1.2.0  
cairosvg 2.5.2  
cffi 1.14.5  
chess 1.5.0  
click 7.1.2  
cssselect2 0.4.1  
cycler 0.10.0  
decorator 4.4.2  
defusedxml 0.7.1  
imageio 2.31.0  
imutils 0.5.3  
kiwisolver 1.3.1  
lazy-loader 0.2  
libblas 3.9.0  
libcblas 3.9.0  
libcxx 16.0.5  
libgfortran 5.0.0  
libgfortran5 12.2.0  
liblapack 3.9.0  
libopenblas 0.3.23  
libsqlite 3.42.0  
libzlib 1.2.13  
llvm-openmp 16.0.5  
matplotlib 3.3.3  
ncurses 6.3  
networkx 3.1  
numpy 1.24.3  
opencv-contrib-python 4.7.0.72  
opencv-python 4.7.0.72  
opencv-python-headless 4.7.0.72  
openssl 1.1.1u  
packaging 23.1  
pillow 9.5.0  
pip 21.0.1  
protobuf 3.17.1  
pycparser 2.20  
pyparsing 2.4.7  
pyqt5-sip 12.9.0  
pyqtgraph 0.12.1  
python 3.9.2  
python-dateutil 2.8.1  
python-dotenv 0.17.1  
python_abi 3.9  
pywavelets 1.1.1  
readline 8.2  
scikit-image 0.21.0  
scipy 1.10.1  
setuptools 67.7.2  
shapely 2.0.1  
six 1.15.0  
sqlite 3.42.0  
tifffile 2021.3.17  
tinycss2 1.1.0  
tk 8.6.12  
tzdata 2023c  
webencodings 0.5.1  
wheel 0.40.0  
xz 5.2.6  
zlib 1.2.13  

Also trying to start a main.py I have this traceback: Traceback (most recent call last): File "/Users/kirill_smychok/PycharmProjects/chess_recognition-master/src/main.py", line 3, in from model import Game File "/Users/kirill_smychok/PycharmProjects/chess_recognition-master/src/model/init.py", line 3, in from .chessboard_calibration import ChessboardCalibration File "/Users/kirill_smychok/PycharmProjects/chess_recognition-master/src/model/chessboard_calibration.py", line 19, in from model.board import Board File "/Users/kirill_smychok/PycharmProjects/chess_recognition-master/src/model/board.py", line 11, in class Board: File "/Users/kirill_smychok/PycharmProjects/chess_recognition-master/src/model/board.py", line 14, in Board network: Darknet = Darknet.instance() File "/Users/kirill_smychok/PycharmProjects/chess_recognition-master/src/model/darknet.py", line 33, in instance cls.instance = cls() File "/Users/kirill_smychok/PycharmProjects/chess_recognition-master/src/model/darknet.py", line 17, in init self.net = readNetFromDarknet(config.get('CFG_FILE_PATH'), config.get('WEIGHTS_FILE_PATH')) cv2.error: OpenCV(4.7.0) /Users/xperience/GHA-OCV-Python/_work/opencv-python/opencv-python/opencv/modules/dnn/src/darknet/darknet_importer.cpp:210: error: (-212:Parsing error) Failed to open NetParameter file: assets/dnn/yolov4.custom.cfg in function 'readNetFromDarknet'

I know that it is a little bit arrogant to ask you this. On the other hand I must say that I have been trying to find a solution for 3 days (that is a true). I will be really appreciate on your reply and, of course, will mention you as a main developer if I could start up my project

P.S. The brilliant idea if you film a video on YouTube how to start up a project however I can't ask you this, it is too unreasonable for only me

Good buy!

rondinellimorais commented 1 year ago

Hello thank you.

I will help you get started with the project, don't worry, feel free to ask any questions.

I ask you to wait a while until I can prepare a material and then I'll get back to you.

rondinellimorais commented 1 year ago

Hello, You can update the project using git pull... then follow these steps:

Get started

Some configurations are necessary to run the project:

  1. Get YOLO weights file
  2. Configure the camera
  3. Virtual environment
  4. Board mapping
  5. Start
## 1. Get YOLO weights file Get the file containing the YOLO neural network weights, you can download it at [yolov4_last.weights](https://drive.google.com/open?id=1aY6yIKVfnFlzLUU2jj9bumMCjMJRT9U1), after downloading move the file to `assets/dnn/yolov4_last.weights`
## 2. Configure the camera > > **NOTE** > > Skip this section if you just want to run the example project > In `src/.env` you must specify a camera source, you can do this by setting the `CAM_ADDRESS` parameter. Valid options are: | Option | Example | |:----------|:------------| |IP | `http://192.168.0.111:4747/video` | | device index | `0` (You can select the second camera by passing 1 and so on) | | video file | `/path/file.mp4` |
## 3. Virtual environment Maybe you want to create a virtual environment using [miniconda](https://docs.conda.io/en/latest/miniconda.html) before run start. > > **Create Env with conda** > > ```conda create -n chess_recognition python=3.9 pip --yes``` > > **Activate env** > > ```conda activate chess_recognition``` >
## 4. Board mapping Before we can start the project we need to calibrate the board, you can do this using the command `python3 src/main.py --mapping`. **NOTE:** _Run this command in the root of the project and not inside `src`_ If all goes well, you should see output similar to this one. ```bash frame resolution: (480, 480) /path/chess_recognition/debug/1_raw.jpg /path/chess_recognition/debug/2_biggest_cnt.jpg /path/chess_recognition/debug/3_playable_area.jpg /path/chess_recognition/debug/3.1_padding.jpg /path/chess_recognition/debug/4_squares_corners.jpg /path/chess_recognition/debug/5_mapping.jpg Squares Average......: 3190.3125 Done! ``` Then `chessboard-mapping.json` file must be created in the root of the project. You can look in the `debug` directory step by step calibration of the board, if you don't want to see those logs anymore set `DEBUG=0` in `.env` Note that in `.env` we define the camera for an example video file: ```bash # src/.env CAM_ADDRESS=assets/videos/cam_example.mp4 ``` If you want to test with your own file or the your device camera, you must change this env and then calibrate your board. To calibrate your board, go to the `Game` class, `mapping` method, line `79` and change the parameters according to your needs: | Parameter | Description | |:----------|:------------| | `add_padding` | A boolean indicate if image need a padding. Default is `False` | | `fix_rotate` | A boolean indicate if image need a rotate. Default is `False` | | `rotate_val` | The values of rotate if `fix_rotate` is `True`. Default is `-90` | | `apply_kdilate` | A booelan indicate if image need expand your contours. Default is `True` | | `smooth_ksize` | A tuple of Gaussian Blur ksize. Default is `(11, 11)` |
## 5. Start Now you are ready to start the game, go and run `python3 src/main.py --start` **NOTE:** _Run this command in the root of the project and not inside `src`_

Let me know if you can run the project