opengl_opencv_example/main.cpp

60 lines
1.4 KiB
C++

#include <opencv2/core.hpp>
#include <opencv2/core/opengl.hpp>
#include <opencv2/imgcodecs.hpp>
#include <opencv2/imgproc/imgproc.hpp>
#include <opencv2/highgui.hpp>
#include <iostream>
#ifdef __APPLE__
#include <OpenGL/gl.h>
#include <OpenGL/gl3.h>
#include <GLUT/glut.h>
#else
#include <GL/glew.h>
#include <GL/glut.h>
#endif
using namespace cv;
using namespace std;
Mat image;
GLuint imageTexture;
void displayMe(void)
{
// Set every pixel in the frame buffer to the current clear color.
glClear(GL_COLOR_BUFFER_BIT);
glBegin(GL_POLYGON);
glColor3f(1, 0, 0); glVertex3f(-1.0, -1.0, 0.5);
glColor3f(0, 1, 0); glVertex3f(1.0, -1.0, 0);
glColor3f(0, 0, 1); glVertex3f(1.0, 1.0, 0);
glVertex3f(-1.0, 1.0, 0);
glEnd();
// Flush drawing command buffer to make drawing happen as soon as possible.
glFlush();
}
int main(int argc, char** argv)
{
string image_path = samples::findFile("chart.png");
Mat image = imread(image_path, IMREAD_COLOR);
#if (CV_VERSION_MAJOR >= 4)
cvtColor(image, image, cv::COLOR_BGR2RGB);
#else
cvtColor(image, image, CV_BGR2RGB);
#endif
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_SINGLE);
glutInitWindowSize(1920, 1080);
glutInitWindowPosition(0, 0);
glutCreateWindow("opengl_opencv_example");
glutFullScreen();
glutDisplayFunc(displayMe);
glutMainLoop();
return 0;
}