CMakeList for Gphoto2 and OpenCV

asked 2015-12-10 06:30:38 -0500

Michael Brown gravatar image

updated 2015-12-10 07:30:43 -0500

boaz001 gravatar image

For building the attached cpp file I receive CMAKE_MODULE_PATH error while running make command on Terminal.

It uses Gphoto2 and OpenCV to capture live images from a digital camera. This files is based on

I believe the problem is caused by a wrong CMakeLists.txt file, however I do not know how to fix it. Thanks for your guidance in advance.

grayp.cpp file:

#include <opencv2/imgproc.hpp>
#include <opencv2/highgui.hpp>
#include <opencv2/structured_light.hpp>
#include <iostream>
#include <stdio.h>
using namespace cv;
using namespace std;
int main( )

// Open camera,  using libgphoto2
VideoCapture cap1( CAP_GPHOTO2 );

if( !cap1.isOpened() )
// check if cam1 opened
cout << "cam1 not opened!" << endl;}
cout <<"FFFFFFFFFFFFFFFF"<< endl;

 // the camera will be deinitialized automatically in VideoCapture destructor
cout << "Closing program" << endl;
return 0;

CMakeLists.txt file:

cmake_minimum_required(VERSION 2.8)
project( grayp )
find_package( OpenCV REQUIRED )
add_executable( grayp grayp.cpp )
target_link_libraries( grayp ${OpenCV_LIBS} )
option(GPHOTO2 "test" ON)
find_package( GPHOTO2 REQUIRED )
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/home/pi/code/prof/gray")
edit retag flag offensive close merge delete


I don't know CMake well, but a simple Makefile - or even a gcc command could compile your program. It's something like this:

gcc -c $(shell pkg-config opencv --cflags) grayp.cpp -o grayp.o

gcc $(shell pkg-config opencv --libs) -lgphoto2 grayp.o -o grayp

kbarni gravatar imagekbarni ( 2015-12-10 07:05:07 -0500 )edit