I am new to Ubuntu and OpenCV. Apologies for my amateurishness.
I think I messed up OpenCV installation.
I had installed OpenCV 2.4 months back. The installation was successful (built openCV from source using CMake)
Couple of days back I had also installed OpenCV 3.0 using the same procedure.
The problem began when one of my code gave a segmentation fault for seemingly no reason. On suggestion by a friend on Caffe Neural Network issues forum (https://github.com/BVLC/caffe/issues/3416), it seems that I am compiling with 3.0 headers but linking against the 2.4 libraries.
I checked /usr/local/include. It has the standard openCv header files ( I didn't understand what 'compiling with 3.0 header means' )
In /usr/local/lib I have OpenCV 3.0 libraries ( no 2.4.8 at all).
Now compilation was successful, but when I try to run it, I get the following error.
Program received signal SIGSEGV, Segmentation fault.
0x00007ffff76c49bc in cv::merge(cv::_InputArray const&,
cv::_OutputArray const&) ()
from /usr/lib/x86_64-linux-gnu/libopencv_core.so.2.4
Just to add
"pkg-config --modversion opencv"
3.0.0
whereas dpkg -l | grep libopencv
gave out
i libopencv-calib3d-dev:amd64 2.4.8+dfsg1-2ubuntu1 amd64 development files for libopencv-calib3d
ii libopencv-calib3d2.4:amd64 2.4.8+dfsg1-2ubuntu1 amd64 computer vision Camera Calibration library
ii libopencv-contrib-dev:amd64 2.4.8+dfsg1-2ubuntu1 amd64 development files for libopencv-contrib
.......
q.1> why does my code link to libopencv_core.so.2.4 instead of 3.0. I have checked in /usr/local/lib and did not see a single 2.4 library. I have tried manually defining links to header files and libraries in CMake but still same result.
q.2> Do OpenCV headers have a version number? I don't understand how they are called '2.4 headers'. I have checked the source code but did not see any specific requirement for a version of library. Then what dictates to link to 2.4 version libraries?
Sorry if this is theoretical but this would be highly beneficial to beginners like me. Please do comment for a suitable question title if the current one is not appropriate.
Thanks
Your opencv2.4 libraries are located in /usr/lib/x86_64-linux-gnu/ while the new opencv3 libraries are most likely located in /usr/local/lib. The linker is first looking in the /usr/lib/x86_64-linux-gnu/ directory, and thus finding the opencv2.4 libs first. To fix this you can tell the linker to look in /usr/local/lib first by adding the following to your ~/.bashrc file
export LD_LIBRARY_PATH=/usr/local/lib:$LD_LIBRARY_PATH
Reload the bashrc file in the terminal as follows (or simply close and re-open the terminal):
source ~/.bashrc
And update the library database:
sudo ldconfig
To check the order in which the linker will search for libraries, you can use the following:
ld -lopencv_core --verbose | grep attempt
Related
I am trying to follow a guide to install Opencv however I am having problems.
I am following this guide:
https://www.pyimagesearch.com/2016/12/19/install-opencv-3-on-macos-with-homebrew-the-easy-way/
However there is an addendum when it reaches this point:
Update — 15 May 2017:
Which then sends you to this page:
This Page
As stated in this guide I installed OpenCV3 using this command:
brew install opencv3 --with-contrib --with-python3
I then stepped back to the original install guide here
However when checking my site packages using this line:
ls -l /usr/local/opt/opencv3/lib/python3.7/site-packages/
The directory is not found.
I then tried to cd to this directory one step at a time and found in my 'opt' directory that some of the folders were names incorrectly or at least different than to be expected.
I have two opencv folders:
opencv
opencv#3
I also have three python folders:
python3
python#2
python#3
Should I rename the opencv and python folders? If so how?
Mac OS High Sierra
I am trying to build this code:
https://docs.opencv.org/3.2.0/d5/d6f/tutorial_feature_flann_matcher.html
I am using Ubuntu 16.04 with CLion 2017.3 and have OpenCV 3.4 installed.
xfeatures2d.hpp can't be found on the system.
I have looked at many different problems on the internet, but couldn't find a solution.
Any help?
You have to include cmake comiplation flag to opencv OPENCV_EXTRA_MODULES_PATH and set it to the opencv_contrib/modules.
cmake -DOPENCV_EXTRA_MODULES_PATH=../opencv_contrib/modules
Here's what I had to do to compile OpenCV with xfeatures2d:
Download opencv_contrib (I took a release from the releases page). This step is what gives us xfeatures2d.
Unpack the tarball somewhere, e.g., ~/src/opencv_contrib-4.5.5
When configuring OpenCV (the main OpenCV source like opencv-4.5.2) with CMake, add the following option to cmake command line (adjusting the value to be your actual path to the modules subdirectory of the opencv_contrib tarball):
-DOPENCV_EXTRA_MODULES_PATH=$HOME/src/opencv_contrib-4.5.5/modules/
Now just build as you normally would and install.
The above actions gave me the expected file (among others): /usr/include/opencv4/opencv2/xfeatures2d.hpp.
When I compile a simple program : hello_world.cpp
**I get the error-
**fatal error: cv.h: No such file or directory
compilation terminated.****
Solutions I found but didn't work:
I checked for cv.h and highgui.h if they are there, and got these results:
/home/snu/OpenCV-2.4.0/include/opencv/highgui.h
/usr/lib/perl/5.14.2/CORE/cv.h
/home/snu/OpenCV-2.4.0/include/opencv/cv.h
I checked if opencv is correctly installed by using
pkg-config opencv --libs, this is what i got :
-lopencv_calib3d -lopencv_imgproc -lopencv_contrib -lopencv_legacy -lopencv_core -lopencv_ml -lopencv_features2d -lopencv_objdetect -lopencv_flann -lopencv_video -lopencv_highgui
I made some changes in the header files of hello_world.cpp as-
#include "opencv2/highgui/highgui.hpp"
Welcome to Stack Overflow, the land of the non-answer.
"You are not doing it right, is the problem"
"Do this", with no explanation. Doesn't work.
The cmake answer is ok, but I don't really want to use cmake for the sole purpose of making a single library import.
--- end of roast, my answer:
As per https://answers.opencv.org/question/225224/opencvcvh-not-found/
OpenCV 4 discontinued the C-API in favor of the C++ one, apparently.
So you should install the latest version of OpenCV 3. This can be done using platform specific installer listed below:
https://sourceforge.net/projects/opencvlibrary/files/3.4.10/
For Linux specifically, you want this file from the ones in the link above.
Download and extract it.
Then based on these instructions to install it,
Make a directory, I called my opencv-install and put the extracted folder in it.
opencv-install/opencv-opencv-25a1900
cd opencv-install
rm opencv-opencv-25a1900/CMakeCache.txtls
cmake opencv-opencv-25a1900
make
sudo make install # global install
Then change your import to #include "opencv/cv.h"
Well how about that, you still needed cmake, but at least you don't have to make your project a "cmake project". In fact, if someone else with the same operating system has already done up to step 5, you can simply use their build !
For Linux beginners (requires Debian-base, cmake not needed)
As a little courtesy, and to put my "money" where my "mouth" is, I will provide to you my own build. Understand that using someone else's build assumes a bit more trust than compiling it yourself. I know when I first start with C/Linux compiling OS projects can be kind of daunting so.... here you go! It is for For Debian GNU/Linux 11 (bullseye) x86_64. I think this means it works on Ubuntu, and maybe other OSes that use apt. If you try it and it doesn't work, you should try a different build or make one yourself by starting at step one above.
You are probably not compiling correctly. Add the opencv-include folder in the compiler settings.
Use CMake to link libraries and include directories. It makes your life easier and also for anyone else who will be extending/reading your code in the future. You will not need to add folders specifically into projects as CMake will do that for you automatically.
For example, to link OpenCV, use the follow lines of code:
FIND_PACKAGE( OpenCV REQUIRED )
TARGET_LINK_LIBRARIES( myProject ${OpenCV_LIBS} )
please use the code below for such errors:
#include <opencv/cv.h>
in the place of
#include <cv.h>
I'm currently working on a study comparing the performance of different operating systems in image processing.
Because of this, i have to install OpenCV 2.4.x (2.4.3 preferably) on a FreeBSD system.
The problem is that it includes asm/types.h, which is not a POSIX-compliant library but rather a Linux one.
So i run cmake with the standard flags suggested by the install guide:
cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local ..
Where .. points correctly to the source folder. Everything goes ok, so i run make:
[ 16%] Building CXX object modules/highgui/CMakeFiles/opencv_highgui.dir/src/cap_libv4l.cpp.o
/root/work/OpenCV-2.4.3/modules/highgui/src/cap_libv4l.cpp:238:54: error: asm/types.h: No such file or directory
The question is: what should i do in order to tell the compiler that it needs to include another header instead of the original header file?
This problem was addressed at Bug#651872: opencv: FTBFS on kfreebsd
In modules/highgui/src/cap_libv4l.cpp, remove or comment out the following include:
#include <asm/types.h>
Do the same in modules/highgui/src/cap_v4l.cpp.
I am compiling a dependency for a project on Ubuntu 10.10, and instead of having it install to /usr/local by default, I am instead installing it to /tmp/stage/usr/local. How do I go about informing CMake of the location of this custom installed dependency when I call it to generate the build files for said project.
I am running CMake 2.8.1, and I have tried to set CMAKE_PREFIX_PATH on the cmake command line, like so
cmake -D CMAKE_PREFIX_PATH=/tmp/stage/usr/local
but this doesn't seem to make a difference - the project doesn't seem to detect the dependency.
Also, if it matters, the project in question is OpenCV 2.2, and the dependency in question is FFMPEG...
I figured out how to fix my problem, and trying to point CMake at the appropriate install location isn't the issue.
Apparently, CMake is unable to find the pkg-config files for FFMPEG (i.e. libavcodec.pc, libavdevice.pc, etc.) that tell it where the FFMPEG headers and libraries are located. In a typical install scenario, these files would be located at /usr/lib/pkgconfig. However because of the custom install location, they are instead located at /tmp/stage/usr/local/lib/pkgconfig.
So that CMake could find these files, I had to add the following environment variable:
export PKG_CONFIG_PATH=/tmp/stage/usr/local/lib/pkgconfig
After which point, OpenCV built against FFMPEG as expected.