对opencv读取的图片进行像素调整(1080, 1920) 1.cv2.VideoCapture(构造图片读取) 2.cv2.nameWindow(构建视频显示的窗口) 3.cv2.setWindowProperty(设置图片窗口的像素) 4.video_capture(对图片像素进行设置)

1. cv2.VideoCapture(0) #构建视频抓捕器 

参数说明:0表示需要启动的摄像头,这里也可以写视频的路径

2. cv2.nameWindow(name, cv2.WINDOW_NORMAL)  # 构建视频的窗口

参数说明: 表示窗口的名字, cv2.WINDOW_NORMAL表示窗口的大小,这里窗口的大小是正常, 

3.cv2.setWindowProperty(name, cv2.WND_PROP_FULLSCREEN, cv2.WND_PROP_FULLSCREEN)

参数说明: name表示需要更改像素的窗口名字, cv2.WND_PROP_FULLSCREEN表示全屏

4. video_capture.set(cv2.CAP_PROP_FRAME_WIDTH, 1920) 对窗口像素进行设置

参数说明: cv2.CAP_PROP_FRAME_WIDTH 表示设置其宽的大小, 1920表示设置的像素

video_capture = cv2.VideoCapture(0)
cv2.namedWindow("frame", cv2.WINDOW_NORMAL)
cv2.setWindowProperty("frame", cv2.WND_PROP_FULLSCREEN, cv2.WND_PROP_FULLSCREEN)
video_capture.set(cv2.CAP_PROP_FRAME_WIDTH, 1920)
video_capture.set(cv2.CAP_PROP_FRAME_HEIGHT, 1080)
while True:
    ret, frame = video_capture.read()
    (h, w) = frame.shape[:2]
    print(h, w)
    center = (w/2, h/2)
    print()
    M = cv2.getRotationMatrix2D(center, 90, 1.0)
    rotated = cv2.warpAffine(frame, M, (1920, 1080))
    cv2.imshow('image', rotated)
    cv2.imwrite('2.png', rotated)
    cv2.waitKey(0)

猜你喜欢

转载自www.cnblogs.com/my-love-is-python/p/11457539.html
今日推荐