How to install OpenCV in ubuntu 12.04 - opencv

I already have OpenCV2.4.2 installed as part of ROS(Fuerte) in my computer(installed from Ubuntu Software Center, something due to ROS). How should I install OpenCV as a standalone?
I went through this guide and downloaded the opencv package from here. I am not quite clear as how to proceed. Can anyone give short list of steps to install? I want to use an IDE for my projects, so which IDE is proper for C++ and how to install the proper IDE and configure it correctly?
Also how to check if certain tools are installed?

This link which you also mentioned describes the necessary steps to compile OpenCV on your machine.
The version of OpenCV you install this way will be newer than the one installed with the ROS package, they usually have some delay. (Maybe not with Fuerte.)
Using multiple versions of the same library on a machine might cause problems with linking and it will create a bit of headache for you so I would avoid it.
Try running pkg-config opencv --libs to see if the ROS version pulled by Fuerte is available and you can use this with your projects later on.
For a starter IDE I would recommend Qt Creator.
The easy way to set OpenCV up with your project in Qt Creator is the following:
Create a project
Open the .pro file of the project
Run pkg-config opencv --cflags
Add this to the .pro file: INCLUDEPATH += __result__of__above
pkg-config opencv --libs
Add this to the .pro file: LIBS += __result__of__above
In the end what you add should look something like this:
INCLUDEPATH += -I/opt/ros/fuerte/include
LIBS += -L/opt/ros/fuerte/lib -lopencv_calib3d -lopencv_contrib -lopencv_core -lopencv_features2d -lopencv_flann -lopencv_gpu -lopencv_highgui -lopencv_imgproc -lopencv_legacy -lopencv_ml -lopencv_nonfree -lopencv_objdetect -lopencv_photo -lopencv_stitching -lopencv_ts -lopencv_video -lopencv_videostab

To install OpenCV using the terminal on Ubuntu:
$ su -
# apt-get update
# apt-get install build-essential
# apt-get install libavformat-dev
# apt-get install x264 v4l-utils ffmpeg
# apt-get install libcv2.3 libcvaux2.3 libhighgui2.3 python-opencv opencv-doc libcv-dev libcvaux-dev libhighgui-dev
OpenCV should be installed in /usr/local/ Installation Directory
You may also want to compile and view examples
$ cp -r /usr/share/doc/opencv-doc/examples .
$ cd examples
$ cd c
$ sh build_all.sh
You can read the complete article about How to install OpenCV on Ubuntu from Nam Huy Linux Blog at http://namhuy.net/1205/how-to-install-opencv-on-ubuntu.html

This github user has compiled all the installation steps using a shell script. You can install any OpenCV version you want by running the appropriate shell script inside.
$ git clone https://github.com/jayrambhia/Install-OpenCV.git
$ cd Ubuntu
$ chmod +x *
$ ./opencv_latest.sh

There is an installer for Ubuntu 16.04, and it may work well on Ubuntu 12.04, you could have a try. I have used it to install on Ubuntu 16.04 and it succeed!
An interactive installing script for install openCV on Ubuntu 16.04 LTS

Related

No rule to make target libopencv_calib3d.so.3.2.0 but opencv 3.4.1 installed, when making ROS workspace

I have opencv 3.4.1 installed from source on my ubuntu. But when running command catkin_make -DCMAKE_BUILD_TYPE=Release I get error:
No rule to make target '/usr/lib/x86_64-linux-gnu/libopencv_calib3d.so.3.2.0', needed by '~/ros_ws/devel/lib/stereo_slam/image_handle_node'. Stop.
No rule to make target '/usr/lib/x86_64-linux-gnu/libopencv_calib3d.so.3.2.0', needed by '~/ros_ws/devel/lib/libmetrics_lib.so'. Stop.
I've already tried following this: openCV program compile error "libopencv_core.so.2.4: cannot open shared object file: No such file or directory" in ubuntu 12.04
[EDIT] I get the same error compiling using clion or catkin_make directly from terminal, but clion creates special packages for release and debug versions. I don't quite understand these packages but in files CMakeCache.txt i found folowing lines:
//Dependencies for the target
metrics_lib_LIB_DEPENDS:STATIC=general;/opt/ros/melodic/lib/libtf.so;general;/opt/ros/melodic/lib/libtf2_ros.so;general;/opt/ros/melodic/lib/libactionlib.so;general;/opt/ros/melodic/lib/libmessage_filters.so;general;/opt/ros/melodic/lib/libtf2.so;general;/opt/ros/melodic/lib/libcv_bridge.so;general;/opt/ros/melodic/lib/libimage_geometry.so;general;/usr/lib/x86_64-linux-gnu/libopencv_calib3d.so.3.2.0;general;/usr/lib/x86_64-linux-gnu/libopencv_core.so.3.2.0;general;/usr/lib/x86_64-linux-gnu/libopencv_features2d.so.3.2.0;general;/usr/lib/x86_64-linux-gnu/libopencv_flann.so.3.2.0;general;/usr/lib/x86_64-linux-gnu/libopencv_highgui.so.3.2.0;general;/usr/lib/x86_64-linux-gnu/libopencv_imgcodecs.so.3.2.0;general;/usr/lib/x86_64-linux-gnu/libopencv_imgproc.so.3.2.0;general;/usr/lib/x86_64-linux-gnu/libopencv_ml.so.3.2.0;general;/usr/lib/x86_64-linux-gnu/libopencv_objdetect.so.3.2.0;general;/usr/lib/x86_64-linux-gnu/libopencv_photo.so.3.2.0;general;/usr/lib/x86_64-linux-gnu/libopencv_shape.so.3.2.0;general;/usr/lib/x86_64-linux-gnu/libopencv_stitching.so.3.2.0;general;/usr/lib/x86_64-linux-gnu/libopencv_superres.so.3.2.0;general;/usr/lib/x86_64-linux-gnu/libopencv_video.so.3.2.0;general;/usr/lib/x86_64-linux-gnu/libopencv_videoio.so.3.2.0;general;/usr/lib/x86_64-linux-gnu/libopencv_videostab.so.3.2.0;general;/usr/lib/x86_64-linux-gnu/libopencv_viz.so.3.2.0;general;/usr/lib/x86_64-linux-gnu/libopencv_aruco.so.3.2.0;general;/usr/lib/x86_64-linux-gnu/libopencv_bgsegm.so.3.2.0;general;/usr/lib/x86_64-linux-gnu/libopencv_bioinspired.so.3.2.0;general;/usr/lib/x86_64-linux-gnu/libopencv_ccalib.so.3.2.0;general;/usr/lib/x86_64-linux-gnu/libopencv_datasets.so.3.2.0;general;/usr/lib/x86_64-linux-gnu/libopencv_dpm.so.3.2.0;general;/usr/lib/x86_64-linux-gnu/libopencv_face.so.3.2.0;general;/usr/lib/x86_64-linux-gnu/libopencv_freetype.so.3.2.0;general;/usr/lib/x86_64-linux-gnu/libopencv_fuzzy.so.3.2.0;general;/usr/lib/x86_64-linux-gnu/libopencv_hdf.so.3.2.0;general;/usr/lib/x86_64-linux-gnu/libopencv_line_descriptor.so.3.2.0;general;/usr/lib/x86_64-linux-gnu/libopencv_optflow.so.3.2.0;general;/usr/lib/x86_64-linux-gnu/libopencv_phase_unwrapping.so.3.2.0;general;/usr/lib/x86_64-linux-gnu/libopencv_plot.so.3.2.0;general;/usr/lib/x86_64-linux-gnu/libopencv_reg.so.3.2.0;general;/usr/lib/x86_64-linux-gnu/libopencv_rgbd.so.3.2.0;general;/usr/lib/x86_64-linux-gnu/libopencv_saliency.so.3.2.0;general;/usr/lib/x86_64-linux-gnu/libopencv_stereo.so.3.2.0;general;/usr/lib/x86_64-linux-gnu/libopencv_structured_light.so.3.2.0;general;/usr/lib/x86_64-linux-gnu/libopencv_surface_matching.so.3.2.0;general;/usr/lib/x86_64-linux-gnu/libopencv_text.so.3.2.0;general;/usr/lib/x86_64-linux-gnu/libopencv_ximgproc.so.3.2.0;general;/usr/lib/x86_64-linux-gnu/libopencv_xobjdetect.so.3.2.0;general;/usr/lib/x86_64-linux-gnu/libopencv_xphoto.so.3.2.0;general;/opt/ros/melodic/lib/libroscpp.so;general;/usr/lib/x86_64-linux-gnu/libboost_filesystem.so;general;/usr/lib/x86_64-linux-gnu/libboost_signals.so;general;/opt/ros/melodic/lib/librosconsole.so;general;/opt/ros/melodic/lib/librosconsole_log4cxx.so;general;/opt/ros/melodic/lib/librosconsole_backend_interface.so;general;/usr/lib/x86_64-linux-gnu/liblog4cxx.so;general;/usr/lib/x86_64-linux-gnu/libboost_regex.so;general;/opt/ros/melodic/lib/libxmlrpcpp.so;general;/opt/ros/melodic/lib/libroscpp_serialization.so;general;/opt/ros/melodic/lib/librostime.so;general;/opt/ros/melodic/lib/libcpp_common.so;general;/usr/lib/x86_64-linux-gnu/libboost_system.so;general;/usr/lib/x86_64-linux-gnu/libboost_thread.so;general;/usr/lib/x86_64-linux-gnu/libboost_chrono.so;general;/usr/lib/x86_64-linux-gnu/libboost_date_time.so;general;/usr/lib/x86_64-linux-gnu/libboost_atomic.so;general;/usr/lib/x86_64-linux-gnu/libpthread.so;general;/usr/lib/x86_64-linux-gnu/libconsole_bridge.so.0.4;general;prometheus-cpp::core;general;prometheus-cpp::pull;general;ceres;general;proto;
I don't understand what these metrics_lib_LIB_DEPENDS are, and from where do they come from.
I also used erroneously sudo find / -name "opencv" -exec rm -i {} \; to remove opencv and I had the same problem.
I solved with :
sudo apt remove libopencv-dev
sudo apt remove libopencv-core3.2
However not all the opencv lib will be unistalled with this, so you need to remove all the opencv lib installed with ros (in my case I needed to remove also opencv-data). You can find them with:
sudo apt list --installed | grep opencv
after that you can install again ros melodic (or whatever you are using) :
sudo apt install ros-melodic-desktop-full
Problem was that I uninstalled previous version of opencv via next command:
sudo find / -name "*opencv*" -exec rm -i {} \;
By doing this I also erased the contents of the ROS OpenCV library. Later even after reinstalling ROS, these libraries did not reinstall because the system thinks they are installed but nothing was in them. I had to apt-get each library individually.
Don't purge OpenCV...

What is the difference between openCV and cv2?

I am new to the openCV library. When I was first trying the code for a feature matching tutorial
Python Tutorial Link
All other functions except for the 'drawMatches' function does not work. I figured out that my openCV version is not correct. Then I update my openCV version to the newest version(3.2.0) using command
conda install -c conda-forge opencv' and 'conda update --all
The problem now is that all other functions does not work because it does not recognize cv2. The error I get is like the following:
ImportError: dlopen(/Users/qdai/anaconda/lib/python2.7/site-packages/cv2.so,
Library not loaded: #rpath/libopenblasp-r0.2.19.dylib
Referenced from: /Users/qdai/anaconda/lib/libopencv_hdf.3.2.0.dylib
I don't know what is the relationship between cv2 and opencv. And how do I solve this problem?
From the paths you have in your example, I am assuming you're on Mac?
If so, I had this same problem.
After having homebrew installed this ended up working for me:
brew tap homebrew/science
brew install opencv
cd /Library/Python/2.7/site-packages/
sudo ln -s /usr/local/Cellar/opencv/2.4.9/lib/python2.7/site-packages/cv.py cv.py
sudo ln -s /usr/local/Cellar/opencv/2.4.9/lib/python2.7/site-packages/cv2.so cv2.so
Hope this helps.

Catkin command not found

I have installed ROS indigo and gazebo2 packages in Ubuntu 14.04.5. When I try to use catkin command, I get:
catkin_init_workspace : command not found
So, I tried to install catkin, it displays that ros-indigo-catkin is the latest version.
All I did was,
$ sudo apt-get install ros-indigo-desktop-full
$ sudo apt-get install gazebo2.<They're installed perfectly>
After this, I am getting catkin issue.
Help needed. Someone please find a way to fix this issue.
Had almost the same issue when i tried to run this command (please refer to the pics attached).
$ catkin build
Screenshot for solution applied to solve catkin build error
I solved it by installing catkin ROS build system using the command below (references attached in the links and pictures attached). Screenshot for catkin build error
$ sudo apt-get install ros-kinetic-catkin python-catkin-tools
If the workspace is setup, you properly sourced ROS as stated above, and if catkin_make works, but catkin build doesn't work do this:
sudo apt install python3-catkin-tools python3-osrf-pycommon
This is a catkin-tools dependency which was delinked in Ubuntu 20.04 so it has to be manually specified to be installed.
Probably you forgot to set up the environment after installing ROS.
$ echo "source /opt/ros/indigo/setup.bash" >> ~/.bashrc
$ source ~/.bashrc
Then, I will assume you want to create a package, so you can follow these steps:
$ mkdir -p path_to_my_workspace/workspace_name/src
$ cd path_to_my_workspace/workspace_name/src
$ catkin_init_workspace
$ cd path_to_my_workspace/workspace_name/
$ catkin_make
$ source path_to_my_workspace/workspace_name/devel/setup.bash
After running these commands your workspace is created, so now you can start adding packages.
Maybe you didn't install "catkin ROS build system"
You can install it using the following command for ROS Melodic:
sudo apt-get install ros-melodic-catkin python-catkin-tool
or for ROS kinetic
sudo apt-get install ros-kinetic-catkin python-catkin-tool
If you want to create a ROS package, you can use: catkin create pkg myworkSpace --catkin-deps rospy
this command will create a ROS workspace with a source folder, CMakeLists.txt and package.xml
or use
mkdir catkin
cd catkin
catkin create pkg myworkSpace --catkin-deps rospy
The provided commands are for Python. So, make sure to modify it for Cpp if you want so.

OpenCV on beaglebone. pkg-config issues

So i am running ubuntu 13.04 on the sd card of my new beaglebone black. I am attempting to install opencv-2.4.2. I've got everything installed without errors but when i try to build and run a program
g++ 'pkg-config opencv --cflags' FILE.cpp -o FILE 'pkg-config opencv --libs'
I get the error:
pkg-config opencv --cflags: no such file or directory
pkg-config opencv --libs: no such file or directory
When I run pkg-config --libs opencv it gives me the correct directory (/usr/lib/ .so) with all my libraries and I have confirmed they are all actually there. pkg-config opencv --cflags gives -I/usr/include/opencv. Which also exists.
I have edited my bash.bashrc, opencv.pc, and opencv.conf files reflect these paths. They were /usr/local/lib but no libraries installed there.
I'm running out of ideas guys, any help or suggestions would be great.
Thanks.
you should be using backticks (`) instead of ' to substitute the output of pkg-config into the command line.
opencv-2.4.2 is provided in the angstrom distribution that comes with the BeagleBone Black. One problem I found was that python-opencv is at 2.3 with angstrom, so if you want to do your development work in python you have to downgrade opencv to 2.3.

OpenCV binary deployment (Linux)

In the institute we use Scientific Linux 5 on the cluster and I need to deploy an app that uses a modern OpenCV distribution (2.3.1 or 2.4.0). I don't have root privileges on the cluster.
Essentially, how do I package all the dynamic binary dependencies of ffmpeg (and hopefully x264), opencv so that I can xcopy-deploy my app?
I have a working installation of OpenCV 2.3.1 on Ubuntu. If there was a way to controllably load the executable and copy along all the dynamic dependencies, I could use it.
Thanks,
Vadim
You don't need to install OpenCV in the computers if you don't have permission to do so.
Place the OpenCV libraries and it's dependencies somewhere in the system and before you execute your application make sure you adjust LD_LIBRARY_PATH to add these paths.
To retrieve the list of dependencies of a certain binary application/library, use ldd. You might be interested in reading this post: Copying shared library dependencies
1) Install GCC 4.7.3
sudo apt-get update
sudo apt-get install build-essential
2) Install CMake 2.8.10.1
sudo apt-get install cmake cmake-curses-gui
3) Download OpenCV 2.4.5
cd ~/Downloads
tar -xf opencv-2.4.5.tar.gz
cd opencv-2.4.5
mkdir build
cd build
cmake -DCMAKE_BUILD_TYPE=Release ..
make -j4
sudo make install
cd ../..
rm -rf opencv-2.4.5*
OpenBR uses OpenCV for face recognition. A clear documentation is available to install OpenBR,Here's the link!

Resources