Adding an executable to opencv

asked 2016-11-22 08:02:48 -0600

Gauthier gravatar image

updated 2016-11-22 08:31:00 -0600

I am trying to write a test program for OpenCV's MOG2 background subtraction. My aim is to write tests to aid refactoring the background subtraction for my specific use case.

To achieve that, I created a directory test in modules/video/.

In this directory test/ I created a file test_mog2.cpp. This test source file contains #include "../src/bfbg_gaussmix2.cpp". (That's right, the cpp file, because I want to be able to test the internals of the module without otherwise exposing its help classes to the outside world.)

My problem is to make the build system around this.

I added add_subdirectory(test) to modules/video/CMakeLists.txt.

Then a new modules/video/test/CMakeLists.txt, which content is:

if ( NOT TARGET test-mog2 )
  include_directories(${OpenCV_INCLUDE_DIRS})
  ADD_EXECUTABLE( test-mog2 test_mog2.cpp)
  TARGET_LINK_LIBRARIES( test-mog2
    gtest
    ${OpenCV_LIBS}
    opencv
    )
  SET_PROPERTY( SOURCE test_mog2.cpp APPEND PROPERTY COMPILE_FLAGS -std=c++11 )
endif()

The complier complains:

modules/video/test/../src/precomp.hpp:47:36: fatal error: opencv2/core/utility.hpp: No such file or directory

I tried to print ${OpenCV_INCLUDE_DIRS} in a message(), it seems empty. Is that because I'm inside OpenCV source tree and I haven't done find_package on OpenCV?

How do I make sure that my test source program test/test_mog2.cpp is compiled with the correct -I option?

edit retag flag offensive close merge delete