IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Bibliothèques Discussion :

[OpenGL] Lecteur AVI


Sujet :

Bibliothèques

  1. #1
    Membre à l'essai
    Profil pro
    Inscrit en
    Février 2011
    Messages
    13
    Détails du profil
    Informations personnelles :
    Localisation : Belgique

    Informations forums :
    Inscription : Février 2011
    Messages : 13
    Points : 10
    Points
    10
    Par défaut [OpenGL] Lecteur AVI
    Bonjour à tous,
    Comme vous l'avez lu j'ai besoin d'un lecteur AVI qui utilise l'openGL. En fait le lecteur fonctionne mais j'ai du prendre du code à gauche à droite sur le net + aide d'un pote. Il faut savoir que j'ai commencé l'openGL hier

    Donc voici le code, je voudrais savoir si j'utilise des choses obsolète ou si je me complique la vie, j'utilise openCV pour capturer les frames et je vais avoir besoin d'un kernel CUDA par la suite mais dans un premier temps j'ai besoin du lecteur AVI :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    207
    208
    209
    210
    211
    212
    213
    214
    215
    216
    217
    218
    219
    220
    221
    222
    223
    224
    225
    226
    227
    228
    229
    230
    231
    232
    233
    234
    235
    236
    237
    238
    239
    240
    241
    242
    243
    244
    245
    246
    247
    248
    249
    250
    251
    252
    253
    254
     
    #include <stdio.h>
    #include <stdlib.h>
    #include <cutil_inline.h>
    #include <math.h>
    #include <GL/glew.h>
    #include <GL/glut.h>
    #include <cuda_gl_interop.h>
    #include <rendercheck_gl.h>
    #include <cuda.h>
    #include <cuda_runtime.h>
    #include <cxtypes.h>
    #include <cxcore.h>
    #include <cv.h>
    #include <highgui.h>
    #include <ml.h>
    #include <string.h>
    #include <iostream>
    #include <time.h>
    using namespace std;
     
    char *video_filename = "eddy.avi"; 
     
    IplImage* frame;
    CvCapture* capture=NULL;
    int nbrframes=1;
    clock_t debut,fin;
    char *imgData;
    unsigned int *imgBase;
    unsigned int *imgFrame;
    unsigned int width, height;
    unsigned int * img_base = NULL;
    unsigned int * img_frame = NULL;
    int tblock=0;
    int nbrblk=0;
    int nbroctets=0;
    dim3 DimBlock(512,1,1);
    dim3 DimGrid;
     
    GLuint pbo;
    GLuint texid;
    GLuint shader;
    CheckRender       *g_CheckRender = NULL;
     
    //=================== FONCTION DE SORTIE AVEC AFFICHAGE DU RESULTAT
    void goExit() 
    {
    	fin=clock();
    	double duree = (double) (fin-debut)/ CLOCKS_PER_SEC;
    	cout<<"Time : "<<duree<<endl;
    	duree = nbrframes/duree;
    	cout<<"FPS : "<<duree<<endl;
    	system("PAUSE");
    	exit(0);
    }
    //===============================================================
     
    //==================== BOUCLE DE LECTURE OPENGL
    void display()
    {
        unsigned int *d_result;
     
        glClear(GL_COLOR_BUFFER_BIT); //effacement des pixels du buffer d'affichage
     
    	frame=cvQueryFrame(capture);  //--- image suivante
    	if (!frame) goExit();
     
    	glBindBufferARB(GL_PIXEL_UNPACK_BUFFER_ARB, pbo);
    	glBufferDataARB(GL_PIXEL_UNPACK_BUFFER_ARB, width*height*sizeof(GLubyte)*3, frame->imageData, GL_STREAM_DRAW_ARB);
     
    	//************************************************************************************* CODE GPU
    	//CUDA_SAFE_CALL(cudaGLMapBufferObject((void**)&img_frame, pbo))
    	//Sobel a placer ici
    	//CUDA_SAFE_CALL(cudaGLUnmapBufferObject(pbo));
    	//************************************************************************************* FIN CODE GPU
     
        glBindBufferARB(GL_PIXEL_UNPACK_BUFFER_ARB, pbo);
        glBindTexture(GL_TEXTURE_2D, texid);
        glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, width, height, GL_BGR, GL_UNSIGNED_BYTE, 0);
        glBindBufferARB(GL_PIXEL_UNPACK_BUFFER_ARB, 0);
     
        glBindProgramARB(GL_FRAGMENT_PROGRAM_ARB, shader);
        glEnable(GL_FRAGMENT_PROGRAM_ARB);
        glDisable(GL_DEPTH_TEST);
     
        glBegin(GL_QUADS);
        glVertex2f(0, 0); glTexCoord2f(0, 0);
        glVertex2f(0, 1); glTexCoord2f(1, 0);
        glVertex2f(1, 1); glTexCoord2f(1, 1);
        glVertex2f(1, 0); glTexCoord2f(0, 1);
        glEnd();
     
        glBindTexture(GL_TEXTURE_2D, 0);
        glDisable(GL_FRAGMENT_PROGRAM_ARB);
     
        glutSwapBuffers();
    	nbrframes++;
    }
     
    void idle()
    {
        glutPostRedisplay();
    }
     
    void reshape(int x, int y)
    {
        glViewport(0, 0, x, y); //glViewport definie la portion de l'ecran dans laquelle tu vas dessiner
     
        glMatrixMode(GL_MODELVIEW);
        glLoadIdentity();
     
        glMatrixMode(GL_PROJECTION);
        glLoadIdentity();
        glOrtho(0.0, 1.0, 0.0, 1.0, 0.0, 1.0); //l'angle de vue.
    }
     
    //==================== INITIALISATION DE CUDA
    void initCuda()
    {
    	CUDA_SAFE_CALL (cudaMalloc( (void**) &img_base,  (nbroctets*4) ));
    	cudaMemcpy(img_base,imgBase,nbroctets*4,cudaMemcpyHostToDevice);
     
    }
    //==================== DESALLOCATION CUDA ET POINTEURS
    void cleanup()
    {
        free(imgData);
        CUDA_SAFE_CALL(cudaFree(img_base));
     
    	glDeleteBuffersARB(1, &pbo);
        glDeleteTextures(1, &texid);
        glDeleteProgramsARB(1, &shader);
     
        if (g_CheckRender) {
            delete g_CheckRender; g_CheckRender = NULL;
        }
    }
     
    //================================================================================================================ partie SHADERS
    // shader for displaying floating-point texture
    static const char *shader_code = 
    "!!ARBfp1.0\n"
    "TEX result.color, fragment.texcoord, texture[0], 2D; \n"
    "END";
     
    GLuint compileASMShader(GLenum program_type, const char *code)
    {
        GLuint program_id;
        glGenProgramsARB(1, &program_id);
        glBindProgramARB(program_type, program_id);
        glProgramStringARB(program_type, GL_PROGRAM_FORMAT_ASCII_ARB, (GLsizei) strlen(code), (GLubyte *) code);
     
        GLint error_pos;
        glGetIntegerv(GL_PROGRAM_ERROR_POSITION_ARB, &error_pos);
        if (error_pos != -1) {
            const GLubyte *error_string;
            error_string = glGetString(GL_PROGRAM_ERROR_STRING_ARB);
            fprintf(stderr, "Program error at position: %d\n%s\n", (int)error_pos, error_string);
            return 0;
        }
        return program_id;
    }
    //================================================================================================================
     
    void initOpenGL()
    {
        glGenBuffersARB(1, &pbo); //crée 1 pixel buffer object ->pbo pointe dessus.
    	glBindBufferARB(GL_PIXEL_UNPACK_BUFFER_ARB, pbo); //chargement depuis pbo
    	glBufferDataARB(GL_PIXEL_UNPACK_BUFFER_ARB, width*height*sizeof(GLubyte)*3, frame->imageData, GL_STREAM_DRAW_ARB);
    	glBindBufferARB(GL_PIXEL_UNPACK_BUFFER_ARB, 0); //-----??? efface?
    	CUDA_SAFE_CALL(cudaGLRegisterBufferObject(pbo));//on enregistre avec cuda
     
        // create texture for display
        glGenTextures(1, &texid);
        glBindTexture(GL_TEXTURE_2D, texid);
        glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, width, height, 0, GL_RGB, GL_UNSIGNED_BYTE, NULL);
        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
        glBindTexture(GL_TEXTURE_2D, 0);
     
        // load shader program
        shader = compileASMShader(GL_FRAGMENT_PROGRAM_ARB, shader_code);
    }
     
    //****************************************************************************************************************
    // Program main
    //****************************************************************************************************************
     
    int main( int argc, char** argv) 
    {
     
    	cudaSetDevice(0); //selection de la carte principale
     
    	capture = cvCreateFileCapture(video_filename);
    	frame=cvQueryFrame(capture);
     
        printf("Loaded %d x %d pixels\n", frame->width, frame->height);
    	width=frame->width;
    	height=frame->height;
    	cout<<frame->nChannels<<endl;
    	cout<<frame->colorModel<<endl;
    	cout<<frame->channelSeq<<endl;
    	nbroctets=(int)ceil((double)frame->imageSize/4);
    	imgData= (char*) malloc (nbroctets*4);
    	imgBase=(unsigned int*)imgData;
    	nbrblk=(int)ceil((double)nbroctets/512);
    	tblock=(int)ceil((double)pow(nbrblk,0.5));
     
    	DimGrid.x=tblock;
    	DimGrid.y=tblock;
    	DimGrid.z=1;
     
    	for (int i=0;i<nbroctets;i++) imgBase[i]=0;
     
    	for (int i=0;i<frame->imageSize;i++) 
    	{
    		imgData[i]=frame->imageData[i];
    	}
     
    	frame=cvQueryFrame(capture);
     
        //initialize GLUT
    	//CREER FENETRE
        glutInit(&argc, argv);  
        glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE);
        glutInitWindowSize(width, height);
        glutCreateWindow("CUDA Box Filter");
     
    	//allocation memoire
    	initCuda(); 
     
    	//initialisation des fonctions OGL
        glutDisplayFunc(display);
        glutReshapeFunc(reshape);
        glutIdleFunc(idle);
     
        glewInit(); //initialisation GL et test de compatiobilité
     
    		if (!glewIsSupported( "GL_VERSION_1_5 GL_ARB_vertex_buffer_object GL_ARB_pixel_buffer_object" )) {
    			fprintf(stderr, "Error: failed to get minimal extensions for demo\n");
    			fprintf(stderr, "This sample requires:\n");
    			fprintf(stderr, "  OpenGL version 1.5\n");
    			fprintf(stderr, "  GL_ARB_vertex_buffer_object\n");
    			fprintf(stderr, "  GL_ARB_pixel_buffer_object\n");
    			exit(-1);
    		}
     
        initOpenGL();
        fflush(stdout);
    	atexit(cleanup);
    	debut=clock();
        glutMainLoop();
        CUT_EXIT(argc, argv);
    }
    Merci d'avance.

  2. #2
    Membre du Club
    Inscrit en
    Mai 2005
    Messages
    111
    Détails du profil
    Informations forums :
    Inscription : Mai 2005
    Messages : 111
    Points : 49
    Points
    49
    Par défaut [OpenGL]Textures videos et les pbos
    Bonjour J'aimerai savoir comment utiliser une texture animés et l'accélérer avec les pbos. J'ai trouvé un exemple sur ce forum mais il n'est pas fonctionnel . il utilise OpenCV et OpenGL. Ya til quelqu'un qui peut le corriger et enlever Cuda.
    le code est ici :http://www.developpez.net/forums/d10...l-lecteur-avi/ (gbdivers : discussions fusionnées)

  3. #3
    Inactif  


    Homme Profil pro
    Inscrit en
    Novembre 2008
    Messages
    5 288
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 48
    Localisation : France, Rhône (Rhône Alpes)

    Informations professionnelles :
    Secteur : Santé

    Informations forums :
    Inscription : Novembre 2008
    Messages : 5 288
    Points : 15 620
    Points
    15 620
    Par défaut
    Citation Envoyé par pointer Voir le message
    Ya til quelqu'un qui peut le corriger et enlever Cuda
    Non, c'est un forum d'entraide, pas un forum "faite le boulot à ma place"
    Merci de proposer ton propre code avec les erreurs/problèmes rencontrés

Discussions similaires

  1. Utiliser APN en lecteur vidéo, votre avis?
    Par dockurt2k dans le forum Vidéo
    Réponses: 3
    Dernier message: 09/09/2006, 11h21
  2. Réponses: 3
    Dernier message: 01/08/2006, 23h29

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo