V
V
vvafree2016-11-29 11:13:04
linux
vvafree, 2016-11-29 11:13:04

How to set up OpenCV 2.4.9 in Clion on Ubuntu 14.04?

Installed OpenCV by downloading opencv.sh from github. The installation was successful.
My CMakeLists.txt

project(ar_dip)
set(CMAKE_CXX_STANDARD 11)
set(OpenCV_FOUND 1)
FIND_PACKAGE( OpenCV REQUIRED core highgui imgproc)
find_package(PkgConfig REQUIRED)
pkg_search_module(OpenCV REQUIRED core highgui imgproc)
set(SOURCE_FILES main.cpp)
add_executable(ar_dip ${SOURCE_FILES})

The reload was successful.
My code, which I want to take video from the camera and display in the window.
#include <cv.h>
#include <highgui.h>
#include <stdlib.h>
#include <stdio.h>

int main(int argc, char* argv[])
{
    // получаем любую подключённую камеру
    CvCapture* capture = cvCreateCameraCapture(CV_CAP_ANY); //cvCaptureFromCAM( 0 );
    assert( capture );

    //cvSetCaptureProperty(capture, CV_CAP_PROP_FRAME_WIDTH, 640);//1280);
    //cvSetCaptureProperty(capture, CV_CAP_PROP_FRAME_HEIGHT, 480);//960);

    // узнаем ширину и высоту кадра
    double width = cvGetCaptureProperty(capture, CV_CAP_PROP_FRAME_WIDTH);
    double height = cvGetCaptureProperty(capture, CV_CAP_PROP_FRAME_HEIGHT);
    printf("[i] %.0f x %.0f\n", width, height );

    IplImage* frame=0;

    cvNamedWindow("capture", CV_WINDOW_AUTOSIZE);

    printf("[i] press Enter for capture image and Esc for quit!\n\n");

    int counter=0;
    char filename[512];

    while(true){
        // получаем кадр
        frame = cvQueryFrame( capture );

        // показываем
        cvShowImage("capture", frame);

        char c = cvWaitKey(33);
        if (c == 27) { // нажата ESC
            break;
        }
        else if(c == 13) { // Enter
            // сохраняем кадр в файл
            sprintf(filename, "Image%d.jpg", counter);
            printf("[i] capture... %s\n", filename);
            cvSaveImage(filename, frame);
            counter++;
        }
    }
    // освобождаем ресурсы
    cvReleaseCapture( &capture );
    cvDestroyWindow("capture");
    return 0;
}


What is written below in the console
/home/deus/clion-2016.3/bin/cmake/bin/cmake --build /home/deus/ClionProjects/ar_dip/cmake-build-debug --target all -- -j 6
-- Configuring done
-- Generating done
-- Build files have been written to: /home/deus/ClionProjects/ar_dip/cmake-build-debug
[ 50%] Linking CXX executable ar_dip
CMakeFiles/ar_dip.dir/main.cpp.o: In function `main':
/home/deus/ClionProjects/ar_dip/main.cpp:9: undefined reference to `cvCreateCameraCapture'
/home/deus/ClionProjects/ar_dip/main.cpp:16: undefined reference to `cvGetCaptureProperty'
/home/deus/ClionProjects/ar_dip/main.cpp:17: undefined reference to `cvGetCaptureProperty'
/home/deus/ClionProjects/ar_dip/main.cpp:22: undefined reference to `cvNamedWindow'
/home/deus/ClionProjects/ar_dip/main.cpp:31: undefined reference to `cvQueryFrame'
/home/deus/ClionProjects/ar_dip/main.cpp:34: undefined reference to `cvShowImage'
/home/deus/ClionProjects/ar_dip/main.cpp:36: undefined reference to `cvWaitKey'
/home/deus/ClionProjects/ar_dip/main.cpp:49: undefined reference to `cvReleaseCapture'
/home/deus/ClionProjects/ar_dip/main.cpp:50: undefined reference to `cvDestroyWindow'
/home/deus/ClionProjects/ar_dip/main.cpp:44: undefined reference to `cvSaveImage'
collect2: error: ld returned 1 exit status
make[2]: *** [ar_dip] Ошибка 1
make[1]: *** [CMakeFiles/ar_dip.dir/all] Ошибка 2
make: *** [all] Ошибка 2


I can not understand. Why does not it work? The installation of opencv was successful, so it's not about it. All that's left is make?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Maxim, 2016-11-29
@khrisanfov

Try adding to the cmake file:
By the way, it is better to install libraries from packages.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question