栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Python

python版opencv函数学习笔记-cv.rectangle()全参数理解

Python 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

python版opencv函数学习笔记-cv.rectangle()全参数理解

cv2.rectangle(img, pt1, pt2, color, thickness=None, lineType=None, shift=None )

以下来自官方文档和自己的理解

  • img:指定一张图片,在这张图片的基础上进行绘制;
  • pt1: 矩形的一个顶点;
  • pt2: 与pt1在对角线上相对的矩形的顶点;

     
    • 注意:pt1和pt2并不严格代表着左上角和右上角的点,可以互换的。
  • color:指定边框的颜色,由(B,G,R)组成,当为(255,0,0)时为绿色,可以自由设定;
  • thinkness:线条的粗细值,为正值时代表线条的粗细(以像素为单位),为负值时边框实心;
  • lineType :关于选择线条生成算法的。详见:http://t.csdn.cn/HjDK6
  • shift :

    • 作用(根据效果图的个人理解):对点坐标进行左移的位运算,即对点坐标除以(2^shift)
    • 参数范围:shift>=0
    • 该参数示范代码(函数中最后一个参数为shift):
      • 两个角点分别为(200,200),(0,0)
    • import cv2 as cv
      
      image = np.zeros((512,512,3),dtype=np.uint8)
      
      cv.rectangle(image, (200,200), (0,0), (0,0,255), 1, cv.LINE_8, 3)#红
      cv.rectangle(image, (200,200), (0,0), (0,255,0), 1, cv.LINE_8, 2)#绿
      cv.rectangle(image, (200,200), (0,0), (255,0,0), 1, cv.LINE_8, 1)#蓝
      cv.rectangle(image, (200,200), (0,0), (0,255,255), 1, cv.LINE_8, 0)#黄
      
      cv.imshow("image", image)
      cv.waitKey(0)
      cv.destroyAllWindows()
    •  
      • 两个角点分别为(200,200),(100,100)
        • import cv2 as cv
          
          image = np.zeros((512,512,3),dtype=np.uint8)
          
          cv.rectangle(image, (200,200), (100,100), (0,0,255), 1, cv.LINE_8, 3)
          cv.rectangle(image, (200,200), (100,100), (0,255,0), 1, cv.LINE_8, 2)
          cv.rectangle(image, (200,200), (100,100), (255,0,0), 1, cv.LINE_8, 1)
          cv.rectangle(image, (200,200), (100,100), (0,255,255), 1, cv.LINE_8, 0)
          
          cv.imshow("image", image)
          cv.waitKey(0)
          cv.destroyAllWindows()
      • 两个角点分别为(200,200),(100,0)

        import cv2 as cv
        
        image = np.zeros((512,512,3),dtype=np.uint8)
        
        cv.rectangle(image, (200,200), (100,0), (0,0,255), 1, cv.LINE_8, 3)
        cv.rectangle(image, (200,200), (100,0), (0,255,0), 1, cv.LINE_8, 2)
        cv.rectangle(image, (200,200), (100,0), (255,0,0), 1, cv.LINE_8, 1)
        cv.rectangle(image, (200,200), (100,0), (0,255,255), 1, cv.LINE_8, 0)
        
        cv.imshow("image", image)
        cv.waitKey(0)
        cv.destroyAllWindows()

暑期编程PK赛 得CSDN机械键盘等精美礼品!
转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/1015344.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号