Begginer Problem using external libraries

Before I start, I want to thank you in advance because this thing got me really frustrated recently :( I think this deserves the begginer area but correct me if im wrong.
I downloaded Visual Studio 2010 and opencv 2.4.9 (both the newest versions) and couldn't get this image upload program to work. The imread command couldn't find my image, maybe im puting the picture in the wrong place? I tried puting it in several places inside the project folder too but it was no good.
Anyway, I now downloaded and installed Visual studio 2013 and now code can't read my
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
(fuck)

How i directed everything to the opencv folder:
Went to properties of the project and changed
1. c/c++ -> general -> additional include directories -> added the location of the build/include/opencv of my opencv folder, as well as the same one that ends with build/include/opencv2
2. Linker -> General -> additional library directories -> added the location of the build/x86/vc12/lib of the opencv folder
3. Linker -> input -> additional dependencies -> and added a bunch of stuff that end with .lib
and added a bunch of stuff that end with .lib like - opencv_calib3d249.lib

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <iostream>

using namespace cv;
using namespace std;

int main(int argc, char** argv)
{
	if (argc != 2)
	{
		cout << " Usage: display_image ImageToLoadAndDisplay" << endl;
		return -1;
	}

	Mat image;
	image = imread(argv[1], IMREAD_COLOR); // I tried changing the argv[1] to just c:\\ picturetodesplay   and moved the picturetodesplay to C ofcourse

	if (!image.data)                     
	{
		cout << "Could not open or find the image" << std::endl;
		return -1;
	}

	namedWindow("Display window", WINDOW_AUTOSIZE); 
	imshow("Display window", image);               

	waitKey(0); 
	return 0;
}


Because these are new versions of opencv and c++ I just can't find many guides. You will be surprised how long im stuck on this :/
Again, thanks in advance
Last edited on
so what errors are you exactly receiving? Is it that msvc2013 is telling you it can't find these includes?
Are you getting compile errors or linker errors?
Please post the EXACT text of your errors.
1. c/c++ -> general -> additional include directories -> added the location of the build/include/opencv of my opencv folder, as well as the same one that ends with build/include/opencv2


Make sure you are adding the folder that "contains" the opencv folder to the include path and not adding the opencv folder itself to the include path. So basically you are going to want to add build/include to the path for this project instead of adding build/include/opencv2

The reason behind this is because #include "opencv2/somethinghere.hpp" is saying include the somethinghere header file which is found in the opencv2 folder.

So if we added the opencv folder to the include path it will be searching for this path instead opencv2/opencv2/somethinghere.hpp.

Hopefully that makes sense.

Another thing to keep in mind make sure you add the include paths under both the debug and release versions (This also pertains to the linking of the libaries to).
Last edited on

The errors I got:

Warning 1 warning C4627: '#include <opencv2/core/core.hpp>': skipped when looking for precompiled header use d:\users\user-pc\documents\visual studio 2013\projects\consoleapplication2\consoleapplication2\consoleapplication2.cpp 1 1 ConsoleApplication2
Warning 2 warning C4627: '#include <opencv2/highgui/highgui.hpp>': skipped when looking for precompiled header use d:\users\user-pc\documents\visual studio 2013\projects\consoleapplication2\consoleapplication2\consoleapplication2.cpp 2 1 ConsoleApplication2
Warning 3 warning C4627: '#include <iostream>': skipped when looking for precompiled header use d:\users\user-pc\documents\visual studio 2013\projects\consoleapplication2\consoleapplication2\consoleapplication2.cpp 3 1 ConsoleApplication2
Error 4 error C1010: unexpected end of file while looking for precompiled header. Did you forget to add '#include "stdafx.h"' to your source? d:\users\user-pc\documents\visual studio 2013\projects\consoleapplication2\consoleapplication2\consoleapplication2.cpp 31 1 ConsoleApplication2
5 IntelliSense: cannot open source file "opencv2/core/core.hpp" d:\Users\user-pc\Documents\Visual Studio 2013\Projects\ConsoleApplication2\ConsoleApplication2\ConsoleApplication2.cpp 1 1 ConsoleApplication2
6 IntelliSense: cannot open source file "opencv2/highgui/highgui.hpp" d:\Users\user-pc\Documents\Visual Studio 2013\Projects\ConsoleApplication2\ConsoleApplication2\ConsoleApplication2.cpp 2 1 ConsoleApplication2
7 IntelliSense: name must be a namespace name d:\Users\user-pc\Documents\Visual Studio 2013\Projects\ConsoleApplication2\ConsoleApplication2\ConsoleApplication2.cpp 5 17 ConsoleApplication2
8 IntelliSense: identifier "Mat" is undefined d:\Users\user-pc\Documents\Visual Studio 2013\Projects\ConsoleApplication2\ConsoleApplication2\ConsoleApplication2.cpp 16 2 ConsoleApplication2
9 IntelliSense: identifier "imread" is undefined d:\Users\user-pc\Documents\Visual Studio 2013\Projects\ConsoleApplication2\ConsoleApplication2\ConsoleApplication2.cpp 17 10 ConsoleApplication2
10 IntelliSense: identifier "IMREAD_COLOR" is undefined d:\Users\user-pc\Documents\Visual Studio 2013\Projects\ConsoleApplication2\ConsoleApplication2\ConsoleApplication2.cpp 17 26 ConsoleApplication2
11 IntelliSense: identifier "namedWindow" is undefined d:\Users\user-pc\Documents\Visual Studio 2013\Projects\ConsoleApplication2\ConsoleApplication2\ConsoleApplication2.cpp 25 2 ConsoleApplication2
12 IntelliSense: identifier "WINDOW_AUTOSIZE" is undefined d:\Users\user-pc\Documents\Visual Studio 2013\Projects\ConsoleApplication2\ConsoleApplication2\ConsoleApplication2.cpp 25 32 ConsoleApplication2
13 IntelliSense: identifier "imshow" is undefined d:\Users\user-pc\Documents\Visual Studio 2013\Projects\ConsoleApplication2\ConsoleApplication2\ConsoleApplication2.cpp 26 2 ConsoleApplication2
14 IntelliSense: identifier "waitKey" is undefined d:\Users\user-pc\Documents\Visual Studio 2013\Projects\ConsoleApplication2\ConsoleApplication2\ConsoleApplication2.cpp 28 2 ConsoleApplication2

Hope this means something to you.

Zereo,
I think i had that currectly when I did the c/c++ -> general -> additional include directories part and added the folders called opencv and opencv2, each of these have header files inside such as core and highgui. If thats what you mean.
Can you explain more about how I can add the include paths to the debug and release versions seperatly? I thought writing them down on the code was good for both.
Last edited on
Topic archived. No new replies allowed.