ROI(region of interest),感兴趣的区域
从被处理的图像以方框、圆、椭圆、不规则多边形等方式勾勒出需要处理的区域
可以通过各种算子(Operator)和函数来求得感兴趣区域ROI,并进行图像的下一步处理
import cv2
import numpy as np
a = cv2.imread("e:\\lina.png",cv2.IMREAD_UNCHANGED)
fengjing = cv2.imread("e:\\fengjing.jpg",cv2.IMREAD_UNCHANGED)
b = np.ones((101,101,3)) #3个通道,101行101列
b = a[220:400,250:350]
a[0:180,0:100] = b
fengjing[0:180,0:100] = b
cv2.imshow("original",a)
cv2.imshow("face",b)
cv2.imshow("fengjing",fengjing)
cv2.waitKey(0)
cv2.destroyAllWindows()
通道的拆分与合并
1、拆分通道
img=cv2.imread('abc')
b=img[:,:,0]
g=img[:,:,1]
r=img[:,:,2]
import cv2
import numpy as np
img = cv2.imread("e:\\lina.png",cv2.IMREAD_UNCHANGED)
b,g,r=cv2.split(img)
cv2.imshow("B",b)
cv2.imshow("G",g)
cv2.imshow("R",r)
m=cv2.merge([b,g,r])
cv2.imshow("merge",m)
m1=cv2.merge([r,g,b])
cv2.imshow("merge",m1)
cv2.waitKey()
cv2.destroyAllWindows()
2、合并通道