Juan José Madrigal's profile

Computer vision: Test Pokémon

Test pokémon utilizando visión artificial
Pokémon test using computer vision

En este corto proyecto academico, realicé un test pokémon inspirado en los test de personalidad que te realizan al jugar el juego 'Pokémon mundo misterioso', donde respondes unas cuantas preguntas y al final te dicen que pokémon encaja con tu personalidad; todo esto, interactuando a través de visión artificial, utilizando figuras físicas que eran reconocidas y clasificadas por la cámara web. Este fue el resultado que obtuve, bastante bueno como prototipo pero con posibilidad de mejorarlo utilizando algoritmos más complejos.

In this short academic project, i made a pokémon test, inpired in the personality's test of the games 'Pokémon Mistery Dungeon', where you answer a few questions and the game tell you which pokémon is more like your personality; but this time you interact with computer vision, using real figures that the webcam recognize and classify. This is the result i obtained, pretty good prototype but easily can be fixed with more complex algoritms

Video demostrativo de lo que ve el usuario / Test video from user view
En el video anterior se muestra una prueba de funcionamiento, donde se pueden observar algunos errores de detección y clasificación. No obstante, a continuación te presento el desglose de todo lo realizado para obtener este resultado.

The last video shows a test of the program, where you can see little errors in the detection and classifying of figures. However, below you can see the 'back stage' of this project and what i made to obtained this result.
Concepto / Concept

Primero realicé una mini etapa de planeación e ideación del proyecto, ya que debía hacer algo con detección de formas y clasificarlas. Fue en ese momento que se me ocurrió el test pokémon y comencé a plantear las preguntas y el método como el programa iba a definir cual era tu pokémon. Decidí entonces utilizar 4 figuras: un cuadrado, un círculo, un triángulo y una estrella, los cuales, además, tendrían un color diferente cada uno, siendo azul, rojo, amarillo y rosa respectivamente. Por último cada una tendría una palabra escrita que sería una estación, siendo invierno, otoño, verano y primavera respectivamente.

First, i ideated and planned the project, as i had to do something with detection and classifying of figures. In that moment i decided to do the pokémon test and started to propose the questions and which method would the program use to define which pokémon adjust to user's answers. So i decided use 4 figures: square, circle, triangle and a star, whichones, also, would have a different color, being blue, red, yellow and rose respectively. In last, each figure would have an season writed, being winter, autumn, summer and spring respectively.
Las preguntas fueron:

1. ¿Cuál es tu color favorito?
2. ¿Cuál es tu figura favorita?
3. ¿Cuál es tu estación favorita?

Preguntas que se pueden responder perfectamente con las figuras dadas.

De acuerdo a tu respuesta se iría acumulando un contador (de cuadrado, círculo, etc), por lo que las condiciones de decisión fueron las siguientes:

- 2 veces cuadrado: Naturaleza Fuerte - Pokémon: Riolu
- 2 veces círculo: Naturaleza Alegre - Pokémon: Dedenne
- 2 veces triángulo: Naturaleza Miedosa - Pokémon: Cyndaquil
- 2 veces estrella: Naturaleza Rara - Pokémon: Meowth
- 3 veces la misma figura: Naturaleza Audaz - Pokémon: Rockruff

Hay una opción adicional que es que la persona elija 1 de cada 1, para este se puso un generador de números aleatorios del 0 al 255. Si el número era mayor a 125 daba un resultado y si era menor, otro.

- 1 de cada 1 & mayor a 125 el número aleatorio: Naturaleza Osada - Pokémon: Bagon
- 1 de cada 1 & menor a 125 el número aleatorio: Naturaleza Grosera - Pokémon: Pawniard

The questions were:

1. Whichone is your favorite color?
2. Whichone is your favorite figure?
3. Whichone is your favorite season?

Questions that the user can answer with the figures perfectly.

In accordance to the user's answers, a counter (of square, circle, etc) would increment, so the conditions for deciding your pokémon were:

- 2 times square: Nature Hardy - Pokémon: Riolu
- 2 times circle: Nature Jolly - Pokémon: Dedenne
- 2 times triangle: Nature Timid - Pokémon: Cyndaquil
- 2 times star: Nature Rare - Pokémon: Meowth
- 3 times the same figure: Nature Bold - Pokémon: Rockruff

Another option were if the user chooses a different figure in each question, so there were a random number generator from 0 to 255. If random number were higher than 125 the user obtain one result, if were lower, user obtain another result.

- 1 time each figure & random number higher than 125: Nature Brave - Pokémon: Bagon
- 1 time each figure & random number lower than 125: Nature Sassy - Pokémon: Pawniard
¿Cómo funciona? / How it works?

A continuación podrás ver el código desarrollado en python 3 con la librería Opencv.

Next you can see the code developed using python 3 with Opencv library.

Enlace al código / Link to the code: https://pastebin.com/BzQzXz9R 

Basicamente, el código tiene 2 partes:

1. Segmentación del fondo: Se hace una lectura del tono y la saturación de la imagen para luego calcular los promedios de tono, saturación y desviación estándar, con los cuales luego se borrará el color verde del fondo en tiempo real y permite poner cualquier otra cosa de fondo, en este caso, que pokémon eres. Por esto se debe usar un 'Chroma', para buscar tener un fondo verde uniforme.
A continuación un video de lo que ve la cámara al segementar el fondo.

Basically, the code have 2 parts:

1. Background segmentation: The program does a tone and saturation lecture of the picture to later compute the mean of those and the standard deviation. With these values it erase the green color of the chroma key in real time and allows to put whatever you want instead, in this case, which pokémon you are. Is because this that the project needs a Chroma Key, so we have a nice uniform green background.
Next, a video showing what the webcam sees when segments the background.
Video que muestra la segmentación de fondo / Video that shows the background segmentation
Chroma key usado durante el proyecto / Chroma key used during this project
2. Detección y clasificación de figuras: El resto del programa consiste en una técnica conocida como match template. Primero dibujamos un cuadrado que será nuestra área de interés y posteriormente comparamos el contenido de esa zona con una imágenes diseñadas previamente, y el programa se encarga de buscar similitudes entre lo que está viendo la webcam y la imagen cargada. Si las similitudes superan cierto umbral, la figura es clasificada.

Se hicieron varias pruebas de templates, tanto a blanco y negro como a color. Funciona mucho mejor binarizado (blanco y negro) ya que hay colores que se confunden con el verde o que son muy claros para que la cámara vea figuras definidas, por lo que es mucho mejor trabajar con siluetas.

2. Detection and classifying: The rest of the code consist in a technique know as match template. First we draw an square that would be our region of interest (ROI) and, later, we compare the pixels in that ROI with some pictures we made before. The program is responsible of find similitudes between what webcam sees and the loaded picture. If the similitudes surpass a threshold, the figure is classifyed.

They were made some test of the templates, both black and white as full color. It have better results with a binarized picture (black and white) because there are colors that get confuse with green or they are very clear to the webcam, so it's much better work with silhouettes.
Otros recursos utilizados / Other sources

Aquí están el resto de recursos utilizados para el proyecto.
Here are the rest of sources used to the project.
Video que explica lo que debe hacer el usuario / Video that explains what user have to do
Videos de los posibles resultados / Videos of the possible results
Créditos

Juan José Madrigal - Programador & Conceptualización - Programmer & Concept

Computer vision: Test Pokémon
Published:

Computer vision: Test Pokémon

Todas las imágenes de pokémon les pertenecen a The Pokémon Company, y solo fueron utilizadas con fines académicos.

Published: