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。

相关推荐
李昊哲小课1 天前
Python办公自动化教程 - 第7章 综合实战案例 - 企业销售管理系统
开发语言·python·数据分析·excel·数据可视化·openpyxl
不知名的老吴1 天前
返回None还是空集合?防御式编程的关键细节
开发语言·python
李昊哲小课1 天前
Python办公自动化教程 - 第5章 图表创建 - 让数据可视化
python·信息可视化·数据分析·数据可视化·openpyxl
chushiyunen1 天前
python pygame实现贪食蛇
开发语言·python·pygame
Dream of maid1 天前
Python-基础2(流程控制)
python
Lenyiin1 天前
《Python 修炼全景指南:一》从环境搭建到第一个程序
开发语言·python
涛声依旧393161 天前
Python项目实战:学生信息管理系统
开发语言·python·数据挖掘
kcuwu.1 天前
Python进阶:生成器与协程,高效并发编程的核心实践
windows·python·php
XiaoQiao6669991 天前
python 简单题目练手【详解版】【1】
开发语言·python
ZC跨境爬虫1 天前
极验滑动验证码自动化实战:背景提取、缺口定位与Playwright滑动模拟
前端·爬虫·python·自动化