09 透過 OPENGL 顯示OPENCV 加快顯示速度, 在球體上顯示正確顏色材質貼圖

目的:

透過 OPENGL 顯示OPENCV 加快顯示速度,並加上證券顏色材質貼圖,顯示在球上

函數介紹:


參數值:

使用範例:

sample14-2_OpenGL-貼圖RGB

/* www.powenko.com
 Author: Powen Ko

 $ g++   main.cpp -o main -I/opt/local/include -L/opt/local/lib -lopencv_core.2.4.10 -lopencv_highgui.2.4.10 -framework GLUT -framework OpenGL -Wno-deprecated-declarations `pkg-config --cflags --libs opencv`

 */
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/opencv.hpp>
#include <iostream>
#include <string.h>
#include <fstream>

#include <stdio.h>
#include <opencv/highgui.h>
#ifdef __APPLE__
#include <GLUT/glut.h>

#else
#include <GL/glut.h>
#endif

using namespace cv;
GLuint id[100];

GLUquadric * quadric;
void display()
{
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    glPushMatrix();
   // glutSolidTeapot(0.5);
    gluSphere(quadric,0.8,30,30);
    glPopMatrix();
    glFlush();
}
void init_texture(IplImage * img)
{
    glEnable(GL_TEXTURE_2D);
    glGenTextures(10, id);
    glBindTexture(GL_TEXTURE_2D, id[0]);

    glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_LINEAR);
    glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_LINEAR);
    glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
    glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);

    glTexImage2D(GL_TEXTURE_2D,0,GL_RGB,img->width,img->height,0,
                 GL_RGB,GL_UNSIGNED_BYTE,img->imageData);
}

int main(int argc,char* argv[])
{

    IplImage * image=cvLoadImage("1.jpg");

    cvCvtColor(image, image, CV_BGR2RGB);

    glutInit(&argc,argv);
    glutCreateWindow("Hello World");
    glutDisplayFunc(display);

    quadric=gluNewQuadric();
    gluQuadricTexture(quadric,1);

    init_texture(image);
    glutMainLoop();
}

結果:

Screen Shot 2015-03-01 at 3.24.25 PM

補充資料: