当前位置:   article > 正文

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

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)
      1. import cv2 as cv
      2. image = np.zeros((512,512,3),dtype=np.uint8)
      3. cv.rectangle(image, (200,200), (0,0), (0,0,255), 1, cv.LINE_8, 3)#红
      4. cv.rectangle(image, (200,200), (0,0), (0,255,0), 1, cv.LINE_8, 2)#绿
      5. cv.rectangle(image, (200,200), (0,0), (255,0,0), 1, cv.LINE_8, 1)#蓝
      6. cv.rectangle(image, (200,200), (0,0), (0,255,255), 1, cv.LINE_8, 0)#黄
      7. cv.imshow("image", image)
      8. cv.waitKey(0)
      9. cv.destroyAllWindows()
    •  
      • 两个角点分别为(200,200),(100,100)
          1. import cv2 as cv
          2. image = np.zeros((512,512,3),dtype=np.uint8)
          3. cv.rectangle(image, (200,200), (100,100), (0,0,255), 1, cv.LINE_8, 3)
          4. cv.rectangle(image, (200,200), (100,100), (0,255,0), 1, cv.LINE_8, 2)
          5. cv.rectangle(image, (200,200), (100,100), (255,0,0), 1, cv.LINE_8, 1)
          6. cv.rectangle(image, (200,200), (100,100), (0,255,255), 1, cv.LINE_8, 0)
          7. cv.imshow("image", image)
          8. cv.waitKey(0)
          9. cv.destroyAllWindows()
      • 两个角点分别为(200,200),(100,0)

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

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/Gausst松鼠会/article/detail/216225
推荐阅读
相关标签
  

闽ICP备14008679号