From 026707912cd22542b1d1ee8e41b94ce8e7198635 Mon Sep 17 00:00:00 2001 From: Gary Bradski Date: Sat, 27 May 2017 13:13:53 -0700 Subject: [PATCH 1/3] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 0d89140..81b03dc 100644 --- a/README.md +++ b/README.md @@ -5,7 +5,7 @@ This is the example code that accompanies Learning OpenCV 3 by Adrian Kaehler an **In progress May 24, 2017** -This code is in progress, currently at Chapter 15, bear with us, the code is coming, both Authors are busy, as always, building startups. +This code is in progress, currently at Chapter 15, bear with us, the code is coming, both Authors are busy, as always, building startups. If you want to help, request to join the project. Keep pull requests to one function at a time. It doesn't have to be just examples from the book, it can be other code snippets from the book, exercises, new functionality or even a "how to use" opencv_contrib functions. Note, for your interest, included here is a _Docker_ file that * Loads Ubuntu 16.04 From d375d6942b62df869d4443a8e9b39d57e67b825b Mon Sep 17 00:00:00 2001 From: DolotovEvgeniy Date: Wed, 31 May 2017 14:21:38 +0300 Subject: [PATCH 2/3] add example 09-04 --- CMakeLists.txt | 13 +++++- example_09-04.cpp | 109 +++++++++++++++++++++++++++++++++++----------- 2 files changed, 95 insertions(+), 27 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 2a06f0b..1ab24e6 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -4,8 +4,13 @@ cmake_minimum_required(VERSION 2.8) project( examples ) find_package( OpenCV REQUIRED ) +find_package( OpenGL REQUIRED ) -include_directories( ${OpenCV_INCLUDE_DIRS} ) +if(OPENGL_FOUND) + include_directories( ${OpenCV_INCLUDE_DIRS} ${OPENGL_INCLUDE_DIRS} ) +else() + include_directories( ${OpenCV_INCLUDE_DIRS} ) +endif() add_executable( example_02-01 example_02-01.cpp ) add_executable( example_02-02 example_02-02.cpp ) @@ -30,6 +35,9 @@ add_executable( example_08-03 example_08-03.cpp ) add_executable( example_09-01 example_09-01.cpp ) add_executable( example_09-02 example_09-02.cpp ) add_executable( example_09-03 example_09-03.cpp ) +if(OPENGL_FOUND) + add_executable( example_09-04 example_09-04.cpp ) +endif() add_executable( example_10-01 example_10-01.cpp ) add_executable( example_10-02 example_10-02.cpp ) add_executable( example_10-03 example_10-03.cpp ) @@ -75,6 +83,9 @@ target_link_libraries( example_09-02 ${OpenCV_LIBS} ) target_link_libraries( example_09-03 ${OpenCV_LIBS} ) target_link_libraries( example_09-02 ${OpenCV_LIBS} ) target_link_libraries( example_09-03 ${OpenCV_LIBS} ) +if(OPENGL_FOUND) + target_link_libraries( example_09-04 ${OpenCV_LIBS} ${OPENGL_LIBRARIES} ) +endif() target_link_libraries( example_10-01 ${OpenCV_LIBS} ) target_link_libraries( example_10-02 ${OpenCV_LIBS} ) target_link_libraries( example_10-03 ${OpenCV_LIBS} ) diff --git a/example_09-04.cpp b/example_09-04.cpp index 71ccb3e..1182dbd 100644 --- a/example_09-04.cpp +++ b/example_09-04.cpp @@ -1,35 +1,92 @@ //Example 9-4. Slightly modified code from the OpenCV documentation that draws a //cube every frame; this modified version uses the global variables rotx and roty that are //connected to the sliders in Figure 9-6 +#include +#include #include +#include +#include + using namespace std; -void on_opengl( void* param ) { - glMatrixModel( GL_MODELVIEW ); - glLoadIdentity(); - glTranslated( 0.0, 0.0, -1.0 ); - glRotatef( rotx, 1, 0, 0 ); - glRotatef( roty, 0, 1, 0 ); - glRotatef( 0, 0, 0, 1 ); - static const int coords[6][4][3] = { - { { +1, -1, -1 }, { -1, -1, -1 }, { -1, +1, -1 }, { +1, +1, -1 } }, - { { +1, +1, -1 }, { -1, +1, -1 }, { -1, +1, +1 }, { +1, +1, +1 } }, - { { +1, -1, +1 }, { +1, -1, -1 }, { +1, +1, -1 }, { +1, +1, +1 } }, - { { -1, -1, -1 }, { -1, -1, +1 }, { -1, +1, +1 }, { -1, +1, -1 } }, - { { +1, -1, +1 }, { -1, -1, +1 }, { -1, -1, -1 }, { +1, -1, -1 } }, - { { -1, -1, +1 }, { +1, -1, +1 }, { +1, +1, +1 }, { -1, +1, +1 } } - }; - for (int i = 0; i < 6; ++i) { - glColor3ub( i*20, 100+i*10, i*42 ); - glBegin(GL_QUADS); - for (int j = 0; j < 4; ++j) { - glVertex3d( - 0.2 * coords[i][j][0], - 0.2 * coords[i][j][1], - 0.2 * coords[i][j][2] - ); +int rotx = 55, roty = 40; + +void on_opengl(void* param) { + cv::ogl::Texture2D* backgroundTex = (cv::ogl::Texture2D*)param; + glEnable( GL_TEXTURE_2D ); + backgroundTex->bind(); + cv::ogl::render(*backgroundTex); + glDisable( GL_TEXTURE_2D ); + + glMatrixMode( GL_PROJECTION ); + glLoadIdentity(); + glMatrixMode( GL_MODELVIEW ); + glLoadIdentity(); + glTranslatef(0, 0, -0.5); + glRotatef( rotx, 1, 0, 0 ); + glRotatef( roty, 0, 1, 0 ); + glRotatef( 0, 0, 0, 1 ); + glEnable( GL_DEPTH_TEST ); + glDepthFunc( GL_LESS ); + static const int coords[6][4][3] = { + { { +1, -1, -1 }, { -1, -1, -1 }, { -1, +1, -1 }, { +1, +1, -1 } }, + { { +1, +1, -1 }, { -1, +1, -1 }, { -1, +1, +1 }, { +1, +1, +1 } }, + { { +1, -1, +1 }, { +1, -1, -1 }, { +1, +1, -1 }, { +1, +1, +1 } }, + { { -1, -1, -1 }, { -1, -1, +1 }, { -1, +1, +1 }, { -1, +1, -1 } }, + { { +1, -1, +1 }, { -1, -1, +1 }, { -1, -1, -1 }, { +1, -1, -1 } }, + { { -1, -1, +1 }, { +1, -1, +1 }, { +1, +1, +1 }, { -1, +1, +1 } } + }; + for (int i = 0; i < 6; ++i) { + glColor3ub( i*20, 100+i*10, i*42 ); + glBegin( GL_QUADS ); + for (int j = 0; j < 4; ++j) { + glVertex3d( + 0.2 * coords[i][j][0], + 0.2 * coords[i][j][1], + 0.2 * coords[i][j][2] + ); + } + glEnd(); } - glEnd(); - } +} + +void on_trackbar( int, void* ) { + cv::updateWindow( "Example 9-4" ); +} + +void help(char ** argv) { + cout << "Call: " << argv[0] << " " << endl; + cout << "Here OpenGL is used to render a cube on top of an image.\n" + << "User can rotate the cube with the sliders" < Date: Wed, 31 May 2017 13:48:23 -0700 Subject: [PATCH 3/3] Update example_09-04.cpp Added a comment note about OpenGL --- example_09-04.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/example_09-04.cpp b/example_09-04.cpp index 1182dbd..e9ce7fb 100644 --- a/example_09-04.cpp +++ b/example_09-04.cpp @@ -1,6 +1,8 @@ //Example 9-4. Slightly modified code from the OpenCV documentation that draws a //cube every frame; this modified version uses the global variables rotx and roty that are //connected to the sliders in Figure 9-6 +// Note: This example needs OpenGL installed on your system. It doesn't build if +// the OpenGL libraries cannot be found. #include #include