Skip to content

Commit f62332f

Browse files
committed
Merge pull request #361 from fran6co/glviewer
Removes opencv dependency, add OpenGL viewer & own timer class
2 parents 5b6d4ae + 2db187e commit f62332f

13 files changed

+897
-110
lines changed

examples/protonect/CMakeLists.txt

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ IF(ENABLE_CXX11)
1616
CHECK_CXX_COMPILER_FLAG("-std=c++0x" COMPILER_SUPPORTS_CXX0X)
1717
IF(COMPILER_SUPPORTS_CXX11)
1818
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
19+
SET(LIBFREENECT2_WITH_CXX11_SUPPORT 1)
1920
ELSEIF(COMPILER_SUPPORTS_CXX0X)
2021
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++0x")
2122
ELSE()
@@ -40,14 +41,12 @@ SET(LIBRARY_OUTPUT_PATH ${MY_DIR}/lib)
4041
# dependencies
4142
FIND_PACKAGE(PkgConfig) # try find PKGConfig as it will be used if found
4243
FIND_PACKAGE(LibUSB REQUIRED)
43-
FIND_PACKAGE(OpenCV REQUIRED)
4444
FIND_PACKAGE(TurboJPEG REQUIRED) #does not provide a package-config file
4545

4646
# Add includes
4747
INCLUDE_DIRECTORIES(
4848
"${MY_DIR}/include"
4949
${LIBFREENECT2_THREADING_INCLUDE_DIR}
50-
${OpenCV_INCLUDE_DIRS}
5150
${LibUSB_INCLUDE_DIRS}
5251
${TurboJPEG_INCLUDE_DIRS}
5352
)
@@ -96,15 +95,14 @@ SET(SOURCES
9695
src/resource.cpp
9796
src/command_transaction.cpp
9897
src/registration.cpp
98+
src/timer.cpp
9999
src/libfreenect2.cpp
100100

101101
${LIBFREENECT2_THREADING_SOURCE}
102102
${RESOURCES_INC_FILE}
103103
)
104104

105105
SET(LIBRARIES
106-
${OpenCV_LIBS}
107-
${OpenCV_LIBRARIES}
108106
${LibUSB_LIBRARIES}
109107
${TurboJPEG_LIBRARIES}
110108
${LIBFREENECT2_THREADING_LIBRARIES}
@@ -183,8 +181,21 @@ ENDIF()
183181
MESSAGE("Linking with these libraries: ${LIBRARIES}")
184182
TARGET_LINK_LIBRARIES(freenect2shared ${LIBRARIES})
185183

184+
SET(Protonect_src
185+
Protonect.cpp
186+
)
187+
188+
IF (ENABLE_OPENGL AND OPENGL_FOUND)
189+
LIST(APPEND Protonect_src
190+
viewer.h
191+
viewer.cpp
192+
src/flextGL.c
193+
)
194+
ENDIF()
195+
186196
ADD_EXECUTABLE(Protonect
187-
Protonect.cpp
197+
${Protonect_src}
198+
188199
)
189200

190201
TARGET_LINK_LIBRARIES(Protonect

examples/protonect/Protonect.cpp

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,15 @@
2828
#include <iostream>
2929
#include <signal.h>
3030

31-
#include <opencv2/opencv.hpp>
32-
3331
#include <libfreenect2/libfreenect2.hpp>
3432
#include <libfreenect2/frame_listener_impl.h>
3533
#include <libfreenect2/threading.h>
3634
#include <libfreenect2/registration.h>
3735
#include <libfreenect2/packet_pipeline.h>
36+
#ifdef LIBFREENECT2_WITH_OPENGL_SUPPORT
37+
#include "viewer.h"
38+
#endif
39+
3840

3941
bool protonect_shutdown = false;
4042

@@ -135,24 +137,30 @@ int main(int argc, char *argv[])
135137

136138
libfreenect2::Registration* registration = new libfreenect2::Registration(dev->getIrCameraParams(), dev->getColorCameraParams());
137139

140+
#ifdef LIBFREENECT2_WITH_OPENGL_SUPPORT
141+
Viewer viewer;
142+
viewer.initialize();
143+
#endif
144+
138145
while(!protonect_shutdown)
139146
{
140147
listener.waitForNewFrame(frames);
141148
libfreenect2::Frame *rgb = frames[libfreenect2::Frame::Color];
142149
libfreenect2::Frame *ir = frames[libfreenect2::Frame::Ir];
143150
libfreenect2::Frame *depth = frames[libfreenect2::Frame::Depth];
144151

145-
cv::imshow("rgb", cv::Mat(rgb->height, rgb->width, CV_8UC4, rgb->data));
146-
cv::imshow("ir", cv::Mat(ir->height, ir->width, CV_32FC1, ir->data) / 20000.0f);
147-
cv::imshow("depth", cv::Mat(depth->height, depth->width, CV_32FC1, depth->data) / 4500.0f);
148-
149-
registration->apply(rgb,depth,&undistorted,&registered);
152+
registration->apply(rgb, depth, &undistorted, &registered);
150153

151-
cv::imshow("undistorted", cv::Mat(undistorted.height, undistorted.width, CV_32FC1, undistorted.data) / 4500.0f);
152-
cv::imshow("registered", cv::Mat(registered.height, registered.width, CV_8UC4, registered.data));
154+
#ifdef LIBFREENECT2_WITH_OPENGL_SUPPORT
155+
viewer.addFrame("RGB", rgb);
156+
viewer.addFrame("ir", ir);
157+
viewer.addFrame("depth", depth);
158+
viewer.addFrame("registered", &registered);
153159

154-
int key = cv::waitKey(1);
155-
protonect_shutdown = protonect_shutdown || (key > 0 && ((key & 0xFF) == 27)); // shutdown on escape
160+
protonect_shutdown = viewer.render();
161+
#else
162+
protonect_shutdown = true;
163+
#endif
156164

157165
listener.release(frames);
158166
//libfreenect2::this_thread::sleep_for(libfreenect2::chrono::milliseconds(100));

examples/protonect/include/libfreenect2/config.h.in

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,4 +47,6 @@
4747

4848
#cmakedefine LIBFREENECT2_THREADING_TINYTHREAD
4949

50+
#cmakedefine LIBFREENECT2_WITH_CXX11_SUPPORT
51+
5052
#endif // LIBFREENECT2_CONFIG_H

examples/protonect/include/libfreenect2/depth_packet_processor.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,6 @@ class LIBFREENECT2_API OpenGLDepthPacketProcessor : public DepthPacketProcessor
140140
#endif // LIBFREENECT2_WITH_OPENGL_SUPPORT
141141

142142
// TODO: push this to some internal namespace
143-
// use pimpl to hide opencv dependency
144143
class CpuDepthPacketProcessorImpl;
145144

146145
class LIBFREENECT2_API CpuDepthPacketProcessor : public DepthPacketProcessor

examples/protonect/include/libfreenect2/packet_processor.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@
2727
#ifndef PACKET_PROCESSOR_H_
2828
#define PACKET_PROCESSOR_H_
2929

30+
#include <libfreenect2/timer.h>
31+
3032
namespace libfreenect2
3133
{
3234

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
/*
2+
* This file is part of the OpenKinect Project. http://www.openkinect.org
3+
*
4+
* Copyright (c) 2014 individual OpenKinect contributors. See the CONTRIB file
5+
* for details.
6+
*
7+
* This code is licensed to you under the terms of the Apache License, version
8+
* 2.0, or, at your option, the terms of the GNU General Public License,
9+
* version 2.0. See the APACHE20 and GPL2 files for the text of the licenses,
10+
* or the following URLs:
11+
* http://www.apache.org/licenses/LICENSE-2.0
12+
* http://www.gnu.org/licenses/gpl-2.0.txt
13+
*
14+
* If you redistribute this file in source form, modified or unmodified, you
15+
* may:
16+
* 1) Leave this header intact and distribute it under the same terms,
17+
* accompanying it with the APACHE20 and GPL20 files, or
18+
* 2) Delete the Apache 2.0 clause and accompany it with the GPL2 file, or
19+
* 3) Delete the GPL v2 clause and accompany it with the APACHE20 file
20+
* In all cases you must keep the copyright notice intact and include a copy
21+
* of the CONTRIB file.
22+
*
23+
* Binary distributions must follow the binary distribution requirements of
24+
* either License.
25+
*/
26+
27+
#ifndef TIMER_H_
28+
#define TIMER_H_
29+
30+
#include <libfreenect2/config.h>
31+
32+
namespace libfreenect2
33+
{
34+
35+
class TimerImpl;
36+
37+
class Timer {
38+
public:
39+
Timer();
40+
virtual ~Timer();
41+
42+
void start();
43+
double stop();
44+
45+
private:
46+
TimerImpl *impl_;
47+
};
48+
49+
} /* namespace libfreenect2 */
50+
51+
#endif /* TIMER_H_ */

0 commit comments

Comments
 (0)