dlib note

This commit is contained in:
light
2018-02-25 01:24:12 +08:00
parent 4385b63c3b
commit 6360db8133
15 changed files with 613 additions and 5 deletions
+19
View File
@@ -0,0 +1,19 @@
# 编译opencv程序
## use g++
``` bash
g++ main.cpp `pkg-config opencv --cflags --libs`
```
## use cmake
> nano CMakeLists.txt
``` bash
cmake_minimum_required(VERSION 2.8)
project(test)
find_package(OpenCV REQUIRED)
add_executable(main main.cpp)
target_link_libraries(main ${OpenCV_LIBS})
```
+119
View File
@@ -0,0 +1,119 @@
# opencv 环境部署指南
> http://blog.csdn.net/cocoaqin/article/details/78163171
> http://blog.csdn.net/eds95/article/details/78870194
## ubuntu
``` bash
unzip opencv-3.4.0.zip
cd opencv
sudo apt install cmake
sudo apt install build-essential libgtk2.0-dev libavcodec-dev libavformat-dev libjpeg.dev libtiff4.dev libswscale-dev libjasper-dev
mkdir my_build
cd my_build
## cmake 中会下载安装一个大文件,网速会很慢
cmake -D CMAKE_BUILD_TYPE=Release -D CMAKE_INSTALL_PREFIX=/usr/local ..
sudo make
sudo make install
sudo gedit /etc/ld.so.conf.d/opencv.conf
# add this
"
/usr/local/lib
"
sudo ldconfig
sudo gedit /etc/bash.bashrc
# add this
"
PKG_CONFIG_PATH=$PKG_CONFIG_PATH:/usr/local/lib/pkgconfig
export PKG_CONFIG_PATH
"
source /etc/bash.bashrc
sudo updatedb
# test
cd opencv***/smaples/cpp/example_cmake
cmake .
make
./opencv_example
# and you will see yourself
# compete
```
## raspberry
``` bash
sudo apt update
sudo apt upgrade
sudo rpi-update
sudo reboot
# 图像io库
sudo apt install libjpeg-dev libtiff5-dev libjasper-dev libpng12-dev
# 视频处理库
sudo apt install libavcodec-dev libavformat-dev libswscale-dev libv4l-dev
sudo apt install libxvidcore-dev libx264-dev
# 安装gtk 用于opencv gui显示
sudo apt install libgtk2.0-dev
sudo apt install libatlas-base-dev gfortran
# 安装python 环境
sudo apt-get install python2.7-dev python3-dev
sudo apt-get install build-essential libssl-dev libevent-dev libjpeg-dev libxml2-dev libxslt-dev
unzip ....
cd opencv
mkdir build
cd build
# warning change your path
cmake -D CMAKE_BUILD_TYPE=RELEASE \
-D CMAKE_INSTALL_PREFIX=/usr/local \
-D OPENCV_EXTRA_MODULES_PATH=/program/opencv_contrib-3.3.0/modules \
-D ENABLE_NEON=ON \
-D ENABLE_VFPV3=ON \
-D BUILD_TESTS=OFF \
-D INSTALL_PYTHON_EXAMPLES=OFF \
-D BUILD_EXAMPLES=OFF ..
# 修改swap空间大小
vi /etc/dphys-swapfile
# 找到CONF_SWAPSIZE=100改为1024
# set size to absolute value, leaving empty (default) then uses computed value
# you most likely don't want this, unless you have an special disk situation
CONF_SWAPSIZE=1024
sudo /etc/init.d/dphys-swapfile stop
sudo /etc/init.d/dphys-swapfile start
make -j4
sudo make install
sudo ldconfig
xhost +
export DISPLAY=:0.0
```
+55
View File
@@ -0,0 +1,55 @@
# 利用opencv录制视频
``` cpp
#include <opencv2/core.hpp>
#include <opencv2/imgcodecs.hpp>
#include <opencv2/highgui.hpp>
#include <opencv2/imgproc.hpp>
#include <iostream>
using namespace cv;
using namespace std;
int main( )
{
VideoCapture capture(0);//如果是笔记本,0打开的是自带的摄像头,1 打开外接的相机
Mat img;
VideoWriter vw; //新建一个多媒体文件
namedWindow( "cam" );
int fps = capture.get(CAP_PROP_FPS ); //获取摄像头的帧率
cout << capture.get( CAP_PROP_FRAME_WIDTH )<<capture.get( CAP_PROP_FRAME_HEIGHT )<<fps<<endl;
if(fps <= 0 )fps = 25;
//设置视频的格式
vw.open( "out.avi", VideoWriter::fourcc( 'x', '2', '6', '4' ), fps, Size( capture.get( CAP_PROP_FRAME_WIDTH ), capture.get( CAP_PROP_FRAME_HEIGHT ) ) );
if(!capture.isOpened( )) //判断摄像头是否打开
{
cout << "open video faild";
return 0;
}
cout << "open video success" << endl;
if(!vw.isOpened()) //判断视频文件是否创建
{
cout << "open vw faild"<< endl;
}
cout << "open vw success" << endl;
while(1)
{
capture.read( img); //读取视频帧
if(img.empty( ))
break;
imshow("cam", img ); //显示视频帧
vw.write( img ); //将视频帧写入文件
if(waitKey( 10 ) == 'q') //q键退出录制
break;
}
return 0;
}
```