This program estimates the pose difference between the actual image and the image that the camera should be seeing in order to grasp an object with a robot gripper. It uses OpenCV's solvePnP algorithm and machine learning with YOLOv8.
To install the program, follow these steps:
- Clone the repository:
git clone https://github.com/alantorresve/PnP - Install the required dependencies:
pip install -r requirements.txt
Before using the program, it is necessary to perform camera calibration. The SolvePnP function requires the camera intrinsic parameters, such as the camera matrix and distortion coefficient matrix. These parameters are stored as a numpy array and then imported to the main code.
To perform camera calibration, follow these steps:
- Install the required dependencies mentioned in the Installation section.
- Select the type of calibration to perform based on the chosen pattern.
- Print the pattern and stick it onto a planar surface or object.
- Run the calibration code that corresponds to the chosen pattern.
- Perform real-time calibration by selecting the desired camera (change the number of the video capture from 0 to the desired camera).
- Once the calibration is completed, you can see a calibration 'score' to check if it was done properly.
- Use the
calibrationcheck.pyscript to visually check if the image was undistorted successfully using the results obtained in the calibration process. - After ensuring that the calibration was successful, you can proceed with the other steps.
To use the program, follow these steps:
- Make sure you have installed the required dependencies as mentioned in the Installation section.
- Execute the main code:
python main.py
To perform a custom training procedure for the project, follow these steps:
- Modify the
config.yamlfile: Open theconfig.yamlfile located in themlcubedetectionfolder. Make the necessary modifications to the configuration parameters according to your requirements. Note: Ensure that the path directory in theconfig.yamlfile is modified to the absolute path directory, otherwise the program won't work correctly. - Prepare the dataset: Ensure that your dataset is properly organized and labeled. Place the dataset files in the appropriate directory specified in the
config.yamlfile. - Execute the
train.pyfile: Run thetrain.pyfile located in themlcubedetectionfolder. This script is responsible for training the model using the provided dataset and configuration.
The following dependencies are required to run the program:
- Python 3.11.5
- matplotlib==3.8.1
- numpy==1.24.1
- opencv_python==4.8.1.78
- opencv_python_headless==4.8.0.74
- ultralytics==8.0.222
You can install these dependencies by running pip install -r requirements.txt.