OpenCV won't save picture and not shown any error
Question:
This is my old code, from what I write in my short note it should read video and save each frame in a folder, I try to use it again and it’s not working. There are no error shown all path exist.
filename = 'H2N2A'
trainingfiles = 14
def getFrames():
vidcap = cv2.VideoCapture('Train'+str(trainingfiles)+'/'+filename+'.MP4')
success, image = vidcap.read()
count = 0
success = True
while success:
success, image = vidcap.read()
#print 'Read a new frame: ', success
print count
#print "Train"+str(trainingfiles)+"/"+filename+"/frame%d.jpg" % count, image
cv2.imwrite("Train"+str(trainingfiles)+"/"+filename+"/frame"+str(count)+".jpg", image)
count += 1
vidcap.release()
return count-1
Do anyone have any idea why?
Answers:
Did you try calling the getFrames()
function from somewhere else in your code?
Given the code above, Python will not run the logic in getFrames
unless you call it first.
This is my old code, from what I write in my short note it should read video and save each frame in a folder, I try to use it again and it’s not working. There are no error shown all path exist.
filename = 'H2N2A'
trainingfiles = 14
def getFrames():
vidcap = cv2.VideoCapture('Train'+str(trainingfiles)+'/'+filename+'.MP4')
success, image = vidcap.read()
count = 0
success = True
while success:
success, image = vidcap.read()
#print 'Read a new frame: ', success
print count
#print "Train"+str(trainingfiles)+"/"+filename+"/frame%d.jpg" % count, image
cv2.imwrite("Train"+str(trainingfiles)+"/"+filename+"/frame"+str(count)+".jpg", image)
count += 1
vidcap.release()
return count-1
Do anyone have any idea why?
Did you try calling the getFrames()
function from somewhere else in your code?
Given the code above, Python will not run the logic in getFrames
unless you call it first.