菜鸟关于cv.rectangle()函数的疑惑?
import cv2 as cv
img = cv.imread(r'C:\Users\14485\Desktop\renlianhshiyan/1.jpg')
#画矩形
x,y,w,h = 50,30,50,50
cv.rectangle(img,(x,y),(x+w,y+h),color=(0,255,0),thickness=2) #左上 宽w 高h对角线的两点 color=BGR thickness为线宽 相对坐标
cv.imshow('rectangle_img',img)
cv.rectangle(img,(x,y,x+w,y+h),color=(0,255,0),thickness=2)#绝对坐标
#cv.circle(img,(x,y),radius=500,color=(255,255,0),thickness=2)
#显示图片
cv.imshow('rectangle1_img',img)
#cv.imshow('circle_img',img)
while True:
if ord('q') == cv.waitKey(0):
break;
cv.destroyAllWindows()
在网上查找了一个在图片上画矩形的命令,cv.rectangle(),在使用中发现了其第二个变量,关于在图像中矩形的位置坐标好像不止一种表示方法,无意中发现:
cv.rectangle(img,(x,y),(x+w,y+h),color=(0,255,0),thickness=2)
cv.rectangle(img,(x,y,x+w,y+h),color=(0,255,0),thickness=2)
上述代码会产生不一样的矩形,如图:
这是为什么呢?