cv2.waitkey
module 'cv2' has no attribute 'waitkey'
改为:cv2.waitKey
import cv2 as cv
image =cv.imread('test.jpg')
print(f"width:{image.shape[1]} pixels")
print(f"height:{image.shape[0]} pixels")
print(f"channels:{image.shape[2]} pixels")
cv.imshow("Image",image)
cv.waitKey(0)
cv.imwrite("new_image.jpg",image)
# -*- coding: utf-8 -*-
import cv2 as cv
image =cv.imread('test.jpg')
print(f"width:{image.shape[1]} pixels")
print(f"height:{image.shape[0]} pixels")
print(f"channels:{image.shape[2]} ")
b,g,r=image[10,10]
print(b,g,r)
patch1 = image[0:200,0:500]#不是复制,是直接在读取数据上进行更改
cv.imshow("patch1",patch1)
patch1[0:100,0:100] = (0,255,255)
cv.imshow("patch1",patch1)
cv.imshow("Image",image)
cv.waitKey(0)
#cv.imwrite("new_image.jpg",image)
这样的读取方式不是拷贝,是在原输入上进行更改。
图片旋转
# -*- coding: utf-8 -*-
import cv2 as cv
import numpy as np
image = cv.imread("test.jpg")
h,w = image.shape[:2]
center = (w//2,h//2)
M= cv.getRotationMatrix2D(center,180,0.8)
#getRotationMatrix2D 三个参数 1、旋转时的固定点 2、旋转角度 3、图片缩放的尺寸
Rotated_image = cv.warpAffine(image,M,(w,h))
cv.imshow("rotated_image",Rotated_image)
cv.waitKey(0)
效果:
图片缩放: