跟着@ hugh-pearse和@ leszek-hanusz的回答,稍微调整一下。我从ubuntu 12.10存储库(libopencv - )*安装了opencv并遇到了同样的问题。用export OpenCV_DIR=/usr/share/OpenCV/无法解决它(因为我的OpenCVConfig.cmake已经存在)。当我在OpenCVConfig.cmake文件中更改了一些行时,它就解决了:
# ======================================================
# Include directories to add to the user project:
# ======================================================
# Provide the include directories to the caller
#SET(OpenCV_INCLUDE_DIRS "${OpenCV_INSTALL_PATH}/include/opencv;${OpenCV_INSTALL_PATH}/include")
SET(OpenCV_INCLUDE_DIRS "/usr/include/opencv;/usr/include/opencv2")
INCLUDE_DIRECTORIES(${OpenCV_INCLUDE_DIRS})
# ======================================================
# Link directories to add to the user project:
# ======================================================
# Provide the libs directory anyway, it may be needed in some cases.
#SET(OpenCV_LIB_DIR "${OpenCV_INSTALL_PATH}/lib")
SET(OpenCV_LIB_DIR "/usr/lib")
LINK_DIRECTORIES(${OpenCV_LIB_DIR})这对我的Ubuntu 12.10有用。请记住在CMakeLists.txt中添加target_link_libraries(yourprojectname ${OpenCV_LIBS})。