openCV error while configuring via cmake - opencv

I am trying to visualize the data using ASAP. While configuring it in cmake, I am getting this error. OpenCV is already installed in my ubuntu system in the folder /usr/local/share.
opencv_calib3d opencv_core opencv_features2d opencv_flann opencv_highgui opencv_imgcodecs opencv_imgproc opencv_ml opencv_objdetect opencv_photo opencv_shape opencv_stitching opencv_superres opencv_video opencv_videoio opencv_videostab opencv_viz

This red line probably comes from the line 3 of ASAP/imgproc/CMakeLists.txt.
The message() macro is used without any flag. This produce an "Important information" message displayed in red in cmake-gui, but in this case, it's not an error. Maybe ASAP developpers should have used STATUS mode to print some debug information from CMake script:
message(STATUS ${OpenCV_LIBRARIES})
Maybe you could send a pull request.

Related

CMake could not find OpenCV library like cv.h

I'd wanted to run the project in Ubuntu PC, but I received an error.
When I ran the following code;
make
And, There is a error in following;
asiye#asiye:~/Desktop/cmfd_framework/build$ make
Consolidate compiler generated dependencies of target common
[ 8%] Built target common
[ 10%] Building CXX object ground_truth_db/CMakeFiles/cmfdgt.dir/command_ground_truth.cpp.o
/home/asiye/Desktop/cmfd_framework/ground_truth_db/command_ground_truth.cpp:10:10: fatal error: cv.h: No such file or directory
10 | #include "cv.h"
| ^~~~
compilation terminated.
make[2]: * [ground_truth_db/CMakeFiles/cmfdgt.dir/build.make:76: ground_truth_db/CMakeFiles/cmfdgt.dir/command_ground_truth.cpp.o] Error 1
make[1]: * [CMakeFiles/Makefile2:205: ground_truth_db/CMakeFiles/cmfdgt.dir/all] Error 2
make: * [Makefile:91: all] Error 2
I think Cmake could not find OpenCV library but why ?
Could you explain to me if there is another way to address this problem?
Best Regards,
Cmake Dosyası burada Yunus Temurlenk
CMakeLists.txt
cmake_minimum_required(VERSION 2.6)
project(Vole)
set(Vole_CMFD ON)
set(Vole_CMFD_Ground_Truth ON)
set(Vole_Shell ON)
set(CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake")
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
include(VoleHelperMacros)
include(VoleModuleMacros)
if(WIN32)
add_definitions(-DNOMINMAX) # prevents min- and max-macro brainf*ck in VS 2003
endif(WIN32)
# Global options
option(VOLE_CMAKE_DEBUG_OUTPUT "Show additonal cmake debug output." OFF)
mark_as_advanced(VOLE_CMAKE_DEBUG_OUTPUT)
option(VOLE_CHECK_DEPENDENCIES "Do additional dependency check with nice error messages." ON)
mark_as_advanced(VOLE_CHECK_DEPENDENCIES)
option(VOLE_SINGLE_TARGETS "Build single targets for each command." OFF)
set(VOLE_MODULE_DIRECTORIES "" CACHE STRING "Semicolon-separated list of module directories for vole, e.g. the forensics or the color code.")
# maybe there is a better place for these two options:
option(Boost_NO_SYSTEM_PATHS "Suppress searching in system paths or other locations outside of BOOST_ROOT." OFF)
set(BOOST_ROOT "" CACHE STRING "The preferred installation prefix for searching for Boost. Set this if the module has problems finding the proper Boost installation.")
# Global variables
set(VOLE_PACKAGE_LIST "" CACHE INTERNAL "Package list" FORCE)
set(VOLE_EXTERNAL_SUBDIRECTORIES "" CACHE INTERNAL "External subdirectories" FORCE)
set(VOLE_MODULE_LIST "" CACHE INTERNAL "Module list" FORCE)
include(VoleFindPackages)
# include(VoleFindExternalModules)
add_subdirectory(common core/common)
include_directories(common shell cmfd ground_truth_db)
add_subdirectory(cmfd cmfd)
add_subdirectory(ground_truth_db ground_truth_db)
add_subdirectory(shell core/shell)
include(VoleCheckDependencies)
INCLUDE("CMakeModules/TargetDoc.cmake" OPTIONAL)

CMake error: 'target is not built by this project' Clion Kotlin

I'm trying to load OpenCV Libraries in CMakeFile.txt but it always ends with this error:
CMake Error at CMakeLists.txt:21 (target_link_libraries):
Cannot specify link libraries for target "HelloWorld" which is not built by
this project.
I've searched on the Internet but have got no solution.
cmake_minimum_required(VERSION 3.8)
set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_LIST_DIR}/KotlinCMakeModule)
project(untitled1 Kotlin)
find_package(OpenCV REQUIRED)
IF (OpenCV_FOUND)
include_directories(/usr/local/Cellar/opencv/3.4.0_1/include)
link_libraries(/usr/local/Cellar/opencv/3.4.0_1/lib)
ENDIF(OpenCV_FOUND)
konanc_executable(
NAME HelloWorld
SOURCES hello.kt
)
target_link_libraries(HelloWorld
/usr/local/Cellar/opencv/3.4.0_1/lib
)
Someone can help me? I think it's not working because on the use of konanc_executable instead of add_executable but I need to use Kotlin so I cannot use the add_executable command.

Segmentation fault when running compiled file from Cmake

I am trying to compile a project that depends on PCL and OpenCV.
The CMakeLists.txt looks like:
cmake_minimum_required(VERSION 2.8 FATAL_ERROR)
project(pcl_visualizer_viewports)
find_package(PCL 1.2 REQUIRED)
find_package(OpenCV REQUIRED)
message("this is my message " ${OpenCV_LIBRARIES} )
message("this is my message " ${OpenCV_INCLUDE_DIRS} )
message("this is my message " ${OpenCV_INSTALL_PATH} )
include_directories(${PCL_INCLUDE_DIRS} ${OpenCV_INCLUDE_DIRS})
link_directories(${PCL_LIBRARY_DIRS})
add_definitions(${PCL_DEFINITIONS})
add_executable (pcl_visualizer_demo pcl_visualizer_demo.cpp readInputFile.cpp readInputFile.h defines.h helper.cpp helper.h Image_Safety.h Image_Safety.cpp)
target_link_libraries (pcl_visualizer_demo ${PCL_LIBRARIES} ${OpenCV_LIBRARIES})
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
The result is however a segmentation fault and core dumped. I have read through the Cmake tutorial, but I have not found the issue. CMake generates the object files for all:
Scanning dependencies of target pcl_visualizer_demo
[ 20%] Building CXX object CMakeFiles/pcl_visualizer_demo.dir/Image_Safety.cpp.o
[ 40%] Building CXX object CMakeFiles/pcl_visualizer_demo.dir/helper.cpp.o
[ 60%] Building CXX object CMakeFiles/pcl_visualizer_demo.dir/image_converter.cpp.o
[ 80%] Building CXX object CMakeFiles/pcl_visualizer_demo.dir/readInputFile.cpp.o
[100%] Building CXX object CMakeFiles/pcl_visualizer_demo.dir/pcl_visualizer_demo.cpp.o
Linking CXX executable pcl_visualizer_demo
Looking at the linking verbose information, the different object files are mentioned and I interpret this as they are linked.
What am I missing?
update
Weird so the error occurs in some part of the code using basic opencv functions cv::waitKey and cv::imshow, it may seem to be an issue with QT according to this and this.
I had a similar issue. In the end I had to build PCL without QT (I also found several posts which stated interference, but found no solution)

CMake OpenCV 3.0.0 and building executables and libraries in Ubuntu

I have OpenCV 3.0.0 installed in /usr/local/opencv-3.0.0
I am trying to construct a CMakeLists file to build a library against this OpenCV 3.0.0. The CMakeLists.txt is as follows:
cmake_minimum_required(VERSION 2.8)
project(STT_People_Tracker)
cmake_policy(SET CMP0016 NEW)
# compilation mode setup
#set(CMAKE_BUILD_TYPE Release)
set(CMAKE_BUILD_TYPE Debug)
# set OpenCV directories - CHANGE DEPENDING ON SYSTEM
set(OpenCV_PATH "/usr/local/opencv-3.0.0")
set(OpenCV_INCLUDE_DIRS "${OpenCV_PATH}/include")
set(OpenCV_LIBS "${OpenCV_PATH}/lib/")
# set environment variables
set(SOURCES_PATH "${CMAKE_SOURCE_DIR}/Sources")
set(INCLUDES_PATH "${SOURCES_PATH}/include")
if(CMAKE_BUILD_TYPE MATCHES Debug)
set(OUTPUT_PATH "../Debug")
message(STATUS "Compiling in DEBUG mode")
elseif(CMAKE_BUILD_TYPE MATCHES Release)
set(OUTPUT_PATH "../Release")
message(STATUS "Compiling in RELEASE mode")
endif()
include_directories(${INCLUDES_PATH})
include_directories(${OpenCV_INCLUDE_DIRS})
# compilation of executables
message(STATUS "configuring executables...")
add_executable(${OUTPUT_PATH}/mainTest ${SOURCES_PATH}/mainTest.cpp)
# compilation of libraries
message(STATUS "configuring libraries...")
add_library(${OUTPUT_PATH}/background_substractor ${SOURCES_PATH}/background_substractor.cpp)
# set linker options
link_directories(${OpenCV_LIBS})
target_link_libraries(${OUTPUT_PATH}/mainTest opencv_core opencv_highgui)
target_link_libraries(${OUTPUT_PATH}/background_substractor opencv_core opencv_highgui)
message(STATUS "cmake configuration complete")
It is a fairly simple Cmake file, however, I have the following problems/doubts:
1.-How can I know I am using OpenCV 3, and not other versions of OpenCV present in the system?
2.- When compiling the file background_substractor, its associated header file can not be located, although I have checked the path and it is correctly assigned in the set(INCLUDES_PATH "${SOURCES_PATH}/include"):
/home/alberto/STT_People_Tracking/Sources/background_substractor.cpp:3:36: fatal error: background_substractor.h: No such file or directory
#include "background_substractor.h"
^
compilation terminated.
make[2]: *** [CMakeFiles/../Debug/background_substractor.dir/Sources/background_substractor.cpp.o] Error 1
make[1]: *** [CMakeFiles/../Debug/background_substractor.dir/all] Error 2
make: *** [all] Error 2
3.- Finally, and if I comment the header file, I have problems linking:
Linking CXX static library lib../Debug/background_substractor.a
/usr/bin/ar: lib../Debug/background_substractor.a: No such file or directory
make[2]: *** [lib../Debug/background_substractor.a] Error 1
make[1]: *** [CMakeFiles/../Debug/background_substractor.dir/all] Error 2
make: *** [all] Error 2
I have tried everything: Specifying the include files in the add_executable() and add_library() commands, I have checked paths and they are ok, etc etc.
Could anyone more experienced with CMake, give me a little hand?
Thank you very much in advance,
Alberto
How can I know I am using OpenCV 3, and not other versions of OpenCV present in the system?
Your project should check that.
But usually projects just use find_package command for fill variables related to 3d-party library. This command perform all needed checks. In your case it could be
find_package(OpenCV 3 REQUIRED)
call, which fills OpenCV_LIBS and OpenCV_INCLUDE_DIRS variables automatically. This command, by default, search OpenCV installation in default paths, but you can adjust searching algorithm by using parameters to cmake (so, you needn't to change CMakeLists.txt when you build the project on other machine). E.g., this way
cmake -DOpenCV_DIR=/usr/local/opencv-3.0.0 <source-dir>
you can specify precise installation path of OpenCV.
When compiling the file background_substractor, its associated header file can not be located...
Cannot suggest anything aside from checking file existence
/home/alberto/STT_People_Tracking/Sources/include/background_substractor.h
But this also can be a result of the 3d issue(see below).
Finally, and if I comment the header file, I have problems linking...
Your usage of CMake targets is incorrect. Unlike to make targets, which usually are files, CMake targets are simple names. By default, name of library/executable target determines filename of the library/executable file, produced by this target, but this can be changed. Directory, where resulted file will be located, can be adjusted using CMAKE_<TYPE>_OUTPUT_DIRECTORY variables, where <TYPE> can be ARCHIVE, LIBRARY or RUNTIME depending on target type.
Correct CMake script would be:
cmake_minimum_required(VERSION 2.8)
project(STT_People_Tracker)
cmake_policy(SET CMP0016 NEW)
# compilation mode setup
#set(CMAKE_BUILD_TYPE Release)
set(CMAKE_BUILD_TYPE Debug)
# set OpenCV directories using find_package.
find_package(OpenCV 3 REQUIRED)
# set environment variables
set(SOURCES_PATH "${CMAKE_SOURCE_DIR}/Sources")
set(INCLUDES_PATH "${SOURCES_PATH}/include")
if(CMAKE_BUILD_TYPE MATCHES Debug)
set(OUTPUT_PATH "${CMAKE_BINARY_DIR}/Debug") # Use absolute path
message(STATUS "Compiling in DEBUG mode")
elseif(CMAKE_BUILD_TYPE MATCHES Release)
set(OUTPUT_PATH "${CMAKE_BINARY_DIR}/Release")
message(STATUS "Compiling in RELEASE mode")
endif()
# Set output directory for STATIC libraries and executables
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${OUTPUT_PATH})
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${OUTPUT_PATH})
include_directories(${INCLUDES_PATH})
include_directories(${OpenCV_INCLUDE_DIRS})
# compilation of executables
message(STATUS "configuring executables...")
add_executable(mainTest ${SOURCES_PATH}/mainTest.cpp) # Use simple name as a target
# compilation of libraries
message(STATUS "configuring libraries...")
add_library(background_substractor ${SOURCES_PATH}/background_substractor.cpp) # Use simple name as a target
# set linker options
# Command below is no-op: OpenCV libraries enumerated using absolute paths
# link_directories(${OpenCV_LINK_DIRECTORIES})
target_link_libraries(mainTest ${OpenCV_LIBS}) # Variable OpenCV_LIBS contains OpenCV libraries needed to link with
target_link_libraries(background_substractor ${OpenCV_LIBS})
message(STATUS "cmake configuration complete")

CMake Generated Eclipse CDT Project Does Not Have System Includes

My problem is similar with this: http://www.eclipse.org/forums/index.php/m/649323/
I created a cmake project, and used
cmake .. -G "Eclipse CDT4 - Unix Makefiles"
to create a Eclipse CDT4 project.
But in the CDT IDE, the standard include paths are not listed, and all STL or system build-in header files include directives are marked as "cannot be resolved", so the "Open Declaration" or other a lot of operation cannot be done.
However, I could compile it without any problems.
My co-worker also has a cmake project, but it's very complicated. The CDT project generated from his cmake project DOES have the system includes. But his cmake is way too complicated, and he told me that he didn't do anything special to include the system paths.
Can anyone help me out? Thanks.
My Main CMakeLists.txt:
CMake_Minimum_Required(VERSION 2.8)
# Some settings
Set(CMAKE_ALLOW_LOOSE_LOOP_CONSTRUCTS ON)
CMake_Policy(SET CMP0015 NEW)
#Include(CMakeProcedures.cmake)
#CheckEnvironment()
# Set the compiler and its version if needed
# Create the project
Project(MyProjectName CXX)
# Set the compiler
Set(CMAKE_CXX_COMPILER /usr/bin/g++)
# Detect whether we are in-source
If (CMAKE_SOURCE_DIR STREQUAL CMAKE_BINARY_DIR)
Message(FATAL_ERROR "In-source building is not allowed! Please create a 'build' folder and then do 'cd build; cmake ..'")
EndIf()
# Set the output dirs
Set(EXECUTABLE_OUTPUT_PATH ${PROJECT_BINARY_DIR}/bin)
Set(LIBRARY_OUTPUT_PATH ${PROJECT_BINARY_DIR}/lib)
# Add source subdirs to the build
Add_Subdirectory(src)
# Add_Subdirectory(test EXCLUDE_FROM_ALL)
Peter
One workaround is to manually add these to the CDT IDE:
/usr/include/c++/4.5
/usr/include/c++/4.5/backward
/usr/include/c++/4.5/i686-linux-gnu
/usr/include/i386-linux-gnu
/usr/lib/i386-linux-gnu/gcc/i686-linux-gnu/4.5.2/include
/usr/lib/i386-linux-gnu/gcc/i686-linux-gnu/4.5.2/include-fixed
/usr/local/include
But it's not the solution.
I finally figured out that this line is causing the problem:
Project(MyProjectName CXX)
If we remove the optional paramter CXX, life is good.
Can anyone tell me why?
Peter

Resources