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?

Asked By: Erland Devona

||

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.

Answered By: GotoCode
Categories: questions Tags: ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.