Python-OpenCV的帧类型

python-opencv在图像处理中很重要,那么用OpenCV读摄像头或视频,取出的帧是一种什么样的数据呢?

实验代码如下:

python 复制代码
import cv2

cap = cv2.VideoCapture(r'I:\test.mp4')

if cap.isOpened():
    ret, frame = cap.read()
    print(frame)

cap.release()

运行结果:

bash 复制代码
[[[2 2 2]
  [2 2 2]
  [1 1 1]
  ...
  [0 0 0]
  [0 0 0]
  [0 0 0]]

 [[2 2 2]
  [2 2 2]
  [1 1 1]
  ...
  [0 0 0]
  [0 0 0]
  [0 0 0]]

 [[1 1 1]
  [1 1 1]
  [1 1 1]
  ...
  [0 0 0]
  [0 0 0]
  [0 0 0]]

 ...

 [[0 0 0]
  [0 0 0]
  [0 0 0]
  ...
  [0 0 0]
  [0 0 0]
  [0 0 0]]

 [[0 0 0]
  [0 0 0]
  [0 0 0]
  ...
  [0 0 0]
  [0 0 0]
  [0 0 0]]

 [[0 0 0]
  [0 0 0]
  [0 0 0]
  ...
  [0 0 0]
  [0 0 0]
  [0 0 0]]]

Process finished with exit code 0

检查一下它属于什么类型:

python 复制代码
import cv2

cap = cv2.VideoCapture(r'I:\test.mp4')

if cap.isOpened():
    ret, frame = cap.read()
    print(type(frame))

cap.release()

运行的结果:

python 复制代码
<class 'numpy.ndarray'>

Process finished with exit code 0

很显然,帧取出来后,在Python中以多维数组的形式呈现。类型是numpy.ndarray。

相关推荐
AI视觉网奇几秒前
视频选帧截取
python·opencv·音视频
hmbbcsm6 分钟前
练习python题目小记(七)
开发语言·python
qq_3561969524 分钟前
day27pipeline管道@浙大疏锦行
python
噔噔噔噔@26 分钟前
第一章、基础理论——第一节、软件测试概述
python·单元测试·压力测试
冷雨夜中漫步28 分钟前
AI入坑之路——(1)搭建本地的Python与Jupyter开发环境
人工智能·python·jupyter
CRUD酱29 分钟前
RabbitMQ是如何确保消息的可靠性的?
java·python·rabbitmq
天若有情67336 分钟前
PyTorch与OpenCV 计算机视觉实战指南(入门篇)
pytorch·opencv·计算机视觉
sivdead36 分钟前
Agent平台消息节点输出设计思路
后端·python·agent
盼哥PyAI实验室37 分钟前
【超详细教程】Python 连接 MySQL 全流程实战
python·mysql·oracle
棒棒的皮皮37 分钟前
【OpenCV】Python图像处理之按位逻辑运算
图像处理·python·opencv·计算机视觉