目录
4.调整图像大小,对图像进行缩放或者扩大
5.在原图裁剪图像,取出所选图像
6.在给定图像上绘制形状
4.调整图像大小,对图像进行缩放或者扩大
5.在原图裁剪图像,取出所选图像
import cv2
img = cv2.imread("Resources/lambo.png")
imgResize = cv2.resize(img,(300,200))
imgCropped = img[0:200,200:500]
cv2.imshow("Image",img)
cv2.imshow("Image Resize",imgResize)
cv2.imshow("Image Cropped",imgCropped)
cv2.waitKey(0)
![在这里插入图片描述](https://i-blog.csdnimg.cn/blog_migrate/b7a1b88a0d2303dde8c73681bd8e5dbe.gif#pic_center)
6.在给定图像上绘制形状
import cv2
import numpy as np
img_black= np.zeros((512,512))
print(img.shpae)
img_color = np.zeros((512,512,3),np.uint8)
img_color[200:300,100:300] = 255,0,0
cv2.line(img_color,(0,0),(300,300),(0,255,0),3)
cv2.rectangle(img_color,(0,0),(200,200),(0,255,0),3)
cv2.rectangle(img_color,(0,0),(200,200),(0,255,0),cv2.FILLED)
cv2.circle(img_color,(300,300),50,(255,255,0),3)
cv2.putText(img_color,"OPENCV",cv2.FONT_HERSHEY_COMPLEX,1,(0,255,0),1(300,100),cv2.Font)
cv2.imshow("image",img_color)
cv2.waitKey(0)
![在这里插入图片描述](https://i-blog.csdnimg.cn/blog_migrate/14ee8560a0b31ea43405a8b9f9c45506.gif#pic_center)