1

everyone!

I've been searching on the web if there is a proper CMakelist commands for OpenNI 2, but did not find anything that seems to be working. I found one CMakelists on the following page: CMAKE can't find OpenNI But it turns out that it does not work for me. I am using Ubuntu 10.04 and my CMakeLists.txt looks like this:

cmake_minimum_required(VERSION 2.8)

project( DisplayImage )

# ***************************************
# OpenCV

find_package( OpenCV REQUIRED )
include_directories( ${OpenCV_INCLUDE_DIRS} )
# ***************************************

# *************************************
# OpenNI 2

OPTION (ENABLE_OPENNI2_NITE2 ON)

IF( ENABLE_OPENNI2_NITE2 )
set(OPENNI2_DEFINITIONS ${PC_OPENNI_CFLAGS_OTHER})

FIND_LIBRARY( OPENNI2_LIBRARY
             NAMES OpenNI2
             HINTS ${PC_OPENNI2_LIBDIR} ${PC_OPENNI2_LIBRARY_DIRS} /usr/lib
             PATHS "$ENV{PROGRAMFILES}/OpenNI2/Lib${OPENNI2_SUFFIX}"    "$ENV{PROGRAMW6432}/OpenNI2/Lib${OPENNI2_SUFFIX}" "$ENV{PROGRAMW6432}/OpenNI2"
             PATH_SUFFIXES lib lib64
)
FIND_PATH( OPENNI2_INCLUDE_DIR OpenNI.h
          HINTS ${PC_OPENNI2_INCLUDEDIR} ${PC_OPENNI2_INCLUDE_DIRS} 
                  /usr/include/openni2 /usr/include/ni2
                  PATHS "$ENV{PROGRAMFILES}/OpenNI2/include" "$ENV{PROGRAMW6432}/OpenNI2/include"
          PATH_SUFFIXES openni2 ni2)

FIND_LIBRARY( NITE2_LIBRARY
             NAMES NiTE2
             HINTS ${PC_OPENNI2_LIBDIR} ${PC_OPENNI2_LIBRARY_DIRS} /usr/lib
             PATHS "$ENV{PROGRAMFILES}/PrimeSense/NiTE2/lib${OPENNI2_SUFFIX}" "$ENV{PROGRAMW6432}/PrimeSense/NiTE2/lib${OPENNI2_SUFFIX}"
             PATH_SUFFIXES lib
)
FIND_PATH( NITE2_INCLUDE_DIR NiTE.h
      HINTS ${PC_OPENNI2_INCLUDEDIR} ${PC_OPENNI2_INCLUDE_DIRS} /usr/include/openni2 /usr/include/nite2
      PATHS "$ENV{PROGRAMFILES}/PrimeSense/NiTE2/include" "$ENV{PROGRAMW6432}/PrimeSense/NiTE2/include"
      PATH_SUFFIXES openni2         
)
ENDIF( ENABLE_OPENNI2_NITE2 )

include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(OpenNI2 DEFAULT_MSG
    OPENNI2_LIBRARY OPENNI2_INCLUDE_DIR)

mark_as_advanced(OPENNI2_LIBRARY OPENNI2_INCLUDE_DIR)

if (OPENNI2_FOUND)
    INCLUDE_DIRECTORIES( ${OPENNI2_INCLUDE_DIR} ${NITE2_INCLUDE_DIR} )
    message (STATUS "OpenNI2 found (include: ${OPENNI2_INCLUDE_DIR}, lib: ${OPENNI2_LIBRARY})")
link_directories( ${OPENNI2_LIBRARY} ${NITE2_LIBRARY} 
endif (OPENNI2_FOUND))
# *************************************

# *************************************
# My source codes
# set (SRC_DIR src)
# set (BUILD_DIR build)
# set (INC_DIR include)

# add the binary tree to the search path for include files
# so that we will find the header file
# include_directories("${INC_DIR}")

# you must add the list of your source files for the current target
# set (HEADERS ${INC_DIR}/printer.h)

# *************************************

# *************************************
# Set the output directories
set (CMAKE_RUNTIME_OUTPUT_DIRECTORY ${BUILD_DIR}/bin ) # this is for the binary file
set (CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${BUILD_DIR}/arc) # this is for the archives
set (CMAKE_LIBRARIES_OUTPUT_DIRECTORY ${BUILD_DIR}/lib) # this is for the libraries
# *************************************

add_executable( DisplayImage main.cpp )
target_link_libraries( DisplayImage ${OpenCV_LIBS} ${OPENNI2_LIBRARY} ${NITE2_LIBRARY} )

Once I tried to compile the program, the terminal shows the following error message:

-- Could NOT find OpenNI2 (missing:  OPENNI2_LIBRARY OPENNI2_INCLUDE_DIR) 
CMake Error in CMakeLists.txt:
  A logical block opening on the line

    /home/charly/OpenCV Test/KinectDisplay/src/CMakeLists.txt:51 (if)

  is not closed.


-- Configuring incomplete, errors occurred!
make: *** [cmake_check_build_system] Error 1

But the OpenNI2 directory is the same one addressed in the above CMakeLists. What am I missing? Thanks in advance!

Community
  • 1
  • 1
Megacephalo
  • 11
  • 1
  • 5

1 Answers1

2

I think the error is in:

link_directories( ${OPENNI2_LIBRARY} ${NITE2_LIBRARY} 

you are missing the closing parenthesis, so the next line that has the endif is taken as a directory and not a if closing.

Also, this cmake will only work in windows... I have worked with openni2 in linux and the "installation" is just a rule for the usb and two environment variables ....

So, if you want to make a portable version of your program you may need to add some if for the linux case (and probably mac, but i haven't use it in mac so i can't tell you much about it)

api55
  • 11,070
  • 4
  • 41
  • 57