我试图考虑一下,但是由于新问题-它对我不起作用。
有谁能帮忙,我们应该在此处添加哪些内容以便保存,例如,每3或5帧?
这是代码

    import cv2
    vidcap = cv2.VideoCapture('myvid.mp4')
    success,image = vidcap.read()
    count = 0;
    print "I am in success"
    while success:
      success,image = vidcap.read()
      if count % 3 == 0:
      cv2.imwrite("img_%3d.jpg" % count, image)
      if cv2.waitKey(10) == 27:
          break
      count += 1

非常感谢您在如此愚蠢的问题中的帮助^^'

跳过n帧的代码并保存您需要的内容。每3帧的示例:
import cv2
vidcap = cv2.VideoCapture('myvid.mp4')
success,image = vidcap.read()
count = 0;
print "I am in success"
while success:
  success,image = vidcap.read()
  if count % 3 == 0:
  cv2.imwrite("img_%3d.jpg" % count, image)
  if cv2.waitKey(10) == 27:
      break
  count += 1

最佳答案

您需要做的只是检查count % 3 == 0。但是,您的代码还有另一个问题

import cv2
vidcap = cv2.VideoCapture('myvid.mp4')
success,image = vidcap.read()
count = 0;

# number of frames to skip
numFrameToSave = 3

print "I am in success"
while success: # check success here might break your program
  success,image = vidcap.read() #success might be false and image might be None
  #check success here
  if not success:
    break

  # on every numFrameToSave
  if (count % numFrameToSave ==0):
    cv2.imwrite("img_%3d.jpg" % count, image)

  if cv2.waitKey(10) == 27:
      break
  count += 1

10-05 20:21