python - 将视频保存为帧 OpenCV{PY}

标签 python opencv

我想创建一个程序来保存从网络摄像头拍摄的 .jpg 图像(帧)。 我的程序现在做的是,打开一个网络摄像头,只拍摄一帧,然后一切都停止了。

我想要的不仅仅是一帧 我的错误代码是这个:

import numpy as np
import cv2
cap = cv2.VideoCapture(0)
count = 0

while True:
   # Capture frame-by-frame
   ret, frame = cap.read()

   # Our operations on the frame come here
   gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
   cv2.imwrite("frame%d.jpg" % ret, frame)     # save frame as JPEG file
   count +=1

   # Display the resulting frame
   cv2.imshow('frame',gray)
   if cv2.waitKey(10):
      break

最佳答案

实际上听起来你总是用相同的名字保存你的图像 因为您在 imwrite 方法中连接 ret 而不是 count

试试这个:

name = "frame%d.jpg"%count
cv2.imwrite(name, frame)     # save frame as JPEG file

关于python - 将视频保存为帧 OpenCV{PY},我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27378662/

相关文章:

python - Beautifulsoup 分解()

C++ OpenCV VideoWriter 帧率同步

python - Plotly:如何在两条垂直线之间设置填充颜色?

python - 在 python 中使用大索引(numpy 或列表)

python - 如何将Python字符串传递给C++(extern C)函数

python - 是否可以在 Airflow 中的多个 DAGS 中使用单个任务?

python - 如何使用 cv2.HoughLinesP() 的输出来旋转原始图像?

python - OpenCV-识别符号系列

python - Ipython笔记本(jupyter),opencv(cv2)和绘图?

java - 如何在Java中使用group by聚合CSV数据?