2022最新計算機(jī)視覺學(xué)習(xí)路線(入門篇)
如果你有興趣或計劃做與圖像或視頻相關(guān)的事情,你絕對應(yīng)該考慮使用計算機(jī)視覺。計算機(jī)視覺 (CV) 是人工智能 (AI) 的一個分支,它使計算機(jī)能夠從圖像、視頻和其他視覺輸入中提取有意義的信息,并采取必要的行動。例如自動駕駛汽車、自動交通管理、監(jiān)控、基于圖像的質(zhì)量檢查等等。
什么是 OpenCV?
OpenCV 是一個主要針對計算機(jī)視覺的庫。它擁有你在使用計算機(jī)視覺 (CV) 時所需的所有工具!癘pen”代表開源,“CV”代表計算機(jī)視覺。
我會學(xué)到什么?
本文包含使用 OpenCV 庫開始使用計算機(jī)視覺所需的全部內(nèi)容。你會在計算機(jī)視覺方面感到更加自信和高效。
讀取和顯示圖像
首先讓我們了解如何讀取圖像并顯示它,這是CV的基礎(chǔ)知識。讀取圖像
import numpy as np
import cv2 as cv
import matplotlib.pyplot as plt
img=cv2.imread('../input/images-for-computer-vision/tiger1.jpg')
'img' 包含 numpy 數(shù)組形式的圖像。讓我們打印它的類型和形狀
print(type(img))
print(img.shape)
numpy 數(shù)組的形狀為 (667, 1200, 3),其中,
667 – 圖像高度,1200 – 圖像寬度,3 – 通道數(shù),
在這種情況下,有 RGB 通道,所以我們有 3 個通道。原始圖像是 RGB 的形式,但 OpenCV 默認(rèn)將圖像讀取為 BGR,因此我們必須在顯示之前將其轉(zhuǎn)換回RGB。
顯示圖像:
# Converting image from BGR to RGB for displaying
img_convert=cv.cvtColor(img, cv.COLOR_BGR2RGB)
plt.imshow(img_convert)
在圖像上繪圖
我們可以繪制線條、形狀和文本圖像。
# Rectangle
color=(240,150,240) # Color of the rectangle
cv.rectangle(img, (100,100),(300,300),color,thickness=10, lineType=8) ## For filled rectangle, use thickness = -1
## (100,100) are (x,y) coordinates for the top left point of the rectangle and (300, 300) are (x,y) coordinates for the bottom right point
# Circle
color=(150,260,50)
cv.circle(img, (650,350),100, color,thickness=10) ## For filled circle, use thickness = -1
## (250, 250) are (x,y) coordinates for the center of the circle and 100 is the radius
# Text
color=(50,200,100)
font=cv.FONT_HERSHEY_SCRIPT_COMPLEX
cv.putText(img, 'Save Tigers',(200,150), font, 5, color,thickness=5, lineType=20)
# Converting BGR to RGB
img_convert=cv.cvtColor(img, cv.COLOR_BGR2RGB)
plt.imshow(img_convert)
混合圖像
我們還可以使用 OpenCV 混合兩個或多個圖像。圖像只不過是數(shù)字,你可以對數(shù)字進(jìn)行加、減、乘、除運(yùn)算,從而得到圖像。需要注意的一件事是圖像的大小應(yīng)該相同。
# For plotting multiple images at once
def myplot(images,titles):
fig, axs=plt.subplots(1,len(images),sharey=True)
fig.set_figwidth(15)
for img,ax,title in zip(images,axs,titles):
if img.shape[-1]==3:
img=cv.cvtColor(img, cv.COLOR_BGR2RGB) # OpenCV reads images as BGR, so converting back them to RGB
else:
img=cv.cvtColor(img, cv.COLOR_GRAY2BGR)
ax.imshow(img)
ax.set_title(title)
img1 = cv.imread('../input/images-for-computer-vision/tiger1.jpg')
img2 = cv.imread('../input/images-for-computer-vision/horse.jpg')
# Resizing the img1
img1_resize = cv.resize(img1, (img2.shape[1], img2.shape[0]))
# Adding, Subtracting, Multiplying and Dividing Images
img_add = cv.a(chǎn)dd(img1_resize, img2)
img_subtract = cv.subtract(img1_resize, img2)
img_multiply = cv.multiply(img1_resize, img2)
img_divide = cv.divide(img1_resize, img2)
# Blending Images
img_blend = cv.a(chǎn)ddWeighted(img1_resize, 0.3, img2, 0.7, 0) ## 30% tiger and 70% horse
myplot([img1_resize, img2], ['Tiger','Horse'])
myplot([img_add, img_subtract, img_multiply, img_divide, img_blend], ['Addition', 'Subtraction', 'Multiplication', 'Division', 'Blending'])
乘法圖像幾乎為白色,分割圖像為黑色,這是因?yàn)榘咨硎?55,黑色表示0。當(dāng)我們將圖像的兩個像素值相乘時,我們得到的數(shù)字更大,因此其顏色變?yōu)榘咨蚪咏咨,與分割圖像相反。

發(fā)表評論
請輸入評論內(nèi)容...
請輸入評論/評論長度6~500個字
最新活動更多
-
即日-9.16點(diǎn)擊進(jìn)入 >> 【限時福利】TE 2025國際物聯(lián)網(wǎng)展·深圳站
-
10月23日火熱報名中>> 2025是德科技創(chuàng)新技術(shù)峰會
-
10月23日立即報名>> Works With 開發(fā)者大會深圳站
-
10月24日立即參評>> 【評選】維科杯·OFweek 2025(第十屆)物聯(lián)網(wǎng)行業(yè)年度評選
-
11月27日立即報名>> 【工程師系列】汽車電子技術(shù)在線大會
-
12月18日立即報名>> 【線下會議】OFweek 2025(第十屆)物聯(lián)網(wǎng)產(chǎn)業(yè)大會
推薦專題
- 1 先進(jìn)算力新選擇 | 2025華為算力場景發(fā)布會暨北京xPN伙伴大會成功舉辦
- 2 人形機(jī)器人,正狂奔在批量交付的曠野
- 3 宇樹機(jī)器人撞人事件的深度剖析:六維力傳感器如何成為人機(jī)安全的關(guān)鍵屏障
- 4 解碼特斯拉新AI芯片戰(zhàn)略 :從Dojo到AI5和AI6推理引擎
- 5 AI版“四萬億刺激”計劃來了
- 6 2025年8月人工智能投融資觀察
- 7 騰訊 Q2 財報亮眼:AI 已成第二增長曲線
- 8 a16z最新AI百強(qiáng)榜:硅谷頂級VC帶你讀懂全球生成式AI賽道最新趨勢
- 9 10 Manus跑路,大廠掉線,只能靠DeepSeek了