How to install OpenCV in FEDORA OS
In this post
you will learn how to install OpenCV in your Fedora OS. This post is
experimented in Fedora 20.
Requirements:
- Internet connection
- FEDORA with latest updates running on your system.
- Manually downloaded latest opencv zipped file for linux from opencv website.(We will not download through Terminal utility).
Procedures:
- Open the Terminal app
- go to Desktop using cd Desktop command
- Let us install the Dependencies
sudo yum install cmake pkgconfig gtk2 gcc gcc-c++
(this will install basic
packages required for opencv to run)
4. Now we will install ffmpeg package(one more extra package)
sudo rpm -Uvh http://download1.rpmfusion.org/free/fedora/rpmfusion-free-release-stable.noarch.rpm http://download1.rpmfusion.org/nonfree/fedora/rpmfusion-nonfree-release-stable.noarch.rpm
type the following
sudo yum –y install
ffmpeg
5. So far, we have installed all the
basic packages required
6. Create a folder known as “OpenCV” in
your desktop using GUI and mouse+rightclick+create_new_folder
7. Copy the zipped opencv file inside
the “OpenCV” folder using mouse or keyboard
8. Right click on the file and extract
it. Once extract is done you should be able to notice a directory “opencv-2.4.x”,
where x is the version of opencv that you have downloaded.
9. Create a folder named “build” inside
“opencv-2.4.x” directory
(From
step 6 to 9, we could have done these steps through terminal but to simplify
your life we made use of GUI,mouse and keyboard)
10. Now in
terminal
cd opencv-2.4.x/build
11. Now
we will build the opencv and install it using cmake tool that you
installed in 3rd step and make tool
12. Run
the following commands
cmake –D
CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local –D WITH_TBB=ON -D WITH_EIGEN=ON ..
(don’t miss the two dots)
make
(This will take little
time to generate build of opencv. Once it finishes to 100%, run the following
command)
sudo make install
(this will install opencv
library in /usr/local directory)
13. Once
the installation is done we need to inform certain utility that opencv is available in the system for linking. One such utility we use is “pkg-config”
14. Open
new file “opencv.conf” using vi editor
sudo
/etc/ld.so.conf.d/opencv.conf
add this statement in the
file(press “i” to get insert mode of vi)
/usr/local/lib
once
done press ESC, then :wq for saving the new created file opencv.conf and exit
from vi editor
15. Then type sudo
ldconfig in terminal
16. Then type sudo
vi /etc/profile
add the following line in
the file(press “i” to get insert mode of vi)
export
PKG_CONFIG_PATH=/usr/local/lib/pkgconfig
export
LD_LIBRARY_PATH=/usr/local/lib
once done press ESC, then :wq for saving the new created file opencv.conf and exit from vi editor
17.type source
/etc/profile
Thus we have finished configuring part.So now you
have configured pkg-config utility
to identify the opencv .
Now let us run a small program to check the opencv installation
- save this code in a file with name as "abc.cpp"
- change the path of the image in imread command with your own image available in hard disk(do not use this \, use only /, to separate directories)
- to compile it
#include<opencv2/highgui/highgui.hpp>
using namespace cv ;
int main()
{
Mat img = imread("/home/USER/Pictures/python.jpg",CV_LOAD_IMAGE_COLOR);
imshow("opencvtest",img);
waitKey(0);
return 0;
}
- g++ 'pkg-config --cflags opencv' abc.cpp 'pkg-config --libs opencv' -o abc
- which generates executable named as "abc", now run the abc
- ./abc
By now you must see your image being loaded up in a window
Thus, OpenCV is properly configured in your Linux system
Note: Never ever forget to add header files as shown above in the code(dont miss "opencv2/")
Other header file available in OpenCV are as follows
#include "opencv2/core/core_c.h"
#include "opencv2/core/core.hpp"
#include "opencv2/flann/miniflann.hpp"
#include "opencv2/imgproc/imgproc_c.h"
#include "opencv2/imgproc/imgproc.hpp"
#include "opencv2/photo/photo.hpp"
#include "opencv2/video/video.hpp"
#include "opencv2/features2d/features2d.hpp"
#include "opencv2/objdetect/objdetect.hpp"
#include "opencv2/calib3d/calib3d.hpp"
#include "opencv2/ml/ml.hpp"
#include "opencv2/highgui/highgui_c.h"
#include "opencv2/highgui/highgui.hpp"
#include "opencv2/contrib/contrib.hpp"
or simply add #include "opencv2/opencv.hpp" which includes all the header file mentioned above
Thus, OpenCV is properly configured in your Linux system
Note: Never ever forget to add header files as shown above in the code(dont miss "opencv2/")
Other header file available in OpenCV are as follows
#include "opencv2/core/core_c.h"
#include "opencv2/core/core.hpp"
#include "opencv2/flann/miniflann.hpp"
#include "opencv2/imgproc/imgproc_c.h"
#include "opencv2/imgproc/imgproc.hpp"
#include "opencv2/photo/photo.hpp"
#include "opencv2/video/video.hpp"
#include "opencv2/features2d/features2d.hpp"
#include "opencv2/objdetect/objdetect.hpp"
#include "opencv2/calib3d/calib3d.hpp"
#include "opencv2/ml/ml.hpp"
#include "opencv2/highgui/highgui_c.h"
#include "opencv2/highgui/highgui.hpp"
#include "opencv2/contrib/contrib.hpp"
No comments:
Post a Comment