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。

相关推荐
Flittly7 小时前
【从零手写 ClaudeCode:learn-claude-code 项目实战笔记】(3)TodoWrite (待办写入)
python·agent
千寻girling11 小时前
一份不可多得的 《 Django 》 零基础入门教程
后端·python·面试
databook15 小时前
探索视觉的边界:用 Manim 重现有趣的知觉错觉
python·动效
明月_清风16 小时前
Python 性能微观世界:列表推导式 vs for 循环
后端·python
明月_清风16 小时前
Python 性能翻身仗:从 O(n) 到 O(1) 的工程实践
后端·python
helloweilei1 天前
python 抽象基类
python
用户8356290780511 天前
Python 实现 PPT 转 HTML
后端·python
zone77392 天前
004:RAG 入门-LangChain读取PDF
后端·python·面试
zone77392 天前
005:RAG 入门-LangChain读取表格数据
后端·python·agent
树獭非懒2 天前
AI大模型小白手册|Embedding 与向量数据库
后端·python·llm