惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

云风的 BLOG
云风的 BLOG
M
MIT News - Artificial intelligence
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
V2EX - 技术
V2EX - 技术
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
GbyAI
GbyAI
aimingoo的专栏
aimingoo的专栏
腾讯CDC
C
CERT Recently Published Vulnerability Notes
J
Java Code Geeks
WordPress大学
WordPress大学
博客园 - Franky
V
Vulnerabilities – Threatpost
小众软件
小众软件
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
有赞技术团队
有赞技术团队
The Hacker News
The Hacker News
T
The Blog of Author Tim Ferriss
Recent Commits to openclaw:main
Recent Commits to openclaw:main
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
Martin Fowler
Martin Fowler
Webroot Blog
Webroot Blog
Attack and Defense Labs
Attack and Defense Labs
Google Online Security Blog
Google Online Security Blog
S
Securelist
Security Archives - TechRepublic
Security Archives - TechRepublic
T
Troy Hunt's Blog
Scott Helme
Scott Helme
Project Zero
Project Zero
T
Tailwind CSS Blog
The Register - Security
The Register - Security
A
About on SuperTechFans
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
The GitHub Blog
The GitHub Blog
Security Latest
Security Latest
L
LangChain Blog
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
H
Hackread – Cybersecurity News, Data Breaches, AI and More
大猫的无限游戏
大猫的无限游戏
Cloudbric
Cloudbric
S
Security Affairs
博客园 - 叶小钗
Microsoft Security Blog
Microsoft Security Blog
H
Heimdal Security Blog
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
PCI Perspectives
PCI Perspectives
The Cloudflare Blog
Last Week in AI
Last Week in AI
阮一峰的网络日志
阮一峰的网络日志
AI
AI

博客园 - lykyl的自留地

centos6 安装EPEL "检索COM类工厂中 CLSID为 {00024500-0000-0000-C000-000000000046}的组件时失败,原因是出现以下错误: 80070005" 问题的解决 centos6.x 安装pylucene (20161027改) - lykyl的自留地 趣味python编程之经典俄罗斯方块 python编码规范 改进uwsgi启动脚本,使其支持多个独立配置文件 在CentOS 6.5上安装python2.7 "System.Security.Cryptography.CryptographicException: 拒绝访问" 问题的解决方法 利用SHELL脚本实现文件完整性检测程序(1.2版更新) 获取linux服务器基本信息脚本 DELPHI实现关闭指定进程,自身防杀 基于python编写的天气抓取程序 linux使用心得(持续更新) vim使用心得(持续更新) NFS服务基本配置及使用 利用shell脚本实现计划任务功能 V1.2 利用shell脚本实现计划任务功能 rsync简明手册 linux bash script简明手册(持续更新)
树莓派编译安装opencv3 (2019.1.6更新)
lykyl的自留地 · 2018-03-11 · via 博客园 - lykyl的自留地

一、更新系统

sudo apt-get update  
sudo apt-get upgrade  
sudo rpi-update
#重启系统  
sudo reboot

二、安装依赖库及程序

sudo apt-get -y install build-essential git cmake pkg-config  
sudo apt-get -y install libjpeg8-dev  
sudo apt-get -y install libtiff5-dev  
sudo apt-get -y install libjasper-dev  
sudo apt-get -y install libpng12-dev  
sudo apt-get -y install libavcodec-dev libavformat-dev libswscale-dev libv4l-dev  
sudo apt-get -y install libgtk2.0-dev  
sudo apt-get -y install libsdl2-dev
sudo apt-get -y install libatlas-base-dev gfortran  
sudo apt-get -y install libxvidcore-dev libx264-dev

三、编译安装FFMPEG
之所以要用编译安装是为了确保opencv在cmake时ffmpeg选项为on,这将关系到opencv能否播放视频文件。
先卸载系统默认安装的ffmpeg

sudo apt-get remove ffmpeg

再下载源码并安装最新版ffmpeg

git clone git://source.ffmpeg.org/ffmpeg.git
cd ffmpeg
./configure --enable-shared --disable-static
make -j4
sudo make install
export PKG_CONFIG_PATH="/usr/local/lib/pkgconfig":$PKG_CONFIG_PATH

需要注意一下添加到环境变量PKG_CONFIG_PATH中的地址为ffmpeg编译后存放.pc文件的本地pkgconfig目录。

四、安装更新PYTHON及运行环境

sudo apt-get -y install python2.7-dev python3-dev
curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py
python get-pip.py
pip install numpy  

五、下载、编译安装opencv
在opencv官网下载最新版源码(目前3.X最新版为3.4.5,注意contrib要和opencv的版本要保持一致),要确保opencv和opencv_contrib版本一致,否则会导致编译失败。

wget -O opencv.zip https://github.com/opencv/opencv/archive/3.4.5.zip
wget -O opencv_contrib.zip https://github.com/opencv/opencv_contrib/archive/3.4.5.zip
unzip opencv.zip
unzip opencv_contrib.zip

预编译

cd ~/opencv  
mkdir build  
cd build  
cmake -D CMAKE_BUILD_TYPE=RELEASE \
    -D CMAKE_INSTALL_PREFIX=/usr/local \
    -D INSTALL_PYTHON_EXAMPLES=ON \
    -D OPENCV_EXTRA_MODULES_PATH=~/opencv_contrib-3.4.5/modules \
    -D WITH_FFMPEG=ON \
    -D BUILD_EXAMPLES=ON ..

编译opencv,在树莓派3中建议加上-j4参数,这样编译速度能快一点。

make -j4
sudo make install  
sudo ldconfig  

六、部署到PYTHON系统库(此步似乎可以跳过)
python2.7

ln -s /usr/local/lib/python2.7/dist-packages/cv2/python-2.7/cv2.so /usr/local/lib/python2.7/dist-packages/cv2.so

python 3.0

ln -s /usr/local/lib/python3.5/dist-packages/cv2/python-3.5/cv2.cpython-35m-arm-linux-gnueabihf.so /usr/local/lib/python3.5/dist-packages/cv2.so

七、配置环境
为了使opencv能够正常打开SPI摄像头需要编辑/etc/rc.local
在exit 0之前加入 modprobe bcm2835-v4l2

八、测试
编辑 cameratest.py,添加如下内容,保存并退出。

import cv2
import numpy as np

cap = cv2.VideoCapture(0)
cap.set(3,640) # set Width
cap.set(4,480) # set Height

while(True):
  ret, frame = cap.read()
  frame = cv2.flip(frame, -1) # Flip camera vertically
  gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
  cv2.imshow('frame', frame)
  cv2.imshow('gray', gray)
  k = cv2.waitKey(30)  & 0xff
  if k == 27: # press 'ESC' to quit
    break
cap.release()
cv2.destroyAllWindows()

执行

python cameratest.py