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()
- 两个角点分别为(200,200),(100,100)