Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 18 additions & 3 deletions examples/protonect/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,12 @@ SET(LIBRARY_OUTPUT_PATH ${MY_DIR}/lib)

# dependencies
FIND_PACKAGE(PkgConfig) # try find PKGConfig as it will be used if found
FIND_PACKAGE(OpenCV)
FIND_PACKAGE(LibUSB REQUIRED)
FIND_PACKAGE(OpenCV REQUIRED)
FIND_PACKAGE(TurboJPEG REQUIRED) #does not provide a package-config file
IF(OPENCV_FOUND)
SET(LIBFREENECT2_OPENCV_FOUND 1)
ENDIF()

# Add includes
INCLUDE_DIRECTORIES(
Expand Down Expand Up @@ -103,7 +106,6 @@ SET(SOURCES
)

SET(LIBRARIES
${OpenCV_LIBS}
${OpenCV_LIBRARIES}
${LibUSB_LIBRARIES}
${TurboJPEG_LIBRARIES}
Expand Down Expand Up @@ -183,8 +185,21 @@ ENDIF()
MESSAGE("Linking with these libraries: ${LIBRARIES}")
TARGET_LINK_LIBRARIES(freenect2shared ${LIBRARIES})

SET(Protonect_src
Protonect.cpp
)

IF (ENABLE_OPENGL AND OPENGL_FOUND)
LIST(APPEND Protonect_src
viewer.h
viewer.cpp
src/flextGL.c
)
ENDIF()

ADD_EXECUTABLE(Protonect
Protonect.cpp
${Protonect_src}

)

TARGET_LINK_LIBRARIES(Protonect
Expand Down
28 changes: 22 additions & 6 deletions examples/protonect/Protonect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,19 @@
#include <iostream>
#include <signal.h>

#include <opencv2/opencv.hpp>

#include <libfreenect2/libfreenect2.hpp>
#include <libfreenect2/frame_listener_impl.h>
#include <libfreenect2/threading.h>
#include <libfreenect2/registration.h>
#include <libfreenect2/packet_pipeline.h>
#ifdef LIBFREENECT2_WITH_OPENGL_SUPPORT
#include "viewer.h"
#endif

#ifdef LIBFREENECT2_OPENCV_FOUND
#include <opencv2/opencv.hpp>
#endif


bool protonect_shutdown = false;

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

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

Viewer viewer;
viewer.initialize();

while(!protonect_shutdown)
{
listener.waitForNewFrame(frames);
libfreenect2::Frame *rgb = frames[libfreenect2::Frame::Color];
libfreenect2::Frame *ir = frames[libfreenect2::Frame::Ir];
libfreenect2::Frame *depth = frames[libfreenect2::Frame::Depth];

registration->apply(rgb, depth, &undistorted, &registered);

#if defined(LIBFREENECT2_WITH_OPENGL_SUPPORT) && !defined(LIBFREENECT2_OPENCV_FOUND)
viewer.addFrame("RGB", rgb);
viewer.addFrame("ir", ir);
viewer.addFrame("depth", depth);
viewer.addFrame("registered", &registered);

protonect_shutdown = viewer.render();
#else
cv::imshow("rgb", cv::Mat(rgb->height, rgb->width, CV_8UC4, rgb->data));
cv::imshow("ir", cv::Mat(ir->height, ir->width, CV_32FC1, ir->data) / 20000.0f);
cv::imshow("depth", cv::Mat(depth->height, depth->width, CV_32FC1, depth->data) / 4500.0f);

registration->apply(rgb,depth,&undistorted,&registered);

cv::imshow("undistorted", cv::Mat(undistorted.height, undistorted.width, CV_32FC1, undistorted.data) / 4500.0f);
cv::imshow("registered", cv::Mat(registered.height, registered.width, CV_8UC4, registered.data));

int key = cv::waitKey(1);
protonect_shutdown = protonect_shutdown || (key > 0 && ((key & 0xFF) == 27)); // shutdown on escape
#endif

listener.release(frames);
//libfreenect2::this_thread::sleep_for(libfreenect2::chrono::milliseconds(100));
Expand Down
2 changes: 2 additions & 0 deletions examples/protonect/include/libfreenect2/config.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,6 @@

#cmakedefine LIBFREENECT2_THREADING_TINYTHREAD

#cmakedefine LIBFREENECT2_OPENCV_FOUND

#endif // LIBFREENECT2_CONFIG_H
Loading