调整 cv2.VideoCapture 的帧大小

Tru*_*ang 5 python opencv numpy machine-learning computer-vision

我正在尝试将原始 (480,640,3) 中的帧图像数组调整为 (224,224,3),但我使用 CV_CAP_PROP_FRAME_WIDTH、CV_CAP_PROP_FRAME_HEIGHT,仅更改屏幕上显示的帧的大小。非常感谢!我的代码在这里!

import cv2
import numpy as np

cap = cv2.VideoCapture(0)

while(True): 
    # Capture frame-by-frame
    ret, frame = cap.read()
    frame = cv2.flip(frame, 1)

    # Display the resulting frame
    cv2.imshow('frame',frame)
    print(frame.shape)
    if cv2.waitKey(1) & 0xFF == ord('q'):
        break
# When everything done, release the capture
cap.release()
cv2.destroyAllWindows()
Run Code Online (Sandbox Code Playgroud)

Vin*_*ant 3

您可以在 while 循环中添加以下代码,

框架 = cv2.resize(框架, (224, 224))

打印(框架.形状)