在Fedora22中安装OpenCV3.0.0

时间:2021-06-27 07:03:44

1.安装编译环境

$ sudo dnf install gcc gcc-c++ ncurses-devel cmake


2.安装GTK+2.x

$ sudo dnf install gtk2 gtk2-devel gtk2-devel-docs

$ sudo dnf install libgnome-devel gnome-devel-docs

$ sudo dnf install zlib glib atk pango gdk-pixbuf2 gdk-pixbuf2-devel


3.安装各种需要的包

$ sudo dnf install gtk+ gtk2-devel pkgconfig python-devel python-numpydoc

$ sudo dnf install libavc1394 libavc1394-devel libdc1394 libdc1394-devel jasper-devel

$ sudo dnf install ffmpeg ffmpeg-devel openjpeg-devel libjpeg-devel libpng-devel libtiff-devel


4.在opencv.org下载opencv的linux包

$ unzip opencv-3.0.0.zip -d ~/OpenCV

$ cd ~/OpenCV

$ mkdir release

$ cd release

$ cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local -D BUILD_PYTHON_SUPPORT=ON ..

$ make

$ sudo make install


5.添加opencv.conf文件

$ sudo vim /etc/ld.so.conf.d/opencv.conf

添加内容:/usr/local/lib

保存退出


6.添加环境变量

# vim /etc/profile

在最后添加内容:

export PKG_CONFIG_PATH=$PKG_CONFIG_PATH:/usr/local/lib/pkgconfig

export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/lib

保存退出

# source /etc/profile

# vim /etc/bashrc

在最后添加内容:

export PKG_CONFIG_PATH=$PKG_CONFIG_PATH:/usr/local/lib/pkgconfig

export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/lib
保存退出

# source /etc/bashrc

# ldconfig


7.查询包是否安装成功

$ pkg-config --cflags opencv
-I/usr/local/include/opencv -I/usr/local/include

$ pkg-config --libs opencv
-L/usr/local/lib -lopencv_shape -lopencv_stitching -lopencv_objdetect -lopencv_superres -lopencv_videostab -lopencv_calib3d -lopencv_features2d -lopencv_highgui -lopencv_videoio -lopencv_imgcodecs -lopencv_video -lopencv_photo -lopencv_ml -lopencv_imgproc -lopencv_flann -lopencv_core -lopencv_hal
$ pkg-config --modversion gtk+-2.0
2.24.28


8.写一个测试程序test.cpp

$ vim test.cpp

#include "opencv/cv.h"
#include "opencv/highgui.h"

int main(int argc, char **argv)
{
IplImage* pImage;
if(argc==2 && (pImage=cvLoadImage(argv[1],1))!=0)
{
cvNamedWindow("Image",1);
cvShowImage("Image",pImage);
cvWaitKey(0);
cvDestroyWindow("Image");
cvReleaseImage(&pImage);
return 0;
}
return -1;
}

9.直接编译

$ g++ `pkg-config --cflags opencv` -o test test.cpp `pkg-config --libs opencv`

先编译再连接

$ g++ `pkg-config --cflags opencv` -c test.cpp

$ g++ `pkg-config --libs     opencv` -o test test.o


10.运行测试程序

$ ./test lena.jpg

在Fedora22中安装OpenCV3.0.0