【问题标题】:Processing video frame by frame using opencv使用opencv逐帧处理视频
【发布时间】:2015-08-28 01:49:54
【问题描述】:
import numpy as np
import cv2
cap = cv2.VideoCapture(0)
count = 0

fourcc = cv2.VideoWriter_fourcc("drop.avi")
out = cv2.VideoWriter('drop.avi',fourcc, 20.0, (640,480))

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

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


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

【问题讨论】:

  • 我收到 TypeError: required argument 'c2' (pos 2) not found 运行代码时。我想运行一个视频文件,然后从视频帧中捕获图片。
  • 你的fourcc错了。应该是:cv2.VideoWriter_fourcc(*'XVID')
  • processing 标签只能用于处理语言相关的问题。

标签: python image opencv numpy


【解决方案1】:

您指定的焦点错误。

fourcc = cv2.cv.CV_FOURCC(*'XVID') 
video_writer = cv2.VideoWriter("drop.avi", fourcc, 20, (640,480))

查看here了解更多信息

【讨论】:

  • 谢谢。我分别用fourcc = cv2.VideoWriter_fourcc("drop.avi") out = cv2.VideoWriter('drop.avi',fourcc, 20.0, (640,480)) 替换这些行,我收到AttributeError:'module' object has no attribute '简历'
  • 你用的是什么版本的open cv?导入打开的 cv 后,python 终端中的 cv2.__version__。
猜你喜欢
  • 1970-01-01
  • 2015-06-12
  • 1970-01-01
  • 2013-09-28
  • 2019-12-31
  • 2017-01-11
  • 2013-11-08
  • 2019-01-11
  • 1970-01-01
相关资源
最近更新 更多