2022最新計算機視覺學(xué)習(xí)路線(入門篇)
如果你有興趣或計劃做與圖像或視頻相關(guān)的事情,你絕對應(yīng)該考慮使用計算機視覺。計算機視覺 (CV) 是人工智能 (AI) 的一個分支,它使計算機能夠從圖像、視頻和其他視覺輸入中提取有意義的信息,并采取必要的行動。例如自動駕駛汽車、自動交通管理、監(jiān)控、基于圖像的質(zhì)量檢查等等。
什么是 OpenCV?
OpenCV 是一個主要針對計算機視覺的庫。它擁有你在使用計算機視覺 (CV) 時所需的所有工具!癘pen”代表開源,“CV”代表計算機視覺。
我會學(xué)到什么?
本文包含使用 OpenCV 庫開始使用計算機視覺所需的全部內(nèi)容。你會在計算機視覺方面感到更加自信和高效。
讀取和顯示圖像
首先讓我們了解如何讀取圖像并顯示它,這是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ù)字進行加、減、乘、除運算,從而得到圖像。需要注意的一件事是圖像的大小應(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'])
乘法圖像幾乎為白色,分割圖像為黑色,這是因為白色表示255,黑色表示0。當(dāng)我們將圖像的兩個像素值相乘時,我們得到的數(shù)字更大,因此其顏色變?yōu)榘咨蚪咏咨,與分割圖像相反。

請輸入評論內(nèi)容...
請輸入評論/評論長度6~500個字
最新活動更多
-
7月22-29日立即報名>> 【線下論壇】第三屆安富利汽車生態(tài)圈峰會
-
7.30-8.1火熱報名中>> 全數(shù)會2025(第六屆)機器人及智能工廠展
-
7月31日免費預(yù)約>> OFweek 2025具身智能機器人產(chǎn)業(yè)技術(shù)創(chuàng)新應(yīng)用論壇
-
免費參會立即報名>> 7月30日- 8月1日 2025全數(shù)會工業(yè)芯片與傳感儀表展
-
即日-2025.8.1立即下載>> 《2024智能制造產(chǎn)業(yè)高端化、智能化、綠色化發(fā)展藍(lán)皮書》
-
8月5日立即報名>> 【在線會議】CAE優(yōu)化設(shè)計:醫(yī)療器械設(shè)計的應(yīng)用案例與方案解析
推薦專題