Skip to content
Merged
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: 16 additions & 5 deletions examples/protonect/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ IF(ENABLE_CXX11)
CHECK_CXX_COMPILER_FLAG("-std=c++0x" COMPILER_SUPPORTS_CXX0X)
IF(COMPILER_SUPPORTS_CXX11)
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
SET(LIBFREENECT2_WITH_CXX11_SUPPORT 1)
ELSEIF(COMPILER_SUPPORTS_CXX0X)
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++0x")
ELSE()
Expand All @@ -40,14 +41,12 @@ SET(LIBRARY_OUTPUT_PATH ${MY_DIR}/lib)
# dependencies
FIND_PACKAGE(PkgConfig) # try find PKGConfig as it will be used if found
FIND_PACKAGE(LibUSB REQUIRED)
FIND_PACKAGE(OpenCV REQUIRED)
FIND_PACKAGE(TurboJPEG REQUIRED) #does not provide a package-config file

# Add includes
INCLUDE_DIRECTORIES(
"${MY_DIR}/include"
${LIBFREENECT2_THREADING_INCLUDE_DIR}
${OpenCV_INCLUDE_DIRS}
${LibUSB_INCLUDE_DIRS}
${TurboJPEG_INCLUDE_DIRS}
)
Expand Down Expand Up @@ -96,15 +95,14 @@ SET(SOURCES
src/resource.cpp
src/command_transaction.cpp
src/registration.cpp
src/timer.cpp
src/libfreenect2.cpp

${LIBFREENECT2_THREADING_SOURCE}
${RESOURCES_INC_FILE}
)

SET(LIBRARIES
${OpenCV_LIBS}
${OpenCV_LIBRARIES}
${LibUSB_LIBRARIES}
${TurboJPEG_LIBRARIES}
${LIBFREENECT2_THREADING_LIBRARIES}
Expand Down Expand Up @@ -183,8 +181,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
30 changes: 19 additions & 11 deletions examples/protonect/Protonect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,15 @@
#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


bool protonect_shutdown = false;

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

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

#ifdef LIBFREENECT2_WITH_OPENGL_SUPPORT
Viewer viewer;
viewer.initialize();
#endif

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];

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);
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));
#ifdef LIBFREENECT2_WITH_OPENGL_SUPPORT
viewer.addFrame("RGB", rgb);
viewer.addFrame("ir", ir);
viewer.addFrame("depth", depth);
viewer.addFrame("registered", &registered);

int key = cv::waitKey(1);
protonect_shutdown = protonect_shutdown || (key > 0 && ((key & 0xFF) == 27)); // shutdown on escape
protonect_shutdown = viewer.render();
#else
protonect_shutdown = true;
#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_WITH_CXX11_SUPPORT

#endif // LIBFREENECT2_CONFIG_H
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,6 @@ class LIBFREENECT2_API OpenGLDepthPacketProcessor : public DepthPacketProcessor
#endif // LIBFREENECT2_WITH_OPENGL_SUPPORT

// TODO: push this to some internal namespace
// use pimpl to hide opencv dependency
class CpuDepthPacketProcessorImpl;

class LIBFREENECT2_API CpuDepthPacketProcessor : public DepthPacketProcessor
Expand Down
2 changes: 2 additions & 0 deletions examples/protonect/include/libfreenect2/packet_processor.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@
#ifndef PACKET_PROCESSOR_H_
#define PACKET_PROCESSOR_H_

#include <libfreenect2/timer.h>

namespace libfreenect2
{

Expand Down
51 changes: 51 additions & 0 deletions examples/protonect/include/libfreenect2/timer.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/*
* This file is part of the OpenKinect Project. http://www.openkinect.org
*
* Copyright (c) 2014 individual OpenKinect contributors. See the CONTRIB file
* for details.
*
* This code is licensed to you under the terms of the Apache License, version
* 2.0, or, at your option, the terms of the GNU General Public License,
* version 2.0. See the APACHE20 and GPL2 files for the text of the licenses,
* or the following URLs:
* http://www.apache.org/licenses/LICENSE-2.0
* http://www.gnu.org/licenses/gpl-2.0.txt
*
* If you redistribute this file in source form, modified or unmodified, you
* may:
* 1) Leave this header intact and distribute it under the same terms,
* accompanying it with the APACHE20 and GPL20 files, or
* 2) Delete the Apache 2.0 clause and accompany it with the GPL2 file, or
* 3) Delete the GPL v2 clause and accompany it with the APACHE20 file
* In all cases you must keep the copyright notice intact and include a copy
* of the CONTRIB file.
*
* Binary distributions must follow the binary distribution requirements of
* either License.
*/

#ifndef TIMER_H_
#define TIMER_H_

#include <libfreenect2/config.h>

namespace libfreenect2
{

class TimerImpl;

class Timer {
public:
Timer();
virtual ~Timer();

void start();
double stop();

private:
TimerImpl *impl_;
};

} /* namespace libfreenect2 */

#endif /* TIMER_H_ */
Loading