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。

相关推荐
xurileidian2 小时前
第 24 篇 · 边玩边学Python · while 与死循环怎么退
服务器·前端·python
有个傻瓜3 小时前
工具调用参数每次都差一截:finish_reason=length 输出预算截断的排错复盘与四种分诊实测
python·故障排查·ai agent·大模型应用开发·function calling
zhanghongyi_cpp3 小时前
第5章 学习自测
python·学习
打工仔折腾 AI4 小时前
L3 静态源码取证|工程评测:python-oracledb 驱动评估中的样本偏差陷阱
开发语言·人工智能·后端·python·性能优化
IvanCodes5 小时前
LangChain(15):LangSmith 应用评估与回归测试
python·langchain·agent
炸薯条!6 小时前
Python基础学习:文件操作详解(打开、读取、写入与路径)
java·服务器·python
jason_renyu7 小时前
Playwright 入门与实操:从安装、定位、断言到自动发博客,把浏览器自动化讲明白
运维·python·自动化·前端开发·浏览器自动化·playwright·e2e测试
维克兜率天7 小时前
【维克】布林带:通道类指标的“量化基石“
人工智能·python·算法
向科→向总工→空间动态计系统8 小时前
机器人大脑系统
开发语言·人工智能·python·机器人
染指11108 小时前
194.DeepAgents-在DeepAgents中使用自定义沙盒环境OpenSandBox
网络·人工智能·python·langchain·deepagents