简体   繁体   中英

python cv2 won't save picture and not shown any error

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM