├── .gitignore ├── LICENSE ├── README.md └── src ├── arduino └── arduino.ino ├── fritzing └── diagrama.fzz ├── img ├── diagrama_bb.png ├── ex.png ├── ex1.JPG └── ex2.JPG └── processing └── processing.pde /.gitignore: -------------------------------------------------------------------------------- 1 | # Compiled Object files 2 | *.slo 3 | *.lo 4 | *.o 5 | *.obj 6 | 7 | # Precompiled Headers 8 | *.gch 9 | *.pch 10 | 11 | # Compiled Dynamic libraries 12 | *.so 13 | *.dylib 14 | *.dll 15 | 16 | # Fortran module files 17 | *.mod 18 | 19 | # Compiled Static libraries 20 | *.lai 21 | *.la 22 | *.a 23 | *.lib 24 | 25 | # Executables 26 | *.exe 27 | *.out 28 | *.app 29 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2016 Francisco de Assis Souza Rodrigues 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Reconhecimento Facial com Arduino+Processing+OpenCV 2 | Visão computacional: simples projeto de reconhecimento facial. 3 | 4 | ![](https://github.com/rodriguesfas/Reconhecimento-Facial-Com-Arduino-Processing-OpenCV/blob/master/src/img/ex1.JPG) 5 | ![](https://github.com/rodriguesfas/Reconhecimento-Facial-Com-Arduino-Processing-OpenCV/blob/master/src/img/ex2.JPG) 6 | ![](https://github.com/rodriguesfas/Reconhecimento-Facial-Com-Arduino-Processing-OpenCV/blob/master/src/img/ex.png) 7 | - Esse projeto, mostra um exemplo simples de detecção facial com opencv e rastreamento de face com processing e arduino. 8 | 9 | # Software 10 | - Arduino 11 | - Processing 12 | - OpenCV 13 | - Lib OpenCV P/Processing 14 | - Fritzing 15 | 16 | # Desenho esquemático 17 | ![](https://github.com/rodriguesfas/Reconhecimento-Facial-Com-Arduino-Processing-OpenCV/blob/master/src/img/diagrama_bb.png) 18 | 19 | # Créditos 20 | -------------------------------------------------------------------------------- /src/arduino/arduino.ino: -------------------------------------------------------------------------------- 1 | /** =========================================================================== 2 | * @ Software: Reconhecimento Facial 3 | * @ Data: 08 de março de 2016 4 | * @ Versao: 0.1 5 | * @ Developer: Rodrigues F.A.S. 6 | * @ Site: https://rodriguesfas.github.io 7 | * ========================================================================================= 8 | */ 9 | 10 | 11 | // Inclui as bibliotecas.. 12 | #include 13 | #include 14 | #include 15 | 16 | // Cria os objetos dos servos motores(controladores).. 17 | Servo servoHor; 18 | Servo servoVer; 19 | 20 | // Define uma posiçao inicial para cada servo motor.. 21 | int valorHor = 90; 22 | int valorVer = 90; 23 | 24 | ThreadController cpu; 25 | Thread threadServos; 26 | 27 | int dados; 28 | 29 | /** 30 | * setup - Configuraçoes iniciais. 31 | */ 32 | void setup() { 33 | Serial.begin(9600); // Inicia uma comunicaço serial.. 34 | 35 | // Define a configuraçao das portas em que os servos estao conectados... 36 | servoHor.attach(10); 37 | servoVer.attach(11); 38 | 39 | threadServos.setInterval(15); // tempo de espera. 40 | threadServos.onRun(lerServos); // metodo solicitador. 41 | 42 | // adiciona thread filha a mae. 43 | cpu.add(&threadServos); 44 | } 45 | 46 | /** 47 | * loop 48 | */ 49 | void loop() { 50 | cpu.run(); // start thread System. 51 | } 52 | 53 | /** 54 | * lerServos - 55 | */ 56 | void lerServos(){ 57 | if (Serial.available() > 0) { 58 | dados = Serial.read();// leitura da porta serial.. 59 | switch (dados) { 60 | case 'a' : 61 | if (valorHor >= 180) { 62 | valorHor = 180; 63 | } 64 | else { 65 | valorHor += 1; 66 | } 67 | break; 68 | 69 | case 'd' : 70 | if (valorHor <= 0) { 71 | valorHor = 0; 72 | } 73 | else { 74 | valorHor -= 1; 75 | } 76 | break; 77 | 78 | case 's' : 79 | if (valorVer >= 180) { 80 | valorVer = 180; 81 | } 82 | else { 83 | valorVer += 1; 84 | } 85 | break; 86 | 87 | case 'w' : 88 | if (valorVer <= 0) { 89 | valorVer = 0; 90 | } 91 | else { 92 | valorVer -= 1; 93 | } 94 | break; 95 | } 96 | 97 | // estabelece um posiço no servo de acordo com o valor de "val" 98 | servoHor.write(valorHor); 99 | servoVer.write(valorVer); 100 | 101 | //Serial.print(valorHor); 102 | //Serial.print(valorVer); 103 | } 104 | } 105 | 106 | 107 | -------------------------------------------------------------------------------- /src/fritzing/diagrama.fzz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rodriguesfas/Reconhecimento-Facial-Com-Arduino-Processing-OpenCV/8dbf3c80136abd36cb015dcc8ee4a995e45f4086/src/fritzing/diagrama.fzz -------------------------------------------------------------------------------- /src/img/diagrama_bb.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rodriguesfas/Reconhecimento-Facial-Com-Arduino-Processing-OpenCV/8dbf3c80136abd36cb015dcc8ee4a995e45f4086/src/img/diagrama_bb.png -------------------------------------------------------------------------------- /src/img/ex.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rodriguesfas/Reconhecimento-Facial-Com-Arduino-Processing-OpenCV/8dbf3c80136abd36cb015dcc8ee4a995e45f4086/src/img/ex.png -------------------------------------------------------------------------------- /src/img/ex1.JPG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rodriguesfas/Reconhecimento-Facial-Com-Arduino-Processing-OpenCV/8dbf3c80136abd36cb015dcc8ee4a995e45f4086/src/img/ex1.JPG -------------------------------------------------------------------------------- /src/img/ex2.JPG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rodriguesfas/Reconhecimento-Facial-Com-Arduino-Processing-OpenCV/8dbf3c80136abd36cb015dcc8ee4a995e45f4086/src/img/ex2.JPG -------------------------------------------------------------------------------- /src/processing/processing.pde: -------------------------------------------------------------------------------- 1 | /** =========================================================================== 2 | * @ Software: Reconhecimento Facial 3 | * @ Data: 08 de março de 2016 4 | * @ Versao: 0.1 5 | * @ Developer: Rodrigues F.A.S. 6 | * @ Site: https://rodriguesfas.github.io 7 | * ========================================================================================= 8 | */ 9 | 10 | // Inclui as bibliotecas.. 11 | import gab.opencv.*; 12 | import processing.video.*; 13 | import java.awt.Rectangle; 14 | import processing.serial.*; 15 | 16 | Capture video; // Conexao com webcam 17 | OpenCV opencv; // Cerebro 18 | Serial arduinoPort; // Porta comunicação com arduino.. 19 | 20 | /** 21 | * setup - configuração incial... 22 | */ 23 | void setup() { 24 | size(320, 240); /*tamanho da tela.. */ 25 | println(Serial.list()); /* lista todas as portas seriais.. */ 26 | arduinoPort = new Serial(this, Serial.list()[0], 9600); /* configura porta serial.. */ 27 | //frameRate(10); 28 | 29 | String[] cameras = Capture.list(); /* captura uma lista de webcam's ativas hardware.. */ 30 | 31 | /* Verifica se existe alguma webcam disponivel.. */ 32 | if (cameras.length == 0) { 33 | println("Não há câmeras disponíveis para a captura."); /* Notificação usuário.. */ 34 | exit(); /* Feixa aplicação */ 35 | } else { /* Se webcam disponivel .. */ 36 | println("Câmeras disponíveis:"); /* Notifica ao usuário.. */ 37 | 38 | video = new Capture(this, width, height); 39 | opencv = new OpenCV(this, width, height); 40 | opencv.loadCascade(OpenCV.CASCADE_FRONTALFACE); 41 | 42 | video.start(); /* inicia video captura.. */ 43 | } 44 | } 45 | 46 | /** 47 | * draw 48 | */ 49 | void draw() { 50 | //scale(2); 51 | opencv.loadImage(video); 52 | image(video, 0, 0); 53 | Rectangle[] faces = opencv.detect(); 54 | 55 | /* 56 | fill(255); 57 | rect(10, 210, 50, 30); 58 | rect(580, 210, 50, 30); 59 | 60 | fill(0); 61 | triangle(30, 215, 15, 225, 30, 235); 62 | triangle(610, 215, 610, 235, 625, 225); 63 | */ 64 | 65 | noFill(); 66 | stroke(0, 255, 0); /* cor das retas.. */ 67 | strokeWeight(3); /* largura das retas */ 68 | 69 | //println(faces.length); 70 | 71 | for (int i = 0; i < faces.length; i++) { 72 | // Imprime no monitor os valores das posições da face.. 73 | //println(faces[i].x + "," + faces[i].y); 74 | 75 | rect(faces[i].x, faces[i].y, faces[i].width, faces[i].height); 76 | 77 | if (faces[i].x < 80) { 78 | //println("Esquerda"); 79 | arduinoPort.write("a"); 80 | } 81 | if (faces[i].x + faces[i].width > 240) { 82 | //println("Direita"); 83 | arduinoPort.write("d"); 84 | } 85 | if (faces[i].y < 80) { 86 | //println("Cima"); 87 | arduinoPort.write("w"); 88 | } 89 | if (faces[i].y + faces[i].height > 160) { 90 | //println("Baixo"); 91 | arduinoPort.write("s"); 92 | } 93 | } /* FIM for */ 94 | } /* FIM draw */ 95 | 96 | /** 97 | * captureEvent 98 | */ 99 | void captureEvent(Capture c) { 100 | c.read(); 101 | } 102 | 103 | /** 104 | * mousePressed 105 | */ 106 | /* 107 | void mousePressed() { 108 | println("mouseX: "+mouseX +" mouseY: "+mouseY); 109 | 110 | //click da esquerda.. 111 | if ((mouseX <= 60) && (mouseX >= 11) && (mouseY >= 211) && (mouseY <= 239)) { 112 | arduinoPort.write('e'); 113 | println("ESQUERDA"); 114 | } 115 | 116 | //Click da direita.. 117 | if ((mouseX <= 630) && (mouseX >= 581) && (mouseY >= 211) && (mouseY <= 239)) { 118 | arduinoPort.write('d'); 119 | println("DIREITA"); 120 | } 121 | } 122 | */ 123 | --------------------------------------------------------------------------------