Chargement de l'image - anna-barry/OCR GitHub Wiki

ouvrir une image avec SDL

#include <err.h>
#include "SDL/SDL.h"
#include "SDL/SDL_image.h"

// TODO: Insert all the above functions
void init_sdl()
{
    // Init only the video part.
    // If it fails, die with an error message.
    if(SDL_Init(SDL_INIT_VIDEO) == -1)
        errx(1,"Could not initialize SDL: %s.\n", SDL_GetError());
}

SDL_Surface* load_image(char *path)
{
    SDL_Surface *img;

    // Load an image using SDL_image with format detection.
    // If it fails, die with an error message.
    img = IMG_Load(path);
    if (!img)
        errx(3, "can't load %s: %s", path, IMG_GetError());

    return img;
}

SDL_Surface* display_image(SDL_Surface *img)
{
    SDL_Surface *screen;

    // Set the window to the same size as the image
    screen = SDL_SetVideoMode(img->w, img->h, 0, SDL_SWSURFACE|SDL_ANYFORMAT);
    if (screen == NULL)
    {
        // error management
        errx(1, "Couldn't set %dx%d video mode: %s\n",
                img->w, img->h, SDL_GetError());
    }

    // Blit onto the screen surface
    if(SDL_BlitSurface(img, NULL, screen, NULL) < 0)
        warnx("BlitSurface error: %s\n", SDL_GetError());

    // Update the screen
    SDL_UpdateRect(screen, 0, 0, img->w, img->h);

    // return the screen for further uses
    return screen;
}

void wait_for_keypressed()
{
    SDL_Event event;

    // Wait for a key to be down.
    do
    {
        SDL_PollEvent(&event);
    } while(event.type != SDL_KEYDOWN);

    // Wait for a key to be up.
    do
    {
        SDL_PollEvent(&event);
    } while(event.type != SDL_KEYUP);
}

int main()
{
    SDL_Surface* image_surface;
    SDL_Surface* screen_surface;

    // TODO: Initialize the SDL
    init_sdl();

    image_surface = load_image("my_image.jpg");
    // TODO: Display the image.
    display_image(image_surface);

    // TODO: Wait for a key to be pressed.
    wait_for_keypressed();

    // TODO: Free the image surface.
    void SDL_FreeSurface(SDL_Surface image_surface);
    // TODO: Free the screen surface.
    void SDL_FreeSurface(SDL_Surface screen_surface);

    return 0;
}

Makefile

# Simple SDL mini Makefile

CC=gcc

CPPFLAGS= `pkg-config --cflags sdl` -MMD
CFLAGS= -Wall -Wextra -Werror -std=c99 -O3
LDFLAGS=
LDLIBS= `pkg-config --libs sdl` -lSDL_image

all: the_file

the_file: the_file.o


clean:
	${RM} *.o
	${RM} *.d
	${RM} the_file

# END

documentation sur le filtre median

filtre non linéaire le plus utilisé : le filtre médian remplace la valeur d’un pixel par la médiane des valeurs de ses voisins.

  • supprime le bruit impulsionnel. 􏰅 􏰅* préserve l’information de contour.

  • peut être appliqué itérativement.

⚠️ **GitHub.com Fallback** ⚠️