Problem with cmake and OpenCV 2.0 in Ubuntu - c++

Goodnight, I'm working in a project where we use Cmake and OpenCV 2.0 in Ubuntu 10.04, everyone in the team(we are a micro-mouse contest team) can compile code just fine, but I cant.
This is what Cmake says to me:
tiago#tiago-laptop:~/bioloid/build$ cmake ..
-- Checking GNUCXX version 3/4 to determine OpenCV /opt/net/ path
CMake Error at CMakeModules/FindOpenCV.cmake:348 (MESSAGE):
OpenCV required but some headers or libs not found. Please specify it's
location with OpenCV_ROOT_DIR env. variable.
Call Stack (most recent call first):
CMakeLists.txt:45 (FIND_PACKAGE)
-- Configuring incomplete, errors occurred!
If I try to export the variable like this:
export OpenCV_ROOT_DIR=/usr/local/lib
It keeps giving the same error, this is the output from pkg-config --cflags --libs opencv:
-I/usr/local/include/opencv -I/usr/local/include -L/usr/local/lib -lopencv_core -lopencv_imgproc -lopencv_highgui -lopencv_ml -lopencv_video -lopencv_features2d -lopencv_calib3d -lopencv_objdetect -lopencv_contrib -lopencv_legacy -lopencv_flann
No one in the team knows what do do, I have already removed and re-instaled opencv, is there any chance that this is because I also have opencv 2.2 instaled in my computer?

As you are using a custom Find macro to find opencv (CMakeModules/FindOpenCV.cmake) you should actually check which libraries this macro requires to find. As it looks like this macro is actually under your control, I would just add debug messages to its processing to find out at which point it fails. If the macro uses a call to MARK_AS_ADVANCED a good strategy could be print out all variables that are passed into this macro. All variables need to have a value that is not empty, false or XXX-NOTFOUND.
Apart from that, making the code of this find macro available to us would help in debugging.

Related

How to find out the registered name of a library in C++ compilation

When I do the link phase in C++ compilation to produce an executable, I often need to use the -l flag to link a few libraries. For example,
-lopencv_core -lopencv_highgui -lopencv_imgproc -lopencv_videoio -lsigc-2.0 -lglibmm-2.4 -lglib-2.0 -lstdc++ -lncurses -lflycapture
My question is how do I know the names of these libraries in the first place?
For example, if I want to use the opencv/highgui.h library, how do I know the name is opencv_highgui instead of opencv-highgui? Are there any commands I can use to figure out what libraries have been registered to the Linux system? Thanks!
If a function you try to use is not in any "standard" library, you will get a linker error reporting the missing function name. Read the manual page for the function (e.g., man crypt for the function crypt). The name of the library will be usually mentioned in the page:
Link with -lcrypt.

Qt Creator cannot find openCV libraries

First of all I know this question has been asked (see here) but those solutions did not work for me.
I am trying to install opencv to use with Qt Creator on ubuntu 14.04.
I followed this tutorial exactly and confirmed that it worked by running the facedetect example.
I then started on this tutorial for using Qt creator with opencv. I followed the steps in the video exactly, however when I build and run the example I get the following errors:
/usr/bin/ld: cannot find -lopencv_core
/usr/bin/ld: cannot find -lopencv_imgcodecs
/usr/bin/ld: cannot find -lopencv_highgui
full compile output:
g++ -Wl,-rpath,/home/tpst/Program_Files/Qt-5.3.1/5.3/gcc_64 -Wl,-rpath,/home/tpst/Program_Files/Qt-5.3.1/5.3/gcc_64/lib -o test main.o -L/usr/local/lib -lopencv_core -lopencv_imgcodecs -lopencv_highgui -L/home/tpst/Program_Files/Qt-5.3.1/5.3/gcc_64/lib -lQt5Core -lpthread
/usr/bin/ld: cannot find -lopencv_core
/usr/bin/ld: cannot find -lopencv_imgcodecs
/usr/bin/ld: cannot find -lopencv_highgui
collect2: error: ld returned 1 exit status
make: *** [test] Error 1
23:02:50: The process "/usr/bin/make" exited with code 2.
Error while building/deploying project test (kit: Desktop Qt 5.3 GCC 64bit)
When executing step 'Make'
And here is the contents of my .pro file:
QT += core
QT -= gui
TARGET = test
CONFIG += console
CONFIG -= app_bundle
TEMPLATE = app
INCLUDEPATH += /usr/local/include/opencv
LIBS += -L/usr/local/lib -lopencv_core -lopencv_imgcodecs -lopencv_highgui
SOURCES += main.cpp
I have also tried to compile using terminal and get the same (/usr/bin/ld: cannot find -llib)
I dont understand why Qt cant find the libraries. You can see that they exist in the directory
Some help would be appreciated. I'm new to linux and Qt, I dont really understand the solutions posted to similar questions and have not been able to solve this myself.
afaik your linked libraries must look like libName.so but your libraries are named libName.so.version so the linker doesn't find them. Try to create symbolic links:
ln /usr/local/lib/libopencv_core.so.3.0.0 /usr/local/lib/libopencv_core.so
ln /usr/local/lib/libopencv_imgcodecs.so.3.0.0 /usr/local/lib/libopencv_imgcodecs.so
ln /usr/local/lib/libopencv_highgui.so.3.0.0 /usr/local/lib/libopencv_highgui.so

Opencv + Boost: Undefined references

I have a computer vision source code that is related to find copy and move portions in a forged image. I cannot compile this source code that uses openCV and Boost, some of the errors include undefined references to OpenCv stuff, for example:.
main.cpp:(.text+0x3cc1): undefined reference to `cvSetZero'
My makefile is the following. I think I correctly indicate the boost and opencv libraries. What could be wrong?
# Boost library is required
BOOST_LIBS=-L/usr/include/boost -lboost_system -lboost_random
BOOST_INCLUDE=-I/usr/include/boost
BOOST_VERSION=103500
OPENCV_INCLUDE=-I/usr/include/opencv2/
OPENCV_LIBS=-L/usr/include/opencv2/ -lopencv_core -lopencv_imgproc -lopencv_highgui -lopencv_flann -lopencv_calib3d
OPENCV_LIBS=-L/usr/lib/opencv2/ -lopencv_core ...
^^^
You might want to check if OpenCV is installed correctly and where this installation is located. Afterwards you can adjust your makefile. How to do this depends on your OS.
E.g. on Linux you might want to search for the opencv_core.so (e.g. via locate -b opencv_core).
In my case it would be
OPENCV_LIBS=-L/usr/lib/ -lopencv_core
if you have pkg-config installed, and if it knows where OpenCV is, you can try
OPENCV_INCLUDE=$$(pkg-config --cflags opencv)
OPENCV_LIBS=$$(pkg-config --libs opencv)

Compile issues with OpenCV and Juce on Xcode4.1 in 32bit on Lion

I'm trying to compile my VST Plugin with Xcode4.1 in 32Bit. I'm using the Juce Framework and integrated OpenCV 2.2 in it. I installed OpenCV with homebrew and this command:
sudo brew install opencv -build32
But when I'm compiling the project with Xcode4.1 in 32bit I will get this errors:
Undefined symbols for architecture i386: "_cvLoadImage", referenced from: ...
In my Build Settings I have defined the header and library search paths.
header search paths: /usr/local/Cellar/opencv/2.2/include
/usr/local/Cellar/opencv/2.2/include/opencv
/usr/local/Cellar/opencv/2.2/include/opencv2
library search paths: /usr/local/Cellar/opencv/2.2/lib
other linker flags: -L/usr/local/Cellar/opencv/2.2/lib -lopencv_core -lopencv_imgproc -lopencv_highgui -lopencv_ml -lopencv_video -lopencv_features2d -lopencv_calib3d -lopencv_objdetect -lopencv_contrib -lopencv_legacy -lopencv_flann
But it doesn't compile successful. I hope someone can help me?
I have solved the problem with the help of the wiki article section Using the OpenCV libraries in an Xcode OS X project. Just needed to add the dylib files to my project. :-)

Runtime errors when coding OpenCV programs using codeBlocks in linux

When I try to compile a C++ program which uses the openCV library in CodeBlocks it gives me a runtime error :
error while loading shared libraries: libopencv_calib3d.so.2.2:
cannot open shared object file: no such file or directory
This is in spite of the fact that I have added all the required libraries using linker settings for the Code Blocks IDE (including the one named libopencv_calib3d.so.2.2 which is a symbolic link).
However I'm able to compile the program using the command line by issuing the command :
g++ hello-world.cpp -o hello-world \
-I /usr/local/include/opencv -L /usr/local/lib
\ -lm -lcv -lhighgui -lcvaux
Can somebody advise me on how I can get to run the same using Code Blocks.
Thanks!
The file libopencv_calib3d.so.2.2 is part of OpenCV 2.2. There is, however, no libcv, libhighgui or libcvaux part of OpenCV 2.2. This means that your g++ call links against another version of OpenCV.
To link against OpenCV 2.2, you would need flags like -lopencv_core -lopencv_imgproc -lopencv_highgui -lopencv_ml -lopencv_video -lopencv_features2d -lopencv_calib3d -lopencv_objdetect -lopencv_contrib -lopencv_legacy -lopencv_flann.
You should also not put them in manually, but instead use
export PKG_CONFIG_PATH=/usr/local/share/opencv/:$PKG_CONFIG_PATH
g++ `pkg-config --cflags --libs opencv` hello-world.cpp -o hello-world
I would recommend installing a reasonably up-to-date version of OpenCV for Linux, 2.4.9 for example, at this time of writing, appears to build with the current version of gcc that I have (4.8.2). There are a few steps you need to complete in order to get a simple OpenCV example up and running in Code::Blocks. The OpenCV documentation tells you to create a build directory within your OpenCV root directory and run cmake, make, sudo make install etc in order to generate the libraries your project may need to link to, including the libopencv_calib3d.so you mention:
This blog posting gives explanations on how to install OpenCV and configure it's use for Code::Blocks in Ubuntu Linux environments:
http://www.technical-recipes.com/2014/using-opencv-in-codeblocks-in-linux/