# Coin Recognition Approach in Social Environments Using Virtual Organizations of Agents
## 4 Coins Recognition Process
### Cardboard Detection  
In order to determine what type of coin appears in an image, it is necessary to know its size and colour. This work is based on the use of a smartphone, where the location of the camera is not fixed, and its position varies depending on the movement of the user. The movements that can be made  
Figure 3: Stages of the proposed process for coins recognition.  
with the smartphone during recognition make the distance between the camera and the coins will be variable. Depending on the distance of the coins to the camera, their sizes are different due to perspective of the image taken. Also, if the camera is not perpendicularly located on the objects to be recognised, a shadow is cast on each coin making detection difficult or making the coin size larger than the actual size. Therefore, if the position of the camera is unknown, a perspective effect is produced and knowing precisely the size of the coins becomes a complex task. It is of vital importance to add in the field of camera vision, a reference object with known dimensions. In our case study, and at the request of users, we have opted for the use of black cardboard that must always be visible during the recognition process. In order to obtain a relative scale of the dimension of the elements appearing in the image, the distances between the four vertices of our reference object are determined, and a scale is obtained. Next, we explain the steps followed for detecting our reference object: (1) Detect borders; (1a) Resize the image to a fixed size; (1b) Convert the input image and detect the edges using Canny Edge detection algorithm. Once all the edges in the image have been extracted, it is necessary to obtain the largest contour by obtaining the four points of the quadrilateral. In order to do this, the following process has been carried out: (2) Obtain the vertices of our reference object; (2a) Obtain the contours of the image; (2b) From each one of the contours determine its area, ordering them and obtaining the widest; (2c) Generate the convex hull of the contour using approxPolyDP function in order to obtain the polygon of minimum area containing a set of points; and finally (2d) Determine the 4 points of the quadrilateral. Next, Algorithm 1 shows the algorithm used in this phase.  
```
Input: Image matrix: matrix Output: Polygon corresponding to cardboard reference
```  
```
1. // 1) Detect borders
2. grayScaleMatrix \(\leftarrow\) GrayScale(matrix) 1a)
3. resizedMatrix \(\leftarrow\) Resize(grayScaleMatrix)
4. blurMatrix \(\leftarrow\) BlurFilter(resizedMatrix)
5. blurMatrix \(\leftarrow\) BlurFilter(resizedMatrix)
6. thr1 Histeresis \(\leftarrow\) 30
7. thr2 Histeresis \(\leftarrow\) 100
8. edgesMatrix \(\leftarrow\) Canny(blurMatrix, thr1 Histeresis, thr2 Histeresis)
9. // 2) Obtain vertices of cardboard
10. retreivalMode \(\leftarrow\) RETR_EXTERNAL
11. method \(\leftarrow\) CHAIN_APPROX_NONE
12. contours \(\leftarrow\) findContours(edgesMatrix, retreivalMode, method) 2a)
13. for each contour in contoursdo
14. area \(\leftarrow\) calculateArea(contour)
15. areasCountourCollection.insert(<contour,area>)
16. endfor
17. hull \(\leftarrow\) convexHull(widestAreaContour) 2c)
18. epsilonAccuracy \(\leftarrow\) 20
19. polygon \(\leftarrow\) approxPolyDP(hull,epsilonAccuracy) 2d)
20. ifisQuadrilateral(polygon)then
21. return polygon
22. else
23. return cardboardNotFound
```  
**Algorithm 1**Pseudocode of cardboard detection algorithm.  
Figure 4 shows a real image of the result after the application of the algorithm used. As it can be seen in the image, the four vertices of the reference object that has been used to correct the effect of the perspective of the image have been correctly obtained.