python - 调整 cv2.VideoCapture 的帧大小

标签 python numpy machine-learning computer-vision cv2

我正在尝试将原始 (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()

最佳答案

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

frame = cv2.resize(frame, (224, 224))

打印(框架.形状)

关于python - 调整 cv2.VideoCapture 的帧大小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58887056/

相关文章:

python numpy argmax到多维数组中的最大值

python - 为什么 get_weights 返回一个空列表?

machine-learning - 随机森林机器学习支持字符串字符吗?

python - Pydantic验证器删除空白字符串?

python - Django 中的双向查询,无需循环引用

python - Pandas ,处理 "Out of bounds timestamp..."

python - 计算 numpy 数组的平均值

python - 多个标签掩码上的 Numpy,矢量化函数

python - gensim 4.1.2 的 KeyedVectors\' object has no attribute\' wv

python - 将 NaN 的 csv 文件清空,里面什么也没有