AruCo Markers

From Rsewiki
(Difference between revisions)
Jump to: navigation, search
(information about different aspects with the ArUco and camera calibration functions)
Line 1: Line 1:
==== ArUco functions and camera calibration overview ====
+
= ArUco functions and camera calibration overview =
 
The ArUco functions in the camera class are meant as an inspiration, to give a starting point to people, who want to use the OpenCv ArUco library.
 
The ArUco functions in the camera class are meant as an inspiration, to give a starting point to people, who want to use the OpenCv ArUco library.
  
=== Settings ===
+
The ArUcu module from the OpenCv library is used to detect the markers. The library can be downloaded on [https://docs.opencv.org/4.1.1/d5/dae/tutorial_aruco_detection.html this] website, where there also is some information about the functions from the library.
  
Some of the settings is dependable of the printed ArUcu markers and the hardware (camera) used to detect. So the first thing to do, when starting a new project is to check and if necessary update this parameter.
+
The objective of the implementation of the functions from the OpenCv library is to detect markers on a 3D printed block. The block has 6 ArUco markers on it. One on each side. The markers are placed in the following way:
  
 +
top: 30, bottom: 31, front: 33, back: 34, right: 35, left: 36
  
=== How to use the functions from the umission ===
+
The functions are only tested with this specific block, but it should also work with other markers if the last digit in their ID corresponds to those on the blocks. eg the numbers {50, 51, 53, 54, 55, 56}
 +
== Settings ==
  
When a new detection of AcUco markers is wantet, simply call the function:
+
Some of the settings are dependable of the printed ArUcu markers and the hardware (camera) used to detect. So the first thing to do, when starting a new project is to check and if necessary update this parameter.
 +
 
 +
=== markerDictionary ===
 +
 
 +
The DICT_4X4_100 predefined dictionary is used in this code. DICT_4X4_100 means that the marker is a grid of 4 by 4 black or white squares and valid marker Id are from 0 to 99.
 +
Change the variable markerDictionary if it desired to be able to detect other markers.
 +
 +
===arucoSqaureDimentions===
 +
The physical size of the markers influences the scale of the translation vector. In this setup, the markers with Id 30 and 31 are 10 cm the other 4 markers are 2 cm. A variable arucoSqaureDimentionsSmall is used to scale the vector if it has detected a small marker
 +
Change the arucoSqaureDimentions and/or arucoSqaureDimentionsSmall, if it is desired to detect markers of other sizes.
 +
 
 +
===cameraMatrix and distanceCoefficients===
 +
To estimate the position of the markers is a camera matrix and distance coefficients needed. The file "ILoveCameraCalibration" contains these variables. At the beginning of the program is the variable loaded from the file. The camera matrix and distance coefficients can also be obtained by running the camera calibration process. The camera calibration process changes the variables in the file.
 +
It is recommended to run the camera calibration process, to be sure that the values in the file not have been obtained on another robot.
 +
 
 +
== How to use the functions from the umission ==
 +
 
 +
When a new detection of AcUco markers is wanted, simply call the function:
 
  cam->startWebcamMonitoring();
 
  cam->startWebcamMonitoring();
  
The function takes a picture and run trough all the AruCo functions. The results is saved in an array of structs called arUcoVal. The values are directly azzessable fra umission. For example can the distance to the AruCo marker 30, be accessed in the following way:
+
The function takes a picture and runs through all the AruCo functions. The results are saved in an array of structs called arUcoVal. The values are directly accessible from umission. For example, can the distance to the AruCo marker 30, be accessed in the following way:
 
  cam->arUcoVal[30].disteance2marker;
 
  cam->arUcoVal[30].disteance2marker;
 +
 +
== Rotation and Translation ==
 +
 +
 +
== Camera Calibration ==
 +
The Ucamera class also include functions to find the camera matrix, by using a checkerboard to calibrate the camera. 
 +
follow the following procedure to calibrate the camera: 
 +
# Measure the size of a single square on the checkerboard and update chessboardDimensions. (be as accurate as possible and use a Caliper)
 +
# Count the number of squares in each row and column and subtract 1. And update chessboardDimensions. (A normal board used for a game of chess has Size(7,7) )
 +
# Then uncomment the function cameraCalibrationProcess(cameraMatrix, distanceCoefficients);
 +
# Run the program.
 +
# Position the checkerboard in front of the camera and confirm by looking at the screen that it has been detected.
 +
# Press space to save the frame (in the image window, not the terminal).
 +
# Move the checkerboard to a new position and repeat from step 5.
 +
# When more than 15 frames have been saved the enter button can be pushed to calibrate. 15 is the minimum frames the code will accept, but it is advisable to take 20+. The more frames the better result. 
 +
# When the terminal writes “calibrated and saved", exit the calibration by pressing ESC.
 +
# The cameraMatrix and the distanceCoefficients are saved to a file called ILoveCameraCalibration. The function loadCameraCalibration loads the values from the file. The function loadCameraCalibration is called by the UCamera constructor
 +
 +
 +
Last updated by --[[User:S130067|S130067]] ([[User talk:S130067|talk]]) 18:13, 26 August 2019 (CEST)

Revision as of 18:13, 26 August 2019

Contents

ArUco functions and camera calibration overview

The ArUco functions in the camera class are meant as an inspiration, to give a starting point to people, who want to use the OpenCv ArUco library.

The ArUcu module from the OpenCv library is used to detect the markers. The library can be downloaded on this website, where there also is some information about the functions from the library.

The objective of the implementation of the functions from the OpenCv library is to detect markers on a 3D printed block. The block has 6 ArUco markers on it. One on each side. The markers are placed in the following way:

top: 30, bottom: 31, front: 33, back: 34, right: 35, left: 36

The functions are only tested with this specific block, but it should also work with other markers if the last digit in their ID corresponds to those on the blocks. eg the numbers {50, 51, 53, 54, 55, 56}

Settings

Some of the settings are dependable of the printed ArUcu markers and the hardware (camera) used to detect. So the first thing to do, when starting a new project is to check and if necessary update this parameter.

markerDictionary

The DICT_4X4_100 predefined dictionary is used in this code. DICT_4X4_100 means that the marker is a grid of 4 by 4 black or white squares and valid marker Id are from 0 to 99. Change the variable markerDictionary if it desired to be able to detect other markers.

arucoSqaureDimentions

The physical size of the markers influences the scale of the translation vector. In this setup, the markers with Id 30 and 31 are 10 cm the other 4 markers are 2 cm. A variable arucoSqaureDimentionsSmall is used to scale the vector if it has detected a small marker Change the arucoSqaureDimentions and/or arucoSqaureDimentionsSmall, if it is desired to detect markers of other sizes.

cameraMatrix and distanceCoefficients

To estimate the position of the markers is a camera matrix and distance coefficients needed. The file "ILoveCameraCalibration" contains these variables. At the beginning of the program is the variable loaded from the file. The camera matrix and distance coefficients can also be obtained by running the camera calibration process. The camera calibration process changes the variables in the file. It is recommended to run the camera calibration process, to be sure that the values in the file not have been obtained on another robot.

How to use the functions from the umission

When a new detection of AcUco markers is wanted, simply call the function:

cam->startWebcamMonitoring();

The function takes a picture and runs through all the AruCo functions. The results are saved in an array of structs called arUcoVal. The values are directly accessible from umission. For example, can the distance to the AruCo marker 30, be accessed in the following way:

cam->arUcoVal[30].disteance2marker;

Rotation and Translation

Camera Calibration

The Ucamera class also include functions to find the camera matrix, by using a checkerboard to calibrate the camera.  follow the following procedure to calibrate the camera: 

  1. Measure the size of a single square on the checkerboard and update chessboardDimensions. (be as accurate as possible and use a Caliper)
  2. Count the number of squares in each row and column and subtract 1. And update chessboardDimensions. (A normal board used for a game of chess has Size(7,7) )
  3. Then uncomment the function cameraCalibrationProcess(cameraMatrix, distanceCoefficients);
  4. Run the program.
  5. Position the checkerboard in front of the camera and confirm by looking at the screen that it has been detected.
  6. Press space to save the frame (in the image window, not the terminal).
  7. Move the checkerboard to a new position and repeat from step 5.
  8. When more than 15 frames have been saved the enter button can be pushed to calibrate. 15 is the minimum frames the code will accept, but it is advisable to take 20+. The more frames the better result. 
  9. When the terminal writes “calibrated and saved", exit the calibration by pressing ESC.
  10. The cameraMatrix and the distanceCoefficients are saved to a file called ILoveCameraCalibration. The function loadCameraCalibration loads the values from the file. The function loadCameraCalibration is called by the UCamera constructor


Last updated by --S130067 (talk) 18:13, 26 August 2019 (CEST)

Personal tools
Namespaces

Variants
Actions
Navigation
Toolbox