用这个the book "Mastering OpenCV with Practical Computer Vision Projects"工程代码:https://github.com/MasteringOpenCV/code/tree/master/Chapter3_MarkerlessAR
这是cmakelists文件
cmake_minimum_required(VERSION 2.6) project(EXAMPLE_MARKERLESS_AR) find_package(OpenCV REQUIRED ) find_package(OpenGL REQUIRED ) include_directories(${OpenCV_INCLUDE_DIR}) include_directories(${OpenGL_INCLUDE_DIR}) link_directories(${OpenCV_LIBRARY_DIR}) link_directories(${OpenGL_LIBRARY_DIR}) include_directories(${EXAMPLE_MARKERLESS_AR_SOURCE_DIR}/src) add_subdirectory(src)
由于最近遇到这样的问题:
OpenCV Error: No OpenGL support (Library was built without OpenGL support) in cvNamedWindow, file /tmp/buildd/ros-hydro-opencv2-2.4.9-2precise-20141231-1923/modules/highgui/src/window_gtk.cpp, line 845
检查我CMAKE安装的bash文件 和配置结果输出显示
cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local -D WITH_TBB=ON -D BUILD_NEW_PYTHON_SUPPORT=ON -D WITH_V4L=ON -D INSTALL_C_EXAMPLES=ON -D INSTALL_PYTHON_EXAMPLES=ON -D BUILD_EXAMPLES=ON -D WITH_QT=ON -D WITH_OPENGL=ON ..
此opencv支持openGL, 。怀疑是 find_package(OpenCV REQUIRED ) 找到的是安装时ROS时安装的opencv ,它不支持opengl。
所以下面必须设置选用的opencv的路径. 或 用IDE QT在系统变量中设置 OpenCV_DIR。。
ps:
在OpenCV_DIR下存在配置文件 OpenCVConfig.cmake. ( 缺省安装中只有OpenCVConfig.cmake.in文件, 当使用cmake编译OpenCV后,
会根据上述的.cmake.in文件产生对应的 OpenCVConfig.cmake文件.)
检查 OpenCVConfig.cmake 中的路径变量是否正确, 并做修改后保存.
与INCLUDE路径相关的变量: OpenCV_INCLUDE_DIRS
与LIB路径相关的变量: OpenCV_LIB_DIR
<pre name="code" class="html">cmake_minimum_required(VERSION 2.6) project(EXAMPLE_MARKERLESS_AR) set(OpenCV_DIR /home/agv/OpenCV/opencv-2.4.9/build) ############### find_package(OpenCV REQUIRED ) find_package(OpenGL REQUIRED ) include_directories(${OpenCV_INCLUDE_DIR}) include_directories(${OpenGL_INCLUDE_DIR}) link_directories(${OpenCV_LIBRARY_DIR}) link_directories(${OpenGL_LIBRARY_DIR}) include_directories(${EXAMPLE_MARKERLESS_AR_SOURCE_DIR}/src) add_subdirectory(src)
参考:
http://www.cmake.org/cmake/help/v3.0/command/find_package.html
http://www.cnblogs.com/coderfenghc/archive/2012/07/15/2592758.html
http://www.yeolar.com/note/2014/12/16/cmake-how-to-find-libraries/