Cinder-OpenCV on Linux/Ubuntu

Hi,

I’d like to know how to build the Cinder-OpenCV package on a Linux machine (I’m using Ubuntu 18.04). I’m new to Cinder and a project I wish to build requires Cinder-OpenCV. The README on the GitHub page doesn’t provide any information on how to build it so I’m hoping someone can help me here. Apologizing in advance if there’s something basic I’ve overlooked.

Thanks

This is what I use with Cinder-OpenCV3 (https://github.com/cinder/Cinder-OpenCV3).

Install the OpenCV dev package.

Place this in the file proj/cmake/cinder-opencv3-config.cmake in the block directory.

if( NOT TARGET Cinder-OpenCV3 )

	get_filename_component( CINDER_OPENCV3_PATH "${CMAKE_CURRENT_LIST_DIR}/../.." ABSOLUTE )

	list( APPEND Cinder-OpenCV3_INCLUDES
		${CINDER_OPENCV3_PATH}/include
	)

    if( CINDER_LINUX )
		find_package( PkgConfig )
		find_package( OpenCV REQUIRED )

		list( APPEND Cinder-OpenCV3_INCLUDES ${OpenCV_INCLUDE_DIRS} )
		list( APPEND Cinder-OpenCV3_LIBRARIES ${OpenCV_LIBRARIES} )
	endif()
endif()

in your app CMakeLists.txt you can list Cinder-OpenCV3 in the ci_make_app section similar to this:

ci_make_app(
    APP_NAME ${APP_NAME}
    INCLUDES ${APP_INCS}
    SOURCES ${APP_SRCS}
    CINDER_PATH ${CINDER_PATH}
    BLOCKS Cinder-OpenCV3
)

Thanks for the answer @gabor_papp!

To clarify, is proj/cmake/cinder-opencv3-config.cmake within the Cinder-OpenCV3 directory or the root Cinder directory? I don’t have a proj/cmake within Cinder-OpenCV3 so in case of the former, should I create this?

Secondly, the project I’m trying to build is someone else’s source code and they don’t seem to have followed the recommended way of using Cinder-OpenCV as a CinderBlock (as explained here). So there is no ci_map_app section in the CMakeLists.txt.

I believe there is a FindCinder.cmake file that sets the paths to the necessary Cinder include and library directories. Will be happy to attach the contents of that file if that would help! However, currently, it points only to Cinder, and not Cinder-OpenCV both.

Considering this, is there a way to link Cinder-OpenCV3 to build with Cinder itself so FindCinder.cmake can directly access the Cinder-OpenCV3 files through Cinder?

To clarify, is proj/cmake/cinder-opencv3-config.cmake within the Cinder-OpenCV3 directory or the root Cinder directory? I don’t have a proj/cmake within Cinder-OpenCV3 so in case of the former, should I create this?

You should create it in Cinder-OpenCV3.

Secondly, the project I’m trying to build is someone else’s source code and they don’t seem to have followed the recommended way of using Cinder-OpenCV

Ok. This can be slighlty more difficult then. Since Cinder-OpenCV is header only, it is enough to add the include folder of Cinder-OpenCV to your include path and add the OpenCV libraries and includes to your project. This is what happens basically in the cmake file above. Try adding the include and library lines to the project CMakeLists.txt.

-Gabor

2 Likes

This worked, thank you so much! :blush:

I just included the folder of Cinder-OpenCV directly to my include path in the project’s CMakeLists.txt.

1 Like