2017-05-23 17:36:54 +02:00
|
|
|
#include "fonction.h"
|
2017-05-23 14:30:22 +02:00
|
|
|
|
|
|
|
|
|
|
|
int main(int argc, char* argv[])
|
|
|
|
{
|
2017-05-23 17:36:54 +02:00
|
|
|
//Initialisations
|
2017-05-23 14:30:22 +02:00
|
|
|
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;
|
|
|
|
|
|
|
|
//Ouverture flux camera
|
|
|
|
CvCapture* capture = cvCaptureFromCAM( 0 );
|
|
|
|
|
|
|
|
if( !capture ){
|
|
|
|
printf("ERROR: capture is NULL \n" );
|
|
|
|
exit(EXIT_FAILURE);
|
2017-05-23 17:36:54 +02:00
|
|
|
}
|
2017-05-23 14:30:22 +02:00
|
|
|
|
2017-05-23 17:36:54 +02:00
|
|
|
//Initialisation frame
|
2017-05-23 14:30:22 +02:00
|
|
|
IplImage* frame = cvQueryFrame( capture );
|
2017-05-23 17:36:54 +02:00
|
|
|
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();
|
2017-05-23 14:30:22 +02:00
|
|
|
|
|
|
|
#ifdef SFML
|
2017-05-23 17:36:54 +02:00
|
|
|
//Initialisation SFML
|
|
|
|
sf::Texture txFlux;
|
|
|
|
sf::Sprite spFlux;
|
|
|
|
sf::Image imFlux;
|
|
|
|
sf::Event event;
|
|
|
|
|
|
|
|
tracking = 0; //Pas de tracking de base en mode SFML
|
2017-05-23 14:30:22 +02:00
|
|
|
//Création de la fenetre principale
|
|
|
|
sf::RenderWindow window(sf::VideoMode(width+300, height), "KirbyTrack");
|
|
|
|
#endif
|
|
|
|
|
|
|
|
//Controle couleur
|
|
|
|
#ifdef KIRBY
|
2017-05-23 17:36:54 +02:00
|
|
|
int tab_HSV[6] = {152,179,48,255,101,255};
|
2017-05-23 14:30:22 +02:00
|
|
|
#endif
|
|
|
|
|
2017-05-23 17:36:54 +02:00
|
|
|
#ifdef ETOILE
|
|
|
|
int tab_HSV[6] = {20,30,100,255,100,255};
|
2017-05-23 14:30:22 +02:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef CONFIG
|
|
|
|
//Affichage du panneau de config
|
2017-05-23 17:36:54 +02:00
|
|
|
config(tab_HSV,tab_HSV+1,tab_HSV+2,tab_HSV+3,tab_HSV+4,tab_HSV+5);
|
2017-05-23 14:30:22 +02:00
|
|
|
|
|
|
|
boucle = 1;
|
2017-05-23 17:36:54 +02:00
|
|
|
tracking = 0; //Tracking de base en mode CONFIG
|
2017-05-23 14:30:22 +02:00
|
|
|
#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
|
|
|
|
while (window.pollEvent(event))
|
|
|
|
{
|
|
|
|
// évènement "fermeture demandée" : on ferme la fenêtre
|
|
|
|
if (event.type == sf::Event::Closed)
|
|
|
|
window.close();
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
// Get one frame
|
|
|
|
frame = cvQueryFrame( capture );
|
|
|
|
|
|
|
|
if( !frame ){
|
|
|
|
perror("ERROR: frame is null...");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2017-05-23 17:36:54 +02:00
|
|
|
detect_and_draw(frame,cascade);
|
2017-05-23 14:30:22 +02:00
|
|
|
|
|
|
|
#ifdef 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;
|
|
|
|
}
|
|
|
|
*/
|
|
|
|
|
|
|
|
//Enregistrement de la frame openCV
|
|
|
|
cvSaveImage("Stock SFML/temp.jpg", frame);
|
|
|
|
|
|
|
|
//Chargement de la frame en texture SFML
|
|
|
|
if (!txFlux.loadFromFile("Stock SFML/temp.jpg")){
|
|
|
|
printf("Erreur chargement image SFML\n" );
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
spFlux.setTexture(txFlux);
|
|
|
|
|
|
|
|
window.draw(spFlux);
|
|
|
|
|
2017-05-23 17:36:54 +02:00
|
|
|
//TEST SFML
|
2017-05-23 14:30:22 +02:00
|
|
|
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, 60));
|
|
|
|
|
|
|
|
window.draw(button_reset);
|
|
|
|
*/
|
|
|
|
//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));
|
|
|
|
|
|
|
|
window.draw(Link);
|
|
|
|
*/
|
|
|
|
/* Update the window */
|
|
|
|
window.display();
|
|
|
|
#endif
|
|
|
|
|
2017-05-23 17:36:54 +02:00
|
|
|
|
2017-05-23 14:30:22 +02:00
|
|
|
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
|
2017-05-23 17:36:54 +02:00
|
|
|
/*
|
2017-05-23 14:30:22 +02:00
|
|
|
affichage_config(frame, hsv_frame, threshold); //Affichage du flux vidéo et de ses traitements
|
2017-05-23 17:36:54 +02:00
|
|
|
*/
|
2017-05-23 14:30:22 +02:00
|
|
|
if( (cvWaitKey(10) ) >= 0 ) break; //Arret capture
|
|
|
|
#endif
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
//cvWaitKey(0); //Fin programme
|
|
|
|
|
|
|
|
// Release the capture device housekeeping
|
|
|
|
cvReleaseCapture( &capture );
|
|
|
|
cvReleaseImage(&threshold);
|
|
|
|
cvReleaseImage(&hsv_frame);
|
|
|
|
cvReleaseImage(&frame);
|
|
|
|
|
|
|
|
return EXIT_SUCCESS;
|
|
|
|
}
|