Fedora25 下 OpenCV2.4.12 的安装
你必须非常努力,才能看起来毫不费力。---------------感谢原作者的分享。
opencv官网上面给出的 linux 下安装方式,基本上都是通过编译源码,即下载代码, cmake->make->make install。
但是对于Fedora来说,可以不用这么做。dnf实际上提供了自动安装,并处理依赖。
实际上,可以通过linux的官方源进行安装,譬如,在fedora下可以通过yum安装
sudo yum install opencv opencv-devel
然后,yum会自动的解决依赖关系
针对python的接口也是
sudo yum install opencv-python
执行完了之后,测试C++的可以用g++命令
g++ `pkg-config opencv --cflags` `pkg-config opencv --libs` yourcode.cpp -o yourcode
在这里注意,“`"是左上角Esc键下面的,而不是单引号,因为这个问题,我一直怀疑自己装错了,试了很多遍,后来才发现自己的错误
#include <iostream>
#include <fstream>
using namespace std;
#include<opencv/cv.h>
#include<opencv/highgui.h>
#include<opencv2/core/core.hpp>
#include "opencv2/highgui/highgui.hpp"
#include<opencv2/imgproc/imgproc.hpp>
#include "opencv2/contrib/contrib.hpp"
#include "opencv2/legacy/legacy.hpp"
#include "opencv2/flann/flann.hpp"
using namespace cv;
int main()
{
Mat src = imread("lena.jpg",1);
imshow("src",src);
waitKey();
return 0;
}
针对python的,主要就是其对库的引用有所改变,如下列代码:
# -*- coding: utf-8
# test.py
import sys
#
from cv import *
import cv
#import cv2
if __name__ == '__main__':
image = LoadImage("lena.jpg")
NamedWindow("mywin")
ShowImage("mywin", image)
WaitKey(0)
这里可以import cv和import cv2,而且必须要有一个
_________________________________________________________________________________________________________________________________________________
每一个不曾起舞的日子,都是对生命的辜负。
But it is the same with man as with the tree. The more he seeks to rise into the height and light, the more vigorously do his roots struggle earthward, downward, into the dark, the deep - into evil.
其实人跟树是一样的,越是向往高处的阳光,它的根就越要伸向黑暗的地底。----尼采
每一个不曾起舞的日子,都是对生命的辜负。
But it is the same with man as with the tree. The more he seeks to rise into the height and light, the more vigorously do his roots struggle earthward, downward, into the dark, the deep - into evil.
其实人跟树是一样的,越是向往高处的阳光,它的根就越要伸向黑暗的地底。----尼采

浙公网安备 33010602011771号