CamAdventure
 All Classes Files Functions Variables Macros Pages
Navy.c
Go to the documentation of this file.
1 
11 #include "fonction.h"
12 //#include "fonction.c" //Pour le problème de référence indéfinie à la compilation
13 
14 
21 int main(int argc, char* argv[])
22 {
23  //Initialisations
24  int height,width; //parameters of the image we are working on
25  int boucle = 1; //On effectuera la boucle principale au moins une fois
26  int i;
27  float scale_x, scale_y;
28  int BGR[3];
29 
30  //Initialisation detection visage
31  CvHaarClassifierCascade* cascade = init_cascade();
32  face* tab_face[MAX_FACE];
33  for (i=0;i<2;i++){
34  tab_face[i] = (face*)malloc(sizeof(face));
35  }
36  int rdy[MAX_FACE];
37 
38  //Link
39  sf::Texture txLink;
40  sf::Sprite Link;
41 
42  if (!txLink.loadFromFile("Stock SFML/link.png")){
43  printf("Erreur chargement image SFML\n" );
44  return EXIT_FAILURE;
45  }
46 
47  sf::Vector2u vec_link = txLink.getSize();
48 
49  //Ganon
50  sf::Texture txGanon;
51  sf::Sprite Ganon;
52 
53  if (!txGanon.loadFromFile("Stock SFML/ganon.png")){
54  printf("Erreur chargement image SFML\n" );
55  return EXIT_FAILURE;
56  }
57 
58  sf::Vector2u vec_ganon = txGanon.getSize();
59 
60  //Initialisation SFML
61 
62  sf::Texture txFlux;
63  sf::Sprite spFlux;
64  sf::Image imFlux;
65  sf::Event event;
66 
67  //Chargement son
68  sf::Music aile;
69  if (!aile.openFromFile("Stock SFML/aile.ogg"))
70  return EXIT_FAILURE;
71  aile.setLoop(true);
72  aile.play();
73 
74  sf::Music hey;
75  if (!hey.openFromFile("Stock SFML/hey_listen.ogg"))
76  return EXIT_FAILURE;
77  sf::Music watchout;
78  if (!watchout.openFromFile("Stock SFML/watchout.ogg"))
79  return EXIT_FAILURE;
80 
81  //Ouverture flux camera
82  CvCapture* capture = cvCaptureFromCAM( 0 );
83 
84  if( !capture ){
85  printf("ERROR: capture is NULL \n" );
86  exit(EXIT_FAILURE);
87  }
88 
89 
90  // grab an image from the capture
91  IplImage* frame = cvQueryFrame( capture );
92 
93  // get the image data
94  height = frame->height;
95  width = frame->width;
96 
97  // capture size -
98  // CvSize size = cvSize(width,height);
99 
100 
101 
102  //Création de la fenetre principale
103  sf::RenderWindow window(sf::VideoMode(width, height), "KirbyTrack");
104 
105 
106  while(boucle)
107  {
108 
109  boucle = window.isOpen();
110 
111  // on inspecte tous les évènements de la fenêtre qui ont été émis depuis la précédente itération
112  while (window.pollEvent(event))
113  {
114  // évènement "fermeture demandée" : on ferme la fenêtre
115  if (event.type == sf::Event::Closed)
116  window.close();
117  }
118 
119  // Get one frame
120  frame = cvQueryFrame( capture );
121 
122  if( !frame ){
123  perror("ERROR: frame is null...");
124  break;
125  }
126 
127 
128  detect_and_draw(frame,cascade,tab_face);
129 
130 
131 //Affichage SFML
132  /* Clear the screen */
133  window.clear(sf::Color::White);
134 
135 //Affichage de la frame
136 
137  //Le chargement pourrait etre plus optimisé en créant nous me l'image SFML en parcourant l'IplImage
138 
139  //Enregistrement de la frame openCV
140  cvSaveImage("Stock SFML/temp.jpg", frame);
141 
142  //Chargement de la frame en texture SFML
143  if (!txFlux.loadFromFile("Stock SFML/temp.jpg")){
144  printf("Erreur chargement image SFML\n" );
145  break;
146  }
147 
148  spFlux.setTexture(txFlux);
149  window.draw(spFlux);
150 
151  Link.setTexture(txLink);
152  Link.setOrigin(sf::Vector2f(vec_link.x/2,vec_link.y/2));
153  Link.setPosition(sf::Vector2f(tab_face[0]->point.x, tab_face[0]->point.y));
154  scale_x = tab_face[0]->largeur / (1.0*vec_link.x);
155  scale_y = tab_face[0]->largeur / (1.0*vec_link.y);
156  //printf("%d , %d et%lf, %lf\n",tab_face[0]->largeur,vec_link.x,scale_x,scale_y);
157  Link.setScale(sf::Vector2f(scale_x, scale_y));
158 
159  Ganon.setTexture(txGanon);
160  Ganon.setOrigin(sf::Vector2f(vec_ganon.x/2,vec_ganon.y/2));
161  Ganon.setPosition(sf::Vector2f(tab_face[1]->point.x, tab_face[1]->point.y));
162  scale_x = tab_face[1]->largeur / (1.0*vec_ganon.x);
163  scale_y = tab_face[1]->largeur / (1.0*vec_ganon.y);
164  Ganon.setScale(sf::Vector2f(scale_x, scale_y));
165 
166  window.draw(Link);
167  window.draw(Ganon);
168 
169  /* Update the window */
170 
171  window.display();
172 
173  //Marqueurs rdy
174  for (i=0 ; i<MAX_FACE ; i++){
175  if(tab_face[i]->largeur==0){
176  rdy[i]=1;
177  }
178  }
179 
180  if((tab_face[1]->largeur>0) && (watchout.getStatus()==sf::Sound::Stopped) && rdy[1]){
181  watchout.play();
182  rdy[1]=0;
183  }
184  if((tab_face[0]->largeur>0) && (hey.getStatus()==sf::Sound::Stopped) && rdy[0]){
185  hey.play();
186  rdy[0]=0;
187 
188  printf("a\n");
189  get_color(frame, tab_face[0],BGR);
190  printf("B = %d, G = %d, R = %d\n",BGR[0],BGR[1],BGR[2]);
191  }
192 
193 
194 
195 }
196  // Release the capture device housekeeping
197  cvReleaseCapture( &capture );
198 
199  cvReleaseImage(&frame);
200 
201  return EXIT_SUCCESS;
202 }
203 
204 /*
205  //musique
206  if(aye.getStatus()==sf::Sound::Stopped){
207  aye.setPitch(0.5);
208  aye.setVolume(150);
209  aye.setLoop(true);
210  aye.play();
211  }
212 */
213 
void detect_and_draw(IplImage *img, CvHaarClassifierCascade *cascade, face **tab_face)
Détecte et renvoie un rectangle pour chaque visage sur l'image.
Definition: fonction.c:200
CvHaarClassifierCascade * init_cascade()
Charge les fichiers cascades pour la reconnaissance faciale.
Definition: fonction.c:182
Bibliothèque, Headers et Documentation des fonctions.
#define MAX_FACE
Nombre maximum de faces traitées.
Definition: fonction.h:55
int main(int argc, char *argv[])
Entrée du programme.
Definition: KirbyTrack.c:23
Contient les informations sur chaque face détectée : positions, largeur.