Ubuntu安装Opencv

本文详细介绍了在Linux环境下安装OpenCV的过程,包括依赖库的安装、源码下载、编译配置及samples程序的编译与运行。通过示例程序cpp-example-facedetect演示了如何进行面部检测。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

安装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+空格+”.”

这里写图片描述

这里写图片描述

sudo make
编译比较慢

这里写图片描述

四、
sudo make install

这里写图片描述

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

这里写图片描述

这里写图片描述

参考资料:
http://blog.youkuaiyun.com/u011762313/article/details/47263845

两个分类器的测试对比:

1、haarcascade_frontalface_alt.xml

这里写图片描述

这里写图片描述

2、haarcascade_frontalface_alt2.xml

这里写图片描述

这里写图片描述

测试对比发现haarcascade_frontalface_alt.xml较好
测试照片源于网上,用于研究,如有侵权,联系删除

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值