Where / How to Place Build Files in OpenCV

I'm just starting to work with OpenCV, and I have the following example .cpp file (with opencv.org):

#include <stdio.h>
#include <opencv2/opencv.hpp>

using namespace cv;

int main( int argc, char** argv )
{
    Mat image;
    image = imread( argv[1], 1 );

    if( argc != 2 || !image.data )
    {
        printf( "No image data \n" );
        return -1;
    }

    namedWindow( "Display Image", CV_WINDOW_AUTOSIZE );
    imshow( "Display Image", image );

    waitKey(0);

    return 0;
}

and I have the following CMakeList.cmake file:

project(opencvTEST)
cmake_minimum_required(VERSION 2.6 FATAL_ERROR)

find_package(OpenCV REQUIRED)

# Project Executable
add_executable (test test.cpp)
target_link_libraries(test ${OpenCV_LIBS})

I have a Mac (OS 10.6.8), and I installed OpenCV 2.4.3 with CMake, and I searched high and low, and tried many different things to build this test program (I use the command line - no IDE), but I get the following compilation error (obviously due to a malfunctioning statement include):

test.cpp:3:30: error: opencv2/opencv.hpp: No such file or directory
test.cpp:5: error: ‘cv’ is not a namespace-name
test.cpp:5: error: expected namespace-name before ‘;’ token
test.cpp: In function ‘int main(int, char**)’:
test.cpp:9: error: ‘Mat’ was not declared in this scope
test.cpp:9: error: expected `;' before ‘image’
test.cpp:10: error: ‘image’ was not declared in this scope
test.cpp:10: error: ‘imread’ was not declared in this scope
test.cpp:18: error: ‘CV_WINDOW_AUTOSIZE’ was not declared in this scope
test.cpp:18: error: ‘namedWindow’ was not declared in this scope
test.cpp:19: error: ‘imshow’ was not declared in this scope
test.cpp:21: error: ‘waitKey’ was not declared in this scope

I have a folder with a name opencv2in the same directory as test.cpp, but opencv.hpplocated in opencv2, so I don’t understand why it does not find it. Any ideas?

Also, in general, where does OpenCV expect you to put source files (.cpp, etc.)?

+5
4

. opencv

error: ‘CV_WINDOW_AUTOSIZE’ was not declared in this scope

, :

#include <opencv/highgui.h>
+5

CMakeLists.txt

include_directories(${OpenCV_INCLUDE_DIRS})

find_package ( OpenCV)

+3

, , , , , OpenCV 2.4.3, OpenCV 2.4.4 (I ' , ).

OpenCV 2.4.4, , OpenCV 2.4.3 ( rm -rf , ) 2.4.4 ( homebrew: brew uninstall opencv). , , ( homebrew):

$ brew update #just in case you're missing updates
$ brew tap homebrew/science #skip this if you already have the science formulae
$ brew install opencv #this took about 15 minutes

Finally, I followed this tutorial , and voila, it worked! I do this to work with new software that was not intuitive, frustrated, and trying to run OpenCV 273 in different ways. I think all this is connected with the installation, which I did not know about, which (I think) caused serious problems. Am I the only one who found it difficult to work with OpenCV?

+1
source

There is another include folder with a path: opencv \ build \ include. There are full headers here, and you can set OpenCV_INCLUDE_DIR to this directory

0
source

All Articles