2022最新計算機視覺學習路線(入門篇)
如果你有興趣或計劃做與圖像或視頻相關的事情,你絕對應該考慮使用計算機視覺。計算機視覺 (CV) 是人工智能 (AI) 的一個分支,它使計算機能夠從圖像、視頻和其他視覺輸入中提取有意義的信息,并采取必要的行動。例如自動駕駛汽車、自動交通管理、監(jiān)控、基于圖像的質(zhì)量檢查等等。
什么是 OpenCV?
OpenCV 是一個主要針對計算機視覺的庫。它擁有你在使用計算機視覺 (CV) 時所需的所有工具。“Open”代表開源,“CV”代表計算機視覺。
我會學到什么?
本文包含使用 OpenCV 庫開始使用計算機視覺所需的全部內(nèi)容。你會在計算機視覺方面感到更加自信和高效。
讀取和顯示圖像
首先讓我們了解如何讀取圖像并顯示它,這是CV的基礎知識。讀取圖像
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 默認將圖像讀取為 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ù)字進行加、減、乘、除運算,從而得到圖像。需要注意的一件事是圖像的大小應該相同。
# 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'])

乘法圖像幾乎為白色,分割圖像為黑色,這是因為白色表示255,黑色表示0。當我們將圖像的兩個像素值相乘時,我們得到的數(shù)字更大,因此其顏色變?yōu)榘咨蚪咏咨c分割圖像相反。
請輸入評論內(nèi)容...
請輸入評論/評論長度6~500個字
最新活動更多
-
2 華為,重大突破!
- 1 人形機器人“第一股”來了!宇樹科技即將上會
- 2 全球股市陷AI獨大結構性瘋狂
- 3 AI狂歡遇上油價破百,全球股市還能漲多久? | 產(chǎn)聯(lián)看全球
- 4 DeepSeek融資500億,梁文鋒難逃資本局
- 5 谷歌2026 I/O大會完整回顧:模型依然重要,但智能體正在接管一切
- 6 全球資本,重倉中國機器人
- 7 Figure AI 交付突破350臺,陪跑特斯拉會迎來iPhone 時刻嗎?
- 8 “國產(chǎn)GPU第一股”摩爾線程首季扭虧,但造血能力仍待考驗
- 9 Anthropic發(fā)布2028年全球AI領導力的兩種情景報告
- 10 特斯拉宣布監(jiān)督版FSD登陸中國?
- 高級軟件工程師 廣東省/深圳市
- 自動化高級工程師 廣東省/深圳市
- 光器件研發(fā)工程師 福建省/福州市
- 銷售總監(jiān)(光器件) 北京市/海淀區(qū)
- 激光器高級銷售經(jīng)理 上海市/虹口區(qū)
- 光器件物理工程師 北京市/海淀區(qū)
- 激光研發(fā)工程師 北京市/昌平區(qū)
- 技術專家 廣東省/江門市
- 封裝工程師 北京市/海淀區(qū)
- 結構工程師 廣東省/深圳市


分享













