2022最新計(jì)算機(jī)視覺學(xué)習(xí)路線(入門篇)
圖像變換
圖像變換包括平移、旋轉(zhuǎn)、縮放、裁剪和翻轉(zhuǎn)圖像。
img=cv.imread('../input/images-for-computer-vision/tiger1.jpg')
width, height, _=img.shape
# Translating
M_translate=np.float32([[1,0,200],[0,1,100]]) # 200=> Translation along x-axis and 100=>translation along y-axis
img_translate=cv.warpAffine(img,M_translate,(height,width))
# Rotating
center=(width/2,height/2)
M_rotate=cv.getRotationMatrix2D(center, angle=90, scale=1)
img_rotate=cv.warpAffine(img,M_rotate,(width,height))
# Scaling
scale_percent = 50
width = int(img.shape[1] * scale_percent / 100)
height = int(img.shape[0] * scale_percent / 100)
dim = (width, height)
img_scale = cv.resize(img, dim, interpolation = cv.INTER_AREA)
# Flipping
img_flip=cv.flip(img,1) # 0:Along horizontal axis, 1:Along verticle axis, -1: first along verticle then horizontal
# Shearing
srcTri = np.a(chǎn)rray( [[0, 0], [img.shape[1] - 1, 0], [0,img.shape[0] - 1]] ).a(chǎn)stype(np.float32)
dstTri = np.a(chǎn)rray( [[0, img.shape[1]*0.33], [img.shape[1]*0.85, img.shape[0]*0.25], [img.shape[1]*0.15, img.shape[0]*0.7]] ).a(chǎn)stype(np.float32)
warp_mat = cv.getAffineTransform(srcTri, dstTri)
img_warp = cv.warpAffine(img, warp_mat, (height, width))
myplot([img, img_translate, img_rotate, img_scale, img_flip, img_warp],
['Original Image', 'Translated Image', 'Rotated Image', 'Scaled Image', 'Flipped Image', 'Sheared Image'])
圖像預(yù)處理
閾值處理:在閾值處理中,小于閾值的像素值變?yōu)?0(黑色),大于閾值的像素值變?yōu)?255(白色)。
我將閾值設(shè)為 150,但你也可以選擇任何其他數(shù)字。
# For visualising the filters
import plotly.graph_objects as go
from plotly.subplots import make_subplots
def plot_3d(img1, img2, titles):
fig = make_subplots(rows=1, cols=2,
specs=[[{'is_3d': True}, {'is_3d': True}]],
subplot_titles=[titles[0], titles[1]],
)
x, y=np.mgrid[0:img1.shape[0], 0:img1.shape[1]]
fig.a(chǎn)dd_trace(go.Surface(x=x, y=y(tǒng), z=img1[:,:,0]), row=1, col=1)
fig.a(chǎn)dd_trace(go.Surface(x=x, y=y(tǒng), z=img2[:,:,0]), row=1, col=2)
fig.update_traces(contours_z=dict(show=True, usecolormap=True,
highlightcolor="limegreen", project_z=True))
fig.show()
img=cv.imread('../input/images-for-computer-vision/simple_shapes.png')
# Pixel value less than threshold becomes 0 and more than threshold becomes 255
_,img_threshold=cv.threshold(img,150,255,cv.THRESH_BINARY)
plot_3d(img, img_threshold, ['Original Image', 'Threshold Image=150'])
應(yīng)用閾值后,150 的值變?yōu)榈扔?255
過濾: 圖像過濾是通過改變像素的值來改變圖像的外觀。每種類型的過濾器都會(huì)根據(jù)相應(yīng)的數(shù)學(xué)公式更改像素值。我不會(huì)在這里詳細(xì)介紹數(shù)學(xué),但我將通過在 3D 中可視化它們來展示每個(gè)過濾器的工作原理。
limg=cv.imread('../input/images-for-computer-vision/simple_shapes.png')
# Gaussian Filter
ksize=(11,11) # Both should be odd numbers
img_guassian=cv.GaussianBlur(img, ksize,0)
plot_3d(img, img_guassian, ['Original Image','Guassian Image'])
# Median Filter
ksize=11
img_medianblur=cv.medianBlur(img,ksize)
plot_3d(img, img_medianblur, ['Original Image','Median blur'])
# Bilateral Filter
img_bilateralblur=cv.bilateralFilter(img,d=5, sigmaColor=50, sigmaSpace=5)
myplot([img, img_bilateralblur],['Original Image', 'Bilateral blur Image'])
plot_3d(img, img_bilateralblur, ['Original Image','Bilateral blur'])
高斯濾波器:通過去除細(xì)節(jié)和噪聲來模糊圖像。
中值濾波器:非線性過程可用于減少脈沖噪聲或椒鹽噪聲
雙邊濾波器:邊緣保留和降噪平滑。
簡單來說,過濾器有助于減少或去除亮度或顏色隨機(jī)變化的噪聲,這稱為平滑
特征檢測(cè)
特征檢測(cè)是一種通過計(jì)算圖像信息的抽象,在每個(gè)圖像點(diǎn)上做出局部決策的方法。例如,對(duì)于一張臉的圖像,特征是眼睛、鼻子、嘴唇、耳朵等,我們嘗試識(shí)別這些特征。
讓我們首先嘗試識(shí)別圖像的邊緣。
邊緣檢測(cè)
img=cv.imread('../input/images-for-computer-vision/simple_shapes.png')
img_canny1=cv.Canny(img,50, 200)
# Smoothing the img before feeding it to canny
filter_img=cv.GaussianBlur(img, (7,7), 0)
img_canny2=cv.Canny(filter_img,50, 200)
myplot([img, img_canny1, img_canny2],
['Original Image', 'Canny Edge Detector(Without Smoothing)', 'Canny Edge Detector(With Smoothing)'])
這里我們使用 Canny 邊緣檢測(cè)器,它是一種邊緣檢測(cè)算子,它使用多階段算法來檢測(cè)圖像中的各種邊緣。它由 John F. Canny 于 1986 年開發(fā)。我不會(huì)詳細(xì)介紹 Canny 的工作原理,但這里的關(guān)鍵點(diǎn)是它用于提取邊緣。
在使用 Canny 邊緣檢測(cè)方法檢測(cè)邊緣之前,我們平滑圖像以去除噪聲。正如你從圖像中看到的,平滑后我們得到清晰的邊緣。
輪廓
img=cv.imread('../input/images-for-computer-vision/simple_shapes.png')
img_copy=img.copy()
img_gray=cv.cvtColor(img,cv.COLOR_BGR2GRAY)
_,img_binary=cv.threshold(img_gray,50,200,cv.THRESH_BINARY)
#Edroing and Dilating for smooth contours
img_binary_erode=cv.erode(img_binary,(10,10), iterations=5)
img_binary_dilate=cv.dilate(img_binary,(10,10), iterations=5)
contours,hierarchy=cv.findContours(img_binary,cv.RETR_TREE, cv.CHAIN_APPROX_SIMPLE)
cv.drawContours(img, contours,-1,(0,0,255),3) # Draws the contours on the original image just like draw function
myplot([img_copy, img], ['Original Image', 'Contours in the Image'])
侵蝕,使用用于探測(cè)和降低包含在圖像中的形狀的結(jié)構(gòu)元素的侵蝕操作。
膨脹:將像素添加到圖像中對(duì)象的邊界,與侵蝕相反
Hull
simg=cv.imread('../input/images-for-computer-vision/simple_shapes.png',0)
_,threshold=cv.threshold(img,50,255,cv.THRESH_BINARY)
contours,hierarchy=cv.findContours(threshold,cv.RETR_TREE, cv.CHAIN_APPROX_SIMPLE)
hulls=[cv.convexHull(c) for c in contours]
img_h(yuǎn)ull=cv.drawContours(img, hulls,-1,(0,0,255),2) #Draws the contours on the original image just like draw function
plt.imshow(img)
總結(jié)
我們看到了如何讀取和顯示圖像、在圖像上繪制形狀、文本、混合兩個(gè)圖像、旋轉(zhuǎn)、縮放、平移等變換圖像,使用高斯模糊、中值模糊、雙邊模糊過濾圖像,以及檢測(cè)使用 Canny 邊緣檢測(cè)和在圖像中查找輪廓的特征。
原文標(biāo)題 : 2022最新計(jì)算機(jī)視覺學(xué)習(xí)路線(入門篇)

發(fā)表評(píng)論
請(qǐng)輸入評(píng)論內(nèi)容...
請(qǐng)輸入評(píng)論/評(píng)論長度6~500個(gè)字
最新活動(dòng)更多
-
3月27日立即報(bào)名>> 【工程師系列】汽車電子技術(shù)在線大會(huì)
-
4月30日立即下載>> 【村田汽車】汽車E/E架構(gòu)革新中,新智能座艙挑戰(zhàn)的解決方案
-
5月15-17日立即預(yù)約>> 【線下巡回】2025年STM32峰會(huì)
-
即日-5.15立即報(bào)名>>> 【在線會(huì)議】安森美Hyperlux™ ID系列引領(lǐng)iToF技術(shù)革新
-
5月15日立即下載>> 【白皮書】精確和高效地表征3000V/20A功率器件應(yīng)用指南
-
5月16日立即參評(píng) >> 【評(píng)選啟動(dòng)】維科杯·OFweek 2025(第十屆)人工智能行業(yè)年度評(píng)選
推薦專題
- 1 UALink規(guī)范發(fā)布:挑戰(zhàn)英偉達(dá)AI統(tǒng)治的開始
- 2 北電數(shù)智主辦酒仙橋論壇,探索AI產(chǎn)業(yè)發(fā)展新路徑
- 3 “AI寒武紀(jì)”爆發(fā)至今,五類新物種登上歷史舞臺(tái)
- 4 降薪、加班、裁員三重暴擊,“AI四小龍”已折戟兩家
- 5 國產(chǎn)智駕迎戰(zhàn)特斯拉FSD,AI含量差幾何?
- 6 光計(jì)算迎來商業(yè)化突破,但落地仍需時(shí)間
- 7 東陽光:2024年扭虧、一季度凈利大增,液冷疊加具身智能打開成長空間
- 8 地平線自動(dòng)駕駛方案解讀
- 9 封殺AI“照騙”,“淘寶們”終于不忍了?
- 10 優(yōu)必選:營收大增主靠小件,虧損繼續(xù)又逢關(guān)稅,能否乘機(jī)器人東風(fēng)翻身?