Ubuntu安装Opencv

安装Opencv

一、sudo apt-get install build-essential

sudo apt-get install cmake git libgtk2.0-dev pkg-config libavcodec-dev libavformat-dev libswscale-dev

sudo apt-get install python-dev python-numpy libtbb2 libtbb-dev libjpeg-dev libpng-dev libtiff-dev libjasper-dev libdc1394-22-dev

learning@learning-virtual-machine:~/opencv$ wget https://github.com/Itseez/opencv/archive/3.0.0-alpha.zip -O opencv-3.0.0-alpha.zip
--2016-05-11 10:35:40--  https://github.com/Itseez/opencv/archive/3.0.0-alpha.zip
Resolving github.com (github.com)... 192.30.252.123
Connecting to github.com (github.com)|192.30.252.123|:443... connected.
HTTP request sent, awaiting response... 302 Found
Location: https://codeload.github.com/Itseez/opencv/zip/3.0.0-alpha [following]
--2016-05-11 10:35:42--  https://codeload.github.com/Itseez/opencv/zip/3.0.0-alpha
Resolving codeload.github.com (codeload.github.com)... 192.30.252.163
Connecting to codeload.github.com (codeload.github.com)|192.30.252.163|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: unspecified [application/zip]
Saving to: ‘opencv-3.0.0-alpha.zip’

opencv-3.0.0-alpha.     [            <=>       ]  93.72M   521KB/s   in 13m 6s 

2016-05-11 10:48:51 (122 KB/s) - ‘opencv-3.0.0-alpha.zip’ saved [98276816]

learning@learning-virtual-machine:~/opencv$ 

二、
learning@learning-virtual-machine:~/opencv$ unzip opencv-3.0.0-alpha.zip

三、
learning@learning-virtual-machine:~/opencv/opencv-3.0.0-alpha$ cmake . # cmake+空格+”.”

Ubuntu安装Opencv_第1张图片

Ubuntu安装Opencv_第2张图片

sudo make
编译比较慢

Ubuntu安装Opencv_第3张图片

四、
sudo make install

Ubuntu安装Opencv_第4张图片

sudo /bin/bash -c ‘echo “/usr/local/lib” > /etc/ld.so.conf.d/opencv.conf’

sudo ldconfig

五、编译samples程序

sudo cmake .

learning@learning-virtual-machine:~/opencv/opencv-3.0.0-alpha/samples$ sudo cmake .
-- The C compiler identification is GNU 5.2.1 -- The CXX compiler identification is GNU 5.2.1 -- Check for working C compiler: /usr/bin/cc -- Check for working C compiler: /usr/bin/cc -- works -- Detecting C compiler ABI info -- Detecting C compiler ABI info - done -- Detecting C compile features -- Detecting C compile features - done -- Check for working CXX compiler: /usr/bin/c++ -- Check for working CXX compiler: /usr/bin/c++ -- works -- Detecting CXX compiler ABI info -- Detecting CXX compiler ABI info - done -- Detecting CXX compile features -- Detecting CXX compile features - done -- Configuring done -- Generating done -- Build files have been written to: /home/learning/opencv/opencv-3.0.0-alpha/samples learning@learning-virtual-machine:~/opencv/opencv-3.0.0-alpha/samples$ 

sudo make -j $(nproc)

六、运行

./cpp-example-facedetect ../data/lena.jpg

learning@learning-virtual-machine:~/opencv/opencv-3.0.0-alpha/samples/cpp$  ./cpp-example-facedetect ../data/lena.jpg

This program demonstrates the cascade recognizer. Now you can use Haar or LBP features.
This classifier can recognize many kinds of rigid objects, once the appropriate classifier is trained.
It's most known use is for faces.
Usage:
./facedetect [--cascade=<cascade_path> this is the primary trained classifier such as frontal face]
   [--nested-cascade[=nested_cascade_path this an optional secondary classifier such as eyes]]
   [--scale=<image scale greater or equal to 1, try 1.3 for example>]
   [--try-flip]
   [filename|camera_index]

see facedetect.cmd for one call:
./facedetect --cascade="../../data/haarcascades/haarcascade_frontalface_alt.xml" --nested-cascade="../../data/haarcascades/haarcascade_eye.xml" --scale=1.3

During execution:
    Hit any key to quit.
    Using OpenCV version 3.0.0-alpha

Processing 1 ../data/lena.jpg
Failed to load OpenCL runtime
Capture from AVI didn't work
In image read
learning@learning-virtual-machine:~/opencv/opencv-3.0.0-alpha/samples/cpp$ 

路径不对,改为:

learning@learning-virtual-machine:~/opencv/opencv-3.0.0-alpha/samples/cpp$ ./cpp-example-facedetect lena.jpg

Ubuntu安装Opencv_第5张图片

Ubuntu安装Opencv_第6张图片

参考资料:
http://blog.csdn.net/u011762313/article/details/47263845

你可能感兴趣的:(ubuntu,opencv)