CSDN标题里个括号对应视频的分P
ROI简单来说就是截取区域。本章来了解以下OpenCV如何简单的截取ROI。
ROI就是局部图像处理
#%%
import cv2
import matplotlib.pyplot as plt
import numpy as np
input_img={}
input_img['rgb'] = cv2.imread('Resource\cat.png')
# 截取ROI区域
input_img['roi'] = input_img['rgb'][0:50,0:200]
# 展示ROI区域
cv2.imshow('roi',input_img['roi'])
cv2.waitKey(0)
运行结果
#%%
import cv2
import matplotlib.pyplot as plt
import numpy as np
input_img={}
input_img['rgb'] = cv2.imread('Resource\cat.png')
# 截取ROI区域
input_img['roi'] = input_img['rgb'][0:50,0:200]
# 展示ROI区域
# cv2.imshow('roi',input_img['roi'])
# 截取颜色通道
b,g,r = cv2.split(input_img['rgb'])
# 将RGB更新到字典中
input_img.update({
'r':r,
'g':g,
'b':b
})
# 展示BGR画面
cv2.imshow('b',input_img['b'])
cv2.imshow('g',input_img['g'])
cv2.imshow('r',input_img['r'])
cv2.waitKey(0)
cv2.destroyAllWindows()
#%%
import cv2
import matplotlib.pyplot as plt
import numpy as np
input_img={}
input_img['rgb'] = cv2.imread('Resource\cat.png')
# 截取ROI区域
input_img['roi'] = input_img['rgb'][0:50,0:200]
# 展示ROI区域
# cv2.imshow('roi',input_img['roi'])
# 截取颜色通道
b,g,r = cv2.split(input_img['rgb'])
# 将RGB更新到字典中
input_img.update({
'r':r,
'g':g,
'b':b
})
# 展示BGR画面
# cv2.imshow('b',input_img['b'])
# cv2.imshow('g',input_img['g'])
# cv2.imshow('r',input_img['r'])
# 将BGR合并
input_img['merge']= cv2.merge((input_img['b'],input_img['g'],input_img['r']))
print(input_img['merge'])
cv2.imshow('merge',input_img['merge'])
cv2.waitKey(0)
cv2.destroyAllWindows()