Skip to content

Commit 49d2b8d

Browse files
christiankerlfran6co
authored andcommitted
A opengl viewer to use instead of opencv.
1 parent 5b6d4ae commit 49d2b8d

File tree

8 files changed

+760
-88
lines changed

8 files changed

+760
-88
lines changed

examples/protonect/CMakeLists.txt

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,12 @@ SET(LIBRARY_OUTPUT_PATH ${MY_DIR}/lib)
3939

4040
# dependencies
4141
FIND_PACKAGE(PkgConfig) # try find PKGConfig as it will be used if found
42+
FIND_PACKAGE(OpenCV)
4243
FIND_PACKAGE(LibUSB REQUIRED)
43-
FIND_PACKAGE(OpenCV REQUIRED)
4444
FIND_PACKAGE(TurboJPEG REQUIRED) #does not provide a package-config file
45+
IF(OPENCV_FOUND)
46+
SET(LIBFREENECT2_OPENCV_FOUND 1)
47+
ENDIF()
4548

4649
# Add includes
4750
INCLUDE_DIRECTORIES(
@@ -103,7 +106,6 @@ SET(SOURCES
103106
)
104107

105108
SET(LIBRARIES
106-
${OpenCV_LIBS}
107109
${OpenCV_LIBRARIES}
108110
${LibUSB_LIBRARIES}
109111
${TurboJPEG_LIBRARIES}
@@ -183,8 +185,21 @@ ENDIF()
183185
MESSAGE("Linking with these libraries: ${LIBRARIES}")
184186
TARGET_LINK_LIBRARIES(freenect2shared ${LIBRARIES})
185187

188+
SET(Protonect_src
189+
Protonect.cpp
190+
)
191+
192+
IF (ENABLE_OPENGL AND OPENGL_FOUND)
193+
LIST(APPEND Protonect_src
194+
viewer.h
195+
viewer.cpp
196+
src/flextGL.c
197+
)
198+
ENDIF()
199+
186200
ADD_EXECUTABLE(Protonect
187-
Protonect.cpp
201+
${Protonect_src}
202+
188203
)
189204

190205
TARGET_LINK_LIBRARIES(Protonect

examples/protonect/Protonect.cpp

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,19 @@
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+
40+
#ifdef LIBFREENECT2_OPENCV_FOUND
41+
#include <opencv2/opencv.hpp>
42+
#endif
43+
3844

3945
bool protonect_shutdown = false;
4046

@@ -135,24 +141,34 @@ int main(int argc, char *argv[])
135141

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

144+
Viewer viewer;
145+
viewer.initialize();
146+
138147
while(!protonect_shutdown)
139148
{
140149
listener.waitForNewFrame(frames);
141150
libfreenect2::Frame *rgb = frames[libfreenect2::Frame::Color];
142151
libfreenect2::Frame *ir = frames[libfreenect2::Frame::Ir];
143152
libfreenect2::Frame *depth = frames[libfreenect2::Frame::Depth];
144153

154+
registration->apply(rgb, depth, &undistorted, &registered);
155+
156+
#if defined(LIBFREENECT2_WITH_OPENGL_SUPPORT) && !defined(LIBFREENECT2_OPENCV_FOUND)
157+
viewer.addFrame("RGB", rgb);
158+
viewer.addFrame("ir", ir);
159+
viewer.addFrame("depth", depth);
160+
viewer.addFrame("registered", &registered);
161+
162+
protonect_shutdown = viewer.render();
163+
#else
145164
cv::imshow("rgb", cv::Mat(rgb->height, rgb->width, CV_8UC4, rgb->data));
146165
cv::imshow("ir", cv::Mat(ir->height, ir->width, CV_32FC1, ir->data) / 20000.0f);
147166
cv::imshow("depth", cv::Mat(depth->height, depth->width, CV_32FC1, depth->data) / 4500.0f);
148-
149-
registration->apply(rgb,depth,&undistorted,&registered);
150-
151167
cv::imshow("undistorted", cv::Mat(undistorted.height, undistorted.width, CV_32FC1, undistorted.data) / 4500.0f);
152168
cv::imshow("registered", cv::Mat(registered.height, registered.width, CV_8UC4, registered.data));
153-
154169
int key = cv::waitKey(1);
155170
protonect_shutdown = protonect_shutdown || (key > 0 && ((key & 0xFF) == 27)); // shutdown on escape
171+
#endif
156172

157173
listener.release(frames);
158174
//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_OPENCV_FOUND
51+
5052
#endif // LIBFREENECT2_CONFIG_H

0 commit comments

Comments
 (0)