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。

相关推荐
合尘猫2 小时前
图片表格变结构化数据:OCR 后的三个坑
python·ocr
小小张说故事2 小时前
Python 里弱引用到底弱在哪:拆开 weakref.ref、回调陷阱和 WeakValueDictionary
python
用户019027581613 小时前
用 DuckDB 存查 A 股 K 线:零服务、SQL 直接分析
python
程序员果子4 小时前
本体构建方法
人工智能·python·知识图谱·agent框架·本体
天天被压力4 小时前
【A股分钟级高频数据完全手册 #11】券商实时行情数据接口:实时交易(券商源)接入与字段
java·人工智能·python
总裁余(余登武)5 小时前
【python项目】:1操作EXCEl自动化开发
python·自动化·excel
芝梵家电数据笔记5 小时前
用字段表核对暖菜板长期使用条件:结构、暖区、质保边界
python·家电·数据校验·dataclass·选购
天天被压力5 小时前
【A股分钟级高频数据完全手册 #12】股票五档盘口数据接口:买卖五档实时盘口解析
java·人工智能·python
LongRunning17 小时前
【Linux】RK3568-OpenCV+YOLO(八)
linux·opencv·yolo
卷无止境17 小时前
RAGFlow 项目全景报告:从文档解析引擎到 Agent 原生数据库
后端·python