樹莓派安裝OpenCV3完整過程的實現
更新時間:2019年10月10日 15:34:55 作者:kyoRan
這篇文章主要介紹了樹莓派安裝OpenCV3完整過程的實現,小編覺得挺不錯的,現在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧
1. 配置并更新樹莓派系統(tǒng)
sudo raspi-config // 進入后打開攝像頭、SSH sudo apt-get update sudo apt-get upgrade sudo rpi-update
2. 安裝OpenCV的相關工具
sudo apt-get install build-essential cmake git pkg-config
3. 安裝OpenCV的圖像工具包
sudo apt-get install libjpeg8-dev sudo apt-get install libtiff5-dev sudo apt-get install libjasper-dev sudo apt-get install libpng12-dev
4. 安裝視頻I/O包
sudo apt-get install libavcodec-dev libavformat-dev libswscale-dev libv4l-dev
5.安裝gtk2.0和優(yōu)化函數包
sudo apt-get install libgtk2.0-dev sudo apt-get install libatlas-base-dev gfortran
6. 下載OpenCV源碼
可以在 [ OpenCV ] 查看所有版本源碼
git clone https://github.com/opencv/opencv.git
7. 安裝OpenCV
// 根據下載的版本而定 cd opencv-3.2.0 // 創(chuàng)建release文件夾 mkdir release // 進入release目錄下 cd release // cmake讀入所有源文件之后,自動生成makefile cmake -D CMAKE_BUILD_TYPE=RELEASE \ -D CMAKE_INSTALL_PREFIX=/usr/local .. // 編譯 sudo make // 安裝 sudo make install //更新動態(tài)鏈接庫 sudo ldconfig
8. 解決無法打開攝像頭硬件問題
sudo nano /etc/modules // 進入編輯界面后,在末尾添加輸入 snd-bcm2835 bcm2835-v4l2

9. 測試用例Python代碼
# -*- coding: utf-8 -*-
__author__ = "kyoRan"
import cv2
cap = cv2.VideoCapture(0) # 打開攝像頭
print("VideoCapture is opened?", cap.isOpened())
while(True):
ret, frame = cap.read() # 讀取攝像頭圖像
center = (frame.shape[1]//2, frame.shape[0]//2) # 圖像中心點位置
gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY) # 轉灰度
cv2.circle(gray, center=center, radius=100, color=(0,0,255)) # 畫圓
cv2.imshow("frame", gray) # 顯示圖片
if cv2.waitKey(1) & 0xFF == ord('q'):
break
cap.release() # 釋放攝像頭
cv2.destroyAllWindows() # 關閉所有窗口
測試結果如下

以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持腳本之家。
相關文章
python基礎之while循環(huán)、for循環(huán)詳解及舉例
所謂循環(huán)結構就是程序中控制某條或某些指令重復執(zhí)行的結構,下面這篇文章主要給大家介紹了關于python基礎之while循環(huán)、for循環(huán)的相關資料,文中通過實例代碼介紹的非常詳細,需要的朋友可以參考下2022-04-04

