mirror of
https://github.com/AntoineHX/LivingMachine.git
synced 2025-05-04 05:40:46 +02:00
Ajout du bouton On/Off + texte associé (possible problème de vsync)
This commit is contained in:
parent
b76276082d
commit
fb72cb60d0
6 changed files with 57 additions and 24 deletions
|
@ -10,8 +10,8 @@
|
||||||
#include <SFML/Audio.hpp>
|
#include <SFML/Audio.hpp>
|
||||||
#include <SFML/Graphics.hpp>
|
#include <SFML/Graphics.hpp>
|
||||||
|
|
||||||
#define CONFIG
|
//#define CONFIG
|
||||||
//#define SFML
|
#define SFML
|
||||||
|
|
||||||
#define KIRBY
|
#define KIRBY
|
||||||
//#define ETOILE
|
//#define ETOILE
|
||||||
|
@ -44,6 +44,8 @@ int main(int argc, char* argv[])
|
||||||
double angle[2] = {100,100};
|
double angle[2] = {100,100};
|
||||||
int vecX, vecY;
|
int vecX, vecY;
|
||||||
|
|
||||||
|
int tracking;
|
||||||
|
|
||||||
|
|
||||||
#ifdef SFML
|
#ifdef SFML
|
||||||
//Initialisation SFML
|
//Initialisation SFML
|
||||||
|
@ -53,6 +55,8 @@ int main(int argc, char* argv[])
|
||||||
sf::Image imFlux;
|
sf::Image imFlux;
|
||||||
sf::Event event;
|
sf::Event event;
|
||||||
|
|
||||||
|
tracking = 0; //Pas de tracking de base en mode SFML
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
//Ouverture flux camera
|
//Ouverture flux camera
|
||||||
|
@ -115,6 +119,7 @@ int main(int argc, char* argv[])
|
||||||
config(&iLowH, &iHighH, &iLowS, &iHighS, &iLowV, &iHighV);
|
config(&iLowH, &iHighH, &iLowS, &iHighS, &iLowV, &iHighV);
|
||||||
|
|
||||||
boucle = 1;
|
boucle = 1;
|
||||||
|
tracking = 1; //Tracking de base en mode CONFIG
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
while(boucle)
|
while(boucle)
|
||||||
|
@ -161,6 +166,7 @@ int main(int argc, char* argv[])
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
|
|
||||||
//Enregistrement de la frame openCV
|
//Enregistrement de la frame openCV
|
||||||
cvSaveImage("Stock SFML/temp.jpg", frame);
|
cvSaveImage("Stock SFML/temp.jpg", frame);
|
||||||
|
|
||||||
|
@ -175,32 +181,57 @@ int main(int argc, char* argv[])
|
||||||
window.draw(spFlux);
|
window.draw(spFlux);
|
||||||
|
|
||||||
//TEST SFML
|
//TEST SFML
|
||||||
sf::Texture texture;
|
sf::Vector2i PosMouse = sf::Mouse::getPosition(window);
|
||||||
if (!texture.loadFromFile("Stock SFML/red_button.jpeg")){
|
//Detection du bouton tracking
|
||||||
printf("Erreur chargement image SFML\n" );
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
//printf("Pos Mouse : %d %d \n", PosMouse.x, PosMouse.y);
|
||||||
|
|
||||||
|
//Dessin du bouton
|
||||||
|
sf::CircleShape button(20, 100);
|
||||||
|
button.setPosition(sf::Vector2f(width+20, 20));
|
||||||
|
|
||||||
|
if(tracking){ button.setFillColor(sf::Color::Green); }
|
||||||
|
else{ button.setFillColor(sf::Color::Red); }
|
||||||
|
|
||||||
|
window.draw(button);
|
||||||
|
|
||||||
|
|
||||||
|
//Ajout du texte
|
||||||
|
sf::Font font;
|
||||||
|
if (!font.loadFromFile("Stock SFML/arial.ttf")){
|
||||||
|
printf("Erreur chargement police SFML\n" );
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
sf::Sprite sprite;
|
sf::Text text;
|
||||||
sprite.setTexture(texture);
|
// choix de la police à utiliser
|
||||||
|
text.setFont(font); // font est un sf::Font
|
||||||
|
|
||||||
sprite.setPosition(sf::Vector2f(width, 0));
|
// choix de la chaîne de caractères à afficher
|
||||||
|
text.setString("Hello world");
|
||||||
|
|
||||||
window.draw(sprite);
|
// choix de la taille des caractères
|
||||||
|
text.setCharacterSize(24); // exprimée en pixels, pas en points !
|
||||||
|
|
||||||
sf::Vector2i PosMouse = sf::Mouse::getPosition(window);
|
//text.setFillColor(sf::Color::Black);
|
||||||
|
text.setColor(sf::Color::Black);
|
||||||
|
|
||||||
if (sf::Mouse::isButtonPressed(sf::Mouse::Left)&&(PosMouse.x>640)&&(PosMouse.x<760)&&(PosMouse.y>0)&&(PosMouse.y<120)){
|
text.setPosition(sf::Vector2f(width+40, 20));
|
||||||
printf("\n\n\n OK \n\n\n");
|
|
||||||
}
|
|
||||||
|
|
||||||
printf("Pos Mouse : %d %d \n", PosMouse.x, PosMouse.y);
|
|
||||||
|
window.draw(text);
|
||||||
|
|
||||||
/* Update the window */
|
/* Update the window */
|
||||||
window.display();
|
window.display();
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
/*
|
||||||
|
if(tracking){
|
||||||
//Mouvements moteurs
|
//Mouvements moteurs
|
||||||
printf("-PREMAJ_ANGLE...: %d %d\n",width,height);
|
printf("-PREMAJ_ANGLE...: %d %d\n",width,height);
|
||||||
|
|
||||||
|
@ -208,6 +239,8 @@ int main(int argc, char* argv[])
|
||||||
controle_moteur(angle);
|
controle_moteur(angle);
|
||||||
|
|
||||||
cvWaitKey(100);
|
cvWaitKey(100);
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
#ifdef CONFIG
|
#ifdef CONFIG
|
||||||
affichage_config(frame, hsv_frame, threshold); //Affichage du flux vidéo et de ses traitements
|
affichage_config(frame, hsv_frame, threshold); //Affichage du flux vidéo et de ses traitements
|
||||||
|
@ -327,13 +360,13 @@ void traitement(IplImage* frame, IplImage* HSV, IplImage* Binaire, int LowH, int
|
||||||
|
|
||||||
//Binarisation
|
//Binarisation
|
||||||
|
|
||||||
CvScalar valinf={LowH,LowS,LowV};
|
//CvScalar valinf={LowH,LowS,LowV};
|
||||||
CvScalar valsup={HighH,HighS,HighV};
|
//CvScalar valsup={HighH,HighS,HighV};
|
||||||
|
|
||||||
|
//cvInRangeS(HSV, valinf,valsup, Binaire);
|
||||||
|
|
||||||
//En cas d'erreur sur les trois ligne précédentes
|
//En cas d'erreur sur les trois ligne précédentes
|
||||||
cvInRangeS(HSV, valinf,valsup, Binaire);
|
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
|
//cvSmooth( Binaire, Binaire, CV_GAUSSIAN, 9, 9 ); //Legère suppression des parasites
|
||||||
}
|
}
|
||||||
|
|
BIN
Code/Stock SFML/arial.ttf
Normal file
BIN
Code/Stock SFML/arial.ttf
Normal file
Binary file not shown.
BIN
Code/Stock SFML/button.png
Normal file
BIN
Code/Stock SFML/button.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 17 KiB |
Binary file not shown.
Before Width: | Height: | Size: 2.2 KiB |
Binary file not shown.
Before Width: | Height: | Size: 2.5 KiB |
Binary file not shown.
Before Width: | Height: | Size: 54 KiB After Width: | Height: | Size: 69 KiB |
Loading…
Add table
Add a link
Reference in a new issue