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
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;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue