opencv新手村
example:
import cv2 #cv2就是庫
import numpy as np #numpy is good
camera = cv2.VideoCapture(0) #開啟攝像頭
ret,frame = camera.read() #讀取第一幀
cv2.imwrite("test.jpg",frame) #儲存拍下的這個圖片為test.jpg
img = cv2.imread('test.jpg') #讀取test.jpg為img
cv2.imshow("test",img)
while True:
ret,frame = camera.read()#讀取第一幀
if not ret:
break
cv2.imshow("carema",frame)
key = cv2.waitKey(10)
if key==ord('q'):
break
cv2.imread(filepath,flags),
filepath:完整路徑
flags:讀入圖片的標誌
cv2.IMREAD_COLOR:預設,讀入彩色圖片,忽略alpha(不透明度)通道
cv2.IMREAD_GRAYSCALE:讀入灰度圖片
cv2.IMREAD_UNCHANGED:完整圖片包含alpha
cv2.IMREAD_ANYCOLOR:原影像格式
cv2.IMREAD_ANYDEPTH:按原影像深度讀取
import cv2
img = cv2.imread('test.jpg',cv2.IMREAD_GRAYSCALE)
cv2.imshow("test",img)
cv2.imshow(winname,mat)
winname:視窗名
mat:影像矩陣
mat詳情可參考這篇部落格,雖然我自己沒看懂2333
https://blog.csdn.net/u010248552/article/details/79962132
cv2.waitKey()
waitKey(delay=None)
delay = 按下後的延遲時間,單位為ms
ep:
key = cv2.waitKey(10)
if key==ord('q'):
break
cv2.destoryWindow(winname)
功能如其名,關閉一個因為imshow開的window
cv2.destoryAllWindows()
關閉所有imshow開啟的視窗
cv2.blur(src,ksize,dst=None,anchor=None,borderType=None)
對影像進行算術平均值模糊,均值濾波函式
ksize的設定,基本是這樣: (5,5)表示5*5畫素矩陣的一個卷積核
ksize,積卷核的大小,dst,寫入dst矩陣
import cv2
img = cv2.imread("image\\lenaNoise.png")
result = cv2.blur(img,(5,5))
cv2.imshow("img",img)
cv2.imshow("result",result)
cv2.waitKey()
cv2.destroyAllWindows()
效果
來自https://blog.csdn.net/weixin_40922285/article/details/102801633
cv2.boxFilter(img,-1,ksize,normalize=True)
當normalize = True 與均值濾波相同
normalize = False 則對加和後的結果不進行平均操作,大於255的使用255處理
import cv2
img=cv2.imread("image\\lenaNoise.png")
result=cv2.boxFilter(img,-1,(2,2),normalize=False)
cv2.imshow("img",img)
cv2.imshow("result",result)
cv2.waitKey()
cv2.destroyAllWindows()
效果
cv2.GuassianBlur(img,ksize,sigmaX,sigmaY高斯!
sigmaX=X方向的標準偏差
sigmaY=Y方向的標準偏差
僅指定sigmaX則兩者相同
兩者都為0,則根據核心來計算他們
mport cv2
img=cv2.imread("image\\lenaNoise.png")
result=cv2.GaussianBlur(img,(5,5),0,0)
cv2.imshow("img",img)
cv2.imshow("result",result)
cv2.waitKey()
cv2.destroyAllWindows()
效果
cv2.medianBlur(img,k)
img為原影像,k為方框尺寸,相當於將方框中的個值進行排序,選出中值作為當前值
對椒鹽噪聲有效
import cv2
img=cv2.imread("image\\lenaNoise.png")
result=cv2.medianBlur(img,3)
cv2.imshow("img",img)
cv2.imshow("result",result)
cv2.waitKey()
cv2.destroyAllWindows()
cv2.bilateralFilter(img,d,sigmaColor,sigmaSpace)雙邊濾波
d為鄰域直徑,sigmaColor為空間高斯函式標準差
引數越大,臨近畫素將會在越遠的地方越小
sigmaSpace灰度值相似性高斯函式標準差,引數越大,那些顏色相近的顏色的影響越大
能夠保邊去噪
一個函式是由幾何空間決定界定濾波器係數,另一個由畫素差值決定濾波器係數
處理耗時
保證邊緣效果好
import cv2
img=cv2.imread("image\\lenaNoise.png")
result=cv2.bilateralFilter(img,25,100,100)
cv2.imshow("img",img)
cv2.imshow("result",result)
cv2.waitKey()
cv2.destroyAllWindows()
cv2filter2D(img,-1,kernel)2D卷積
kernel為卷積核
import cv2
import numpy as np
img=cv2.imread("image\\lena.bmp")
kernel = np.ones((9,9),np.float32)/81
result = cv2.filter2D(img,-1,kernel)
cv2.imshow("img",img)
cv2.imshow("result",result)
cv2.waitKey()
cv2.destroyAllWindows()
相關文章
- 演算法專項—新手村演算法
- [Flutter新手村]—除錯通關攻略Flutter除錯
- 力扣新手村之1342、1672、412力扣
- Terraform 新手村指南,萌新必讀!ORM
- 演算法專項-碼蹄集 新手村演算法
- [Flutter新手村] 入村攻略—前言和環境安裝Flutter
- OpenCV()OpenCV
- opencvOpenCV
- delphi opencvOpenCV
- 【OpenCV教程】OpenCV中的資料型別OpenCV資料型別
- VS2019+opencv4.2.0+opencv contrib4.2.0OpenCV
- 【opencv學習筆記】001之opencv配置(win10+VS2015+OpenCV3.1.0)OpenCV筆記Win10
- 影片作品播放量低:自媒體作者如何走出新手村
- 【OpenCV教程】OpenCV中對矩陣的常用操作OpenCV矩陣
- opencv中SVMOpenCV
- opencv 學習OpenCV
- OpenCV(cv::minMaxLoc())OpenCV
- OpenCV(cv::convertScaleAbs())OpenCV
- OpenCV(cv::Canny())OpenCV
- OpenCV(Alpha通道)OpenCV
- OpenCV(cv::bilateralFilter())OpenCVFilter
- OpenCV(cv::circle())OpenCV
- OpenCV(cv::NAryMatIterator)OpenCV
- OpenCv(cv::undistort())OpenCV
- OpenCV(cv::findChessboardCorners())OpenCV
- OpenCV 基本使用OpenCV
- opencv-debugtoolOpenCV
- 使用vs2015+cmake編譯opencv+opencv_contrib編譯OpenCV
- 解決OpenCV(4.1.2) C:\projects\opencv-python\opencv\modules\highgui\src\window.cpp:376: error: (-215:AOpenCVProjectPythonGUIError
- opencv呼叫caffe模型OpenCV模型
- OpenCV 初體驗OpenCV
- 配置QT Mingw & opencvQTOpenCV
- OpenCV新增中文(五)OpenCV
- opencv + SVM 程式碼OpenCV
- opencv圖片操作OpenCV
- opencv SVM的使用OpenCV
- opencv 修改畫素OpenCV
- opencv 黑帽操作OpenCV