Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Color integration #15

Open
wants to merge 21 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
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
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
.gitignore
.idea/
build/
build_xcode/
24 changes: 23 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,32 @@ list(APPEND CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake/Modules/")
include(cmake/Utils.cmake)
include(cmake/Targets.cmake)

# Find OpenMP
# the gcc-4.2.1 coming with MacOS X is not compatible with the OpenMP pragmas we use, so disabling OpenMP for it
if((NOT (${CMAKE_SYSTEM_NAME} MATCHES "Darwin")) OR (NOT CMAKE_COMPILER_IS_GNUCXX) OR (GCC_VERSION VERSION_GREATER 4.2.1) OR (CMAKE_CXX_COMPILER_ID STREQUAL "Clang"))
find_package(OpenMP)
endif()
if(OPENMP_FOUND)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${OpenMP_C_FLAGS}")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OpenMP_CXX_FLAGS}")
message (STATUS "Found OpenMP")
if(MSVC90 OR MSVC10)
if(MSVC90)
set(OPENMP_DLL VCOMP90)
elseif(MSVC10)
set(OPENMP_DLL VCOMP100)
endif(MSVC90)
set(CMAKE_SHARED_LINKER_FLAGS_DEBUG "${CMAKE_SHARED_LINKER_FLAGS_DEBUG} /DELAYLOAD:${OPENMP_DLL}D.dll")
set(CMAKE_SHARED_LINKER_FLAGS_RELEASE "${CMAKE_SHARED_LINKER_FLAGS_RELEASE} /DELAYLOAD:${OPENMP_DLL}.dll")
endif(MSVC90 OR MSVC10)
else(OPENMP_FOUND)
message (STATUS "Not found OpenMP")
endif()

# ---[ find dependencies
find_package(OpenCV 2.4.8 REQUIRED COMPONENTS core viz highgui)
find_package(CUDA 5.0 REQUIRED)
find_package(OpenNI REQUIRED)
find_package(OpenNI)
include_directories(${OpenCV_INCLUDE_DIRS} ${CUDA_INCLUDE_DIRS} ${OPENNI_INCLUDE_DIR})

# ---[ misc settings
Expand Down
35 changes: 26 additions & 9 deletions apps/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,13 +1,30 @@
include_directories(${CMAKE_SOURCE_DIR}/kfusion/include)

file(GLOB srcs *.cpp *.hpp)
add_executable(demo ${srcs})
target_link_libraries(demo ${OpenCV_LIBS} kfusion)
# Not recommended by CMake to use GLOB
# file(GLOB srcs *.cpp *.hpp)

set_target_properties(demo PROPERTIES
DEBUG_POSTFIX "d"
ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib"
RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin")
# APP 01: OpenNI capture
if (OPENNI_FOUND)
add_executable(demo demo.cpp)
target_link_libraries(demo ${OpenCV_LIBS} kfusion)

install(TARGETS demo RUNTIME DESTINATION bin COMPONENT main)
install(FILES ${srcs} DESTINATION app COMPONENT main)
set_target_properties(demo PROPERTIES
DEBUG_POSTFIX "d"
ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib"
RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin")

install(TARGETS demo RUNTIME DESTINATION bin COMPONENT main)
install(FILES demo.cpp DESTINATION app COMPONENT main)
endif(OPENNI_FOUND)

# APP 02: BinGrabber capture
add_executable(demo_bin demo_bin.cpp)
target_link_libraries(demo_bin ${OpenCV_LIBS} kfusion)

set_target_properties(demo_bin PROPERTIES
DEBUG_POSTFIX "d"
ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib"
RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin")

install(TARGETS demo_bin RUNTIME DESTINATION bin COMPONENT main)
install(FILES demo_bin.cpp DESTINATION app COMPONENT main)
42 changes: 36 additions & 6 deletions apps/demo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,18 @@ struct KinFuApp
viz.registerKeyboardCallback(KeyboardCallback, this);
}

KinFuApp(OpenNISource& source, const KinFuParams& params) : exit_ (false), iteractive_mode_(false), capture_ (source), pause_(false)
{
kinfu_ = KinFu::Ptr( new KinFu(params) );

capture_.setRegistration(true);

cv::viz::WCube cube(cv::Vec3d::all(0), cv::Vec3d(params.volume_size), true, cv::viz::Color::apricot());
viz.showWidget("cube", cube, params.volume_pose);
viz.showWidget("coor", cv::viz::WCoordinateSystem(0.1));
viz.registerKeyboardCallback(KeyboardCallback, this);
}

void show_depth(const cv::Mat& depth)
{
cv::Mat display;
Expand All @@ -61,9 +73,17 @@ struct KinFuApp
{
cuda::DeviceArray<Point> cloud = kinfu.tsdf().fetchCloud(cloud_buffer);
cv::Mat cloud_host(1, (int)cloud.size(), CV_32FC4);
cloud.download(cloud_host.ptr<Point>());
viz.showWidget("cloud", cv::viz::WCloud(cloud_host));
//viz.showWidget("cloud", cv::viz::WPaintedCloud(cloud_host));
if (kinfu.params().integrate_color) {
kinfu.color_volume()->fetchColors(cloud, color_buffer);
cv::Mat color_host(1, (int)cloud.size(), CV_8UC4);
cloud.download(cloud_host.ptr<Point>());
color_buffer.download(color_host.ptr<RGB>());
viz.showWidget("cloud", cv::viz::WCloud(cloud_host, color_host));
} else
{
cloud.download(cloud_host.ptr<Point>());
viz.showWidget("cloud", cv::viz::WCloud(cloud_host));
}
}

bool execute()
Expand All @@ -80,17 +100,22 @@ struct KinFuApp
return std::cout << "Can't grab" << std::endl, false;

depth_device_.upload(depth.data, depth.step, depth.rows, depth.cols);
color_device_.upload(image.data, image.step, image.rows, image.cols);

{
SampledScopeTime fps(time_ms); (void)fps;
has_image = kinfu(depth_device_);
if (kinfu.params().integrate_color)
has_image = kinfu(depth_device_, color_device_);
else
has_image = kinfu(depth_device_);
}

if (has_image)
show_raycasted(kinfu);

show_depth(depth);
//cv::imshow("Image", image);
if (kinfu.params().integrate_color)
cv::imshow("Image", image);

if (!iteractive_mode_)
viz.setViewerPose(kinfu.getCameraPose());
Expand Down Expand Up @@ -120,7 +145,9 @@ struct KinFuApp
cv::Mat view_host_;
cuda::Image view_device_;
cuda::Depth depth_device_;
cuda::Image color_device_;
cuda::DeviceArray<Point> cloud_buffer;
cuda::DeviceArray<RGB> color_buffer;
};


Expand All @@ -145,7 +172,10 @@ int main (int argc, char* argv[])
//capture.open("d:/onis/20111013-224551.oni");
//capture.open("d:/onis/20111013-224719.oni");

KinFuApp app (capture);
KinFuParams custom_params = KinFuParams::default_params();
custom_params.integrate_color = true;

KinFuApp app (capture, custom_params);

// executing
try { app.execute (); }
Expand Down
Loading