mirror of
https://github.com/AntoineHX/LivingMachine.git
synced 2025-05-03 13:20:45 +02:00
Merge branch 'master' of https://epudx.polytech.upmc.fr/git/rob3-projetsinfo-g15-2017
merge n°2
This commit is contained in:
commit
85c3af61b5
1 changed files with 78 additions and 37 deletions
|
@ -10,8 +10,8 @@
|
|||
#include <SFML/Audio.hpp>
|
||||
#include <SFML/Graphics.hpp>
|
||||
|
||||
#define CONFIG
|
||||
//#define SFML
|
||||
//#define CONFIG
|
||||
#define SFML
|
||||
|
||||
#define KIRBY
|
||||
//#define ETOILE
|
||||
|
@ -31,7 +31,7 @@ void Affichage_Tracking(IplImage* frame, int posX, int posY, int width, int heig
|
|||
void Position_moy(IplImage* Binaire, int* posX, int * posY); //Effectue le baricentre des pixels d'une image binaire pour obtenir la postion de l'objet
|
||||
void traitement(IplImage* frame, IplImage* HSV, IplImage* Binaire, int LowH, int HighH, int LowS, int HighS, int LowV, int HighV); //Effectue une binarisation de frame en fonction des bornes HSV
|
||||
|
||||
int image_CV2SFML(IplImage* imcv, sf::Image imsf); //Construction de imsf (RGBA) à partir de imcv (BGR), avec alpha constant (=1)
|
||||
int image_CV2SFML(IplImage* imcv, sf::Image imFlux); //Construction de imsf (RGBA) à partir de imcv (BGR), avec alpha constant (=1)
|
||||
|
||||
|
||||
int main(int argc, char* argv[])
|
||||
|
@ -40,9 +40,11 @@ int main(int argc, char* argv[])
|
|||
int height,width,step,channels; //parameters of the image we are working on
|
||||
int posX, posY; //Position objet
|
||||
int boucle;
|
||||
|
||||
int angle[2] = {100,100};
|
||||
int vecX, vecY;
|
||||
|
||||
|
||||
#ifdef SFML
|
||||
//Initialisation SFML
|
||||
|
||||
|
@ -51,8 +53,6 @@ int main(int argc, char* argv[])
|
|||
sf::Image imFlux;
|
||||
sf::Event event;
|
||||
|
||||
//Création de la fenetre principale
|
||||
sf::RenderWindow window(sf::VideoMode(800, 600), "KirbyTrack");
|
||||
#endif
|
||||
|
||||
//Ouverture flux camera
|
||||
|
@ -72,20 +72,19 @@ int main(int argc, char* argv[])
|
|||
width = frame->width;
|
||||
step = frame->widthStep;
|
||||
|
||||
// capture size -
|
||||
CvSize size = cvSize(width,height);
|
||||
|
||||
// capture size -
|
||||
CvSize size = cvSize(width,height);
|
||||
|
||||
|
||||
#ifdef SFML
|
||||
//Intialisation de la texture
|
||||
if (!txFlux.create(width, height)){
|
||||
printf("Erreur création texture\n");
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
//Création de la fenetre principale
|
||||
sf::RenderWindow window(sf::VideoMode(width, height), "KirbyTrack");
|
||||
#endif
|
||||
|
||||
// Initialize different images that are going to be used in the program
|
||||
IplImage* hsv_frame = cvCreateImage(size, IPL_DEPTH_8U, 3); // image converted to HSV plane
|
||||
IplImage* threshold = cvCreateImage(size, IPL_DEPTH_8U, 1);
|
||||
// Initialize different images that are going to be used in the program
|
||||
IplImage* hsv_frame = cvCreateImage(size, IPL_DEPTH_8U, 3); // image converted to HSV plane
|
||||
IplImage* threshold = cvCreateImage(size, IPL_DEPTH_8U, 1);
|
||||
|
||||
|
||||
//Controle couleur
|
||||
#ifdef KIRBY
|
||||
|
@ -118,9 +117,9 @@ int main(int argc, char* argv[])
|
|||
boucle = 1;
|
||||
#endif
|
||||
|
||||
//BOUCLE PRINCIPALE
|
||||
while(boucle)//while(window.isOpen())
|
||||
{
|
||||
<<<<<<< HEAD
|
||||
while(boucle)
|
||||
{
|
||||
|
||||
#ifdef SFML
|
||||
boucle = window.isOpen();
|
||||
|
@ -151,26 +150,36 @@ int main(int argc, char* argv[])
|
|||
//Dessine les informations de tracking sur frame
|
||||
Affichage_Tracking(frame, posX, posY, width, height);
|
||||
|
||||
#ifdef SFML
|
||||
//Affichage SFML
|
||||
/* Clear the screen */
|
||||
window.clear(sf::Color::Black);
|
||||
|
||||
//Conversion de la frame en image smfl
|
||||
if(image_CV2SFML(frame, imFlux)){
|
||||
printf("Erreur conversion OpenCV-SFML\n");
|
||||
break;
|
||||
}
|
||||
|
||||
spFlux.setTexture(txFlux);
|
||||
#ifdef SFML
|
||||
//Affichage SFML
|
||||
/* Clear the screen */
|
||||
window.clear(sf::Color::Black);
|
||||
|
||||
//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("temp.jpg", frame);
|
||||
|
||||
//Chargement de la frame en texture SFML
|
||||
if (!txFlux.loadFromFile("temp.jpg")){
|
||||
printf("Erreur chargement image SFML\n" );
|
||||
break;
|
||||
}
|
||||
|
||||
spFlux.setTexture(txFlux);
|
||||
|
||||
|
||||
window.draw(spFlux);
|
||||
|
||||
/* Update the window */
|
||||
//window.display();
|
||||
|
||||
//sfSprite_destroy(sprite);
|
||||
//sfTexture_destroy(texture);
|
||||
/* Update the window */
|
||||
window.display();
|
||||
|
||||
#endif
|
||||
|
||||
//Mouvements moteurs
|
||||
|
@ -262,12 +271,42 @@ void controle_moteur(int* angle){
|
|||
return;
|
||||
}
|
||||
|
||||
/*Verifie que les valeurs envoyees aux moteurs sont correctes*/
|
||||
int limite_moteur(int val_pwm){
|
||||
int MAX_PWM = 255;
|
||||
if (val_pwm > MAX_PWM || val_pwm < 0){
|
||||
return 0;
|
||||
}
|
||||
else{
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
int image_CV2SFML(IplImage* imcv, sf::Image imFlux){
|
||||
|
||||
int R, G, B;
|
||||
int w = imcv->widthStep;
|
||||
char* ptr = imcv->imageData;
|
||||
|
||||
imFlux.create(imcv->width,imcv->height, NULL); //Initialise une image vide
|
||||
|
||||
for( int y=0; y<imcv->height; y++ ) {
|
||||
//uchar* ptr = (uchar*) ( imcv->imageData + y * imcv->widthStep );
|
||||
for( int x=0; x<imcv->width; x++ ) {
|
||||
//Recupération du pixel
|
||||
B = ptr[y*w + 3*x];
|
||||
G = ptr[y*w + 3*x + 1];
|
||||
R = ptr[y*w + 3*x + 2];
|
||||
|
||||
//Ecriture du pixel associé
|
||||
imFlux.setPixel(x,y,sf::Color(R,G,B,1)); //Alpha channel = 1
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
*/
|
||||
|
||||
|
||||
void traitement(IplImage* frame, IplImage* HSV, IplImage* Binaire, int LowH, int HighH, int LowS, int HighS, int LowV, int HighV){ //Effectue une binarisation de frame en fonction des bornes HSV
|
||||
|
||||
|
@ -282,7 +321,9 @@ void traitement(IplImage* frame, IplImage* HSV, IplImage* Binaire, int LowH, int
|
|||
CvScalar valinf={LowH,LowS,LowV};
|
||||
CvScalar valsup={HighH,HighS,HighV};
|
||||
|
||||
cvInRangeS(HSV, valinf,valsup, Binaire);
|
||||
//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);
|
||||
|
||||
//cvSmooth( Binaire, Binaire, CV_GAUSSIAN, 9, 9 ); //Legère suppression des parasites
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue