mirror of
https://github.com/AntoineHX/LivingMachine.git
synced 2025-05-04 05:40:46 +02:00
Ajout de fonctionnalités sur Navy
This commit is contained in:
parent
e2bf98b7f8
commit
25b7096cce
113 changed files with 6698 additions and 1857 deletions
|
@ -5,10 +5,8 @@
|
|||
* \brief Figure Imposé : Suivi d'un objet coloré.
|
||||
*
|
||||
* \details Suivie d'un Kirby (Rose) ou d'une étoile (Jaune) par une caméra avec mode interface utilisateur ou configuration
|
||||
* \bug (Résolu ?) SFML ne supporte qu'un nombre limité de sprite en fonction du PC
|
||||
* \bug Affichage OpenCV incompatible avec SFML
|
||||
* \todo Optimisation du chargement de la frame en image SFML
|
||||
* \todo Verifier les angles du RESET
|
||||
*/
|
||||
|
||||
|
||||
|
@ -234,8 +232,8 @@ sf::Vector2i PosMouse = sf::Mouse::getPosition(window);
|
|||
|
||||
tracking = 0;
|
||||
//Reset Position moteur
|
||||
angle[0]=0; //ANGLES A VERIFIER
|
||||
angle[1]=0;
|
||||
angle[0]=60; //ANGLES A VERIFIER
|
||||
angle[1]=100;
|
||||
controle_moteur(angle);
|
||||
|
||||
aye.play();
|
||||
|
@ -284,5 +282,28 @@ sf::Vector2i PosMouse = sf::Mouse::getPosition(window);
|
|||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
/*
|
||||
//musique
|
||||
if(aye.getStatus()==sf::Sound::Stopped){
|
||||
aye.setPitch(0.5);
|
||||
aye.setVolume(150);
|
||||
aye.setLoop(true);
|
||||
aye.play();
|
||||
}
|
||||
*/
|
||||
|
||||
/*
|
||||
//Link
|
||||
sf::Texture txLink;
|
||||
sf::Sprite Link;
|
||||
|
||||
if (!txLink.loadFromFile("Stock SFML/link.png")){
|
||||
printf("Erreur chargement image SFML\n" );
|
||||
break;
|
||||
}
|
||||
|
||||
Link.setTexture(txLink);
|
||||
Link.setPosition(sf::Vector2f(posX-75, posY-75));
|
||||
|
||||
window.draw(Link);
|
||||
*/
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
|
||||
EXEC= Navy KirbyTrack
|
||||
EXEC= Navy KirbyTrack
|
||||
|
||||
LDFLAGS = -lsfml-graphics -lsfml-window -lsfml-system -lsfml-audio `pkg-config opencv --libs`
|
||||
CFLAGS = -Wall -g3 -pg `pkg-config opencv --cflags`
|
||||
|
|
|
@ -1,14 +0,0 @@
|
|||
all : KirbyTrack
|
||||
|
||||
|
||||
KirbyTrack : KirbyTrack.o
|
||||
gcc -o $@ $< `pkg-config opencv --libs` -lsfml-graphics -lsfml-window -lsfml-audio -lsfml-system
|
||||
|
||||
KirbyTrack.o : KirbyTrack.c
|
||||
gcc -o $@ -c $< `pkg-config opencv --cflags`
|
||||
|
||||
clean:
|
||||
rm -rf *.o
|
||||
|
||||
mrproper : clean
|
||||
rm -rf KirbyTrack
|
294
Code/Navy.c
294
Code/Navy.c
|
@ -5,21 +5,79 @@
|
|||
* \brief Figure Libre
|
||||
*
|
||||
* \details Suivie d'un Kirby (Rose) ou d'une étoile (Jaune) par une caméra avec mode interface utilisateur ou configuration
|
||||
*
|
||||
* \todo Reprendre nouvelle structure SFML de Kirbytrack
|
||||
*
|
||||
* \todo Stabiliser detection faciale
|
||||
*/
|
||||
|
||||
#include "fonction.h"
|
||||
//#include "fonction.c" //Pour le problème de référence indéfinie à la compilation
|
||||
|
||||
|
||||
/**
|
||||
* \fn int main(int argc, char* argv[])
|
||||
* \brief Entrée du programme
|
||||
* \author Antoine / Jacques
|
||||
* \return EXIT_SUCCESS : Arrêt normal du programme, EXIT_FAILURE : Le programme a rencontrée une erreur au cours de son execution
|
||||
*/
|
||||
int main(int argc, char* argv[])
|
||||
{
|
||||
//Initialisations
|
||||
//Initialisations
|
||||
int height,width; //parameters of the image we are working on
|
||||
int posX, posY; //Position objet
|
||||
int boucle;
|
||||
double angle[2] = {100,100};
|
||||
int tracking;
|
||||
int boucle = 1; //On effectuera la boucle principale au moins une fois
|
||||
int i;
|
||||
float scale_x, scale_y;
|
||||
int BGR[3];
|
||||
|
||||
//Initialisation detection visage
|
||||
CvHaarClassifierCascade* cascade = init_cascade();
|
||||
face* tab_face[MAX_FACE];
|
||||
for (i=0;i<2;i++){
|
||||
tab_face[i] = (face*)malloc(sizeof(face));
|
||||
}
|
||||
int rdy[MAX_FACE];
|
||||
|
||||
//Link
|
||||
sf::Texture txLink;
|
||||
sf::Sprite Link;
|
||||
|
||||
if (!txLink.loadFromFile("Stock SFML/link.png")){
|
||||
printf("Erreur chargement image SFML\n" );
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
sf::Vector2u vec_link = txLink.getSize();
|
||||
|
||||
//Ganon
|
||||
sf::Texture txGanon;
|
||||
sf::Sprite Ganon;
|
||||
|
||||
if (!txGanon.loadFromFile("Stock SFML/ganon.png")){
|
||||
printf("Erreur chargement image SFML\n" );
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
sf::Vector2u vec_ganon = txGanon.getSize();
|
||||
|
||||
//Initialisation SFML
|
||||
|
||||
sf::Texture txFlux;
|
||||
sf::Sprite spFlux;
|
||||
sf::Image imFlux;
|
||||
sf::Event event;
|
||||
|
||||
//Chargement son
|
||||
sf::Music aile;
|
||||
if (!aile.openFromFile("Stock SFML/aile.ogg"))
|
||||
return EXIT_FAILURE;
|
||||
aile.setLoop(true);
|
||||
aile.play();
|
||||
|
||||
sf::Music hey;
|
||||
if (!hey.openFromFile("Stock SFML/hey_listen.ogg"))
|
||||
return EXIT_FAILURE;
|
||||
sf::Music watchout;
|
||||
if (!watchout.openFromFile("Stock SFML/watchout.ogg"))
|
||||
return EXIT_FAILURE;
|
||||
|
||||
//Ouverture flux camera
|
||||
CvCapture* capture = cvCaptureFromCAM( 0 );
|
||||
|
@ -27,52 +85,28 @@ int main(int argc, char* argv[])
|
|||
if( !capture ){
|
||||
printf("ERROR: capture is NULL \n" );
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
}
|
||||
|
||||
//Initialisation frame
|
||||
|
||||
// grab an image from the capture
|
||||
IplImage* frame = cvQueryFrame( capture );
|
||||
height = frame->height;
|
||||
width = frame->width;
|
||||
CvSize size = cvSize(width,height);
|
||||
IplImage* hsv_frame = cvCreateImage(size, IPL_DEPTH_8U, 3); // image converted to HSV plane
|
||||
IplImage* threshold = cvCreateImage(size, IPL_DEPTH_8U, 1);
|
||||
|
||||
//Initialisation detection visage
|
||||
CvHaarClassifierCascade* cascade = init_cascade();
|
||||
|
||||
#ifdef SFML
|
||||
//Initialisation SFML
|
||||
sf::Texture txFlux;
|
||||
sf::Sprite spFlux;
|
||||
sf::Image imFlux;
|
||||
sf::Event event;
|
||||
|
||||
tracking = 0; //Pas de tracking de base en mode SFML
|
||||
//Création de la fenetre principale
|
||||
sf::RenderWindow window(sf::VideoMode(width+300, height), "KirbyTrack");
|
||||
#endif
|
||||
|
||||
//Controle couleur
|
||||
#ifdef KIRBY
|
||||
int tab_HSV[6] = {152,179,48,255,101,255};
|
||||
#endif
|
||||
// get the image data
|
||||
height = frame->height;
|
||||
width = frame->width;
|
||||
|
||||
// capture size -
|
||||
// CvSize size = cvSize(width,height);
|
||||
|
||||
|
||||
#ifdef ETOILE
|
||||
int tab_HSV[6] = {20,30,100,255,100,255};
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG
|
||||
//Affichage du panneau de config
|
||||
config(tab_HSV,tab_HSV+1,tab_HSV+2,tab_HSV+3,tab_HSV+4,tab_HSV+5);
|
||||
//Création de la fenetre principale
|
||||
sf::RenderWindow window(sf::VideoMode(width, height), "KirbyTrack");
|
||||
|
||||
|
||||
boucle = 1;
|
||||
tracking = 0; //Tracking de base en mode CONFIG
|
||||
#endif
|
||||
|
||||
while(boucle)
|
||||
{
|
||||
|
||||
#ifdef SFML
|
||||
boucle = window.isOpen();
|
||||
|
||||
// on inspecte tous les évènements de la fenêtre qui ont été émis depuis la précédente itération
|
||||
|
@ -82,7 +116,6 @@ int main(int argc, char* argv[])
|
|||
if (event.type == sf::Event::Closed)
|
||||
window.close();
|
||||
}
|
||||
#endif
|
||||
|
||||
// Get one frame
|
||||
frame = cvQueryFrame( capture );
|
||||
|
@ -93,20 +126,16 @@ int main(int argc, char* argv[])
|
|||
}
|
||||
|
||||
|
||||
pface tab_face[2];
|
||||
detect_and_draw(frame,cascade,tab_face);
|
||||
|
||||
#ifdef SFML
|
||||
//Affichage SFML
|
||||
|
||||
//Affichage SFML
|
||||
/* Clear the screen */
|
||||
window.clear(sf::Color::White);
|
||||
|
||||
//Conversion de la frame en image smfl
|
||||
/*if(image_CV2SFML(frame, imFlux)){
|
||||
printf("Erreur conversion OpenCV-SFML\n");
|
||||
break;
|
||||
}
|
||||
*/
|
||||
//Affichage de la frame
|
||||
|
||||
//Le chargement pourrait etre plus optimisé en créant nous me l'image SFML en parcourant l'IplImage
|
||||
|
||||
//Enregistrement de la frame openCV
|
||||
cvSaveImage("Stock SFML/temp.jpg", frame);
|
||||
|
@ -118,133 +147,56 @@ int main(int argc, char* argv[])
|
|||
}
|
||||
|
||||
spFlux.setTexture(txFlux);
|
||||
|
||||
window.draw(spFlux);
|
||||
|
||||
//TEST SFML
|
||||
sf::Vector2i PosMouse = sf::Mouse::getPosition(window);
|
||||
//Detection du bouton tracking
|
||||
if (sf::Mouse::isButtonPressed(sf::Mouse::Left)&&(PosMouse.x>640)&&(PosMouse.x<760)&&(PosMouse.y>0)&&(PosMouse.y<120)){
|
||||
//printf("\n\n\n OK \n\n\n");
|
||||
if (tracking){ tracking = 0;}
|
||||
else tracking = 1;
|
||||
cvWaitKey(100);
|
||||
}
|
||||
//printf("Pos Mouse : %d %d \n", PosMouse.x, PosMouse.y);
|
||||
|
||||
//Dessin du bouton de tracking
|
||||
sf::Texture txBut;
|
||||
sf::Sprite button_tracking;
|
||||
|
||||
if (!txBut.loadFromFile("Stock SFML/button.png")){
|
||||
printf("Erreur chargement image SFML\n" );
|
||||
break;
|
||||
}
|
||||
|
||||
button_tracking.setTexture(txBut);
|
||||
button_tracking.setScale(0.5,0.5);
|
||||
button_tracking.setPosition(sf::Vector2f(width+20, 20));
|
||||
|
||||
if(tracking){ button_tracking.setColor(sf::Color::Green); }
|
||||
else{ button_tracking.setColor(sf::Color::Red); }
|
||||
|
||||
window.draw(button_tracking);
|
||||
|
||||
//Dessin du bouton reset
|
||||
sf::Texture txBut2;
|
||||
sf::Sprite button_reset;
|
||||
|
||||
if (!txBut2.loadFromFile("Stock SFML/button.png")){
|
||||
printf("Erreur chargement image SFML\n" );
|
||||
break;
|
||||
}
|
||||
|
||||
button_reset.setTexture(txBut2);
|
||||
button_reset.setScale(0.5,0.5);
|
||||
button_reset.setPosition(sf::Vector2f(width+20, 100));
|
||||
|
||||
window.draw(button_reset);
|
||||
/*
|
||||
//musique
|
||||
if(aye.getStatus()==sf::Sound::Stopped){
|
||||
aye.setPitch(0.5);
|
||||
aye.setVolume(150);
|
||||
aye.setLoop(true);
|
||||
aye.play();
|
||||
}
|
||||
*/
|
||||
|
||||
/*
|
||||
//Ajout du texte
|
||||
sf::Font font;
|
||||
if (!font.loadFromFile("Stock SFML/arial.ttf")){
|
||||
printf("Erreur chargement police SFML\n" );
|
||||
break;
|
||||
}
|
||||
|
||||
sf::Text text;
|
||||
// choix de la police à utiliser
|
||||
text.setFont(font); // font est un sf::Font
|
||||
|
||||
// choix de la chaîne de caractères à afficher
|
||||
text.setString("Tracking Moteur");
|
||||
|
||||
// choix de la taille des caractères
|
||||
text.setCharacterSize(24); // exprimée en pixels, pas en points !
|
||||
|
||||
//text.setFillColor(sf::Color::Black);
|
||||
text.setColor(sf::Color::Black);
|
||||
|
||||
text.setPosition(sf::Vector2f(width+100, 35));
|
||||
|
||||
window.draw(text);
|
||||
*/
|
||||
/*
|
||||
//Link
|
||||
sf::Texture txLink;
|
||||
sf::Sprite Link;
|
||||
|
||||
if (!txLink.loadFromFile("Stock SFML/link.png")){
|
||||
printf("Erreur chargement image SFML\n" );
|
||||
break;
|
||||
}
|
||||
|
||||
Link.setTexture(txLink);
|
||||
Link.setPosition(sf::Vector2f(posX-75, posY-75));
|
||||
Link.setOrigin(sf::Vector2f(vec_link.x/2,vec_link.y/2));
|
||||
Link.setPosition(sf::Vector2f(tab_face[0]->point.x, tab_face[0]->point.y));
|
||||
scale_x = tab_face[0]->largeur / (1.0*vec_link.x);
|
||||
scale_y = tab_face[0]->largeur / (1.0*vec_link.y);
|
||||
//printf("%d , %d et%lf, %lf\n",tab_face[0]->largeur,vec_link.x,scale_x,scale_y);
|
||||
Link.setScale(sf::Vector2f(scale_x, scale_y));
|
||||
|
||||
Ganon.setTexture(txGanon);
|
||||
Ganon.setOrigin(sf::Vector2f(vec_ganon.x/2,vec_ganon.y/2));
|
||||
Ganon.setPosition(sf::Vector2f(tab_face[1]->point.x, tab_face[1]->point.y));
|
||||
scale_x = tab_face[1]->largeur / (1.0*vec_ganon.x);
|
||||
scale_y = tab_face[1]->largeur / (1.0*vec_ganon.y);
|
||||
Ganon.setScale(sf::Vector2f(scale_x, scale_y));
|
||||
|
||||
window.draw(Link);
|
||||
*/
|
||||
window.draw(Ganon);
|
||||
|
||||
/* Update the window */
|
||||
|
||||
window.display();
|
||||
#endif
|
||||
|
||||
/*
|
||||
if(tracking){
|
||||
//Mouvements moteurs
|
||||
//printf("-PREMAJ_ANGLE...: %d %d\n",width,height);
|
||||
|
||||
maj_angle(ajust_pos(posX-width/2,width), ajust_pos(posY-height/2,height), height*JEU, angle);
|
||||
controle_moteur(angle);
|
||||
|
||||
cvWaitKey(50);
|
||||
}
|
||||
*/
|
||||
|
||||
#ifdef CONFIG
|
||||
/*
|
||||
affichage_config(frame, hsv_frame, threshold); //Affichage du flux vidéo et de ses traitements
|
||||
*/
|
||||
if( (cvWaitKey(10) ) >= 0 ) break; //Arret capture
|
||||
#endif
|
||||
|
||||
}
|
||||
|
||||
//cvWaitKey(0); //Fin programme
|
||||
|
||||
//Marqueurs rdy
|
||||
for (i=0 ; i<MAX_FACE ; i++){
|
||||
if(tab_face[i]->largeur==0){
|
||||
rdy[i]=1;
|
||||
}
|
||||
}
|
||||
|
||||
if((tab_face[1]->largeur>0) && (watchout.getStatus()==sf::Sound::Stopped) && rdy[1]){
|
||||
watchout.play();
|
||||
rdy[1]=0;
|
||||
}
|
||||
if((tab_face[0]->largeur>0) && (hey.getStatus()==sf::Sound::Stopped) && rdy[0]){
|
||||
hey.play();
|
||||
rdy[0]=0;
|
||||
|
||||
printf("a\n");
|
||||
get_color(frame, tab_face[0],BGR);
|
||||
printf("B = %d, G = %d, R = %d\n",BGR[0],BGR[1],BGR[2]);
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
// Release the capture device housekeeping
|
||||
cvReleaseCapture( &capture );
|
||||
cvReleaseImage(&threshold);
|
||||
cvReleaseImage(&hsv_frame);
|
||||
|
||||
cvReleaseImage(&frame);
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
|
|
Binary file not shown.
Before Width: | Height: | Size: 74 KiB After Width: | Height: | Size: 47 KiB |
Binary file not shown.
Before Width: | Height: | Size: 36 KiB After Width: | Height: | Size: 35 KiB |
Binary file not shown.
Before Width: | Height: | Size: 50 KiB After Width: | Height: | Size: 84 KiB |
|
@ -1,125 +0,0 @@
|
|||
// Sample Application to demonstrate how Face detection can be done as a part of your source code.
|
||||
|
||||
// Include header files
|
||||
#include "cv.h"
|
||||
#include "highgui.h"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <assert.h>
|
||||
#include <math.h>
|
||||
#include <float.h>
|
||||
#include <limits.h>
|
||||
#include <time.h>
|
||||
#include <ctype.h>
|
||||
|
||||
|
||||
// Create a string that contains the exact cascade name
|
||||
const char* cascade_name =
|
||||
"C:/Program Files/OpenCV/data/haarcascades/haarcascade_frontalface_alt.xml";
|
||||
/* "haarcascade_profileface.xml";*/
|
||||
|
||||
|
||||
// Function prototype for detecting and drawing an object from an image
|
||||
void detect_and_draw( IplImage* image );
|
||||
|
||||
// Main function, defines the entry point for the program.
|
||||
int main( int argc, char** argv )
|
||||
{
|
||||
|
||||
//Ouverture flux camera
|
||||
CvCapture* capture = cvCaptureFromCAM( 0 );
|
||||
|
||||
if( !capture ){
|
||||
printf("ERROR: capture is NULL \n" );
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
// Call the function to detect and draw the face positions
|
||||
detect_and_draw(img);
|
||||
|
||||
// Wait for user input before quitting the program
|
||||
cvWaitKey();
|
||||
|
||||
// Release the image
|
||||
cvReleaseImage(&img);
|
||||
|
||||
// Destroy the window previously created with filename: "result"
|
||||
cvDestroyWindow("result");
|
||||
|
||||
// return 0 to indicate successfull execution of the program
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Function to detect and draw any faces that is present in an image
|
||||
void detect_and_draw( IplImage* img )
|
||||
{
|
||||
|
||||
// Create memory for calculations
|
||||
static CvMemStorage* storage = 0;
|
||||
|
||||
// Create a new Haar classifier
|
||||
static CvHaarClassifierCascade* cascade = 0;
|
||||
|
||||
int scale = 1;
|
||||
|
||||
// Create a new image based on the input image
|
||||
IplImage* temp = cvCreateImage( cvSize(img->width/scale,img->height/scale), 8, 3 );
|
||||
|
||||
// Create two points to represent the face locations
|
||||
CvPoint pt1, pt2;
|
||||
int i;
|
||||
|
||||
// Load the [[HaarClassifierCascade]]
|
||||
cascade = (CvHaarClassifierCascade*)cvLoad( cascade_name, 0, 0, 0 );
|
||||
|
||||
// Check whether the cascade has loaded successfully. Else report and error and quit
|
||||
if( !cascade )
|
||||
{
|
||||
fprintf( stderr, "ERROR: Could not load classifier cascade\n" );
|
||||
return;
|
||||
}
|
||||
|
||||
// Allocate the memory storage
|
||||
storage = cvCreateMemStorage(0);
|
||||
|
||||
// Create a new named window with title: result
|
||||
cvNamedWindow( "result", 1 );
|
||||
|
||||
// Clear the memory storage which was used before
|
||||
cvClearMemStorage( storage );
|
||||
|
||||
// Find whether the cascade is loaded, to find the faces. If yes, then:
|
||||
if( cascade )
|
||||
{
|
||||
|
||||
// There can be more than one face in an image. So create a growable sequence of faces.
|
||||
// Detect the objects and store them in the sequence
|
||||
CvSeq* faces = cvHaarDetectObjects( img, cascade, storage,
|
||||
1.1, 2, CV_HAAR_DO_CANNY_PRUNING,
|
||||
cvSize(40, 40) );
|
||||
|
||||
// Loop the number of faces found.
|
||||
for( i = 0; i < (faces ? faces->total : 0); i++ )
|
||||
{
|
||||
// Create a new rectangle for drawing the face
|
||||
CvRect* r = (CvRect*)cvGetSeqElem( faces, i );
|
||||
|
||||
// Find the dimensions of the face,and scale it if necessary
|
||||
pt1.x = r->x*scale;
|
||||
pt2.x = (r->x+r->width)*scale;
|
||||
pt1.y = r->y*scale;
|
||||
pt2.y = (r->y+r->height)*scale;
|
||||
|
||||
// Draw the rectangle in the input image
|
||||
cvRectangle( img, pt1, pt2, CV_RGB(255,0,0), 3, 8, 0 );
|
||||
}
|
||||
}
|
||||
|
||||
// Show the image in the window named "result"
|
||||
cvShowImage( "result", img );
|
||||
|
||||
// Release the temp image created.
|
||||
cvReleaseImage( &temp );
|
||||
}
|
|
@ -105,14 +105,14 @@ void traitement(IplImage* frame, IplImage* HSV, IplImage* Binaire, int LowH, int
|
|||
cvSmooth( HSV, HSV, CV_GAUSSIAN, 15, 0,0,0); //suppression des parasites par flou gaussien
|
||||
|
||||
//Binarisation
|
||||
/*
|
||||
|
||||
CvScalar valinf={(double)LowH,(double)LowS,(double)LowV};
|
||||
CvScalar valsup={(double)HighH,(double)HighS,(double)HighV};
|
||||
|
||||
cvInRangeS(HSV, valinf,valsup, Binaire);
|
||||
*/
|
||||
|
||||
//En cas d'erreur sur les trois ligne précédentes
|
||||
cvInRangeS(HSV, CvScalar(LowH,LowS,LowV),CvScalar(HighH,HighS,HighV), Binaire);
|
||||
//cvInRangeS(HSV, CvScalar(LowH,LowS,LowV),CvScalar(HighH,HighS,HighV), Binaire);
|
||||
|
||||
//cvSmooth( Binaire, Binaire, CV_GAUSSIAN, 9, 9 ); //Legère suppression des parasites
|
||||
}
|
||||
|
@ -197,7 +197,7 @@ CvHaarClassifierCascade* init_cascade(){
|
|||
}
|
||||
|
||||
// Function to detect and draw any faces that is present in an image
|
||||
void detect_and_draw( IplImage* img, CvHaarClassifierCascade* cascade, pface* tab_face)
|
||||
void detect_and_draw( IplImage* img, CvHaarClassifierCascade* cascade, face** tab_face)
|
||||
{
|
||||
|
||||
// Create memory for calculations
|
||||
|
@ -227,6 +227,10 @@ void detect_and_draw( IplImage* img, CvHaarClassifierCascade* cascade, pface* ta
|
|||
// Detect the objects and store them in the sequence
|
||||
CvSeq* faces = cvHaarDetectObjects( img, cascade, storage,1.1, 2, 0, cvSize(60, 60),cvSize(500, 500));
|
||||
|
||||
//Reset faces
|
||||
tab_face[0]->largeur = 0;
|
||||
tab_face[1]->largeur = 0;
|
||||
|
||||
// Loop the number of faces found.
|
||||
for( i = 0; i < (faces ? faces->total : 0); i++ ){
|
||||
// Create a new rectangle for drawing the face
|
||||
|
@ -246,7 +250,7 @@ void detect_and_draw( IplImage* img, CvHaarClassifierCascade* cascade, pface* ta
|
|||
tab_face[i]->point.y = (pt1.y + pt2.y)/2;
|
||||
tab_face[i]->largeur = r->width;
|
||||
|
||||
printf("VALEURS FACES : %d %d %d\n",tab_face[i]->point.x,tab_face[i]->point.y,tab_face[i]->largeur);
|
||||
printf("VALEURS FACES n°%d : %d %d %d\n",i, tab_face[i]->point.x,tab_face[i]->point.y,tab_face[i]->largeur);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -257,3 +261,35 @@ void detect_and_draw( IplImage* img, CvHaarClassifierCascade* cascade, pface* ta
|
|||
//free
|
||||
cvReleaseImage( &temp );
|
||||
}
|
||||
|
||||
//Renvoie la couleur moyenne de rec_face
|
||||
void get_color(IplImage* image, face* rec_face, int* BGR){
|
||||
printf("z\n");
|
||||
CvScalar colors;
|
||||
int largeur = rec_face->largeur;
|
||||
printf("e\n");
|
||||
cvSetImageROI(image,cvRect(rec_face->point.x -largeur/2, rec_face->point.y -largeur/2, largeur,largeur));
|
||||
printf("r\n");
|
||||
colors = cvAvg(image);
|
||||
printf("t\n");
|
||||
cvResetImageROI(image);
|
||||
printf("y\n");
|
||||
BGR[0] = colors.val[0];
|
||||
BGR[1] = colors.val[1];
|
||||
BGR[2] = colors.val[2];
|
||||
printf("u\n");
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -39,10 +39,13 @@
|
|||
* \brief Programme en mode suivi de Kirby (Objet rose)
|
||||
*
|
||||
* \def ETOILE
|
||||
* \brief Programme en mide suivi de l'étoile (Objet jaune)
|
||||
* \brief Programme en mode suivi de l'étoile (Objet jaune)
|
||||
*
|
||||
* \def JEU
|
||||
* \brief Coefficient de tolérance pour le suivi d'objet
|
||||
*
|
||||
* \def MAX_FACE
|
||||
* \brief Nombre maximum de faces traitées
|
||||
*/
|
||||
//#define CONFIG
|
||||
#define SFML
|
||||
|
@ -52,11 +55,16 @@
|
|||
#define MAX_FACE 2
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* \struct face
|
||||
* \brief Contient les informations sur chaque face détectée : positions, largeur
|
||||
* \param point coordonnées en x et y du centre de la face
|
||||
* \param largeur largeur de la face
|
||||
*/
|
||||
/*STRUCTURE*/
|
||||
typedef struct _face{
|
||||
CvPoint point;
|
||||
int largeur;
|
||||
CvPoint point; /*!< coordonnées en x et y du centre de la face */
|
||||
int largeur; /*!< largeur de la face */
|
||||
} face;
|
||||
|
||||
typedef face* pface;
|
||||
|
@ -174,10 +182,44 @@ void Position_moy(IplImage* Binaire, int* posX, int * posY); //Effectue le baric
|
|||
*/
|
||||
void traitement(IplImage* frame, IplImage* HSV, IplImage* Binaire, int LowH, int HighH, int LowS, int HighS, int LowV, int HighV); //Effectue une binarisation de frame en fonction des bornes HSV
|
||||
|
||||
/**
|
||||
* \fn int image_CV2SFML(IplImage* imcv, sf::Image imFlux)
|
||||
* \brief Convertit une image opencv (IplImage) en une image SFML (sf::Image)
|
||||
* \author Antoine
|
||||
* \param imcv image OpenCv à convertir
|
||||
* \param imFlux image SFML convertie en sortie de la fonction
|
||||
* \return 0 si la convertion est réussie
|
||||
* \bug A debugger ! Inutilisable en l'état
|
||||
*/
|
||||
int image_CV2SFML(IplImage* imcv, sf::Image imFlux); //Construction de imsf (RGBA) à partir de imcv (BGR), avec alpha constant (=1)
|
||||
|
||||
/**
|
||||
* \fn CvHaarClassifierCascade* init_cascade()
|
||||
* \brief Charge les fichiers cascades pour la reconnaissance faciale
|
||||
* \details fichier(s) chargé(s) : "haarcascade_frontalface_alt.xml"
|
||||
* \author Jacques
|
||||
* \return Renvoie la cascade
|
||||
*/
|
||||
CvHaarClassifierCascade* init_cascade();
|
||||
void detect_and_draw( IplImage* img, CvHaarClassifierCascade* cascade, pface* tab_face );
|
||||
|
||||
/**
|
||||
* \fn void detect_and_draw( IplImage* img, CvHaarClassifierCascade* cascade, face** tab_face )
|
||||
* \brief Détecte et renvoie un rectangle pour chaque visage sur l'image
|
||||
* \author Jacques
|
||||
* \param img Image sur laquelle on veut détecter des visages
|
||||
* \param cascade structure contenant les données pour alimenter l'algorithme de reconnaissance d'image
|
||||
* \param tab_face tableau des faces détectées
|
||||
*/
|
||||
void detect_and_draw( IplImage* img, CvHaarClassifierCascade* cascade, face** tab_face );
|
||||
|
||||
/**
|
||||
* \fn int* get_color(IplImage* image, face* rec_face)
|
||||
* \brief retourne la couleur moyenne des pixels dans rec_face
|
||||
* \author Antoine / Jacques
|
||||
* \param image image d'où on cherche la moyenne
|
||||
* \param imFlux image SFML convertie en sortie de la fonction
|
||||
* \return 0 si la convertion est réussie
|
||||
*/
|
||||
void get_color(IplImage* image, face* rec_face, int* BGR);
|
||||
|
||||
#endif
|
||||
|
|
BIN
Code/gmon.out
BIN
Code/gmon.out
Binary file not shown.
Loading…
Add table
Add a link
Reference in a new issue