Numpy图像操作
创建矩阵
import numpy as np
a = np.array([1,2,3])
b = np.array([[1,2,3],[4,5,6]])
#高 宽
c = np.zeros((480, 640, 3), np.uint8)
d = np.ones((8,8,3), np.uint8)
e = np.full((8,8), 255, np.uint8)
#单位矩阵
f = np.identity(4)
#长方形 指定第一个参数退化为identity
g = np.eye(5, 7, k = 3)
print(g)
检索与赋值
img = np.zeros((480, 640, 3), np.uint8)
#bgr(0,1,2)
img[y, x, 2] = 255
img[y, x] = [0,0,255]
获取子矩阵
#获取img x(100-200) y(100-200)
roi = img[100:200, 100:200]
#区域的像素全为r
roi[:,:] = [0,0,255]
Mat结构体
class CV_EXPORTS Mat{
public:
···
int dims;//维数
int rows, cols;
uchar *data;//图片数据指针
int *refcount;//指向图片数据的引用计数
···
};
#浅拷贝
img = img0;
#深拷贝
img1 = img.copy()
}
#通道的分割
b,g,r  = cv2.split(img)
#通道的合并
img2 =  cv2.merge((b,g,r))

 
                
            
         
         浙公网安备 33010602011771号
浙公网安备 33010602011771号