大家!
我一直在网上搜索是否有适用于OpenNI 2的CMakelist命令,但没有找到任何可行的方法。我在以下页面上找到了一个CMakelist:
CMAKE can't find OpenNI
但事实证明,它对我不起作用。我正在使用Ubuntu 10.04,我的CMakeLists.txt如下所示:
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} )
一旦我尝试编译程序,终端将显示以下错误消息:
-- 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
但是OpenNI2目录与上述CMakeLists中的目录相同。我想念什么?提前致谢!
最佳答案
我认为错误在于:
link_directories( ${OPENNI2_LIBRARY} ${NITE2_LIBRARY}
您缺少右括号,因此具有endif的下一行将被视为目录,而不是if结束。
此外,此cmake仅在Windows中工作...我在Linux中使用过openni2,“安装”只是usb和两个环境变量的规则....
因此,如果要制作程序的可移植版本,则可能需要为Linux情况添加一些(如果可能的话,可能是Mac,但是我没有在Mac中使用它,因此我无法告诉您太多信息)