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