mirror of
https://github.com/AntoineHX/LivingMachine.git
synced 2025-05-03 13:20:45 +02:00
Test SFML, import fichiers drive
This commit is contained in:
parent
73704e5139
commit
36962dc598
12 changed files with 314 additions and 0 deletions
29
CMakeLists.txt
Normal file
29
CMakeLists.txt
Normal file
|
@ -0,0 +1,29 @@
|
|||
cmake_minimum_required(VERSION 2.8)
|
||||
|
||||
|
||||
#Configuration du projet
|
||||
|
||||
project(DisplayImage)
|
||||
|
||||
#Configuration de la sortie
|
||||
|
||||
set(EXECUTABLE_OUTPUT_PATH bin)
|
||||
|
||||
#Configuration de l'exécutable
|
||||
|
||||
file(
|
||||
GLOB_RECURSE
|
||||
|
||||
source_files
|
||||
|
||||
src/*
|
||||
)
|
||||
|
||||
#Recherche des bibliothèques
|
||||
|
||||
find_package( OpenCV REQUIRED )
|
||||
find_package(SFML 2 COMPONENTS system window graphics audio REQUIRED)
|
||||
|
||||
add_executable( DisplayImage ${source_files} )
|
||||
target_link_libraries( DisplayImage ${OpenCV_LIBS} )
|
||||
|
BIN
Etudes préliminaires.odt
Normal file
BIN
Etudes préliminaires.odt
Normal file
Binary file not shown.
BIN
Test - SFML/arial.ttf
Normal file
BIN
Test - SFML/arial.ttf
Normal file
Binary file not shown.
BIN
Test - SFML/main
Executable file
BIN
Test - SFML/main
Executable file
Binary file not shown.
76
Test - SFML/main.c
Normal file
76
Test - SFML/main.c
Normal file
|
@ -0,0 +1,76 @@
|
|||
#include <SFML/Audio.h>
|
||||
#include <SFML/Graphics.h>
|
||||
|
||||
/*
|
||||
Installation :
|
||||
sudo apt-get install libcsfml-dev
|
||||
|
||||
Commandes :
|
||||
gcc -c main.c
|
||||
gcc main.o -o main -lcsfml-graphics -lcsfml-window -lcsfml-audio -lcsfml-system
|
||||
|
||||
*/
|
||||
|
||||
int main()
|
||||
{
|
||||
sfVideoMode mode = {800, 600, 32};
|
||||
sfRenderWindow* window;
|
||||
sfTexture* texture;
|
||||
sfSprite* sprite;
|
||||
sfFont* font;
|
||||
sfText* text;
|
||||
sfMusic* music;
|
||||
sfEvent event;
|
||||
/* Create the main window */
|
||||
window = sfRenderWindow_create(mode, "SFML window", sfResize | sfClose, NULL);
|
||||
if (!window)
|
||||
return EXIT_FAILURE;
|
||||
/* Load a sprite to display */
|
||||
texture = sfTexture_createFromFile("tree.jpeg", NULL);
|
||||
if (!texture)
|
||||
return EXIT_FAILURE;
|
||||
sprite = sfSprite_create();
|
||||
sfSprite_setTexture(sprite, texture, sfTrue);
|
||||
/* Create a graphical text to display */
|
||||
font = sfFont_createFromFile("arial.ttf");
|
||||
if (!font)
|
||||
return EXIT_FAILURE;
|
||||
text = sfText_create();
|
||||
sfText_setString(text, "Hello SFML");
|
||||
sfText_setFont(text, font);
|
||||
sfText_setCharacterSize(text, 50);
|
||||
/* Load a music to play */
|
||||
//music = sfMusic_createFromFile("nice_music.ogg");
|
||||
if (!music)
|
||||
return EXIT_FAILURE;
|
||||
/* Play the music */
|
||||
sfMusic_play(music);
|
||||
/* Start the game loop */
|
||||
while (sfRenderWindow_isOpen(window))
|
||||
{
|
||||
/* Process events */
|
||||
while (sfRenderWindow_pollEvent(window, &event))
|
||||
{
|
||||
/* Close window : exit */
|
||||
if (event.type == sfEvtClosed)
|
||||
sfRenderWindow_close(window);
|
||||
}
|
||||
/* Clear the screen */
|
||||
sfRenderWindow_clear(window, sfBlack);
|
||||
/* Draw the sprite */
|
||||
sfRenderWindow_drawSprite(window, sprite, NULL);
|
||||
/* Draw the text */
|
||||
sfRenderWindow_drawText(window, text, NULL);
|
||||
/* Update the window */
|
||||
sfRenderWindow_display(window);
|
||||
}
|
||||
/* Cleanup resources */
|
||||
sfMusic_destroy(music);
|
||||
sfText_destroy(text);
|
||||
sfFont_destroy(font);
|
||||
sfSprite_destroy(sprite);
|
||||
sfTexture_destroy(texture);
|
||||
sfRenderWindow_destroy(window);
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
72
Test - SFML/main.c~
Normal file
72
Test - SFML/main.c~
Normal file
|
@ -0,0 +1,72 @@
|
|||
#include <SFML/Audio.h>
|
||||
#include <SFML/Graphics.h>
|
||||
|
||||
/*Commandes :
|
||||
gcc -c main.c
|
||||
gcc main.o -o main -lcsfml-graphics -lcsfml-window -lcsfml-audio -lcsfml-system
|
||||
|
||||
*/
|
||||
|
||||
int main()
|
||||
{
|
||||
sfVideoMode mode = {800, 600, 32};
|
||||
sfRenderWindow* window;
|
||||
sfTexture* texture;
|
||||
sfSprite* sprite;
|
||||
sfFont* font;
|
||||
sfText* text;
|
||||
sfMusic* music;
|
||||
sfEvent event;
|
||||
/* Create the main window */
|
||||
window = sfRenderWindow_create(mode, "SFML window", sfResize | sfClose, NULL);
|
||||
if (!window)
|
||||
return EXIT_FAILURE;
|
||||
/* Load a sprite to display */
|
||||
texture = sfTexture_createFromFile("tree.jpeg", NULL);
|
||||
if (!texture)
|
||||
return EXIT_FAILURE;
|
||||
sprite = sfSprite_create();
|
||||
sfSprite_setTexture(sprite, texture, sfTrue);
|
||||
/* Create a graphical text to display */
|
||||
font = sfFont_createFromFile("arial.ttf");
|
||||
if (!font)
|
||||
return EXIT_FAILURE;
|
||||
text = sfText_create();
|
||||
sfText_setString(text, "Hello SFML");
|
||||
sfText_setFont(text, font);
|
||||
sfText_setCharacterSize(text, 50);
|
||||
/* Load a music to play */
|
||||
//music = sfMusic_createFromFile("nice_music.ogg");
|
||||
if (!music)
|
||||
return EXIT_FAILURE;
|
||||
/* Play the music */
|
||||
sfMusic_play(music);
|
||||
/* Start the game loop */
|
||||
while (sfRenderWindow_isOpen(window))
|
||||
{
|
||||
/* Process events */
|
||||
while (sfRenderWindow_pollEvent(window, &event))
|
||||
{
|
||||
/* Close window : exit */
|
||||
if (event.type == sfEvtClosed)
|
||||
sfRenderWindow_close(window);
|
||||
}
|
||||
/* Clear the screen */
|
||||
sfRenderWindow_clear(window, sfBlack);
|
||||
/* Draw the sprite */
|
||||
sfRenderWindow_drawSprite(window, sprite, NULL);
|
||||
/* Draw the text */
|
||||
sfRenderWindow_drawText(window, text, NULL);
|
||||
/* Update the window */
|
||||
sfRenderWindow_display(window);
|
||||
}
|
||||
/* Cleanup resources */
|
||||
sfMusic_destroy(music);
|
||||
sfText_destroy(text);
|
||||
sfFont_destroy(font);
|
||||
sfSprite_destroy(sprite);
|
||||
sfTexture_destroy(texture);
|
||||
sfRenderWindow_destroy(window);
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
BIN
Test - SFML/main.o
Normal file
BIN
Test - SFML/main.o
Normal file
Binary file not shown.
BIN
Test - SFML/navi hey listen all sounds.mp3
Normal file
BIN
Test - SFML/navi hey listen all sounds.mp3
Normal file
Binary file not shown.
BIN
Test - SFML/nice_music.ogg
Normal file
BIN
Test - SFML/nice_music.ogg
Normal file
Binary file not shown.
11
Test - SFML/test2.c~
Normal file
11
Test - SFML/test2.c~
Normal file
|
@ -0,0 +1,11 @@
|
|||
#include <SFML/Graphics.h>
|
||||
|
||||
int main(){
|
||||
sfVideoMode mode = {800, 600, 32};
|
||||
sfRenderWindow* window;
|
||||
/* Create the main window */
|
||||
window = sfRenderWindow_create(mode, "SFML window", sfResize | sfClose, NULL);
|
||||
|
||||
|
||||
|
||||
}
|
BIN
Test - SFML/tree.jpeg
Normal file
BIN
Test - SFML/tree.jpeg
Normal file
Binary file not shown.
After Width: | Height: | Size: 5.9 KiB |
126
src/DisplayImage.cpp
Normal file
126
src/DisplayImage.cpp
Normal file
|
@ -0,0 +1,126 @@
|
|||
|
||||
#include <cv.h>
|
||||
#include <highgui.h>
|
||||
//#include <cxcore.h>
|
||||
|
||||
//#include <SFML/Window.hpp>
|
||||
|
||||
int main(int argc, char* argv[])
|
||||
{
|
||||
int height,width,step,channels; //parameters of the image we are working on
|
||||
int posX, posY; //Position objet
|
||||
CvMoments *moments = (CvMoments*)malloc(sizeof(CvMoments)); //Variable moyenne position
|
||||
|
||||
// Open capture device. 0 is /dev/video0, 1 is /dev/video1, etc.
|
||||
CvCapture* capture = cvCaptureFromCAM( 0 );
|
||||
|
||||
if( !capture ){
|
||||
printf("ERROR: capture is NULL \n" );
|
||||
return -1;
|
||||
}
|
||||
|
||||
// grab an image from the capture
|
||||
IplImage* frame = cvQueryFrame( capture );
|
||||
|
||||
// Create a window in which the captured images will be presented
|
||||
cvNamedWindow( "Camera", CV_WINDOW_AUTOSIZE );
|
||||
cvNamedWindow( "HSV", CV_WINDOW_AUTOSIZE );
|
||||
cvNamedWindow( "Binaire", CV_WINDOW_AUTOSIZE );
|
||||
|
||||
//sf::Window window;
|
||||
//window.create(sf::VideoMode(800, 600), "My window",sf::Style::Default);
|
||||
|
||||
// get the image data
|
||||
height = frame->height;
|
||||
width = frame->width;
|
||||
step = frame->widthStep;
|
||||
|
||||
// capture size -
|
||||
CvSize size = cvSize(width,height);
|
||||
|
||||
// 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
|
||||
cvNamedWindow("Control", CV_WINDOW_AUTOSIZE); //create a window called "Control"
|
||||
|
||||
//Setup Kirby
|
||||
int iLowH = 139;
|
||||
int iHighH = 179;
|
||||
|
||||
int iLowS = 48;
|
||||
int iHighS = 255;
|
||||
|
||||
int iLowV = 101;
|
||||
int iHighV = 255;
|
||||
|
||||
|
||||
//Create trackbars in "Control" window
|
||||
cvCreateTrackbar("LowH", "Control", &iLowH, 179); //Hue (0 - 179)
|
||||
cvCreateTrackbar("HighH", "Control", &iHighH, 179);
|
||||
|
||||
cvCreateTrackbar("LowS", "Control", &iLowS, 255); //Saturation (0 - 255)
|
||||
cvCreateTrackbar("HighS", "Control", &iHighS, 255);
|
||||
|
||||
cvCreateTrackbar("LowV", "Control", &iLowV, 255); //Value (0 - 255)
|
||||
cvCreateTrackbar("HighV", "Control", &iHighV, 255);
|
||||
|
||||
|
||||
while( 1 )
|
||||
{
|
||||
|
||||
// Get one frame
|
||||
frame = cvQueryFrame( capture );
|
||||
|
||||
if( !frame ){
|
||||
printf("ERROR: frame is null...\n" );
|
||||
break;
|
||||
}
|
||||
|
||||
// Covert color space to HSV as it is much easier to filter colors in the HSV color-space.
|
||||
cvCvtColor(frame, hsv_frame, CV_BGR2HSV);
|
||||
|
||||
//Blur
|
||||
cvSmooth( hsv_frame, hsv_frame, CV_GAUSSIAN, 15, 15); //suppression des parasites par flou gaussien
|
||||
|
||||
//Binarisation
|
||||
cvInRangeS(hsv_frame, cvScalar(iLowH, iLowS, iLowV), cvScalar(iHighH, iHighS, iHighV), threshold);
|
||||
|
||||
//cvSmooth( threshold, threshold, CV_GAUSSIAN, 9, 9 ); //Legère suppression des parasites
|
||||
|
||||
// Calculate the moments to estimate the position of the ball
|
||||
|
||||
cvMoments(threshold, moments, 1);
|
||||
// The actual moment values
|
||||
double moment10 = cvGetSpatialMoment(moments, 1, 0);
|
||||
double moment01 = cvGetSpatialMoment(moments, 0, 1);
|
||||
double area = cvGetCentralMoment(moments, 0, 0);
|
||||
|
||||
posX= moment10/area;
|
||||
posY= moment01/area;
|
||||
|
||||
//Affichage zone suivie objet
|
||||
cvCircle(frame, cvPoint(width/2,height/2), 100, CV_RGB(255, 0, 0), 4, 8, 0 );
|
||||
|
||||
//Affichage position de l'objet
|
||||
cvLine(frame, cvPoint(posX-20,posY), cvPoint(posX+20,posY), CV_RGB(0, 0, 255), 4, 8, 0 );
|
||||
cvLine(frame, cvPoint(posX,posY-20), cvPoint(posX,posY+20), CV_RGB(0, 0, 255), 4, 8, 0 );
|
||||
|
||||
cvShowImage( "Camera", frame ); // Original stream with detected ball overlay
|
||||
cvShowImage( "HSV", hsv_frame); // Original stream in the HSV color space
|
||||
cvShowImage( "Binaire", threshold); // The stream after color filtering
|
||||
|
||||
|
||||
if( (cvWaitKey(10) ) >= 0 ) break; //Arret capture
|
||||
}
|
||||
|
||||
cvWaitKey(0); //Fin programme
|
||||
|
||||
// Release the capture device housekeeping
|
||||
cvReleaseCapture( &capture );
|
||||
|
||||
cvReleaseImage(&threshold);
|
||||
|
||||
return 0;
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue