4 #include "opencv2/core/core.hpp"
5 #include "opencv2/core/gpumat.hpp"
6 #include "opencv2/core/opengl_interop.hpp"
7 #include "opencv2/gpu/gpu.hpp"
8 #include "opencv2/highgui/highgui.hpp"
9 #include "opencv2/contrib/contrib.hpp"
13 using namespace cv::gpu;
17 Timer(const string& msg_)
28 cout << msg << " " << tm.getTimeMilli() << " ms\n";
35 int main(int argc, char* argv[])
39 cout << "Usage: " << argv[0] << " image" << endl;
45 bool haveCuda = getCudaEnabledDeviceCount() > 0;
47 const string openGlMatWnd = "OpenGL Mat";
48 const string openGlBufferWnd = "OpenGL GlBuffer";
49 const string openGlTextureWnd = "OpenGL GlTexture";
50 const string openGlGpuMatWnd = "OpenGL GpuMat";
51 const string matWnd = "Mat";
53 namedWindow(openGlMatWnd, WINDOW_OPENGL | WINDOW_AUTOSIZE);
54 namedWindow(openGlBufferWnd, WINDOW_OPENGL | WINDOW_AUTOSIZE);
55 namedWindow(openGlTextureWnd, WINDOW_OPENGL | WINDOW_AUTOSIZE);
57 namedWindow(openGlGpuMatWnd, WINDOW_OPENGL | WINDOW_AUTOSIZE);
58 namedWindow("Mat", WINDOW_AUTOSIZE);
60 Mat img = imread(argv[1]);
65 setOpenGlContext(openGlBufferWnd);
66 GlBuffer buf(img, GlBuffer::TEXTURE_BUFFER);
68 setOpenGlContext(openGlTextureWnd);
75 cout << "=== First call\n\n";
78 Timer t("OpenGL Mat ");
79 imshow(openGlMatWnd, img);
82 Timer t("OpenGL GlBuffer ");
83 imshow(openGlBufferWnd, buf);
86 Timer t("OpenGL GlTexture");
87 imshow(openGlTextureWnd, tex);
91 Timer t("OpenGL GpuMat ");
92 imshow(openGlGpuMatWnd, d_img);
101 cout << "\n=== Second call\n\n";
104 Timer t("OpenGL Mat ");
105 imshow(openGlMatWnd, img);
108 Timer t("OpenGL GlBuffer ");
109 imshow(openGlBufferWnd, buf);
112 Timer t("OpenGL GlTexture");
113 imshow(openGlTextureWnd, tex);
117 Timer t("OpenGL GpuMat ");
118 imshow(openGlGpuMatWnd, d_img);
129 catch(const exception& e)
131 cout << e.what() << endl;