Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit bd4e8fa

Browse files
committed
Fixed issues on the new README file.
1 parent cebdd47 commit bd4e8fa

File tree

17 files changed

+862
-16
lines changed

17 files changed

+862
-16
lines changed

README.md

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,18 @@ Demos related to **OpenGL**, **Qt/QML**, **OpenCV** and other X technologies.
55

66
Demo | Description | Screenshot
77
----------------------------------|----------------------------------------|----------------------------------------
8-
**cvDisplacementMapFilter** | C++ implementation of Displacement Map Filter in OpenCV that renders two images as a movie clip. | <img src="cvDisplacementMapFilter/screenshot.gif" width="200" height="150"/>
9-
**cvFruitClassification** | C++/OpenCV port of [a cool Python application](http://github.com/eliezerb/FruitClassification) that performs Oranges vs Apples classification using LDA. | <img src="cvFruitClassification/screenshot.jpg" width="200" height="185"/>
10-
**cvImage** | C++/Qt/OpenCV example that displays an image and the RGB values of a pixel based on mouse coordinates. | <img src="cvImage/screenshot.jpg" width="200" height="150"/>
11-
**cvQTcameraGL** | Demonstrates how to use OpenCV to retrieve frames from the default camera and display them on Qt with native OpenGL. | <img src="cvQTcameraGL/screenshot.jpg" width="200" height="150"/>
12-
**cvVideo** | Demonstrates how to use OpenCV/Qt to display video files with configurable Aspect Ratio. | <img src="cvVideo/screenshot.gif" width="250" height="130"/>
13-
**cvWatershedSegmentation** | [Stackoverflow example](https://stackoverflow.com/a/25851951/176769) that uses OpenCV's watershed segmentation with distance transform to segment beans. | <img src="cvWatershedSegmentation/screenshot.jpg" width="200" height="200"/>
14-
**ipcQtGesture** | A Qt application that uses the old *Intel® Perceptual Computing SDK 2013* for gesture recognition. Windows only. | No image available
15-
**qmlBattery** | A QML Battery element that displays the amount of energy left as horizontal bars according to the charge. On this demo, the charge is set dynamically and randomly from the C++ side. | <img src="qmlBattery/screenshot.gif" width="200" height="180"/>
16-
**qtArduinoSerial** | An application that prints data from a serial (COM) port connected to an Arduino. | No image available
17-
**qtFPSvsTIMEAnimation** | A Qt implementation of FPS-based and Time-based animation techniques, as explained by [Steven Lambert](http://blog.sklambert.com/using-time-based-animation-implement/) | <img src="qtFPSvsTIMEAnimation/screenshot.gif" width="200" height="280"/>
18-
**qtKinectVideo** | An application based on "Color Basics" from Kinect for Windows SDK 1.8. This demo shows how to display the Color Stream on your Qt application. | No image available
19-
**qtLinearRegressionGD** | A C++/Eigen implementation of Linear Regression based on [Daniel Shiffman's tutorials](https://www.youtube.com/watch?v=szXbuO3bVRk). Data is plotted with [Madplotlib](https://github.com/madplotlib/madplotlib) | <img src="qtLinearRegressionGD/screenshot.jpg" width="200" height="130"/>
20-
**qtLogoBlurGL** | A Qt/OpenGL demo that renders a logo on a texture and performs a blur for glow. | <img src="qtLogoBlurGL/screenshot.jpg" width="200" height="150"/>
21-
**qtSmoothColorTransition** | A Qt application that takes a grayscale image and performs a smooth color transition using a predefined color palette for linear interpolation. | <img src="qtSmoothColorTransition/screenshot.jpg" width="200" height="200"/>
8+
**cvDisplacementMapFilter** | A Displacement Map Filter implemenatation in C++/OpenCV that renders two images as a movie clip. | <img src="cvDisplacementMapFilter/screenshot.gif" width="200"/>
9+
**cvFruitClassification** | C++/OpenCV port of [a cool Python application](http://github.com/eliezerb/FruitClassification) that performs Oranges vs Apples classification using LDA. | <img src="cvFruitClassification/screenshot.jpg" width="200"/>
10+
**cvImage** | C++/Qt/OpenCV example that displays an image and the RGB values of a pixel based on mouse coordinates. | <img src="cvImage/screenshot.jpg" width="200"/>
11+
**cvQTcameraGL** | Just another demo on how to use C++/OpenCV to retrieve frames from the camera and draw them in a Qt widget using an OpenGL context for GPU rendering. | <img src="cvQTcameraGL/screenshot.gif" width="200"/>
12+
**cvVideo** | A C++/OpenCV/Qt example on how to display video files with configurable Aspect Ratio. | <img src="cvVideo/screenshot.gif" width="200"/>
13+
**cvWatershedSegmentation** | [Stackoverflow answer](https://stackoverflow.com/a/25851951/176769) that uses C++/OpenCV's watershed segmentation with distance transform to segment beans. | <img src="cvWatershedSegmentation/screenshot.jpg" width="200"/>
14+
**ipcQtGesture** | A C++/Qt application that uses the old *Intel® Perceptual Computing SDK 2013* for gesture recognition. Windows only. | No image available
15+
**qmlBattery** | A Qt/QML Battery element that displays the amount of energy left as horizontal bars according to the charge. On this demo, the charge is set dynamically and randomly from the C++ side. | <img src="qmlBattery/screenshot.gif" width="200"/>
16+
**qtArduinoSerial** | An C++/Qt example on how to print data from a serial (COM) port connected to Arduino. | No image available
17+
**qtFPSvsTIMEAnimation** | A C++/Qt implementation of FPS-based and Time-based animation techniques, as explained by [Steven Lambert](http://blog.sklambert.com/using-time-based-animation-implement/) | <img src="qtFPSvsTIMEAnimation/screenshot.gif" width="180"/>
18+
**qtKinectVideo** | C++/Qt application based on "Color Basics" from Kinect for Windows SDK 1.8. This demo shows how to display the Color Stream. | No image available
19+
**qtLinearRegressionGD** | A C++/Eigen implementation of Linear Regression based on [Daniel Shiffman's tutorials](https://www.youtube.com/watch?v=szXbuO3bVRk). Data is plotted with [Madplotlib](https://github.com/madplotlib/madplotlib) (Qt required). | <img src="qtLinearRegressionGD/screenshot.jpg" width="200"/>
20+
**qtLogoBlurGL** | A silly C++/Qt/OpenGL demo that renders a logo on a texture and performs a blur for glowing purposes. | <img src="qtLogoBlurGL/screenshot.jpg" width="200"/>
21+
**qtSmoothColorTransition** | A C++/Qt application that takes a grayscale image and performs a smooth color transition using a predefined color palette based on linear interpolation. | <img src="qtSmoothColorTransition/screenshot.jpg" width="200"/>
2222

cvQTcameraGL/main.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* Copyright (C) 2013 Karl Phillip Buhr <[email protected]>
1+
/* Copyright (C) 2013-2020 Karl Phillip Buhr <[email protected]>
22
*
33
* This work is licensed under the Creative Commons Attribution-ShareAlike License.
44
* To view a copy of this license, visit:

cvQTcameraGL/screenshot.jpg

-165 KB
Binary file not shown.

cvQTcameraGL/widget.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* Copyright (C) 2013 Karl Phillip Buhr <[email protected]>
1+
/* Copyright (C) 2013-2020 Karl Phillip Buhr <[email protected]>
22
*
33
* This work is licensed under the Creative Commons Attribution-ShareAlike License.
44
* To view a copy of this license, visit:

cvQtCameraGL/cvQTcameraGL.pro

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
QT += core gui opengl
2+
3+
contains(QT_VERSION, ^5\\.[0-8]\\..*) {
4+
message("* Using Qt $${QT_VERSION}.")
5+
QT += widgets
6+
7+
# On my system I have to specify g++ as compiler else it will use clang++ by default
8+
#QMAKE_CXX=g++
9+
#QMAKE_CC=gcc
10+
}
11+
12+
SOURCES += \
13+
main.cpp \
14+
widget.cpp
15+
16+
HEADERS += \
17+
widget.h
18+
19+
## OpenCV settings for Unix/Linux
20+
unix:!mac {
21+
message("* Using settings for Unix/Linux.")
22+
INCLUDEPATH += /usr/local/include/opencv
23+
24+
LIBS += -L/usr/local/lib/ \
25+
-lopencv_core \
26+
-lopencv_highgui \
27+
-lopencv_imgproc
28+
}
29+
30+
## OpenCV settings for Mac OS X with OpenCV 3.1
31+
macx {
32+
message("* Using settings for Mac OS X.")
33+
34+
# Solve imwrite() undefined symbol
35+
QMAKE_CXXFLAGS += -stdlib=libc++
36+
37+
INCLUDEPATH += "/usr/local/opt/opencv3/include"
38+
39+
LIBS += -L"/usr/local/opt/opencv3/lib" \
40+
-lopencv_core \
41+
-lopencv_highgui \
42+
-lopencv_imgproc \
43+
-lopencv_imgcodecs \
44+
-lopencv_videoio \
45+
-lc++
46+
}
47+
48+
## OpenCV settings for Windows and OpenCV 4.5.0
49+
win32 {
50+
message("* Using settings for Windows.")
51+
INCLUDEPATH += "C:\\opencv\\build\\install\\include" \
52+
"C:\\opencv\\build\\install\\include\\opencv2" \
53+
54+
LIBS += -lopengl32
55+
56+
CONFIG(debug, debug | release) {
57+
LIBS += -L"C:\\opencv\\build\\install\\x64\\vc16\\lib" \
58+
-lopencv_core450d \
59+
-lopencv_highgui450d \
60+
-lopencv_imgproc450d \
61+
-lopencv_imgcodecs450d \
62+
-lopencv_videoio450d
63+
64+
# Projects > Build & Run > Run
65+
# Check: add build library search path to PATH
66+
# This allows OpenCV DLLs to be found when running this application
67+
LIBS += -L"C:\\opencv\\build\\install\\x64\\vc16\\bin"
68+
}
69+
70+
CONFIG(release, debug | release) {
71+
LIBS += -L"C:\\opencv\\build\\install\\x64\\vc16\\lib" \
72+
-lopencv_core450 \
73+
-lopencv_highgui450 \
74+
-lopencv_imgproc450 \
75+
-lopencv_imgcodecs450 \
76+
-lopencv_videoio450
77+
78+
# Projects > Build & Run > Run
79+
# Check: add build library search path to PATH
80+
# This allows OpenCV DLLs to be found when running this application
81+
LIBS += -L"C:\\opencv\\build\\install\\x64\\vc16\\bin"
82+
}
83+
}

cvQtCameraGL/main.cpp

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/* Copyright (C) 2013-2020 Karl Phillip Buhr <[email protected]>
2+
*
3+
* This work is licensed under the Creative Commons Attribution-ShareAlike License.
4+
* To view a copy of this license, visit:
5+
* https://creativecommons.org/licenses/by-sa/2.5/legalcode
6+
*
7+
* Or to read the human-readable summary of the license:
8+
* https://creativecommons.org/licenses/by-sa/2.5/
9+
*/
10+
#include <QApplication>
11+
#include "widget.h"
12+
13+
int main(int argc, char* argv[])
14+
{
15+
QApplication app(argc, argv);
16+
17+
// For OpenGL Graphics
18+
GLWidget gl_widget;
19+
gl_widget.show();
20+
21+
return app.exec();
22+
}
23+

cvQtCameraGL/screenshot.gif

1.59 MB
Loading

cvQtCameraGL/widget.cpp

Lines changed: 187 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,187 @@
1+
/* Copyright (C) 2013-2020 Karl Phillip Buhr <[email protected]>
2+
*
3+
* This work is licensed under the Creative Commons Attribution-ShareAlike License.
4+
* To view a copy of this license, visit:
5+
* https://creativecommons.org/licenses/by-sa/2.5/legalcode
6+
*
7+
* Or to read the human-readable summary of the license:
8+
* https://creativecommons.org/licenses/by-sa/2.5/
9+
*/
10+
#include "widget.h"
11+
#include <iostream>
12+
#include <QKeyEvent>
13+
#include <QTimer>
14+
15+
#ifndef M_PI
16+
#define M_PI 3.14159265358979323846
17+
#endif
18+
19+
// Enables the use of 3D perspective
20+
//#define USE_PERSPECTIVE
21+
22+
23+
GLWidget::GLWidget(QWidget *parent)
24+
: QGLWidget(parent)
25+
{
26+
_width = 0;
27+
_height = 0;
28+
_texture = 0;
29+
_fps = 0;
30+
}
31+
32+
GLWidget::~GLWidget()
33+
{
34+
glDeleteTextures(1, &_texture);
35+
}
36+
37+
void GLWidget::_tick()
38+
{
39+
// triggers paintGL()
40+
updateGL();
41+
42+
// Set timer according to FPS
43+
QTimer::singleShot(1000/_fps, this, SLOT(_tick()));
44+
}
45+
46+
void GLWidget::initializeGL()
47+
{
48+
// Set clear color as black
49+
glClearColor(1.0f, 0.0f, 0.0f, 1.0f);
50+
51+
// Select pixel storage mode used by glTexImage2D
52+
glPixelStorei (GL_UNPACK_ALIGNMENT, 1);
53+
54+
// Create the texture
55+
glGenTextures(1, &_texture);
56+
57+
/* Open default camera device */
58+
59+
cv_capture.open(0);
60+
if (!cv_capture.isOpened())
61+
{
62+
std::cout << "GLWidget::initializeGL: !!! Failed to open camera" << std::endl;
63+
return;
64+
}
65+
66+
// Retrieve FPS from the camera
67+
_fps = cv_capture.get(cv::CAP_PROP_FPS);
68+
if (!_fps) // if the function fails, fps is set to 15
69+
_fps = 15;
70+
71+
std::cout << "GLWidget::initializeGL: " << _fps << " fps" << std::endl;
72+
73+
// Retrieve the width and height of the captured frame
74+
_width = cv_capture.get(cv::CAP_PROP_FRAME_WIDTH);
75+
_height = cv_capture.get(cv::CAP_PROP_FRAME_HEIGHT);
76+
resize(QSize(_width, _height));
77+
78+
std::cout << "GLWidget::initializeGL: capture size=" << _width << "x" << _height << std::endl;
79+
std::cout << "GLWidget::initializeGL: window size=" << this->width() << "x" << this->height() << std::endl;
80+
81+
/* Start the timer */
82+
83+
_tick();
84+
}
85+
86+
void GLWidget::paintGL()
87+
{
88+
// Abort drawing if OpenCV was unable to open the camera
89+
if (!cv_capture.isOpened())
90+
{
91+
std::cout << "GLWidget::paintGL: !!! Failed to open camera" << std::endl;
92+
return;
93+
}
94+
95+
// Clear the screen and depth buffer (with black) then S«select the model view matrix and reset it
96+
glClear(GL_COLOR_BUFFER_BIT);
97+
glMatrixMode(GL_MODELVIEW);
98+
glLoadIdentity();
99+
100+
#ifdef USE_PERSPECTIVE
101+
glTranslatef(0.0f, 0.0f, -1.5);
102+
#endif
103+
104+
// Note: trying to retrieve more frames than the camera can give you makes the output video blink a lot
105+
cv_capture >> cv_frame;
106+
if (cv_frame.empty())
107+
{
108+
std::cout << "GLWidget::paintGL: !!! Failed to retrieve frame" << std::endl;
109+
return;
110+
}
111+
112+
//std::cout << "GLWidget::paintGL: frame size " << cv_frame.cols << "x" << cv_frame.rows << std::endl;
113+
114+
cv::cvtColor(cv_frame, cv_frame, cv::COLOR_BGR2RGBA);
115+
116+
glEnable(GL_TEXTURE_RECTANGLE_ARB);
117+
118+
// Typical texture generation using data from the bitmap
119+
glBindTexture(GL_TEXTURE_RECTANGLE_ARB, _texture);
120+
121+
// Transfer image data to the GPU
122+
glTexImage2D(GL_TEXTURE_RECTANGLE_ARB, 0,
123+
GL_RGBA, cv_frame.cols, cv_frame.rows, 0,
124+
GL_RGBA, GL_UNSIGNED_BYTE, cv_frame.data);
125+
if (glGetError() != GL_NO_ERROR)
126+
{
127+
std::cout << "GLWidget::paintGL: !!! Failed glTexImage2D" << std::endl;
128+
}
129+
130+
// Draw a 2D face with texture
131+
glBegin(GL_QUADS);
132+
#ifdef USE_PERSPECTIVE
133+
// glPerspective (3D)
134+
glTexCoord2f(0, 0); glVertex2f(1.0, 1.0);
135+
glTexCoord2f(cv_frame.cols, 0); glVertex2f(-1.0, 1.0);
136+
glTexCoord2f(cv_frame.cols, cv_frame.rows); glVertex2f(-1.0, -1.0);
137+
glTexCoord2f(0, cv_frame.rows); glVertex2f(1.0, -1.0);
138+
#else
139+
// glOrtho (2D)
140+
glTexCoord2f(0, 0); glVertex2f( 0.0, 0.0);
141+
glTexCoord2f(cv_frame.cols, 0); glVertex2f(_width, 0.0);
142+
glTexCoord2f(cv_frame.cols, cv_frame.rows); glVertex2f(_width, _height);
143+
glTexCoord2f(0, cv_frame.rows); glVertex2f( 0.0, _height);
144+
#endif
145+
glEnd();
146+
147+
glDisable(GL_TEXTURE_RECTANGLE_ARB);
148+
149+
glFlush();
150+
}
151+
152+
void glPerspective(GLdouble fovy, GLdouble aspect, GLdouble zNear, GLdouble zFar)
153+
{
154+
GLdouble ymax = zNear * tan( fovy * M_PI / 360.0 );
155+
GLdouble ymin = -ymax;
156+
GLdouble xmin = ymin * aspect;
157+
GLdouble xmax = ymax * aspect;
158+
159+
glFrustum( xmin, xmax, ymin, ymax, zNear, zFar );
160+
}
161+
162+
void glOrtho2D(GLdouble left, GLdouble right, GLdouble bottom, GLdouble top)
163+
{
164+
glOrtho(left, right, bottom, top, -1, 1);
165+
}
166+
167+
void GLWidget::resizeGL(int w, int h)
168+
{
169+
_width = w;
170+
_height = h;
171+
172+
glViewport ( 0, 0, _width, _height );
173+
glMatrixMode ( GL_PROJECTION );
174+
glLoadIdentity ( );
175+
176+
#ifdef USE_PERSPECTIVE
177+
if (h == 0)
178+
glPerspective( 60, ( float ) w, 1.0, 100.0 );
179+
else
180+
glPerspective( 60, ( float ) w / ( float ) h, 1.0, 100.0 );
181+
#else
182+
glOrtho(0, _width, _height, 0, 1, -1);
183+
#endif
184+
185+
glMatrixMode(GL_MODELVIEW);
186+
glLoadIdentity();
187+
}

cvQtCameraGL/widget.h

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
/* Copyright (C) 2013-2020 Karl Phillip Buhr <[email protected]>
2+
*
3+
* This work is licensed under the Creative Commons Attribution-ShareAlike License.
4+
* To view a copy of this license, visit:
5+
* https://creativecommons.org/licenses/by-sa/2.5/legalcode
6+
*
7+
* Or to read the human-readable summary of the license:
8+
* https://creativecommons.org/licenses/by-sa/2.5/
9+
*/
10+
#pragma once
11+
#include <opencv2/opencv.hpp>
12+
#include <QGLWidget>
13+
#include <QImage>
14+
15+
class GLWidget : public QGLWidget
16+
{
17+
Q_OBJECT
18+
public:
19+
explicit GLWidget(QWidget* parent = 0);
20+
virtual ~GLWidget();
21+
22+
/* OpenGL initialization, viewport resizing, and painting */
23+
24+
void initializeGL();
25+
void paintGL();
26+
void resizeGL( int width, int height);
27+
28+
private:
29+
int _width;
30+
int _height;
31+
cv::Mat cv_frame;
32+
cv::VideoCapture cv_capture;
33+
int _fps;
34+
GLuint _texture;
35+
36+
protected slots:
37+
void _tick();
38+
};

0 commit comments

Comments
 (0)