Skip to content

Commit

Permalink
Update for 2.4.0
Browse files Browse the repository at this point in the history
  • Loading branch information
nesnes committed Apr 24, 2018
1 parent d6d22d5 commit a02825a
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 56 deletions.
46 changes: 22 additions & 24 deletions CMakeLists.txt
Expand Up @@ -10,30 +10,28 @@ endif(COMMAND cmake_policy)
SET(EXECUTABLE_OUTPUT_PATH ".")

find_package(ZED 2 REQUIRED)
find_package(CUDA REQUIRED)
find_package(PCL)
find_package(CUDA ${ZED_CUDA_VERSION} EXACT REQUIRED)
find_package(PCL REQUIRED)

if(PCL_FOUND)
include_directories(${CUDA_INCLUDE_DIRS})
include_directories(${PCL_INCLUDE_DIRS})
include_directories(${ZED_INCLUDE_DIRS})
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/include)

link_directories(${ZED_LIBRARY_DIR})
link_directories(${CUDA_LIBRARY_DIRS})
link_directories(${PCL_LIBRARY_DIRS})

FILE(GLOB_RECURSE SRC_FILES src/*.cpp)
ADD_EXECUTABLE(${execName} ${SRC_FILES})

add_definitions(-std=c++11 -g -O3)
list(REMOVE_ITEM PCL_LIBRARIES "vtkproj4") ## needed if you install pcl from repo (and libproj-dev)

TARGET_LINK_LIBRARIES(${execName}
${ZED_LIBRARIES}
${OpenCV_LIBRARIES}
${PCL_LIBRARIES}
${CUDA_LIBRARIES} ${CUDA_npps_LIBRARY} ${CUDA_NPP_LIBRARIES_ZED} )
else()
message(WARNING "PCL not found, sample not build")
include_directories(${CUDA_INCLUDE_DIRS})
include_directories(${PCL_INCLUDE_DIRS})
include_directories(${ZED_INCLUDE_DIRS})
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/include)

link_directories(${ZED_LIBRARY_DIR})
link_directories(${CUDA_LIBRARY_DIRS})
link_directories(${PCL_LIBRARY_DIRS})

FILE(GLOB_RECURSE SRC_FILES src/*.cpp)
ADD_EXECUTABLE(${execName} ${SRC_FILES})

add_definitions(-std=c++11 -g -O3)
list(REMOVE_ITEM PCL_LIBRARIES "vtkproj4") ## needed if you install pcl from repo (and libproj-dev)

TARGET_LINK_LIBRARIES(${execName}
${ZED_LIBRARIES}
${OpenCV_LIBRARIES}
${PCL_LIBRARIES}
${CUDA_LIBRARIES} ${CUDA_npps_LIBRARY} ${CUDA_NPP_LIBRARIES_ZED} )
endif()
65 changes: 33 additions & 32 deletions src/main.cpp
Expand Up @@ -23,7 +23,7 @@
************************************************************************************/

// ZED includes
#include <sl/Camera.hpp>
#include <sl_zed/Camera.hpp>

// PCL includes
// Undef on Win32 min/max for PCL
Expand Down Expand Up @@ -58,27 +58,30 @@ shared_ptr<pcl::visualization::PCLVisualizer> createRGBVisualizer(pcl::PointClou
inline float convertColor(float colorIn);

// Main process
int main(int argc, char **argv){

if (argc > 2)
{
int main(int argc, char **argv) {

if (argc > 2) {
cout << "Only the path of a SVO can be passed in arg" << endl;
return -1;
}

// Set configuration parameters
InitParameters init_params;
init_params.camera_resolution = RESOLUTION_HD1080;
if (argc == 2)
init_params.svo_input_filename = argv[1];
else {
init_params.camera_resolution = RESOLUTION_VGA;
init_params.camera_fps = 30;
}
init_params.coordinate_units = UNIT_METER;
init_params.coordinate_system = COORDINATE_SYSTEM_RIGHT_HANDED_Y_UP;
init_params.depth_mode = DEPTH_MODE_PERFORMANCE;

// Open the camera
ERROR_CODE err = zed.open(init_params);
if (err != SUCCESS) {
cout << errorCode2str(err) << endl;
cout << toString(err) << endl;
zed.close();
return 1;
}
Expand Down Expand Up @@ -118,7 +121,7 @@ int main(int argc, char **argv){
// Unlock data and update Point cloud
mutex_input.unlock();
viewer->updatePointCloud(p_pcl_point_cloud);
viewer->spinOnce(15);
viewer->spinOnce(10);
} else
sleep_ms(1);
}
Expand All @@ -133,9 +136,9 @@ int main(int argc, char **argv){
}

/**
* This functions start the ZED's thread that grab images and data.
**/
void startZED(){
* This functions start the ZED's thread that grab images and data.
**/
void startZED() {
// Start the thread for grabbing ZED data
stop_signal = false;
has_data = false;
Expand All @@ -147,36 +150,34 @@ void startZED(){
}

/**
* This function loops to get the point cloud from the ZED. It can be considered as a callback.
**/
void run(){
while (!stop_signal)
{
if (zed.grab(SENSING_MODE_STANDARD) == SUCCESS)
{
* This function loops to get the point cloud from the ZED. It can be considered as a callback.
**/
void run() {
while (!stop_signal) {
if (zed.grab(SENSING_MODE_STANDARD) == SUCCESS) {
mutex_input.lock(); // To prevent from data corruption
zed.retrieveMeasure(data_cloud, MEASURE_XYZRGBA);
mutex_input.unlock();
has_data = true;
}
sleep_ms(1);
} else
sleep_ms(1);
}
}

/**
* This function frees and close the ZED, its callback(thread) and the viewer
**/
void closeZED(){
* This function frees and close the ZED, its callback(thread) and the viewer
**/
void closeZED() {
// Stop the thread
stop_signal = true;
zed_callback.join();
zed.close();
}

/**
* This function creates a PCL visualizer
**/
shared_ptr<pcl::visualization::PCLVisualizer> createRGBVisualizer(pcl::PointCloud<pcl::PointXYZRGB>::ConstPtr cloud){
* This function creates a PCL visualizer
**/
shared_ptr<pcl::visualization::PCLVisualizer> createRGBVisualizer(pcl::PointCloud<pcl::PointXYZRGB>::ConstPtr cloud) {
// Open 3D viewer and add point cloud
shared_ptr<pcl::visualization::PCLVisualizer> viewer(new pcl::visualization::PCLVisualizer("PCL ZED 3D Viewer"));
viewer->setBackgroundColor(0.12, 0.12, 0.12);
Expand All @@ -189,11 +190,11 @@ shared_ptr<pcl::visualization::PCLVisualizer> createRGBVisualizer(pcl::PointClou
}

/**
* This function convert a RGBA color packed into a packed RGBA PCL compatible format
**/
inline float convertColor(float colorIn){
uint32_t color_uint = *(uint32_t *)&colorIn;
unsigned char *color_uchar = (unsigned char *)&color_uint;
color_uint = ((uint32_t)color_uchar[0] << 16 | (uint32_t)color_uchar[1] << 8 | (uint32_t)color_uchar[2]);
return *reinterpret_cast<float *>(&color_uint);
* This function convert a RGBA color packed into a packed RGBA PCL compatible format
**/
inline float convertColor(float colorIn) {
uint32_t color_uint = *(uint32_t *) & colorIn;
unsigned char *color_uchar = (unsigned char *) &color_uint;
color_uint = ((uint32_t) color_uchar[0] << 16 | (uint32_t) color_uchar[1] << 8 | (uint32_t) color_uchar[2]);
return *reinterpret_cast<float *> (&color_uint);
}

0 comments on commit a02825a

Please sign in to comment.