I can't get it to compile (using OpenCV libraries)

I'm trying to run code called squares.cpp (from https://code.ros.org/trac/opencv/browser/trunk/opencv/samples/cpp/squares.cpp?rev=4079) and it uses OpenCV, which I've installed (following the instructions on http://docs.opencv.org/doc/tutorials/introduction/linux_install/linux_install.html#linux-installation). However, it doesn't compile (I'm using g++ squares.cpp -o squares ) and I get the error message that opencv2/core/core.hpp does not exist - the code begins with:

5	#include "opencv2/core/core.hpp"
6	#include "opencv2/imgproc/imgproc.hpp"
7	#include "opencv2/highgui/highgui.hpp" 

Now, the .hpp files do exist, but not in folders exactly as above - do I need to create those folders and copy those files there? Does it matter where I saved squares.cpp (that is, are those locations relative to wherever the executable is?)? I'm working in ubuntu (I would've used Bloodshed, but the instructions to install OpenCV in Windows were far worse than those for installing it in Linux) but if anyone knows a simple way of getting this to run in Windows I'm all ears.

Alternatively, if anyone knows some software for identifying rectangles in an image (or even better, a stack of images or a video) and getting coordinates of centres (or centroids) and their angles I'd be very grateful, too (I've used the Mosaic plugin for ImageJ and it's worked pretty well for some purposes but now I need rectangles, not circles, which is what Mosaic finds). The images are black and white.
> Now, the .hpp files do exist, but not in folders exactly as above
┬┐where are they?
They should be in /usr/{local/,}include

Also, later you may have `undefined reference' errors.
You need to link against the libraries.
The easiest way is
g++ $(pkg-config --libs opencv)
that will translate to
g++ -lopencv_{core,highgui,imgproc,...}

For the rectangle detection you may use http://en.wikipedia.org/wiki/Hough_transform
Last edited on
Thanks, I've copied the files to the necessary folders but it still won't compile - it now it does find the files but it's finding an undeclared variable CV_AA, which is indeed not declared in the main code. I'm not sure if this is a bug or if I've made a mistake in copying all the needed files (I couldn't find another way of copying them other than sudo gedit on the relevant name and pasting the file contents into gedit).

I'm trying to do the Hough transform, but I'm also having trouble compiling, I'm going to check if I do better in windows.
CV_AA is a macro defined in `opercv2/core/core_c.h'
To copy you may use the `cp' command, but it would be simpler to use your package manager to install it.
Last edited on
Topic archived. No new replies allowed.