美文网首页
opencv-python 学习(一)

opencv-python 学习(一)

作者: zealone | 来源:发表于2022-04-04 17:06 被阅读0次

基本原理

  1. 单通道 一个像素块对应一个矩阵的值 像素的亮度从0~255 从暗到亮
  2. RGB通道一个像素块对应矩阵中的一个向量, 如[24,180, 50],分别表示三种颜色的比列, 即对应深度上的数字。
  3. 需要注意的是,由于历史遗留问题,opencv采用BGR模式,而不是RGB

opencv-python 的安装

pip install opencv-python

基本的函数使用

1.BGR的切分
原始图片


1.png

对原始图片进行单色通道的获取并保存为新的图片

  import cv2
  img = cv2.imread('./imgs/1.png')
  b,g,r = cv2.split(img)
  cv2.imwrite('brr.png',b)
  cv2.imwrite('grr.png',g)
  cv2.imwrite('rrr.png',r)

结果展示


屏幕截图 2022-04-04 170529.png

2.img对象的属性

   import cv2
   img = cv2.imread('./imgs/1.png')
   print(img.shape) # (397, 397, 3)  width:397,height:397,chnnel=3
   print(img.size) # width*height*3
   print(img.dtype) # datatype
  

相关文章

网友评论

      本文标题:opencv-python 学习(一)

      本文链接:https://www.haomeiwen.com/subject/xricsrtx.html