提取碼:4x7v
在終端依次輸入即可:
sudo apt-get update
sudo apt-get install libjpeg-dev
sudo apt-get install libatlas-base-dev
sudo apt-get install libtiff5-dev
sudo apt-get install libpng12-dev
sudo apt-get install libqtgui4 libqt4-test
sudo apt-get install libjasper-dev
開啟終端,輸入sudo pip3 install opencv(然後按tab補全)
然後安裝就成功了
將usb攝像頭插入樹莓派執行如下程式測試攝像頭和cv的安裝是否成功
import cv2
cap = cv2.videocapture(0) # 開啟攝像頭
while true:
ret, frame = cap.read() # 讀攝像頭
cv2.imshow("video", frame)
if cv2.waitkey(1) & 0xff == ord('q'): # 按q退出
break
cap.release()
cv2.destroyallwindows()
import cv2
import numpy as np
camera = cv2.videocapture(0) # 引數0表示第乙個攝像頭
if (camera.isopened()):
print('open')
else:
print('攝像頭未開啟')
size = (int(camera.get(cv2.cap_prop_frame_width)),
int(camera.get(cv2.cap_prop_frame_height)))
print('size:'+repr(size))
es = cv2.getstructuringelement(cv2.morph_ellipse, (9, 4))
kernel = np.ones((5, 5), np.uint8)
background = none
while true:
grabbed, frame_lwpcv = camera.read()
# 對幀進行預處理,先轉灰度圖,再進行高斯濾波。
gray_lwpcv = cv2.cvtcolor(frame_lwpcv, cv2.color_bgr2gray)
gray_lwpcv = cv2.gaussianblur(gray_lwpcv, (21, 21), 0)
# 將第一幀設定為整個輸入的背景
if background is none:
background = gray_lwpcv
continue
# 對於每個從背景之後讀取的幀都會計算其與背景之間的差異,並得到乙個差分圖(different map)。
# 還需要應用閾值來得到一幅黑白影象,並通過下面**來膨脹(dilate)影象,從而對孔(hole)和缺陷(imperfection)進行歸一化處理
diff = cv2.absdiff(background, gray_lwpcv)
diff = cv2.threshold(diff, 25, 255, cv2.thresh_binary)[1] # 二值化閾值處理
diff = cv2.dilate(diff, es, iterations=2) # 形態學膨脹
# 顯示矩形框
for c in contours:
if cv2.contourarea(c) < 1500: # 對於矩形區域,只顯示大於給定閾值的輪廓,所以一些微小的變化不會顯示。對於光照不變和雜訊低的攝像頭可不設定輪廓最小尺寸的閾值
continue
(x, y, w, h) = cv2.boundingrect(c) # 該函式計算矩形的邊界框
cv2.rectangle(frame_lwpcv, (x, y), (x+w, y+h), (0, 255, 0), 2)
cv2.imshow('contours', frame_lwpcv)
cv2.imshow('dis', diff)
key = cv2.waitkey(1) & 0xff
# 按'q'健退出迴圈
if key == ord('q'):
break
# when everything done, release the capture
camera.release()
cv2.destroyallwindows()
樹莓派安裝
然後把安裝系統的sd卡插入樹莓派進行連線。我沒有顯示器,而且買不起。只能用我的電腦了,樹莓派有三種方式連線電腦 用usb轉串列埠晶元連線樹莓派和電腦,一開始我就是這麼打算的。但是比較無奈的是我用ch340和樹莓派不相容,pl232和win 10相容性太差,一開始是檢測不到 試了好多個驅動後終於檢測到...
樹莓派 無法安裝mysql 樹莓派安裝mysql
前置,更新系統 sudo apt get update sudo apt get upgrade 安裝與配置mysql 因為系統版本不同所以我們要根據自己的系統版本來換相應的源 更換源時,必須先將原來的源複製乙份 cp etc apt sources.list cp etc apt sources....
樹莓派 安裝opencv
1.更新源 sudo apt get update 2.安裝opencv sudo apt get install libcv dev 3.安裝完成之後,opencv相關的標頭檔案被安裝到 usr lib目錄中,該目錄是linux預設標頭檔案查詢路徑。opencv calib3d 相機校準和三維重建...